Exemple #1
0
        [TestMethod("PG-02 Загрузка узлов")] public void PG_02()
        {
            ApplicationObject publication = Test.PG_InfoBase
                                            .Publications.Values
                                            .Where(r => r.Name == "ПланОбмена")
                                            .FirstOrDefault();

            Assert.IsNotNull(publication);

            PublicationDataMapper mapper = new PublicationDataMapper();

            mapper.UseConnectionString(Test.PG_ConnectionString);
            mapper.UseDatabaseProvider(DatabaseProvider.PostgreSQL);
            mapper.SelectSubscribers((Publication)publication);

            Assert.IsNotNull(((Publication)publication).Publisher);
        }
Exemple #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);
                }
            }
        }