Beispiel #1
0
        static void Main(string[] args)
        {
            ControlServerDB serverDB = null;

            try
            {
                int daysSecond = ReadDaysSecond();
                serverDB = new ControlServerDB(daysSecond);
                if (serverDB.MongoClientsAvailability())
                {
                    serverDB.ObjectOverload();
                }
                serverDB.StartListeningQueuesRabbit();
                Console.WriteLine("Сервер запущен. Нажмите любую клавишу для заершения работы.");
                Console.ReadKey();
            }
            catch (Exception exception)
            {
                if (!ControlServerDB.CheckException(exception))
                {
                    Log.Error(exception.ToString);
                }
            }
            finally
            {
                if (serverDB != null)
                {
                    serverDB.StopServer();
                }
                else
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Конструктор объекта имитации деятельности клиента
 /// </summary>
 /// <param name="clientServer"></param>
 /// <param name="serverDB"></param>
 public ImitationClientActivity(ClientServerDB clientServer, ControlServerDB serverDB)
 {
     ServerDB            = serverDB;
     ClientServer        = clientServer;
     ImitationActivity   = new Thread(new ThreadStart(GettingAndReadingBook));
     MutexJointOperation = new Mutex();
     MySqlConnection     = new MySqlSDB(ServerDB);
     MongoConnection     = new MongoDbSDB(ServerDB);
     WaitHandler         = new AutoResetEvent(true);
 }
Beispiel #3
0
 /// <summary>
 /// Получение и чтение книг клиентом
 /// </summary>
 private void GettingAndReadingBook()
 {
     try
     {
         TryGettingAndReadingBook();
     }
     catch (Exception exception)
     {
         if (!ControlServerDB.CheckException(exception))
         {
             Log.Error(exception.ToString);
         }
         ServerDB.StopServer();
     }
 }
        /// <summary>
        /// Конструктор объекта работы с MongoDB
        /// </summary>
        public MongoDbSDB(ControlServerDB serverDB)
        {
            ServerDB = serverDB;
            string         connectionStringMongo = ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString;;
            string         dataBase      = "SystemDistributionBook";
            string         collection    = "SDBCollection";
            MongoClient    ClientMongo   = new MongoClient(connectionStringMongo);
            IMongoDatabase DatabaseMongo = ClientMongo.GetDatabase(dataBase);

            try
            {
                DatabaseMongo.RunCommand((Command <BsonDocument>) "{ping:1}");
            }
            catch (Exception exception)
            {
                Log.Error(exception.ToString);
                ServerDB.StopServer();
            }
            CollectionMongo = DatabaseMongo.GetCollection <ClientServerDB>(collection);
        }
Beispiel #5
0
        /// <summary>
        /// Конструктор объекта работы с MySQL
        /// </summary>
        public MySqlSDB(ControlServerDB serverDB)
        {
            ServerDB = serverDB;
            string connectionString = ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString;

            ConnectionMySQL = new MySqlConnection(connectionString);
            try
            {
                ConnectionMySQL.Open();
            }
            catch (Exception exception)
            {
                Log.Error(exception.ToString);
                StopApplication();
            }
            finally
            {
                ConnectionMySQL.Close();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Конструктор объекта работы с RabbitMQ
        /// </summary>
        /// <param name="serverDB">Объект управления сервером</param>
        public RabbitmqSDB(ControlServerDB serverDB)
            : base()
        {
            ServerDB = serverDB;
            InitializationStringComponentSDB();

            try
            {
                ChannelBook.QueueDeclare(QueueUnallocated, true, false, false, null);
                ChannelBook.QueueBind(QueueUnallocated, ExchangeBook, RoutingUnallocated, null);

                ConsumerBook   = new EventingBasicConsumer(ChannelBook);
                ConsumerClient = new EventingBasicConsumer(ChannelClient);
            }
            catch (Exception exception)
            {
                Log.Error(exception.ToString);
                StopApplication();
            }

            InitializationMethodsConsumers();
        }
Beispiel #7
0
 /// <summary>
 /// Конструктор списка имитаций деятельности клиентов
 /// </summary>
 /// <param name="serverDB">Объект управления сервером</param>
 public GroupImitationClientActivity(ControlServerDB serverDB)
 {
     ServerDB         = serverDB;
     ClientDictionary = new Dictionary <string, ImitationClientActivity>();
 }