Exemple #1
0
 static void Main(string[] args)
 {
     if (File.Exists(_logFile))
     {
         _logger = NLog.Web.NLogBuilder.ConfigureNLog(_logFile).GetCurrentClassLogger();
     }
     try
     {
         using (var container = new ServiceContainer(new ContainerOptions {
             EnablePropertyInjection = false
         }))
         {
             var provider = ConfigureServices(container);
             // run the service
             ServiceHostProvider
             .ConfigureService <BinnerWebHostService>(container, provider)
             .Run();
         }
     }
     catch (Exception ex)
     {
         _logger?.Error(ex, "Main exception");
         throw;
     }
     finally
     {
         NLog.LogManager.Shutdown();
     }
 }
        /// <summary>
        /// return the list of states
        /// </summary>
        /// <param name="property"></param>
        /// <returns>List<Item> </returns>
        public List <WordListEntry> ItemsArray()
        {
            var path = ServiceHostProvider.FindFile("Alexa/Wordy/wordlist.json");
            var str1 = System.IO.File.ReadAllText(path);
            var lst  = JsonConvert.DeserializeObject <List <WordListEntry> >(str1);

            return(lst);
        }
Exemple #3
0
        static ServiceHost GetServiceHost(ServiceHostProvider provider)
        {
            var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);

            while (string.IsNullOrWhiteSpace(sh.CommandMessageQueue))
            {
                Thread.Sleep(500);
                sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
            }

            return sh;
        }
 private void UpdateCmdMsgQ(EnvironmentComponents envConfig, string publicationAddress)
 {
     var mongoEnv = envConfig.Config.Where(kvp => kvp.Key.StartsWith("Mongo"));
     var provider = new ServiceHostProvider(mongoEnv);
     var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
     sh.CommandMessageQueue = publicationAddress;
     sh = provider.Update(sh);
 }
        private void ManageServiceComponents(EnvironmentComponents envComponents)
        {
            var environment = envComponents.Environment;
            var mongoEnv = envComponents.Config.Where(kvp => kvp.Key.StartsWith("Mongo"));

            var provider = new ServiceHostProvider(mongoEnv);
            var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
            var configuredComponents = sh.Components;

            var configuredIds = configuredComponents.Select(c => c.Id);
            var existingIds = envComponents.Components.Select(c => c.Id);

            // newly configured components
            foreach (var newlyConfiguredId in configuredIds.Except(existingIds))
                envComponents.Components.Add(new RunningServiceComponent(environment, this.ConfigURL, configuredComponents.Single(c => c.Id == newlyConfiguredId), envComponents.Config));

            // newly removed components
            foreach (var newlyDeletedId in existingIds.Except(configuredIds))
            {
                RunningServiceComponent rsc = envComponents.Components.Single(c => c.Id == newlyDeletedId);
                rsc.Stop(envComponents.EventProducer);
                envComponents.Components.Remove(rsc);
            }

            // not new, not deleted, possibly updated
            foreach (var possiblyUpdatedId in configuredIds.Intersect(existingIds))
            {
                var rsc = envComponents.Components.Single(c => c.Id == possiblyUpdatedId);
                var sc = configuredComponents.Single(c => c.Id == possiblyUpdatedId);

                if (rsc.RowVersion != sc.RowVersion)
                    rsc.Update(envComponents.EventProducer, sc);
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var timeout = TimeSpan.FromSeconds(1d);

            var configClient = new SvcComponentConfig.SvcComponentConfigClient();

            // Get the list of environments, and make sure Dev is in the list
            var environments = configClient.GetEnvironments();
            var env = environments.Single(s => s == "Dev");

            // Get the Dev environment configuration
            var environment = configClient.GetEnvironmentConfig(env);
            var mongoEnv = environment.Where(kvp => kvp.Key.StartsWith("Mongo"));
            var rabbitEnv = environment.Where(kvp => kvp.Key.StartsWith("Rabbit"));

            var provider = new ServiceHostProvider(mongoEnv);

            using (var mbc = new MessageBrokerConnection(rabbitEnv))
            using (var cs = new CommandProducer(mbc.Connection))
            using (var wp = new WorkProducer(mbc.Connection))
            {
                var exit = false;
                Console.WriteLine("Press F to reload Files");
                Console.WriteLine("Press C to reload Configuration");
                Console.WriteLine("Press T to sTart component");
                Console.WriteLine("Press P to stoP component");
                Console.WriteLine("Press A to Activate component");
                Console.WriteLine("Press D to Deactivate component");
                Console.WriteLine("Press S to pauSe component");
                Console.WriteLine("Press N to coNtinue component");
                Console.WriteLine("Press W to create work");
                Console.WriteLine("Press x to exit");

                do
                {
                    var cki = Console.ReadKey(true);
                    string keyChar = new string(cki.KeyChar, 1);

                    if (string.Compare("x", keyChar, true, CultureInfo.InvariantCulture) == 0)
                        exit = true;

                    else if (string.Compare("w", keyChar, true, CultureInfo.InvariantCulture) == 0)
                        wp.Publish(new SampleWorkItem(), "SampleWorkQueue");

                    else
                    {
                        var sh = GetServiceHost(provider);
                        var pa = PublicationAddress.Parse(sh.CommandMessageQueue);

                        if (string.Compare("f", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ReloadFiles() { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("c", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ReloadConfiguration() { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("t", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new StartComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("p", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new StopComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("a", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ActivateComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("d", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new DeactivateComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("s", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new PauseComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("n", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ContinueComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);
                    }
                }
                while (!exit);
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var mongoEnv = new List<KeyValuePair<string, string>>();

            mongoEnv.Add(new KeyValuePair<string, string>("MongoServer", "localhost"));
            mongoEnv.Add(new KeyValuePair<string, string>("MongoPort", "27017"));
            mongoEnv.Add(new KeyValuePair<string, string>("MongoRepositorySvcConfig", "ServiceConfig"));

            //ServiceComponentProvider scp = new ServiceComponentProvider(mongoEnv);
            //ServiceComponent sc = new ServiceComponent()
            //{
            //	Assembly = "SampleServiceComponent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
            //	Class = "DKK.SampleServiceComponent.SampleComponent",
            //	CommandMessageQueue = string.Empty,
            //	Config = string.Empty,
            //	CreateDate = DateTime.UtcNow,
            //	Creator = $@"{Environment.UserDomainName}\\{Environment.UserName}",
            //	FriendlyName = "Sample Component I",
            //	IsActive = true,
            //	IsPaused = false,
            //	Machine = Environment.MachineName,
            //	ParamsAssembly = "SampleServiceComponent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
            //	ParamsClass = "DKK.SampleServiceComponent.SampleComponentParams",
            //};

            //Guid origId = sc.Id;

            //scp.Insert(sc);

            //ServiceComponent sc2 = scp.Queryable().Single(x => x.Id == origId);

            //if (origId != sc2.Id)
            //	throw new Exception("Ids do not match");

            //ServiceComponent sc = scp.Queryable().FirstOrDefault();
            //SampleComponentParams theParams = new SampleComponentParams() { IdleMessageRate = 1 };

            //sc.Config = JsonConvert.SerializeObject(theParams, Formatting.None, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
            //sc.ParamsAssembly = theParams.GetType().Assembly.FullName;
            //sc.ParamsClass = theParams.GetType().FullName;

            //scp.Update(sc);

            var theComponent = new SampleComponent();
            var theParams = new SampleComponentParams() { IdleMessageRate = 1, WorkQueue = "SampleWorkQueue" };

            var sc1 = new ServiceComponent()
            {
                Id = Guid.NewGuid(),
                Assembly = theComponent.GetType().Assembly.FullName,
                Class = theComponent.GetType().FullName,
                Config = JsonConvert.SerializeObject(theParams, Formatting.None, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }),
                FriendlyName = "Sample Component I",
                IsActive = true,
                IsPaused = false,
                ParamsAssembly = theParams.GetType().Assembly.FullName,
                ParamsClass = theParams.GetType().FullName,
            };

            //ServiceComponent sc2 = new ServiceComponent()
            //{
            //	Id = Guid.NewGuid(),
            //	Assembly = theComponent.GetType().Assembly.FullName,
            //	Class = theComponent.GetType().FullName,
            //	Config = JsonConvert.SerializeObject(theParams, Formatting.None, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }),
            //	FriendlyName = "Sample Component II",
            //	IsActive = true,
            //	IsPaused = false,
            //	ParamsAssembly = theParams.GetType().Assembly.FullName,
            //	ParamsClass = theParams.GetType().FullName,
            //};

            var sh = new ServiceHost()
            {
                Machine = Environment.MachineName,
            };
            sh.Components.AddRange(new ServiceComponent[] { sc1, /*sc2*/ });

            var shp = new ServiceHostProvider(mongoEnv);
            shp.Insert(sh);
        }