/// <summary> /// The main method /// </summary> /// <param name="args">Command line arguments. These arguments are expected to be created by <see cref="PackageSmartDetector.Execute"/>.</param> /// <returns>The exit code; 0 if the task successfully executed; otherwise, 1</returns> private static int Main(string[] args) { try { var packagePath = args[0]; var packageName = args[1]; SmartDetectorPackage package = SmartDetectorPackage.CreateFromFolder(packagePath); package.SaveToFile(Path.Combine(packagePath, packageName)); return(0); } catch (InvalidSmartDetectorPackageException exception) { Console.Write(exception.Message); return(1); } catch (IOException ioe) { Console.Write($"Failed to create Smart Detector Package - failed creating the package file: {ioe.Message}"); return(1); } catch (SecurityException securityException) { Console.Write($"Failed to create Smart Detector Package - failed creating the package file: {securityException.Message}"); return(1); } catch (Exception exception) { Console.Write(exception.Message); return(1); } }
/// <summary> /// Executes PackageSmartDetector task. /// </summary> /// <returns>True if the task successfully executed; otherwise, False.</returns> public override bool Execute() { try { SmartDetectorPackage package = SmartDetectorPackage.CreateFromFolder(this.PackagePath); package.SaveToFile(Path.Combine(this.PackagePath, this.PackageName)); } catch (InvalidSmartDetectorPackageException exception) { Log.LogError(exception.Message); return(false); } catch (IOException ioe) { Log.LogError($"Failed to create Smart Detector Package - failed creating the package file: {ioe.Message}"); return(false); } catch (SecurityException securityException) { Log.LogError($"Failed to create Smart Detector Package - failed creating the package file: {securityException.Message}"); return(false); } return(true); }
public async Task WhenLoadingSmartDetectorFromPackageThenItWorks() { // Create the detector package from the detector's folder (instead of from the current folder), // and check that it can be loaded correctly, with its dependencies. DirectoryInfo currentFolder = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string flavor = Path.Combine(currentFolder.Parent.Name, currentFolder.Name); while (currentFolder.Name.ToUpperInvariant() != "TEST") { currentFolder = currentFolder.Parent; } string packageFolder = Path.Combine(currentFolder.FullName, @"testSmartDetector\TestSmartDetectorLibrary\bin", flavor); SmartDetectorPackage package = SmartDetectorPackage.CreateFromFolder(packageFolder); await this.TestLoadSmartDetectorSimple(package, "test title - with dependency - [1,2,3]"); }