private void btnShowAddForm_Click(object sender, EventArgs e) { var form = new AddTaskForm(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var taskInfo = form.ResultTaskInfo; var taskState = new TaskState(); taskState.index = 0; if (taskInfo.apartment) { var THREE = 3; taskState.addTimeout = DateTime.Now.AddDays(THREE); } else taskState.addTimeout = DateTime.Now; taskState.Serialize(Path.Combine("tasks", taskInfo.id + ".state.data")); var task = new Task(taskInfo.id); tasksManager.tasks.Add(task); tasksManager.Save(); RefreshTable(sender, null); Log("Задача успешно добавлена. Количество добавленых записей: " + task.info.count + "."); } }
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 DateTime CalculateNextAddTimeout(Task task) { var remainingMinutes = task.info.calcRemainingTimeMinutes(); var remainingCount = task.info.count - task.state.index; return DateTime.Now.AddSeconds(remainingMinutes * 60 / remainingCount); }