Example #1
0
        private static void GenerateSettingsFiles(string ms, string pg, string d, string u, string p, FileInfo o)
        {
            IMetadataService metadataService = new MetadataService();

            if (!string.IsNullOrWhiteSpace(ms))
            {
                metadataService.UseDatabaseProvider(DatabaseProviders.SQLServer);
                metadataService.ConfigureConnectionString(ms, d, u, p);
            }
            else
            {
                metadataService.UseDatabaseProvider(DatabaseProviders.PostgreSQL);
                metadataService.ConfigureConnectionString(pg, d, u, p);
            }

            InfoBase infoBase = metadataService.LoadInfoBase();

            MessageConsumerSettings consumerSettings = CreateConsumerSettings(infoBase, metadataService);
            MessageProducerSettings producerSettings = CreateProducerSettings(infoBase, metadataService);

            string consumerPath = Path.Combine(o.FullName, CONSUMER_SETTINGS_FILE_NAME);
            string producerPath = Path.Combine(o.FullName, PRODUCER_SETTINGS_FILE_NAME);

            SaveConsumerSettings(consumerPath, consumerSettings);
            SaveProducerSettings(producerPath, producerSettings);
        }
Example #2
0
        private static void CreateRabbitMQQueues(string ms, string pg, string d, string u, string p, string rmq)
        {
            Console.Write(string.Format(CREATE_RABBITMQ_QUEUES_QUESTION, rmq));
            string answer = Console.ReadLine();

            if (answer.ToLowerInvariant() != "y")
            {
                return;
            }

            Console.Write(INPUT_HOST_TEXT);
            string host = Console.ReadLine();

            Console.Write(INPUT_PORT_TEXT);
            string port = Console.ReadLine();

            Console.Write(INPUT_USER_TEXT);
            string user = Console.ReadLine();

            Console.Write(INPUT_PASS_TEXT);
            string pass = Console.ReadLine();

            MessageProducerSettings settings = CreateMessageBrokerSettings(host, port, user, pass);

            IMetadataService metadataService = new MetadataService();

            if (!string.IsNullOrWhiteSpace(ms))
            {
                metadataService.UseDatabaseProvider(DatabaseProviders.SQLServer);
                metadataService.ConfigureConnectionString(ms, d, u, p);
            }
            else
            {
                metadataService.UseDatabaseProvider(DatabaseProviders.PostgreSQL);
                metadataService.ConfigureConnectionString(pg, d, u, p);
            }

            Console.WriteLine(LOADING_METADATA_NOTICE);
            InfoBase infoBase = metadataService.LoadInfoBase();

            Console.WriteLine(METADATA_LOADED_NOTICE);

            MetadataObject metaObject = infoBase.Publications.Values.Where(p => p.Name == rmq).FirstOrDefault();

            if (metaObject == null)
            {
                Console.WriteLine(string.Format(PUBLICATION_IS_NOT_FOUND_WARNING, rmq));
                return;
            }

            if (!(metaObject is Publication publication))
            {
                Console.WriteLine(string.Format(PUBLICATION_IS_NOT_FOUND_WARNING, rmq));
                return;
            }

            PublicationDataMapper mapper = new PublicationDataMapper();

            mapper.UseDatabaseProvider(metadataService.DatabaseProvider);
            mapper.UseConnectionString(metadataService.ConnectionString);
            mapper.SelectSubscribers(publication);

            using (IConnection messageBroker = CreateConnection(settings.MessageBrokerSettings))
            {
                string queueName;
                foreach (Subscriber subscriber in publication.Subscribers)
                {
                    if (subscriber.IsMarkedForDeletion)
                    {
                        continue;
                    }
                    queueName = CreateQueueName(publication.Publisher.Code, subscriber.Code);
                    CreateExchangeAndQueue(messageBroker, queueName);
                    queueName = CreateQueueName(subscriber.Code, publication.Publisher.Code);
                    CreateExchangeAndQueue(messageBroker, queueName);
                }
            }
        }