private static void checkInitialization() { if (!initialized) { PMF.InvokePackageMessageEvent("You must initialize PMF first.\nClosing"); Environment.Exit(0); } }
public Ejercicio24(int minPrimerTirada, int maxPrimerTirada, double[] probPrimerTirada, int strike, int spare, int limite, Dictionary <int, PMF> segundaTiradaProb, string generator) { firstThrow = new PMF(minPrimerTirada, maxPrimerTirada, probPrimerTirada); firstDone = false; secondThrowProbabilities = segundaTiradaProb; strikePoints = strike; sparePoints = spare; threshold = limite; SetRandomGenerator(generator); }
private static void validateManifestFile() { PMF.InvokePackageMessageEvent("Validating manifest file"); if (string.IsNullOrEmpty(Config.ManifestFileName)) { throw new ArgumentNullException(""); } if (!File.Exists(Config.ManifestFileName)) { File.Create(Config.ManifestFileName).Close(); } PMF.InvokePackageMessageEvent("Successfully validated manifest file"); }
/// <summary> /// Initializes the package manager. Required /// </summary> public static void Start() { try { if (!initialized) { LocalPackageManager.Start(); initialized = true; } } catch (Exception ex) { PMF.InvokePackageMessageEvent($"PMF failed to initialize. \n${ex.InnerException.Message}\nClosing."); Environment.Exit(0); } }
/// <summary> /// Gets package info from the server along with all the assets in the json /// </summary> /// <param name="id">The id of the package</param> /// <returns>The package downloaded</returns> public static Package GetPackageInfo(string id) { try { using (WebClient client = new WebClient()) { PMF.InvokePackageMessageEvent("Downloading package information"); string json = client.DownloadString($"{Config.RepositoryEndpoint}/{id}"); PMF.InvokePackageMessageEvent("Parsing package information"); return(JsonConvert.DeserializeObject <Package>(json)); } } catch (WebException) { PMF.InvokePackageMessageEvent("Couldn't download information from the server"); return(null); } }
/// <summary> /// Downloads a specific version of a certain package /// </summary> /// <param name="id">The id of the package</param> /// <param name="asset">The asset that is to be downloaded</param> /// <returns>The zip file path which was downloaded</returns> public static string DownloadAsset(string id, Asset asset) { using (WebClient client = new WebClient()) { PMF.InvokePackageMessageEvent("Downloading asset"); var zipPath = Path.Combine(Config.TemporaryFolder, id); client.DownloadFile(asset.Url, Path.Combine(zipPath, asset.FileName)); foreach (var dependency in asset.Dependencies) { PMF.InvokePackageMessageEvent($"Downloading dependency with id: {dependency.ID}"); client.DownloadFile(dependency.Url, Path.Combine(zipPath, dependency.FileName)); } PMF.InvokePackageMessageEvent("Finished downloading required files"); return(zipPath); } }
/// <summary> /// Cleans up package manager. Required /// </summary> public static void Stop() { try { if (initialized) { LocalPackageManager.Stop(); } } catch (Exception ex) { string message = null; if (ex.InnerException != null) { message = ex.InnerException.Message; } else { message = ex.Message; } PMF.InvokePackageMessageEvent($"Something failed while cleaning up PMF\n{message}"); } }
/// <summary> /// Uninstalls a package /// </summary> /// <param name="id">The id of the package</param> /// <returns>True if uninstalled correctly, false otherwise</returns> public static bool RemovePackage(string id) { if (string.IsNullOrEmpty(id)) { PMF.InvokePackageMessageEvent("Package id must be defined"); return(false); } PMF.InvokePackageMessageEvent($"Removing {id}"); try { string packageDirectory = Path.Combine(Config.PackageInstallationFolder, id); Directory.Delete(packageDirectory, true); PMF.InvokePackageMessageEvent($"Successfully removed package {id}"); } catch { PMF.InvokePackageMessageEvent($"Couldn't find package with id of: {id}. Removing from package list"); } return(PackageManager.PackageList.Remove(id)); }
/// <summary> /// Checks if a given package is installed /// </summary> /// <param name="id">The id of the package</param> /// <param name="package">This value is defined if the package exists, its contents will be the actual package</param> /// <param name="packageDirectory">The directory in which the package is installed</param> /// <returns>True if package is installed, false otherwise</returns> public static bool IsPackageInstalled(string id, out Package package, out string packageDirectory) { PMF.InvokePackageMessageEvent($"Checking if {id} is installed"); package = null; packageDirectory = Path.Combine(Config.PackageInstallationFolder, id); if (!Directory.Exists(packageDirectory)) { return(false); } try { package = PackageManager.PackageList.GetPackage(id); PMF.InvokePackageMessageEvent($"Found {id} with version {package.Assets[0].Version}"); return(true); } catch { PMF.InvokePackageMessageEvent($"Couldn't find {id}"); return(false); } }
private void OnWaterUptakesCalculated(PMF.WaterUptakesCalculatedType SoilWater) { for (int iCrop = 0; iCrop < SoilWater.Uptakes.Length; iCrop++) { if (SoilWater.Uptakes[iCrop].Name == Name) { for (int layer = 0; layer < SoilWater.Uptakes[iCrop].Amount.Length; layer++) swardWaterUptake[layer] = SoilWater.Uptakes[iCrop].Amount[layer]; } } }
/// <summary> /// Extracts zip files and registeres this package as installed /// </summary> /// <param name="remotePackage">The package which is to be installed</param> /// <param name="asset">The version of the asset being installed</param> /// <param name="zipPath">The path to the zip file that is to be installed</param> /// <returns>State of the installation</returns> public static PackageState InstallPackage(Package remotePackage, Asset asset, string zipPath) { PMF.InvokePackageMessageEvent($"Extracting package {remotePackage.ID}"); ZipFile.ExtractToDirectory(Path.Combine(zipPath, asset.FileName), Path.Combine(Config.PackageInstallationFolder, remotePackage.ID)); PMF.InvokePackageMessageEvent($"Finished extracting package {remotePackage.ID}"); bool error = false; // Maybe a library folder and check if is installed foreach (var dependency in asset.Dependencies) { if (dependency.Type == DependencyType.Standalone) { PMF.InvokePackageMessageEvent($"Extracting dependency with id: {dependency.ID} of type standalone"); ZipFile.ExtractToDirectory(Path.Combine(zipPath, dependency.FileName), Path.Combine(Config.PackageInstallationFolder, remotePackage.ID, "Dependencies", dependency.ID)); PMF.InvokePackageMessageEvent($"Finished extracting dependency {dependency.ID}"); } else // DependencyType.Package { PMF.InvokePackageMessageEvent($"Downloading dependency with id: {dependency.ID} of type package"); var success = PackageManager.Install(dependency.ID, dependency.Version, out Package p); if (success == PackageState.Installed) { PMF.InvokePackageMessageEvent($"Package dependency installed successfully"); } else if (success == PackageState.VersionNotFound) { PMF.InvokePackageMessageEvent("Asset not found"); error = true; } else if (success == PackageState.NotExisting) { PMF.InvokePackageMessageEvent("Package not found"); error = true; } else { PMF.InvokePackageMessageEvent($"Something went wrong installing dependency with id: {dependency.ID}"); error = true; } } } remotePackage.Assets.Clear(); remotePackage.Assets.Add(asset); PackageManager.PackageList.Add(remotePackage); if (error) { PMF.InvokePackageMessageEvent($"Couldn't install {remotePackage.ID}@{asset.Version}. See above"); return(PackageState.NotInstalled); } else { PMF.InvokePackageMessageEvent($"Successfully installed {remotePackage.ID}@{asset.Version}"); return(PackageState.Installed); } }
private void SetFirstThrow() { currentThrow = firstThrow; }
private void SetSecondThrow() { currentThrow = GetSecondProbabilities(lastResult); }
private void OnWaterUptakesCalculated(PMF.WaterUptakesCalculatedType SoilWater) { // Gets the water uptake for each layer as calculated by an external module (SWIM) p_waterUptake = 0; for (int i_Crop = 0; i_Crop != SoilWater.Uptakes.Length; i_Crop++) { string MyName = SoilWater.Uptakes[i_Crop].Name; if (MyName == SwardName) { int length = SoilWater.Uptakes[i_Crop].Amount.Length; for (int layer = 0; layer < length; layer++) { SWUptake[layer] = SoilWater.Uptakes[i_Crop].Amount[layer]; p_waterUptake += SoilWater.Uptakes[i_Crop].Amount[layer]; } } } }