Example #1
0
        public async void Basic_Http_Get_Headers_Are_Retrieved()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            PackageHelpers.RegisterRequestPackages();

            manager.AddConsoleReference = true;
            var options = new ExecutionOptions();

            options.HostObjects.Add(new HostObject {
                Name = "subject", Target = subject
            });

            var scriptAwaiter = new ScriptAwaiter();

            options.HostObjects.Add(new HostObject {
                Name = "scriptAwaiter", Target = scriptAwaiter
            });

            var code = "var request = require('request');" +
                       "request({url: 'http://api.icndb.com/jokes/random/1', json: true}," +
                       " function (error, response, body) {subject.Response = response; subject.Headers = response.headers; scriptAwaiter.Callback();});";

            await manager.ExecuteAsync("testScript", code, options);

            await scriptAwaiter.T;

            subject.Headers.Count().ShouldBeGreaterThan(0);
        }
Example #2
0
        public ExecutionResult Update(InstallDto installOptions)
        {
            var logger = new StringLogger();

            try
            {
                var files = Directory.GetFiles(installOptions.Directory, "*.nupkg");

                if (files.Count() == 0)
                {
                    logger.Log("No package to uninstall found, proceeding with a normal install.");
                }

                if (files.Count() >= 1)
                {
                    var filename    = PackageHelpers.ExtractPackageName(files.First()).Trim();
                    var packageInfo = new PackageInfo()
                    {
                        Name    = filename.Substring(filename.LastIndexOf("\\") + 1),
                        Version = PackageHelpers.ExtractPackageVersion(files.First()).Trim(),
                        InstallationDirectory = installOptions.Directory,
                        Configuration         = installOptions.Configuration
                    };
                    var packageRemover = new PackageRemover();
                    packageRemover.Logger = logger;

                    var additionalParams = installOptions.AdditionalParameters;
                    packageRemover.Remove(packageInfo, new string[] { installOptions.Directory }, additionalParams, installOptions.UninstallScript);
                }


                var packageInfo2 = new PackageInfo()
                {
                    Configuration         = installOptions.Configuration,
                    InstallationDirectory = installOptions.Directory,
                    Name    = installOptions.Application,
                    Version = installOptions.Version
                };

                var PackageInstaller = new PackageInstaller();
                PackageInstaller.Logger = logger;
                PackageInstaller.Install(packageInfo2, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform);
                return(new ExecutionResult()
                {
                    Success = logger.Logs.All(x => !x.Error),
                    Log = logger.Logs
                });
            }
            catch (Exception e)
            {
                logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true);

                return(new ExecutionResult()
                {
                    Success = false,
                    Exception = e.InnerException != null ? e.InnerException.Message : e.Message,
                    Log = logger.Logs
                });
            }
        }
Example #3
0
 /// <summary>
 ///     Tries to remove a package from the gallery
 /// </summary>
 /// <param name="package">Package to remove</param>
 /// <param name="version">Version to remove</param>
 /// <param name="gallery">gallery address</param>
 public static void RemovePackage(string package, string version, string gallery)
 {
     try
     {
         PackageHelpers.Delete(package, version, gallery);
     }
     catch (Exception e)
     {
         //ignore the error we just try to delete
     }
 }
        public NetworkPackage Generate(byte[] bytes)
        {
            PackageHelpers packageHelpers = new PackageHelpers();

            NetworkPackage networkPackage = NetworkPackages.FirstOrDefault();

            if (networkPackage != null)
            {
                int rowIndex = networkPackage.Type.RowNumber - 1;

                if (bytes.Count() >= rowIndex)
                {
                    byte type = bytes[rowIndex];
                    networkPackage = NetworkPackages.Where(x => x.Type.Value == type).FirstOrDefault();
                    List <NetworkPackageValue> values = packageHelpers.GetNetworkPackageValues(networkPackage);
                    SetValues(networkPackage, values, bytes);
                }
            }


            return(networkPackage);
        }
Example #5
0
        public ExecutionResult DatabaseDeploy(DatabaseDeployDto options)
        {
            var logger = new StringLogger();

            try
            {
                var stream = PackageHelpers.DownloadDacpac(options.PackageName, options.Version, options.Repository);
                DacpacHelpers.ApplyDacpac(stream, options.ConnectionString, options.DataBase, logger);
            }
            catch (Exception e)
            {
                return(new ExecutionResult()
                {
                    Exception = e.InnerException == null ? e.Message : e.InnerException.Message,
                    Success = false,
                    Log = logger.Logs
                });
            }
            return(new ExecutionResult()
            {
                Success = logger.Logs.All(x => !x.Error),
                Log = logger.Logs
            });
        }
Example #6
0
        /// <summary>
        ///     Executes the bazooka cli program based on the parameters passed
        /// </summary>
        /// <param name="args">Arguments to Bazooka</param>
        static void Main(string[] args)
        {
            string invokedVerb         = "";
            object invokedVerbInstance = null;

            var options = new Options();
            var result  = CommandLine.Parser.Default.ParseArgumentsStrict(args, options,
                                                                          (verb, subOptions) =>
            {
                // if parsing succeeds the verb name and correct instance
                // will be passed to onVerbCommand delegate (string,object)
                invokedVerb         = verb;
                invokedVerbInstance = subOptions;
            });

            switch (invokedVerb)
            {
            case "install":
            {
                var packageInfo = new PackageInfo();

                packageInfo.Configuration         = ((InstallOptions)invokedVerbInstance).Configuration;
                packageInfo.InstallationDirectory = ((InstallOptions)invokedVerbInstance).Directory;
                packageInfo.Name    = ((InstallOptions)invokedVerbInstance).Application;
                packageInfo.Version = ((InstallOptions)invokedVerbInstance).Version;

                var PackageInstaller = new PackageInstaller();
                PackageInstaller.Logger = new ConsoleLogger();
                var additionalParams = ((InstallOptions)invokedVerbInstance).AdditionalParameters;
                var paramDictionary  = new Dictionary <string, string>();

                if (additionalParams.Length > 0)
                {
                    paramDictionary = additionalParams.ToDictionary(x => x.Substring(0, x.IndexOf("=") - 1), x => x.Substring(x.IndexOf("=") + 1));
                }

                PackageInstaller.Install(packageInfo, new string[] { ((InstallOptions)invokedVerbInstance).Repository }, paramDictionary);
            }
            break;

            case "blast":
            {
                //serach directory for packages
                var files = Directory.GetFiles(((BlastOptions)invokedVerbInstance).Directory, "*.nupkg");

                if (files.Count() == 0)
                {
                    Console.WriteLine("No package found");
                    break;
                }


                if (files.Count() > 1)
                {
                    Console.WriteLine("More than one package present");
                    break;
                }

                var packageInfo = new PackageInfo();
                var filename    = PackageHelpers.ExtractPackageName(files.First()).Trim();
                packageInfo.Name    = filename.Substring(filename.LastIndexOf("\\") + 1);
                packageInfo.Version = PackageHelpers.ExtractPackageVersion(files.First());
                packageInfo.InstallationDirectory = ((BlastOptions)invokedVerbInstance).Directory;
                packageInfo.Configuration         = "";

                var packageRemover = new PackageRemover();
                packageRemover.Logger = new ConsoleLogger();

                var additionalParams = ((BlastOptions)invokedVerbInstance).AdditionalParameters;
                var paramDictionary  = new Dictionary <string, string>();

                if (additionalParams.Length > 0)
                {
                    paramDictionary = additionalParams.ToDictionary(x => x.Substring(0, x.IndexOf("=") - 1), x => x.Substring(x.IndexOf("=") + 1));
                }

                packageRemover.Remove(packageInfo, new string[] { ((BlastOptions)invokedVerbInstance).Directory }, paramDictionary, null);
                // if multiples found erro
                //uninstall the remaining one
            }
            break;

            case "update":
            {
                //serach directory for packages
                var files = Directory.GetFiles(((UpdateOptions)invokedVerbInstance).Directory, "*.nupkg");

                if (files.Count() == 0)
                {
                    Console.WriteLine("No package found");
                    break;
                }


                if (files.Count() > 1)
                {
                    Console.WriteLine("More than one package present");
                    break;
                }

                var packageInfo = new PackageInfo();
                var filename    = PackageHelpers.ExtractPackageName(files.First()).Trim();
                packageInfo.Name    = filename.Substring(filename.LastIndexOf("\\") + 1);
                packageInfo.Version = PackageHelpers.ExtractPackageVersion(files.First()).Trim();
                packageInfo.InstallationDirectory = ((UpdateOptions)invokedVerbInstance).Directory;
                packageInfo.Configuration         = ((UpdateOptions)invokedVerbInstance).Configuration;

                var packageRemover = new PackageRemover();
                packageRemover.Logger = new ConsoleLogger();

                var additionalParams = ((UpdateOptions)invokedVerbInstance).AdditionalParameters;
                var paramDictionary  = new Dictionary <string, string>();

                if (additionalParams.Length > 0)
                {
                    paramDictionary = additionalParams.ToDictionary(x => x.Substring(0, x.IndexOf("=") - 1), x => x.Substring(x.IndexOf("=") + 1));
                }

                packageRemover.Remove(packageInfo, new string[] { ((UpdateOptions)invokedVerbInstance).Directory }, paramDictionary, null);

                var packageInfo2 = new PackageInfo();

                packageInfo2.Configuration         = ((UpdateOptions)invokedVerbInstance).Configuration;
                packageInfo2.InstallationDirectory = ((UpdateOptions)invokedVerbInstance).Directory;
                packageInfo2.Name    = ((UpdateOptions)invokedVerbInstance).Application;
                packageInfo2.Version = ((UpdateOptions)invokedVerbInstance).Version;

                var PackageInstaller = new PackageInstaller();
                PackageInstaller.Logger = new ConsoleLogger();
                var additionalParams2 = ((UpdateOptions)invokedVerbInstance).AdditionalParameters;
                var paramDictionary2  = new Dictionary <string, string>();

                if (additionalParams2.Length > 0)
                {
                    paramDictionary2 = additionalParams2.ToDictionary(x => x.Substring(0, x.IndexOf("=") - 1), x => x.Substring(x.IndexOf("=") + 1));
                }

                PackageInstaller.Install(packageInfo2, new string[] { ((UpdateOptions)invokedVerbInstance).Repository }, paramDictionary2);
            }
            break;

            case "uninstall":
            {
                var packageInfo = new PackageInfo();
                packageInfo.Name    = ((UninstallOptions)invokedVerbInstance).Application;
                packageInfo.Version = ((UninstallOptions)invokedVerbInstance).Version;
                packageInfo.InstallationDirectory = ((UninstallOptions)invokedVerbInstance).Directory;
                packageInfo.Configuration         = ((UninstallOptions)invokedVerbInstance).Configuration;

                var packageRemover = new PackageRemover();
                packageRemover.Logger = new ConsoleLogger();

                var additionalParams = ((UninstallOptions)invokedVerbInstance).AdditionalParameters;
                var paramDictionary  = new Dictionary <string, string>();

                if (additionalParams.Length > 0)
                {
                    paramDictionary = additionalParams.ToDictionary(x => x.Substring(0, x.IndexOf("=") - 1), x => x.Substring(x.IndexOf("=") + 1));
                }

                packageRemover.Remove(packageInfo, new string[] { ((UninstallOptions)invokedVerbInstance).Directory }, paramDictionary, null);
            }
            break;
            }
        }
Example #7
0
 public IReadOnlyList <IViewManager> GetViewManagers() => PackageHelpers.GetAllViewManagers();
Example #8
0
            public void ShouldExtractRCVersion()
            {
                var name = PackageHelpers.ExtractPackageVersion("prova.test.1.2.3-rc2.nupkg");

                Assert.AreEqual(name, "1.2.3-rc2");
            }
Example #9
0
            public void ShouldExtractCompositeName()
            {
                var name = PackageHelpers.ExtractPackageName("prova.test.1.2.3.nupkg");

                Assert.AreEqual(name, "prova.test");
            }
Example #10
0
            public void ShouldExtractSimpleName()
            {
                var name = PackageHelpers.ExtractPackageName("prova.1.2.3.nupkg");

                Assert.AreEqual(name, "prova");
            }