Пример #1
0
        public static IEnumerable <MeasurePoint> GetMeasurePoints(this LersServer server, IEnumerable <string> criterias)
        {
            if (criterias == null || !criterias.Any())
            {
                throw new ArgumentException("Не заданы критерии для поиска объектов", nameof(criterias));
            }

            // Выбираем те точки учёта, у которых в имени и в адресе есть все переданные критерии

            return(server.MeasurePoints.GetList().Where(x => x.Type == MeasurePointType.Regular && string.Concat(x.FullTitle, x.Address).ContainsAll(criterias)));
        }
Пример #2
0
        public static IEnumerable <Node> GetNodes(this LersServer server, IEnumerable <string> criterias)
        {
            if (criterias == null)
            {
                throw new ArgumentException("Не заданы критерии для поиска объектов", nameof(criterias));
            }

            // Выбираем те объекты, у которых в имени и в адресе есть все переданные критерии

            return(server.Nodes.GetList().Where(x => string.Concat(x.Title, x.Address).ContainsAll(criterias)));
        }
Пример #3
0
        private void ShowCurrents(User user, string[] arguments)
        {
            if (user.Context == null)
            {
                throw new UnauthorizedCommandException(GetCurrentsCommand);
            }

            LersServer server = user.Context.Server;
            long       chatId = user.ChatId;

            var measurePoint = server.GetMeasurePoints(arguments).FirstOrDefault();

            if (measurePoint == null)
            {
                bot.SendText(chatId, "Точка учёта не найдена");
                return;
            }

            bot.SendText(chatId, $"Точка учёта {measurePoint.FullTitle}");

            var options = new MeasurePointPollCurrentOptions {
                StartMode = Lers.Common.PollManualStartMode.Force
            };

            int pollSessionId = measurePoint.PollCurrent(options);

            bot.SendText(chatId, "Запущен опрос");

            var autoResetEvent = new System.Threading.AutoResetEvent(false);

            MeasurePointData.CurrentsSaved += (sender, e) =>
            {
                try
                {
                    SendCurrents(chatId, e.Consumption);

                    autoResetEvent.Set();
                }
                catch (Exception exc)
                {
                    bot.SendText(chatId, exc.Message);
                }
            };

            MeasurePointData.SubscribeSaveCurrents(server, pollSessionId);

            if (!autoResetEvent.WaitOne(120000))
            {
                bot.SendText(chatId, "Не удалось получить текущие данные за 2 минуты.");
            }

            MeasurePointData.UnsubscribeSaveCurrents(server);
        }
Пример #4
0
        /// <summary>
        /// Устанавливает подключение к серверу.
        /// </summary>
        /// <param name="serverConfig"></param>
        /// <returns></returns>
        private static LersServer ConnectServer(ServerConfig serverConfig)
        {
            logger.Info($"Подключение к серверу {serverConfig.Address}:{serverConfig.Port}");

            var server = new LersServer("Утилита синхронизации данных по точкам учёта.");

            // Игнорируем разницу в версиях.
            server.VersionMismatch += (sender, e) => e.Ignore = true;

            server.Connect(serverConfig.Address, serverConfig.Port, new Lers.Networking.BasicAuthenticationInfo(
                               serverConfig.Login, Lers.Networking.SecureStringHelper.ConvertToSecureString(serverConfig.Password)));

            return(server);
        }
Пример #5
0
        private void LersConnect()
        {
            lersServer = new LersServer();

            string login        = tbLogin.Text;
            string secureString = tbPassword.Text;

            SecureString password = new SecureString();

            foreach (char symbol in secureString)
            {
                password.AppendChar(symbol);
            }

            BasicAuthenticationInfo authInfo = new BasicAuthenticationInfo(login, password);

            try
            {
                //Игнорируем разницу в версиях в ЛЭРС Учет
                lersServer.VersionMismatch += (sender, e) => e.Ignore = true;

                lersServer.Connect(tbServer.Text, Convert.ToUInt16(tbPort.Text), authInfo);
            }
            catch (ServerConnectionException connection)
            {
                MessageBox.Show(connection.Message, "Ошибка подключения", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbLogin.Select();
                return;
            }
            catch (AuthorizationFailedException authorization)
            {
                MessageBox.Show(authorization.Message, "Ошибка входа", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbLogin.Select();
                return;
            }
            catch (LersServerException server)
            {
                MessageBox.Show(server.Message, "Ошибка обработки запроса сервером", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbLogin.Select();
                return;
            }
        }
Пример #6
0
        public MobileCore()
        {
            this.Server = new LersServer("Lers android");

            this.Server.VersionMismatch += (sender, e) => e.Ignore = true;
        }