Exemple #1
0
        public static void RefreshConfigCountry(CountryParameter item, DirectoryInfo rootPathTemp)
        {
            Output.WriteLine($"{item.Name} updating in the version {item.OnlineVersion}");

            // Download
            Output.WriteLine($"Download");
            string filename = Path.Combine(rootPathTemp.FullName, string.Format(@"Black.Beard.Calendarium.{0}.zip", item.Name));
            var    task     = BbClientHttp.DownloadAsync(string.Format(@"https://www.nuget.org/api/v2/package/Black.Beard.Calendarium.{0}/{1}", item.Name, item.OnlineVersion), filename);

            task.Wait();


            // Unzip
            Output.WriteLine($"Uncompress");
            var      dir = rootPathTemp.CreateSubdirectory(string.Format(@"Black.Beard.Calendarium.{0}", item.Name));
            FileInfo f   = new FileInfo(filename);

            f.UnzipFromFile(dir.FullName);


            // copy configurations
            Output.WriteLine($"Save");
            DirectoryInfo p      = new DirectoryInfo(Path.Combine(dir.FullName, @"content\Configuration\Countries"));
            var           file   = p.GetFiles("*.json").FirstOrDefault();
            var           target = new FileInfo(Path.Combine(Constants.RootPathConfig.FullName, item.Name) + ".json");

            if (target.Exists)
            {
                target.Delete();
            }
            file.CopyTo(target.FullName);

            item.LocalVersion = item.OnlineVersion;
        }
        public static CommandLineApplication CommandDownloadNuget(this CommandLineApplication app)
        {
            var cmd = app.Command("download", config =>
            {
                config.Description = "Download nuget at " + Constants.urlNuget;
                config.HelpOption(HelpFlag);

                var validator = new GroupArgument(config, false);

                config.OnExecute(() =>
                {
                    if (validator.Evaluate() > 0)
                    {
                        return(2);
                    }

                    var uri          = new Uri(Constants.urlNuget);
                    BbClientHttp cli = new BbClientHttp(uri);


                    try
                    {
                        if (Constants.NugetFile.Exists)
                        {
                            Output.WriteLine("remove current version of nuget.exe in " + Constants.NugetFile.Directory.FullName);
                            Constants.NugetFile.Delete();
                        }
                    }
                    catch (Exception ex1)
                    {
                        throw new Exception("failed to remove current version of nuget.exe", ex1);
                    }

                    try
                    {
                        Output.WriteLine("download lastest version of nuget.exe in " + Constants.NugetFile.Directory.FullName);
                        BbClientHttp.DownloadAsync(uri, Constants.NugetFile.FullName).Wait();
                    }
                    catch (Exception ex2)
                    {
                        throw new Exception("failed to to downlod nuget.exe", ex2);
                    }

                    Output.WriteLine("download successfull");

                    Result = Constants.NugetFile;

                    return(0);
                });
            });

            return(app);
        }
Exemple #3
0
        private static void DownloadCountryList()
        {
            Dictionary <string, CountryParameter> dic = GetDictionnaryCountry();

            BbClientHttp client = new BbClientHttp(new Uri(@"https://azuresearch-usnc.nuget.org"));
            var          items  = client.Get <JObject>(string.Format(@"https://azuresearch-usnc.nuget.org/query?q=Black.Beard.Calendarium.&prerelease=false&semVerLevel=2.0.0&skip={0}&take=50", 0));

            items.Wait();

            var totalHits = items.Result["totalHits"];
            var count     = int.Parse(totalHits.ToString());

            var array = items.Result["data"] as JArray;

            AddCountries(dic, array);

            for (int i = 50; i < count; i = i + 50)
            {
                items = client.Get <JObject>(string.Format(@"https://azuresearch-usnc.nuget.org/query?q=Black.Beard.Calendarium.&prerelease=false&semVerLevel=2.0.0&skip={0}&take=50", i));
                items.Wait();
                array = items.Result["data"] as JArray;
                AddCountries(dic, array);
            }
        }
        public static CommandLineApplication CommandPushworkflow(this CommandLineApplication app)
        {
            var cmd = app.Command("workflow", config =>
            {
                config.Description = "push a message on workflow server";
                config.HelpOption(HelpFlag);
            });

            var cmd2 = cmd.Command("http", config =>
            {
                config.Description = "push a message on workflow server using http";
                config.HelpOption(HelpFlag);

                var validator = new GroupArgument(config, false);

                var serverName = validator.Argument("server",
                                                    "Url server of the workflow server. (this argument is required)"
                                                    , ValidatorExtension.EvaluateRequired
                                                    );

                var domain = validator.Argument("domain",
                                                "target domain workflow (this argument is required)"
                                                , ValidatorExtension.EvaluateRequired
                                                );

                var content = validator.Argument("content",
                                                 "content that you want to push on the workflow server"
                                                 , ValidatorExtension.EvaluateRequired
                                                 );

                config.OnExecute(() =>
                {
                    if (validator.Evaluate() > 0)
                    {
                        return(2);
                    }

                    string model = GetContent(content.Value);

                    var client = new BbClientHttp(new Uri(serverName.Value));
                    var result = client.Post <RootResultModel <object> >($"api/workflowProcessor/Push/{domain.Value}", model /*, GetToken() */);

                    result.Wait();

                    Output.WriteLine("item successfully pushed on workflow server.");

                    Result = Helper.Parameters.ServerUrl;

                    return(0);
                });
            });

            var cmd3 = cmd.Command("broker", config =>
            {
                config.Description = "push a message on workflow server using http";
                config.HelpOption(HelpFlag);

                var validator = new GroupArgument(config, false);

                var configBroker = validator.Argument("config",
                                                      "broker configuration (this argument is required)"
                                                      , ValidatorExtension.EvaluateRequired
                                                      );

                var publisher = validator.Argument("publisher",
                                                   "server connection string (this argument is required)"
                                                   , ValidatorExtension.EvaluateRequired
                                                   );

                var domain = validator.Argument("domain",
                                                "target domain workflow (this argument is required)"
                                                , ValidatorExtension.EvaluateRequired
                                                );

                var content = validator.Argument("content",
                                                 "content that you want to push on the workflow server"
                                                 , ValidatorExtension.EvaluateRequired
                                                 );

                config.OnExecute(() =>
                {
                    if (validator.Evaluate() > 0)
                    {
                        return(2);
                    }

                    string configRabbit = GetContent(configBroker.Value);
                    var result          = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigurationBroker>(configRabbit);

                    var publisherItem = result.Brokers.Publishers.First(c => c.Name == publisher.Value);

                    string model = GetContent(content.Value);

                    IFactoryBroker brokers = result.ApplyConfiguration(new RabbitFactoryBrokers())
                                             .Initialize();

                    using (var publisherInstance = brokers.CreatePublisher(publisher.Value))
                        using (var trans = publisherInstance.BeginTransaction())
                        {
                            publisherInstance.Publish(publisherItem.DefaultRountingKey, model, new { domain = domain.Value });
                            publisherInstance.Commit();
                        }

                    Output.WriteLine("item successfully pushed on workflow server.");

                    return(0);
                });
            });

            return(app);
        }