public void FillEntity(EfTask entity, TaskJson domainObject) { entity.ID = Guid.Parse(domainObject.ID); entity.Title = domainObject.Title; entity.UnitID = Guid.Parse(domainObject.UnitID); entity.StartDate = DateTime.Parse(domainObject.StartDate); entity.MeetingId = Guid.Parse(domainObject.MeetingID); entity.EstimatedTimeHore = int.Parse(domainObject.EstimatedTimeHore); entity.EstimatedTimeMin = int.Parse(domainObject.EstimatedTimeMin); entity.EstimatedTimeSumMinut = ((entity.EstimatedTimeHore * 60) + entity.EstimatedTimeMin); entity.MasolAnjamID = Guid.Parse(domainObject.MasolAnjamID); entity.Aprove1ID = Guid.Parse(domainObject.Aprove1ID); //if(entity.Aprove2ID!=null) //{ // entity.Aprove2ID = Guid.Parse(domainObject.Aprove2ID); //} //if (entity.Aprove3ID != null) //{ // entity.Aprove3ID = Guid.Parse(domainObject.Aprove3ID); //} //if (entity.Aprove4ID != null) //{ // entity.Aprove4ID = Guid.Parse(domainObject.Aprove4ID); //} entity.IsCarent = int.Parse(domainObject.IsCarent); entity.Persent = int.Parse(domainObject.Persent); entity.StatusSave = int.Parse(domainObject.StatusSave); entity.TarikhStart = domainObject.TarikhStart; }
public EfTask ToEntity(TaskJson domainObject) { var entity = new EfTask(); FillEntity(entity, domainObject); return(entity); }
public void ImportMissingWorkspaceAndProject() { RunAsync(async delegate { var taskJson = new TaskJson() { Id = 2, Name = "Install Linux", WorkspaceId = 1, ProjectId = 2, ModifiedAt = new DateTime(2014, 1, 3), }; var taskData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, taskJson)); Assert.AreNotEqual(Guid.Empty, taskData.WorkspaceId); var workspaceRows = await DataStore.Table <WorkspaceData> ().Where(m => m.Id == taskData.WorkspaceId).ToListAsync(); var workspaceData = workspaceRows.FirstOrDefault(); Assert.IsNotNull(workspaceData); Assert.IsNotNull(workspaceData.RemoteId); Assert.AreEqual(DateTime.MinValue, workspaceData.ModifiedAt); var projectRows = await DataStore.Table <ProjectData> ().Where(m => m.Id == taskData.ProjectId).ToListAsync(); var projectData = projectRows.FirstOrDefault(); Assert.IsNotNull(projectData); Assert.IsNotNull(projectData.RemoteId); Assert.AreEqual(DateTime.MinValue, projectData.ModifiedAt); }); }
public static TaskData Import(this TaskJson json, IDataStoreContext ctx, Guid?localIdHint = null, TaskData mergeBase = null) { var converter = ServiceContainer.Resolve <TaskJsonConverter> (); return(converter.Import(ctx, json, localIdHint, mergeBase)); }
public TaskJson ToDomainObject(EfTask entity) { TaskJson _TaskJson = new TaskJson(); _TaskJson.ID = entity.ID.ToString(); _TaskJson.Title = entity.Title; _TaskJson.UnitID = entity.UnitID.ToString(); _TaskJson.MeetingID = entity.MeetingId.ToString(); _TaskJson.EstimatedTimeHore = entity.EstimatedTimeHore.ToString(); _TaskJson.EstimatedTimeMin = entity.EstimatedTimeMin.ToString(); // _TaskJson.EstimatedTimeMin = ((entity.EstimatedTimeHore * 60) + entity.EstimatedTimeMin).ToString(); _TaskJson.EstimatedTimeText = _TaskJson.EstimatedTimeHore + "." + _TaskJson.EstimatedTimeMin; _TaskJson.MasolAnjamFullName = new UserTranslator().ToDomainObject(entity.MasolAnjam).FullName; _TaskJson.Aprove1IDFullName = new UserTranslator().ToDomainObject(entity.Aprove1).FullName; _TaskJson.MasolAnjamID = entity.MasolAnjam.ToString(); _TaskJson.Aprove1ID = entity.Aprove1ID.ToString(); //_TaskJson.Aprove2ID = entity.Aprove2ID.ToString(); //_TaskJson.Aprove3ID = entity.Aprove3ID.ToString(); //_TaskJson.Aprove4ID = entity.Aprove4ID.ToString(); _TaskJson.IsCarent = entity.IsCarent.ToString(); _TaskJson.Persent = entity.Persent.ToString(); _TaskJson.StatusSave = entity.StatusSave.ToString(); _TaskJson.TarikhStart = entity.TarikhStart.ToString(); return(_TaskJson); }
public TaskData Import (IDataStoreContext ctx, TaskJson json, Guid? localIdHint = null, TaskData mergeBase = null) { var data = GetByRemoteId<TaskData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new TaskMerger (mergeBase) : null; if (merger != null && data != null) merger.Add (new TaskData (data)); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new TaskData (); ImportJson (ctx, data, json); if (merger != null) { merger.Add (data); data = merger.Result; } data = ctx.Put (data); } return data; }
public void UseCloudData() { var result = GetCloudTaskData(); try { JArray localTaskArray = (JArray)JsonConvert.DeserializeObject(result); List <TaskJson> taskJsons = new List <TaskJson>(); PushData pushData = new PushData(); pushData.UserName = userName; pushData.Token = token; foreach (var item in localTaskArray) { TaskJson taskJson = new TaskJson { TaskId = item["TaskId"].ToString(), TaskName = item["TaskName"].ToString(), Date = item["Date"].ToString(), Star = item["Star"].ToString(), Done = item["Done"].ToString(), Remark = item["Remark"].ToString(), UpdateTime = item["UpdateTime"].ToString(), IsDelete = item["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = item["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } pushData.TaskList = taskJsons; string pushDataJsonStr = JsonConvert.SerializeObject(pushData); PushDataToLocal(pushDataJsonStr); } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + e.Message); popupNotice.ShowAPopup(); }); } }
private static void Merge (IDataStoreContext ctx, TaskData data, TaskJson json) { var projectId = GetLocalId<ProjectData> (ctx, json.ProjectId); var workspaceId = GetLocalId<WorkspaceData> (ctx, json.WorkspaceId); data.Name = json.Name; data.IsActive = json.IsActive; data.Estimate = json.Estimate; data.ProjectId = projectId; data.WorkspaceId = workspaceId; MergeCommon (data, json); }
private static void ImportJson(IDataStoreContext ctx, TaskData data, TaskJson json) { var projectId = GetLocalId <ProjectData> (ctx, json.ProjectId); var workspaceId = GetLocalId <WorkspaceData> (ctx, json.WorkspaceId); data.Name = json.Name; data.IsActive = json.IsActive; data.Estimate = json.Estimate; data.ProjectId = projectId; data.WorkspaceId = workspaceId; ImportCommonJson(data, json); }
public void ImportUpdated() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var projectData = await DataStore.PutAsync(new ProjectData() { RemoteId = 3, Name = "Hosting", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 2), }); var taskData = await DataStore.PutAsync(new TaskData() { RemoteId = 2, Name = "", WorkspaceId = workspaceData.Id, ProjectId = projectData.Id, ModifiedAt = new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), }); var taskJson = new TaskJson() { Id = 2, Name = "Install Linux", WorkspaceId = 1, ProjectId = 3, ModifiedAt = new DateTime(2014, 1, 2, 10, 1, 0, DateTimeKind.Utc).ToLocalTime(), // JSON deserialized to local }; taskData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, taskJson)); Assert.AreNotEqual(Guid.Empty, taskData.Id); Assert.AreEqual(2, taskData.RemoteId); Assert.AreEqual("Install Linux", taskData.Name); Assert.AreEqual(new DateTime(2014, 1, 2, 10, 1, 0, DateTimeKind.Utc), taskData.ModifiedAt); Assert.AreEqual(workspaceData.Id, taskData.WorkspaceId); Assert.AreEqual(projectData.Id, taskData.ProjectId); Assert.IsFalse(taskData.IsDirty); Assert.IsFalse(taskData.RemoteRejected); Assert.IsNull(taskData.DeletedAt); }); // Warn the user that the test result might be invalid if (TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes >= 0) { Assert.Inconclusive("The test machine timezone should be set to GTM-1 or less to test datetime comparison."); } }
public void UseLocalData() { var result = GetLocalTaskData(); try { JArray localTaskArray = (JArray)JsonConvert.DeserializeObject(result); List <TaskJson> taskJsons = new List <TaskJson>(); PushData pushData = new PushData(); pushData.UserName = userName; pushData.Token = token; foreach (var item in localTaskArray) { TaskJson taskJson = new TaskJson { TaskId = item["TaskId"].ToString(), TaskName = item["TaskName"].ToString(), Date = item["Date"].ToString(), Star = item["Star"].ToString(), Done = item["Done"].ToString(), Remark = item["Remark"].ToString(), UpdateTime = item["UpdateTime"].ToString(), IsDelete = item["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = item["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } pushData.TaskList = taskJsons; string pushDataJsonStr = JsonConvert.SerializeObject(pushData); PushDataToCloud(pushDataJsonStr); } catch { } }
public TaskData Import(IDataStoreContext ctx, TaskJson json, Guid?localIdHint = null, TaskData mergeBase = null) { var log = ServiceContainer.Resolve <Logger> (); var data = GetByRemoteId <TaskData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new TaskMerger(mergeBase) : null; if (merger != null && data != null) { merger.Add(new TaskData(data)); } if (json.DeletedAt.HasValue) { if (data != null) { log.Info(Tag, "Deleting local data for {0}.", data.ToIdString()); ctx.Delete(data); data = null; } } else if (merger != null || ShouldOverwrite(data, json)) { data = data ?? new TaskData(); ImportJson(ctx, data, json); if (merger != null) { merger.Add(data); data = merger.Result; } if (merger != null) { log.Info(Tag, "Importing {0}, merging with local data.", data.ToIdString()); } else { log.Info(Tag, "Importing {0}, replacing local data.", data.ToIdString()); } data = ctx.Put(data); } else { log.Info(Tag, "Skipping import of {0}.", json.ToIdString()); } return(data); }
public string GetLocalTaskData() { try { List <ToDoTasks> taskListDB = conn.Query <ToDoTasks>("select * from ToDoTasks"); List <TaskJson> taskJsons = new List <TaskJson>(); foreach (var item in taskListDB) { TaskJson taskJson = new TaskJson(); taskJson.TaskId = item.TaskId; taskJson.TaskName = item.Name; taskJson.Date = item.Date; taskJson.Star = item.Star; taskJson.Done = item.Done; taskJson.Remark = item.Remark; taskJson.UpdateTime = item.UpdateTime; taskJson.IsDelete = item.IsDelete; List <ToDoTaskSteps> stepListDB = conn.Query <ToDoTaskSteps>("select *from ToDoTaskSteps where TaskId = ?", item.TaskId); List <StepJson> stepJsons = new List <StepJson>(); foreach (var subItem in stepListDB) { StepJson stepJson = new StepJson(); stepJson.TaskId = subItem.TaskId; stepJson.StepId = subItem.StepId; stepJson.Content = subItem.Content; if (subItem.Finish) { stepJson.Done = "1"; } else { stepJson.Done = "0"; } stepJson.UpdateTime = subItem.UpdateTime; stepJson.IsDelete = subItem.IsDelete; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } return(JsonConvert.SerializeObject(taskJsons)); } catch (Exception e) { return(e.Message); } }
public TaskData Import (IDataStoreContext ctx, TaskJson json, Guid? localIdHint = null, bool forceUpdate = false) { var data = GetByRemoteId<TaskData> (ctx, json.Id.Value, localIdHint); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (data == null || forceUpdate || data.ModifiedAt < json.ModifiedAt) { data = data ?? new TaskData (); Merge (ctx, data, json); data = ctx.Put (data); } return data; }
public void ImportUpdatedOverwriteRejectedLocal() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var projectData = await DataStore.PutAsync(new ProjectData() { RemoteId = 3, Name = "Hosting", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 2), }); var taskData = await DataStore.PutAsync(new TaskData() { RemoteId = 2, Name = "", WorkspaceId = workspaceData.Id, ProjectId = projectData.Id, ModifiedAt = new DateTime(2014, 1, 2, 10, 1, 0, DateTimeKind.Utc), IsDirty = true, RemoteRejected = true, }); var taskJson = new TaskJson() { Id = 2, Name = "Install Linux", WorkspaceId = 1, ProjectId = 3, ModifiedAt = new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc).ToLocalTime(), }; taskData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, taskJson)); Assert.AreEqual("Install Linux", taskData.Name); Assert.AreEqual(new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), taskData.ModifiedAt); }); }
public TaskData Import (IDataStoreContext ctx, TaskJson json, Guid? localIdHint = null, TaskData mergeBase = null) { var log = ServiceContainer.Resolve<ILogger> (); var data = GetByRemoteId<TaskData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new TaskMerger (mergeBase) : null; if (merger != null && data != null) { merger.Add (new TaskData (data)); } if (json.DeletedAt.HasValue) { if (data != null) { log.Info (Tag, "Deleting local data for {0}.", data.ToIdString ()); ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new TaskData (); ImportJson (ctx, data, json); if (merger != null) { merger.Add (data); data = merger.Result; } if (merger != null) { log.Info (Tag, "Importing {0}, merging with local data.", data.ToIdString ()); } else { log.Info (Tag, "Importing {0}, replacing local data.", data.ToIdString ()); } data = ctx.Put (data); } else { log.Info (Tag, "Skipping import of {0}.", json.ToIdString ()); } return data; }
public void ImportPastDeleted() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var projectData = await DataStore.PutAsync(new ProjectData() { RemoteId = 3, Name = "Hosting", WorkspaceId = Guid.NewGuid(), ModifiedAt = new DateTime(2014, 1, 2), }); var taskData = await DataStore.PutAsync(new TaskData() { RemoteId = 2, Name = "Install Linux", WorkspaceId = workspaceData.Id, ProjectId = projectData.Id, ModifiedAt = new DateTime(2014, 1, 3), }); var taskJson = new TaskJson() { Id = 2, DeletedAt = new DateTime(2014, 1, 2), }; var ret = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, taskJson)); Assert.IsNull(ret); var rows = await DataStore.Table <TaskData> ().Where(m => m.Id == taskData.Id).ToListAsync(); Assert.That(rows, Has.Exactly(0).Count); }); }
public void ImportNew() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var projectData = await DataStore.PutAsync(new ProjectData() { RemoteId = 3, Name = "Hosting", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 2), }); var taskJson = new TaskJson() { Id = 2, Name = "Install Linux", WorkspaceId = 1, ProjectId = 3, ModifiedAt = new DateTime(2014, 1, 3), }; var taskData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, taskJson)); Assert.AreNotEqual(Guid.Empty, taskData.Id); Assert.AreEqual(2, taskData.RemoteId); Assert.AreEqual("Install Linux", taskData.Name); Assert.AreEqual(new DateTime(2014, 1, 3), taskData.ModifiedAt); Assert.AreEqual(workspaceData.Id, taskData.WorkspaceId); Assert.AreEqual(projectData.Id, taskData.ProjectId); Assert.IsFalse(taskData.IsDirty); Assert.IsFalse(taskData.RemoteRejected); Assert.IsNull(taskData.DeletedAt); }); }
public void MergeData() { try { var localData = GetLocalTaskData(); var cloudData = GetCloudTaskData(); JArray cloudTaskArray = (JArray)JsonConvert.DeserializeObject(cloudData); JArray localTaskArray = (JArray)JsonConvert.DeserializeObject(localData); List <TaskJson> taskJsons = new List <TaskJson>(); PushData pushData = new PushData(); pushData.UserName = userName; pushData.Token = token; foreach (var cloudTaskItem in cloudTaskArray) { string taskId = cloudTaskItem["TaskId"].ToString(); List <ToDoTasks> tempList = conn.Query <ToDoTasks>("select * from ToDoTasks where TaskId = ?", taskId); if (tempList.Count == 0) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { string localUpdateTimeStr = tempList[0].UpdateTime; string cloudUpdateTimeStr = cloudTaskItem["UpdateTime"].ToString(); DateTime localUpdateTime = Convert.ToDateTime(localUpdateTimeStr); DateTime cloudUpdateTime = Convert.ToDateTime(cloudUpdateTimeStr); if (cloudUpdateTime >= localUpdateTime) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { TaskJson taskJson = new TaskJson { TaskId = tempList[0].TaskId, TaskName = tempList[0].Name, Date = tempList[0].Date, Star = tempList[0].Star, Done = tempList[0].Done, Remark = tempList[0].Remark, UpdateTime = tempList[0].UpdateTime, IsDelete = tempList[0].IsDelete }; List <StepJson> stepJsons = new List <StepJson>(); List <ToDoTaskSteps> subTempList = conn.Query <ToDoTaskSteps>("select * from ToDoTaskSteps where TaskId = ?", taskId); foreach (var subItem in subTempList) { StepJson stepJson = new StepJson() { TaskId = subItem.TaskId, StepId = subItem.StepId, Content = subItem.Content, UpdateTime = subItem.UpdateTime, IsDelete = subItem.IsDelete }; if (subItem.Finish) { stepJson.Done = "1"; } else { stepJson.Done = "0"; } stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } } foreach (var localTaskItem in localTaskArray) { string taskId = localTaskItem["TaskId"].ToString(); foreach (var cloudTaskItem in cloudTaskArray) { bool isItemOnCloud = false; if (cloudTaskItem["TaskId"].ToString().Equals(taskId)) { isItemOnCloud = true; string localUpdateTimeStr = localTaskItem["UpdateTime"].ToString(); string cloudUpdateTimeStr = cloudTaskItem["UpdateTime"].ToString(); DateTime localUpdateTime = Convert.ToDateTime(localUpdateTimeStr); DateTime cloudUpdateTime = Convert.ToDateTime(cloudUpdateTimeStr); if (cloudUpdateTime >= localUpdateTime) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { TaskJson taskJson = new TaskJson { TaskId = localTaskItem["TaskId"].ToString(), TaskName = localTaskItem["TaskName"].ToString(), Date = localTaskItem["Date"].ToString(), Star = localTaskItem["Star"].ToString(), Done = localTaskItem["Done"].ToString(), Remark = localTaskItem["Remark"].ToString(), UpdateTime = localTaskItem["UpdateTime"].ToString(), IsDelete = localTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = localTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } if (!isItemOnCloud) { TaskJson taskJson = new TaskJson { TaskId = localTaskItem["TaskId"].ToString(), TaskName = localTaskItem["TaskName"].ToString(), Date = localTaskItem["Date"].ToString(), Star = localTaskItem["Star"].ToString(), Done = localTaskItem["Done"].ToString(), Remark = localTaskItem["Remark"].ToString(), UpdateTime = localTaskItem["UpdateTime"].ToString(), IsDelete = localTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = localTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } } pushData.TaskList = taskJsons; string pushDataJsonStr = JsonConvert.SerializeObject(pushData); PushDataToLocal(pushDataJsonStr); PushDataToCloud(pushDataJsonStr); this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步成功!"); popupNotice.ShowAPopup(); }); } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + e.Message); popupNotice.ShowAPopup(); }); } }
public Task DeleteTask(TaskJson jsonObject) { var url = new Uri(v8Url, String.Format("tasks/{0}", jsonObject.Id.Value.ToString())); return(DeleteObject(url)); }
public Task <TaskJson> CreateTask(TaskJson jsonObject) { var url = new Uri(v8Url, "tasks"); return(CreateObject(url, jsonObject)); }
public static JObject BuildFromAssembly(Assembly assembly, string pathToDll) { var json = new TaskJson(); json.Name = assembly.GetCustomAttribute <AssemblyProductAttribute>().Product; if (!new Regex("^[a-zA-Z0-9]*$").IsMatch(json.Name)) { throw new ArgumentException("AssemblyProductAttribute must be alphnumeric"); } json.FriendlyName = assembly.GetCustomAttribute <AssemblyTitleAttribute>().Title; json.Description = assembly.GetCustomAttribute <AssemblyDescriptionAttribute>().Description; json.Author = assembly.GetCustomAttribute <AssemblyCompanyAttribute>().Company; json.Category = assembly.GetCustomAttribute <AssemblyConfigurationAttribute>()?.Configuration ?? "Utility"; json.Visibility = new[] { "Build", "Release" }; json.Id = assembly.GetCustomAttribute <GuidAttribute>().Value.ToString(); json.Demands = new[] { "azureps" }; var version = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion.Split('.').Select(i => int.Parse(i)).ToArray(); json.Version = new Models.Version { Major = version[0], Minor = version[1], Patch = version[2] }; json.MinimumAgentVersion = "1.92.0"; json.InstanceNameFormat = ""; if (json.FriendlyName.Length > 40) { throw new ArgumentException($"Task Title can only be up to 40chars : Change {json.FriendlyName}"); } var programOptionsType = assembly.DefinedTypes.SingleOrDefault(t => Attribute.IsDefined(t, typeof(EntryPointAttribute))); json.InstanceNameFormat = programOptionsType.GetCustomAttribute <EntryPointAttribute>().InstanceFormat; var result = TaskHelper.GetTaskInputs(programOptionsType, null); json.Inputs = result.Inputs.OrderByDescending(k => k.Order).ToArray(); json.Groups = result.Groups.ToArray(); json.SourceDefinitions = result.SourceDefinitions.ToArray(); json.Execution = new TaskExecution { ExecutionType = "PowerShell3", Target = "$(currentDirectory)\\OauthBroker.ps1", WorkingDirectory = "$(currentDirectory)", }; var serializer = JsonSerializer.Create(new JsonSerializerSettings { ContractResolver = new CamelCase(), NullValueHandling = NullValueHandling.Ignore }); var obj = JObject.FromObject(json, serializer); Console.WriteLine(obj.ToString(Newtonsoft.Json.Formatting.Indented)); var outputDir = Path.GetDirectoryName(pathToDll); using (var writer = new StreamWriter(File.Open(Path.Combine(outputDir, "OauthBroker.ps1"), FileMode.Create))) { WriteOauthBrokerPowershell(writer, Path.GetFileName(pathToDll), json.Inputs); writer.Flush(); } if (!Directory.Exists(Path.Combine(outputDir, "ps_modules"))) { using (var zip = new ZipArchive(typeof(TaskBuilder).Assembly.GetManifestResourceStream("SInnovations.VSTeamServices.TaskBuilder.ps_modules.zip"), ZipArchiveMode.Read)) { zip.ExtractToDirectory(Path.Combine(outputDir, "ps_modules")); } } File.WriteAllText(Path.Combine(outputDir, "task.json"), obj.ToString(Newtonsoft.Json.Formatting.Indented)); return(obj); }