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; }
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; }