private int m_sleepTick = 60 * 60 * 1000 * 4; // 4 hours - while testing public TimerLogic() { m_timer = new Timer(); m_timer.Interval = m_tick; m_timer.Tick += delegate { m_log.Debug("Tick event happened"); m_timer.Stop(); // Commented until find bugs // if(MousePositionHelper.MouseNotMoving == false) // { List <Task> tasksToShow = new DbHelper().LoadTasksForShowing(); m_log.DebugFormat("Loaded {0} tasks for showing", tasksToShow.Count); foreach (Task task in tasksToShow) { new TaskShowController(task).PrepareWindow(); //Įkėliau viską į preparerį. m_log.DebugFormat("Showed task with id {0}, name {1}, showTime {2}", task.Id, task.Text, DBTypesConverter.ToFullDateStringByCultureInfo(task.DateRemainder)); } // } SetNewTimerInterval(); m_timer.Start(); }; m_timer.Start(); }
public void SaveNewTask(string dataEntered, AbstractMainForm form) { Task task = new Task().ParseString(dataEntered); if (task != null) { task.Save(); form.MTextBox.Text = string.Empty; m_log.DebugFormat("New task was saved. Name {0}, date {1}", task.Text, DBTypesConverter.ToFullDateStringByCultureInfo(task.DateRemainder)); } }
public void ParseRealTimeAndDisplay(object sender, EventArgs e) { string leftText; DateTime date; string remainderDateString; if (TextParser.Parse(m_mainForm.MTextBox.Text, out date, out leftText)) { remainderDateString = DBTypesConverter.ToFullDateStringByCultureInfo(date); } else { remainderDateString = "Unavailable"; } m_mainForm.MDateLabel.Content = remainderDateString; return; }
public void TestSave() { DateTime now = DateTime.Now; Task task = new Task("Darbas", now, "sourceId|15"); task.Save(); using (IConnection con = new ConnectionCollector().GetConnection()) { IDataReader reader = con.ExecuteReader("SELECT NAME, DATE_REMAINDER, SOURCE_ID, SHOWED FROM TASK"); Assert.IsTrue(reader.Read()); Assert.AreEqual(task.Text, reader.GetString(0)); Assert.AreEqual(DBTypesConverter.ToFullDateStringByCultureInfo(task.DateRemainder), reader.GetString(1)); Assert.AreEqual(task.SourceId, reader.GetString(2)); Assert.AreEqual(0, reader.GetInt32(3)); } }
public string FormatNextTaskRemindingDate() { int maxTimeTextLength = 38; // Text length without task description int maxLength = 64; // for NotifyIcon.Text property it's maximum int maxTaskNameLength = maxLength - maxTimeTextLength; string text = "Nothing to be mindered about"; Task nextTask = new DbHelper().NextTaskToShow(); if (nextTask == null) { return(text); } if (string.IsNullOrEmpty(nextTask.Text) == false && nextTask.Text.Length > maxTaskNameLength) { nextTask.Text = nextTask.Text.Substring(0, maxTaskNameLength); } DateTime?nextDate = nextTask.DateRemainder; if (nextDate.HasValue == false) { return(text); } text = string.Format("Task {0} minders at {1}", nextTask.Text, DBTypesConverter.ToFullDateStringByCultureInfo(nextDate.Value)); TimeSpan difference = nextDate.Value.Subtract(DateTime.Now); decimal days = RoundHelper.Round((decimal)difference.TotalDays, 0); if (days < 1) { text = string.Format("Task {0} minders at {1}", nextTask.Text, nextDate.Value.ToShortTimeString()); } decimal minutes = RoundHelper.Round((decimal)difference.TotalMinutes, 0); if (difference.TotalHours < 1) { text = string.Format("Task {0} minders in {1} minutes", nextTask.Text, minutes); } if (minutes < 1) { text = (string.Format("Task {0} minders in less than a minute", nextTask.Text)); } return(text); }
public override string ToString() { return(string.Format("[Task Id={0}, Text={1}, DateRemainder={2}]", m_id, m_text, DBTypesConverter.ToFullDateStringByCultureInfo(m_dateRemainder))); }
public void Sync() { if (string.IsNullOrEmpty(Static.StaticData.Settings.Sync.Id)) { return; } try { DateTime startSync = DateTime.Now; DateTime lastSyncDate = Minder.Static.StaticData.Settings.Sync.LastSyncDate; string dateSync = DBTypesConverter.ToFullDateStringByCultureInfo(lastSyncDate); // new ErrorBox(dateSync); List <Task> allTasks = GenericDbHelper.Get <Task>(string.Format("LAST_MODIFY_DATE >= '{0}'", dateSync)); SyncObject syncObject = new SyncObject(); syncObject.UserId = Static.StaticData.Settings.Sync.Id; syncObject.Tasks = new List <Task>(); syncObject.LastSyncDate = lastSyncDate.ToUniversalTime(); foreach (Task task in allTasks) { task.UserId = Static.StaticData.Settings.Sync.Id; syncObject.Tasks.Add(task); // task.LastModifyDate = task.LastModifyDate.ToUniversalTime(); // task.DateRemainder = task.DateRemainder.ToUniversalTime(); } //Paruošti taskai siuntimui List <Task> tasksFromServer = GetSyncedTasksFromServer(syncObject); SetLocalDate(allTasks.ToArray()); m_newTasks = tasksFromServer.Count; m_log.DebugFormat("Tasks' count retrieved from server {0}", m_newTasks); // using(IConnection con = new ConnectionCollector().GetConnection()) // { foreach (Task task in tasksFromServer) { task.LastModifyDate = task.LastModifyDate.ToLocalTime(); task.DateRemainder = task.DateRemainder.ToLocalTime(); foreach (Task localTask in allTasks) { if (localTask.Equals(task)) { m_newTasks--; } } if (ExistTask(task)) { //Negalime updatinti pagal ID, nes serveryje kitoks id. GenericDbHelper.RunDirectSql(string.Format("DELETE FROM TASK WHERE SOURCE_ID = '{0}'", task.SourceId)); GenericDbHelper.Save(task); m_log.DebugFormat("Updated existing task {0}", task); } else { GenericDbHelper.Save(task); m_log.DebugFormat("Created new task {0}", task); } } GenericDbHelper.Flush(); // } if (m_newTasks > 0) { if (Synced != null) { Synced(); } } Minder.Static.StaticData.Settings.Sync.LastSyncDate = DateTime.Now; TimeSpan span = DateTime.Now - startSync; m_log.InfoFormat("Synced in {0} seconds", span.TotalSeconds); } catch (Exception e) { m_log.Error(e); } }