/// <summary> /// Simple case, send one task /// </summary> public void Test_01_SimpleCase() { string userId = "TEST_SERVICE"; Task task1 = new Task(m_userId); task1.UserId = userId; task1.Text = "Test"; task1.SourceId = "SourceIdTest"; task1.DateRemainder = DateTime.Now.AddDays(1); List <Task> tasks = new List <Task>(); tasks.Add(task1); Minder.Objects.SyncObject syncObject = new Minder.Objects.SyncObject(); syncObject.LastSyncDate = DateTime.Now.AddHours(-1); syncObject.UserId = userId; syncObject.Tasks = tasks; List <Task> result = new SyncController().GetSyncedTasksFromServer(syncObject); Assert.AreEqual(1, result.Count); // We load directly, bypassing sync function and double check it result = GetAllTaskFromServer(); Assert.AreEqual(1, result.Count); }
private List <Task> CreateTaskOnServerReturnSyncResult(DateTime lastSyncDate, params Task[] task) { List <Task> tasks = new List <Task>(task); Minder.Objects.SyncObject syncObject = new Minder.Objects.SyncObject(); syncObject.LastSyncDate = lastSyncDate; syncObject.UserId = m_userId; syncObject.Tasks = tasks; return(new SyncController().GetSyncedTasksFromServer(syncObject)); }
private List <Task> GetAllTaskFromServer() { AdminObject deleteObject = new AdminObject(); deleteObject.UserId = m_userId; deleteObject.Password = ServicesConstants.DELETE_PASSWORD; string json = JsonHelper.ConvertToJson <AdminObject>(deleteObject); string requestString = "{\"json\" : \" "; requestString += Regex.Replace(json, "\"", "\\\""); requestString += "\"}"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://{0}/Minder.WebServices/Default.asmx/GetUserTasks", SyncController.SERVER_IP)); request.ContentType = "application/json; charset=utf-8"; request.Accept = "application/json, text/javascript, */*"; request.Method = "POST"; request.Timeout = 1000 * 10; //10 Seconds using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(requestString); } WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); string resultJson = ""; using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { resultJson += reader.ReadLine(); } } Minder.Objects.SyncObject result = JsonHelper.JsonToObject <Minder.Objects.SyncObject>(resultJson); return(result.Tasks); }
public void Test_01_SimpleCase() { string userId = "TEST_SERVICE"; Task task1 = new Task(m_userId); task1.UserId = userId; task1.Text = "Test"; task1.SourceId = "SourceIdTest"; task1.DateRemainder = DateTime.Now.AddDays(1); List<Task> tasks = new List<Task>(); tasks.Add(task1); Minder.Objects.SyncObject syncObject = new Minder.Objects.SyncObject(); syncObject.LastSyncDate = DateTime.Now.AddHours(-1); syncObject.UserId = userId; syncObject.Tasks = tasks; List<Task> result = new SyncController().GetSyncedTasksFromServer(syncObject); Assert.AreEqual(1, result.Count); // We load directly, bypassing sync function and double check it result = GetAllTaskFromServer(); Assert.AreEqual(1, result.Count); }
private List<Task> CreateTaskOnServerReturnSyncResult(DateTime lastSyncDate, params Task[] task) { List<Task> tasks = new List<Task>(task); Minder.Objects.SyncObject syncObject = new Minder.Objects.SyncObject(); syncObject.LastSyncDate = lastSyncDate; syncObject.UserId = m_userId; syncObject.Tasks = tasks; return new SyncController().GetSyncedTasksFromServer(syncObject); }
public List<Task> GetSyncedTasksFromServer(SyncObject syncObject) { string json = JsonHelper.ConvertToJson<SyncObject>(syncObject); string requestString = "{\"json\" : \" "; requestString += Regex.Replace(json, "\"", "\\\""); requestString += "\"}"; HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(string.Format("http://{0}/Minder.WebServices/Default.asmx/Sync", SERVER_IP)); request.ContentType = "application/json; charset=utf-8"; request.Accept = "application/json, text/javascript, */*"; request.Method = "POST"; request.Timeout = 1000 * 10; //10 Seconds using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(requestString); } WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); string resultJson = ""; using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { resultJson += reader.ReadLine(); } } SyncObject result = JsonHelper.JsonToObject<SyncObject>(resultJson); return result.Tasks; }
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); } }