コード例 #1
0
ファイル: MainForm.cs プロジェクト: Bacher/cabinet-scheduler
        private void CheckApartmentAdd(Agency40Medium ag40)
        {
            var now = DateTime.Now;

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

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

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

                    if (task.info.type == TaskType.ApartmentAdding && task.info.end.Date >= now.Date && task.state.lastRunDate.Date < now.Date) {

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

                        var success = true;
                        int iterationCount = 10;

                        int step = (int)(task.info.count / iterationCount + 0.5);

                        for (var j = 0; j < iterationCount; ++j) {
                            var countLeast = task.info.count - step * j;
                            var count = countLeast < step ? countLeast : step;

                            var xmlDoc = Agency40Medium.GetPartOfXml(Path.Combine("tasks", task.info.id + ".xml"), step * j, count);
                            if (xmlDoc == null) continue;
                            try {
                                ag40.UploadXML(xmlDoc);
                            } catch {
                                task.addingErrorTimeout = now.AddMinutes(5);
                                success = false;
                                break;
                            }
                        }
                        if(success) {
                            task.state.lastRunDate = now;
                            task.Save();
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void CheckSend()
        {
            DateTime now = DateTime.Now;

            Agency40Medium ag40 = new Agency40Medium(AGENCY40_URL);
            bool logged = false;

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

                if (task.addingErrorTimeout > now)
                    continue;

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

                if (task.info.apartment && !task.state.CheckAvailableDeleteIndex(now, task.state.index))
                    continue;

                if (!logged)
                {
                    try
                    {
                        ag40.Login(Ag40Account.Key, Ag40Account.Value);
                        logged = true;
                    }
                    catch (NetMediumException)
                    {
                        task.addingErrorTimeout = now.AddMinutes(5);
                        Log("Agency40.ru не отвечает.", true);
                        return;
                    }
                    catch (LoginMediumException)
                    {
                        task.addingErrorTimeout = now.AddMinutes(5);
                        Log("Agency40.ru логин или пароль не подходят.", true);
                        return;
                    }
                    catch (Exception ex)
                    {
                        task.addingErrorTimeout = now.AddMinutes(5);
                        Log(ex);
                        continue;
                    }
                }

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

                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
                {
                    //Log("Send " + DateTime.Now.ToString());
                    ag40.UploadXML(xmlDoc);
                    task.state.index++;
                    if (task.state.index < task.info.count)
                        task.state.addTimeout = CalculateNextAddTimeout(task);
                    task.Save();
                }
                catch (NetMediumException ex)
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    Log("Agency40.ru не отвечает.", true);
                }
                catch (Exception ex)
                {
                    task.addingErrorTimeout = now.AddMinutes(5);
                    Log(ex);
                }
            }
        }
コード例 #3
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);
            }
        }