public static Config Create()
        {
            var _config = new Config();
            var jReader = new JsonConfigFileReader();

            _config.OperatingMode                        = jReader.GetValue <OperatingMode>(nameof(_config.OperatingMode));
            _config.MaxProcessTorrentsInBatch            = jReader.GetValue <int>(nameof(_config.MaxProcessTorrentsInBatch));
            _config.RestartErrorTorrents                 = jReader.GetValue <bool>(nameof(_config.RestartErrorTorrents));
            _config.DeleteFromTorrentsFolderWhenUnpacked = jReader.GetValue <bool>(nameof(_config.DeleteFromTorrentsFolderWhenUnpacked));
            _config.DeleteAlreadyProcessedTorrents       = jReader.GetValue <bool>(nameof(_config.DeleteAlreadyProcessedTorrents));

            _config.FinalFolder = jReader.GetValue <string>(nameof(_config.FinalFolder));
            _config.DownloadedTorrentsFolder = jReader.GetValue <string>(nameof(_config.DownloadedTorrentsFolder));

            _config.UnpackerParameters      = jReader.GetValue <string>(nameof(_config.UnpackerParameters));
            _config.UnpackerExeFileFullPath = jReader.GetValue <string>(nameof(_config.UnpackerExeFileFullPath));
            _config.UnpackerHideWindow      = jReader.GetValue <bool>(nameof(_config.UnpackerHideWindow));

            _config.ArchiveFirstFilePossibleFileExtensions = jReader.GetValue <string[]>(nameof(_config.ArchiveFirstFilePossibleFileExtensions));
            _config.IsArchivePatterns = jReader.GetValue <string[]>(nameof(_config.IsArchivePatterns));

            _config.TorrentWebApiUrl      = jReader.GetValue <string>(nameof(_config.TorrentWebApiUrl));
            _config.TorrentWebApiLogin    = jReader.GetValue <string>(nameof(_config.TorrentWebApiLogin));
            _config.TorrentWebApiPassword = jReader.GetValue <string>(nameof(_config.TorrentWebApiPassword));


            _config.IgnoreFileExtensionPatterns = jReader.GetValue <string[]>(nameof(_config.IgnoreFileExtensionPatterns));
            _config.IgnoreFileNamePatterns      = jReader.GetValue <string[]>(nameof(_config.IgnoreFileNamePatterns));
            _config.IgnoreFolderPatterns        = jReader.GetValue <string[]>(nameof(_config.IgnoreFolderPatterns));

            _config.SeedingGoals = jReader.GetValue <SeedingGoal[]>(nameof(_config.SeedingGoals));

            return(_config);
        }
        /// <summary>
        /// 1.  The bus needs to be started in order to receive Request-Reply replies.
        ///
        /// If not intending to use Request-Reply, or Fault-To, or Reply-To, no need to start the bus with .Start(),
        /// just configure it and use it to publish Events or get send-endpoints to send Commands/Queries.
        /// </summary>
        private void ConfigureBus()
        {
            try
            {
                // You must configure this in the a config.json file (see the example)
                var connstring = new JsonConfigFileReader().GetValue("AzureSbConnectionString");
                _azureBus = new AzureSbBusConfigurator(connstring).CreateBus();

                LogLine("AzureSB Bus started. ConnString: " + connstring);

                // This is necessary in order to receive replies from the request/reply mechanism.
                // LAB: Try turn it off and see what happens when you send request/replies ..
                //await _azureBus.StartAsync();

                LogLine($"Bus Created. Bus.Adress: {_azureBus.Address}");
            }
            catch (Exception ex)
            {
                LogError("Exception starting Azure Bus!! " + ex.Message);
            }
        }
示例#3
0
        private static IBusControl CreateIBusControl()
        {
            var connstring = new JsonConfigFileReader().GetValue("AzureSbConnectionString");

            var bus = new AzureSbBusConfigurator(connstring)
                      .CreateBus((cfg, host) =>
            {
                //TODO: How to handle pool of receivers? aka "Competing Consumers"
                // https://masstransit.readthedocs.io/en/latest/configuration/gotchas.html#how-to-setup-a-competing-consumer
                // http://docs.masstransit-project.com/en/latest/overview/underthehood.html

                // Command Consumers
                if (_enableCommandConsumers)
                {
                    cfg.ReceiveEndpoint <IUpdateFooCommand>(c =>    // The interface = the queue name
                    {
                        // LAB: Try turn all consumers off and see what happens when sending the commands ..

                        c.Consumer <UpdateFooCommandConsumer>();         // What class will consume the messages
                        c.Consumer <UpdateFooVersion2CommandConsumer>(); // What class will consume the messages
                        c.Consumer <IUpdateFooCommandConsumer>();        // What class will consume the messages
                    });
                }


                // Event Consumers
                if (_enableEventConsumers)
                {
                    cfg.ReceiveEndpoint <IBarEvent>(c =>    // The interface name = the queue name
                    {
                        c.Consumer <BarEventConsumer>();    // What class will consume the messages
                    });
                    cfg.ReceiveEndpoint <IUpdateProductsStartedEvent>(c =>
                    {
                        c.Consumer <UpdateProductsStartedEventConsumer>();
                    });
                    cfg.ReceiveEndpoint <ISagaUpdateProductsBatchCommand>(c =>
                    {
                        c.Consumer <UpdateProductsBatchCommandConsumer>();
                    });
                }

                // Request Reply Consumers
                if (_enableRequestReplyConsumers)
                {
                    cfg.ReceiveEndpoint <ServeBarsCommand>(c =>    // The interface name = the queue name
                    {
                        c.Consumer <ServeBarsCommandConsumer>();   // What class will consume the messages
                    });
                }

                // Saga Consumers
                _machine             = new UpdateProductsStateMachine();
                _updProductsSagaRepo = new InMemorySagaRepository <UpdateProductsSaga>();

                if (_enableSagaConsumers)
                {
                    // It looks like all messages related to the saga must be sent to the same queue? But what if we can't control this? (Look it up)
                    cfg.ReceiveEndpoint("update_products_saga", c =>
                    {
                        c.StateMachineSaga(_machine, _updProductsSagaRepo);
                    });
                }

                // Manual Consumers
                //cfg.ReceiveEndpoint("manual_queue", c =>  // The interface = the queue name
                //{
                //    c.Consumer<AnotherBarEventConsumer>(); // What class will consume the messages
                //});
            });

            // Use this to debug. Example: You send stuff that should arrive to a saga but it doesn't, and you wanna know if the messages are even received, then place breakpoints there.
            bus.ConnectReceiveObserver(new ConsoleOutReceiveObserver());

            return(bus);
        }