Exemplo n.º 1
0
        public static ConfigNotificationParameter ReadNotifConfig()
        {
            string line;
            ConfigNotificationParameter NotifData = new ConfigNotificationParameter();

            try
            {
                StreamReader file = new StreamReader(@"ConfigNotifications.jsn");
                line = file.ReadToEnd();

                JavaScriptSerializer        js      = new JavaScriptSerializer();
                ConfigNotificationParameter confPar = js.Deserialize <ConfigNotificationParameter>(line);

                NotifData = confPar;

                return(NotifData);
            }
            catch (Exception)
            {
                NotifData.Error = "Ошибка ConfigNotifications.jsn";
                return(NotifData);
            }
        }
Exemplo n.º 2
0
        public void ThreadTestResourses()
        {
            ProcessingsView = new ObservableCollection <Resources> {
            };
            MobilesView     = new ObservableCollection <Resources> {
            };
            OthersView      = new ObservableCollection <Resources> {
            };

            List <Resources> Resources = new List <Resources>();

            ConfigResourceParameter     ResourceData = new ConfigResourceParameter();
            ConfigNotificationParameter NotifData    = new ConfigNotificationParameter();

            string[] getStatus = { String.Empty, String.Empty };
            string   messageOffline, messageElectCard, message = String.Empty;
            int      electCard = 0;

            ResourceData = GetConfigs.ReadResourceConfig();
            NotifData    = GetConfigs.ReadNotifConfig();

            if (!String.IsNullOrEmpty(ResourceData.Error) | !String.IsNullOrEmpty(NotifData.Error))
            {
                statusInfo      = ResourceData.Error + " " + NotifData.Error;
                colorBackground = Variables.alertColor;
            }
            else
            {
                while (true)
                {
                    Resources.Clear();

                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        ProcessingsView.Clear();
                        MobilesView.Clear();
                        OthersView.Clear();
                    }));

                    Array.Clear(getStatus, 0, 1);
                    messageOffline   = string.Empty;
                    messageElectCard = string.Empty;
                    message          = string.Empty;
                    countDown        = "Пуск";

                    getStatus       = AdditionalFunc.GetStatus(ResourceData.FlagFilePath, ResourceData.SleepTime);
                    title           = getStatus[0];
                    colorBackground = getStatus[2];

                    for (int j = 0; j < ResourceData.Applications.Length; j++)
                    {
                        statusInfo    = "Проверка " + ResourceData.Applications[j].Name;
                        statusToolTip = "Адрес ресурса: " + ResourceData.Applications[j].Address;

                        Resources.Add(ResoursesInfo.GetResourseInfo(ResourceData.Applications[j]));

                        if (String.Equals(ResourceData.Applications[j].AppType, Variables.processingType))
                        {
                            ResourceData.Applications[j].requestId = Resources[j].requestId;
                            ResourceData.Applications[j].cardNum   = Resources[j].cardNum;

                            Application.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                ProcessingsView.Add(Resources[j]);
                            }));
                        }

                        if (String.Equals(ResourceData.Applications[j].AppType, Variables.mobileType))
                        {
                            Application.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                MobilesView.Add(Resources[j]);
                            }));

                            Int32.TryParse(Resources[j].sucReqElectCard, out electCard);
                        }

                        if (String.Equals(ResourceData.Applications[j].AppType, Variables.otherType))
                        {
                            Application.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                OthersView.Add(Resources[j]);
                            }));
                        }

                        if (String.Equals(Resources[j].status, Variables.offline))
                        {
                            colorBackground = Variables.alertColor;

                            if (String.IsNullOrEmpty(messageOffline))
                            {
                                messageOffline = Resources[j].name + " - оффлайн!";
                            }
                            else
                            {
                                messageOffline = Resources[j].name + ", " + messageOffline;
                            }
                        }

                        if (String.Equals(ResourceData.Applications[j].AppType, Variables.mobileType) & (electCard < Variables.electCardAlert))
                        {
                            colorBackground = Variables.alertColor;

                            if (String.IsNullOrEmpty(messageElectCard))
                            {
                                messageElectCard = Resources[j].name + " - электронных карт осталось меньше " + Variables.electCardAlert;
                            }
                            else
                            {
                                messageElectCard = Resources[j].name + ", " + messageElectCard;
                            }
                        }
                    }

                    if ((!String.IsNullOrEmpty(messageOffline) & String.Equals(getStatus[1], Variables.sendMessage)) | !String.IsNullOrEmpty(messageElectCard))
                    {
                        if (!String.IsNullOrEmpty(messageOffline) & !String.IsNullOrEmpty(messageElectCard))
                        {
                            message = DateTime.Now.ToString("dd-MM HH:mm") + "\n" + getStatus[3] + messageOffline + "\n" + messageElectCard;
                        }
                        else
                        {
                            message = DateTime.Now.ToString("dd-MM HH:mm") + "\n" + getStatus[3] + messageOffline + messageElectCard;
                        }

                        if (NotifData.Channel == "T" | NotifData.Channel == "Telegram")
                        {
                            if (TelegramBot.SendTelegram(NotifData.TelegramParams, message) == Variables.requestStateError)
                            {
                                message = "Прокси более не доступен\n" + message;

                                for (int cnt = 0; cnt < NotifData.SMSParams.MobileNotifications.Length; cnt++)
                                {
                                    AdditionalFunc.SendSMS(NotifData.SMSParams.MobileNotifications[cnt], NotifData.SMSParams.SenderName, message);
                                }
                            }
                            else if (NotifData.Channel == "S" | NotifData.Channel == "SMS")
                            {
                                for (int cnt = 0; cnt < NotifData.SMSParams.MobileNotifications.Length; cnt++)
                                {
                                    AdditionalFunc.SendSMS(NotifData.SMSParams.MobileNotifications[cnt], NotifData.SMSParams.SenderName, message);
                                }
                            }
                        }
                    }

                    statusInfo    = "Проверка закончена!\n" + DateTime.Now;
                    statusToolTip = null;

                    for (cnt = ResourceData.ExaminePause; cnt >= 0; cnt--)
                    {
                        countDown = cnt.ToString();
                        Thread.Sleep(1000);
                    }
                }
            }
        }