CurrentSdkVersion is null by default now
Adjusted README
LocalPackageManager and RemotePackageManager are internal classes now
Added checks for initialization in PackageManager
This commit is contained in:
The Doctor
2020-06-18 11:29:21 +01:00
parent 92e7a9b1cf
commit 421252d138
7 changed files with 94 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
@ -13,4 +13,8 @@
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PMF\PMF.csproj" />
</ItemGroup>
</Project>

View File

@ -1,3 +1,4 @@
using PMF.Managers;
using System;
using Xunit;
@ -8,7 +9,11 @@ namespace PMF.Tests
[Fact]
public void Test1()
{
PackageManager.Start();
// Do stuff
PackageManager.Stop();
}
}
}

View File

@ -25,7 +25,7 @@ namespace PMF
/// <summary>
/// The current SDK version
/// </summary>
public static string CurrentSdkVersion { get; set; }
public static string CurrentSdkVersion { get; set; } = null;
/// <summary>
/// Internal flag to spit out debug info

View File

@ -11,7 +11,7 @@ namespace PMF.Managers
/// <summary>
/// Manages all the local files
/// </summary>
public static class LocalPackageManager
internal static class LocalPackageManager
{
public static List<Package> PackageList { get; private set; }
@ -55,7 +55,7 @@ namespace PMF.Managers
}
}
internal static void validateManifestFile()
public static void validateManifestFile()
{
if (!File.Exists(Config.ManifestFileName))
File.Create(Config.ManifestFileName).Close();

View File

@ -7,6 +7,30 @@ namespace PMF.Managers
{
public static class PackageManager
{
private static bool initialized = false;
/// <summary>
/// Initializes the package manager. Required
/// </summary>
public static void Start()
{
LocalPackageManager.Start();
initialized = true;
}
/// <summary>
/// Cleans up package manager. Required
/// </summary>
public static void Stop()
{
LocalPackageManager.Stop();
}
private static void notInitialized()
{
Console.WriteLine("You must initialize PMF first before using it");
}
/// <summary>
/// Installs a package given a version
/// </summary>
@ -15,6 +39,12 @@ namespace PMF.Managers
/// <returns>true Installation successful, false already installed</returns>
public static PackageState InstallPackage(Package package, Asset asset)
{
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
string zipFile = RemotePackageManager.DownloadAsset(package.ID, asset);
LocalPackageManager.InstallPackage(package, asset, zipFile);
return PackageState.Installed;
@ -31,6 +61,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
// check if is already installed
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
{
@ -64,6 +100,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
// check if is already installed
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
{
@ -97,6 +139,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
// check if is already installed
if (LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
return PackageState.AlreadyInstalled;
@ -122,6 +170,12 @@ namespace PMF.Managers
/// <returns>True if success, false otherwise</returns>
public static bool Uninstall(string id)
{
if (!initialized)
{
notInitialized();
return false;
}
return LocalPackageManager.RemovePackage(id);
}
@ -135,6 +189,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
// check if is already installed
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
return PackageState.NotInstalled;
@ -164,6 +224,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
// check if is already installed
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
return PackageState.NotInstalled;
@ -195,6 +261,12 @@ namespace PMF.Managers
{
package = null;
if (!initialized)
{
notInitialized();
return PackageState.Failed;
}
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string pd))
return PackageState.NotInstalled;

View File

@ -7,7 +7,7 @@ using System.Text;
namespace PMF.Managers
{
public static class RemotePackageManager
internal static class RemotePackageManager
{
/// <summary>
/// Gets package info from the server along with ALL the assets in the json

View File

@ -31,11 +31,11 @@ PMF is a barebones C# library that provides basic support for package management
These functions need to be called at the beggining of the program and at the end, respectively, they handle the manifest.json file that is saved with information regarding packages installed
```csharp
LocalPackageManager.Start();
PackageManager.Start();
// Do stuff
LocalPackageManager.Stop();
PackageManager.Stop();
```
### Install
@ -88,10 +88,10 @@ public static PackageState UpdateBySdkVersion(string id, out Package package, bo
### Configuration
Defines the manifest file name, by default is manifest.json
Defines the manifest file name
```csharp
string Config.ManifestFileName
string Config.ManifestFileName = "manifest.json";
```
Defines the folder where packages are to be installed
@ -106,16 +106,16 @@ The http server where you will be sending information about the packages
string Config.RepositoryEndpoint
```
Current SDK version, if you are not using this just use null
Current SDK version
```csharp
Version Config.CurrentSdkVersion
Version Config.CurrentSdkVersion = null;
```
Temporary folder where zip files will be downloaded to, gets deleted at the end of execution
```csharp
string Config.TemporaryFolder
string Config.TemporaryFolder = ".pmf-temp";
```
## JSON