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;
        }
Esempio n. 2
0
 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;
 }