Beispiel #1
0
        private static void InitializeServices(IServiceCollection services)
        {
            services.AddSingleton <MainWindowViewModel>();
#if DEBUG
            services.AddTransient <IMailService, DebugMailService>();
#else
            services.AddTransient <IMailService, SmtpMailService>();
#endif
            services.AddSingleton <IEncryptorService, Rfc2898Encryptor>();

            // Выбираем либо этот блок
            var memory_store = new InMemoryDataStorage(new Rfc2898Encryptor());
            services.AddSingleton <IServersStorage>(memory_store);
            services.AddSingleton <ISendersStorage>(memory_store);
            services.AddSingleton <IRecipientsStorage>(memory_store);
            services.AddSingleton <IMailsStorage>(memory_store);

            //либо этот. Один надо закомментировать, другой - раскомментировать
            //const string data_file_name = "MailSenderStorage.xml";
            //var file_storage = new InXmlFileDataStorage(data_file_name);
            //services.AddSingleton<IServersStorage>(file_storage);
            //services.AddSingleton<ISendersStorage>(file_storage);
            //services.AddSingleton<IRecipientsStorage>(file_storage);
            //services.AddSingleton<IMailsStorage>(file_storage);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(nodeConfig))
            {
                // Setup an in-memory data store
                var store = new InMemoryDataStorage();
                core.AddModule(new DataModule(core.MessageBus, store));

                // Backplane so we can cluster
                core.AddModule(new BackplaneModule(core));

                // Stitches so we can host the stitch instances
                var stitchesConfig = StitchesConfiguration.GetDefault();
                core.AddModule(new StitchesModule(core, stitchesConfig));

                // Setup logging.
                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                // Create a stitch instance to run on startup
                var groupName   = new StitchGroupName("PenPal.StitchA.1");
                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableArguments, "" },
                            { Parameters.ExecutableName, "PenPal.StitchA.exe" }
                        }
                    },
                };
                store.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name          = "StitchA",
                    GroupName     = groupName,
                    OwnerNodeName = core.Name,
                    OwnerNodeId   = core.NodeId,
                    State         = InstanceStateType.Running
                };
                store.Save(stitch, true);

                core.Start();

                Console.ReadKey();

                core.Stop();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();


            using (var core = new CrossStitchCore(nodeConfig))
            {
                var httpServer = new NancyHttpModule(core.MessageBus);
                core.AddModule(httpServer);

                var dataStorage = new InMemoryDataStorage();
                var data        = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var groupName = new StitchGroupName("HttpTest", "Stitch", "1");

                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "HttpTest.Stitch.exe" },
                            //{ Parameters.ArgumentsFormat, "{ExecutableName} {CoreArgs} -- {CustomArgs}" },
                            //{ Parameters.ExecutableFormat, "dotnet" },
                        }
                    },
                };
                dataStorage.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name      = "HttpTest.Stitch",
                    GroupName = groupName,

                    State = InstanceStateType.Running
                };
                dataStorage.Save(stitch, true);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Log.LogInformation("Started");
                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(nodeConfig))
            {
                var httpServer = new NancyHttpModule(core.MessageBus);
                core.AddModule(httpServer);

                var dataStorage = new InMemoryDataStorage();
                var data        = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var groupName = new StitchGroupName("HttpTest", "Stitch", "1");

                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { CrossStitch.Stitch.ProcessV1.Parameters.DirectoryPath, "." },
                            { CrossStitch.Stitch.ProcessV1.Parameters.ExecutableName, "HttpTest.Stitch.exe" }
                        }
                    },
                };
                dataStorage.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name      = "HttpTest.Stitch",
                    GroupName = groupName,

                    State = InstanceStateType.Running,
                    LastHeartbeatReceived = 0
                };
                dataStorage.Save(stitch, true);

                core.AddModule(new LoggingModule(core, Common.Logging.LogManager.GetLogger("CrossStitch")));

                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
Beispiel #5
0
        public void HandleRequest_Get_Test()
        {
            var storage = new InMemoryDataStorage();
            var entity  = new StitchInstance()
            {
                Name = "A"
            };

            storage.Save(entity, true);
            var id     = entity.Id;
            var target = new DataService(storage, null);

            var result = target.HandleRequest(DataRequest <StitchInstance> .Get(id));

            result.Type.Should().Be(DataResponseType.Success);
            result.Entity.Name.Should().Be("A");
        }
Beispiel #6
0
        private static DataService CreateTarget()
        {
            var storage = new InMemoryDataStorage();

            storage.Save(new StitchInstance()
            {
                Name = "A"
            }, true);
            storage.Save(new StitchInstance()
            {
                Name = "B"
            }, true);
            storage.Save(new StitchInstance()
            {
                Name = "C"
            }, true);
            return(new DataService(storage, null));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var config = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(config))
            {
                var dataStorage = new InMemoryDataStorage();
                var groupName   = new StitchGroupName("JsStitch", "Stitch", "1");
                dataStorage.Save(new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "JsStitch.Stitch.js" }
                        }
                    },
                }, true);
                dataStorage.Save(new StitchInstance
                {
                    Name      = "JsStitch.Stitch",
                    GroupName = groupName,
                    State     = InstanceStateType.Running
                }, true);

                var data = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
        private static void ConfigureServices(HostBuilderContext host, IServiceCollection services)
        {
            services.AddSingleton <MainWindowViewModel>();
#if DEBUG
            services.AddTransient <IMailService, DebugMailService>();
#else
            services.AddTransient <IMailService, SmtpMailService>();
#endif
            var memory_store = new InMemoryDataStorage();
            services.AddSingleton <IServerStorage>(memory_store);
            services.AddSingleton <ISenderStorage>(memory_store);
            services.AddSingleton <IRecipientStorage>(memory_store);
            services.AddSingleton <IMessageStorage>(memory_store);
            //const string data_file_name = "storage.xml";
            //var file_storage = new InXmlFileDataStorage(data_file_name);
            //services.AddSingleton<IServerStorage>(file_storage);
            //services.AddSingleton<ISenderStorage>(file_storage);
            //services.AddSingleton<IRecipientStorage>(file_storage);
            //services.AddSingleton<IMessageStorage>(file_storage);
        }
 public TaskService()
 {
     this.data = InMemoryDataStorage.Instance;
 }
Beispiel #10
0
 public StorageTests()
 {
     storage = new InMemoryDataStorage();
 }
Beispiel #11
0
 public ClientService()
 {
     this.data = InMemoryDataStorage.Instance;
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            var config = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(config))
            {
                var dataStorage = new InMemoryDataStorage();

                var pingGroup   = new StitchGroupName("PingPong", "Ping", "1");
                var pingPackage = new PackageFile
                {
                    Id        = pingGroup.ToString(),
                    GroupName = pingGroup,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "PingPong.Ping.exe" }
                        }
                    },
                };
                var ping = new StitchInstance
                {
                    Name      = "PingPong.Ping",
                    GroupName = pingGroup,
                    State     = InstanceStateType.Running
                };

                var pongGroup   = new StitchGroupName("PingPong", "Pong", "1");
                var pongPackage = new PackageFile
                {
                    Id        = pongGroup.ToString(),
                    GroupName = pongGroup,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "PingPong.Pong.exe" }
                        }
                    },
                };
                var pong = new StitchInstance
                {
                    Name      = "PingPong.Pong",
                    GroupName = pongGroup,
                    State     = InstanceStateType.Running
                };

                dataStorage.Save(pingPackage, true);
                dataStorage.Save(ping, true);
                dataStorage.Save(pongPackage, true);
                dataStorage.Save(pong, true);

                var data = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                // TODO: We need a way to start for initialization to complete, either having Start
                // block or providing an Initialized event which waits for all modules to report
                // being initialized
                core.Start();

                Console.ReadKey();
                core.Stop();
            }
        }