Пример #1
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);
                }
            }
        }
Пример #2
0
 private bool loginAg40IfNeed(Agency40Medium ag40)
 {
     if(!ag40.logged) {
         try {
             ag40.Login(Ag40Account.Key, Ag40Account.Value);
         } catch (NetMediumException) {
             Log("Agency40.ru не отвечает.", true);
             return false;
         } catch (LoginMediumException) {
             Log("Agency40.ru логин или пароль не подходят.", true);
             return false;
         } catch (Exception ex) {
             Log(ex);
             return false;
         }
     }
     return true;
 }