コード例 #1
0
        private bool RemoveFromKH(Task task, int deleteIndex, int countToDelete)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.Combine("tasks", task.info.id + ".xml"));

            var rowDataElement = xmlDoc.DocumentElement.GetElementsByTagName("ROWDATA");

            if (rowDataElement.Count != 1)
            {
                throw new FormatException("Неправильный формат файла.");
            }

            var rows = rowDataElement[0].ChildNodes;

            var khMedium = new KalugaHouseMedium(KALUGA_HOUSE_URL);
            try
            {
                khMedium.Login(KHAccount.Key, KHAccount.Value);
            }
            catch (NetMediumException ex)
            {
                Log("KalugaHouse.ru не отвечает.");
                return false;
            }
            catch (LoginMediumException)
            {
                Log("KalugaHouse.ru логин или пароль не подходят.");
                return false;
            }
            catch (Exception ex)
            {
                Log(ex);
                return false;
            }

            for (int i = deleteIndex; i < task.info.count && i < deleteIndex + countToDelete; ++i)
            {
                var secId = rows[i].Attributes["RLT_MAIN_ID"].Value;
                secId = secId.Substring(0, secId.Length - 5);
                khMedium.RemoveItemBySecondId(secId);
            }
            return true;
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
        private void timerRun_Tick(object sender, EventArgs e)
        {
            if (!parseTimeSpans()) return;

            Agency40Medium ag40 = new Agency40Medium(AGENCY40_URL);
            KalugaHouseMedium kh = new KalugaHouseMedium(KALUGA_HOUSE_URL);

            CheckSend(ag40, kh);
            CheckApartmentRemoving(kh);
            CheckApartmentAdd(ag40);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
        private bool RemoveFromKH(Task task, int deleteIndex, int countToDelete, KalugaHouseMedium kh)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.Combine("tasks", task.info.id + ".xml"));

            var rowDataElement = xmlDoc.DocumentElement.GetElementsByTagName("ROWDATA");

            if (rowDataElement.Count != 1) {
                Log("Неправильный формат файла.");
                return false;
            }

            var rows = rowDataElement[0].ChildNodes;

            if (!loginKhIfNeed(kh)) {
                return false;
            }

            for (int i = deleteIndex; i < task.info.count && i < deleteIndex + countToDelete; ++i) {
                var secId = rows[i].Attributes["RLT_MAIN_ID"].Value;
                var nodeId = rows[i].Attributes["RLT_MAIN_NODEID"].Value.Trim();
                secId = secId.Substring(0, secId.Length - (1 + nodeId.Length));
                kh.RemoveItemBySecondId(secId);
            }
            return true;
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
 private bool loginKhIfNeed(KalugaHouseMedium kh)
 {
     if (!kh.logged) {
         try {
             kh.Login(KHAccount.Key, KHAccount.Value);
         } catch (NetMediumException) {
             Log("KalugaHouse.ru не отвечает.");
             return false;
         } catch (LoginMediumException) {
             Log("KalugaHouse.ru логин или пароль не подходят.");
             return false;
         } catch (Exception ex) {
             Log(ex);
             return false;
         }
     }
     return true;
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
        private void CheckSend(Agency40Medium ag40, KalugaHouseMedium kh)
        {
            DateTime now = DateTime.Now;

            if (!(now >= tsStartWork && now < tsEndWork)) return;

            for (int i = 0, taskCount = tasksManager.tasks.Count; i < taskCount; ++i)
            {
                var task = tasksManager.tasks[i];

                if (task.info.type != TaskType.Other)
                    continue;

                if (task.state.paused == true || task.addingErrorTimeout > now)
                    continue;

                if (task.state.addTimeout > now || task.state.index >= task.info.count)
                    continue;

                if(!loginAg40IfNeed(ag40)) {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    return;
                };

                // Удаление записи
                if (!RemoveFromKH(task, task.state.index, 1, kh))
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    continue;
                }
                Thread.Sleep(100);

                XmlDocument xmlDoc;
                try
                {
                    xmlDoc = Agency40Medium.GetPartOfXml(Path.Combine("tasks", task.info.id + ".xml"), task.state.index);
                }
                catch (Exception ex)
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    Log(ex);
                    continue;
                }

                try
                {
                    ag40.UploadXML(xmlDoc);
                    task.state.index++;
                    if (task.state.index < task.info.count)
                        task.state.addTimeout = CalculateNextAddTimeout(task);
                    task.Save();
                }
                catch (NetMediumException)
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    Log("Agency40.ru не отвечает.", true);
                    continue;
                }
                catch (Exception ex)
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    Log(ex);
                    continue;
                }

                // Проверка добавления
                //Thread.Sleep(300);
                //CheckEntryAndLog(task, task.state.index - 1, kh);
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
        private void CheckApartmentRemoving(KalugaHouseMedium kh)
        {
            var now = DateTime.Now;

            if (now >= tsApartmentDelete && now < tsApartmentDelete.AddHours(1)) {

                for (int i = 0; i < tasksManager.tasks.Count; ++i) {
                    var task = tasksManager.tasks[i];

                    if (task.state.paused == true || task.deletingErrorTimeout > now)
                        continue;

                    if (task.info.type == TaskType.ApartmentDeleting && task.state.index < task.info.count && task.state.lastRunDate.Date < now.Date) {

                        // Delete from task.index to task.index + dayCountToDelete
                        var daysLeast = (task.info.end.Date - now.Date).Days + 1;
                        if (daysLeast < 1) daysLeast = 1;
                        var entriesLeast = task.info.count - task.state.index;
                        var countToDelete = entriesLeast / daysLeast;

                        if (!loginKhIfNeed(kh)) {
                            return;
                        }

                        if (!RemoveFromKH(task, task.state.index, countToDelete, kh)) {
                            task.deletingErrorTimeout = DateTime.Now.AddMinutes(5);
                        } else {
                            task.state.index += countToDelete;
                            task.state.lastRunDate = now;
                            task.Save();
                        }
                    }
                }
            }
        }