public ProjectData Import (IDataStoreContext ctx, ProjectJson json, Guid? localIdHint = null, ProjectData mergeBase = null) { var data = GetByRemoteId<ProjectData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new ProjectMerger (mergeBase) : null; if (merger != null && data != null) merger.Add (new ProjectData (data)); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new ProjectData (); ImportJson (ctx, data, json); if (merger != null) { merger.Add (data); data = merger.Result; } data = ctx.Put (data); } return data; }
public void Dispose () { timeEntryDataList.Clear (); timeEntryData = new TimeEntryData (); projectData = new ProjectData (); clientData = new ClientData (); taskData = new TaskData (); }
public ProjectData (ProjectData other) : base (other) { Name = other.Name; Color = other.Color; IsActive = other.IsActive; IsBillable = other.IsBillable; IsPrivate = other.IsPrivate; IsTemplate = other.IsTemplate; UseTasksEstimate = other.UseTasksEstimate; WorkspaceId = other.WorkspaceId; ClientId = other.ClientId; }
public TimeEntryHolder (IEnumerable<TimeEntryData> timeEntryGroup) { if (timeEntryGroup == null || !timeEntryGroup.Any ()) { throw new ArgumentException ("Must be specified", "timeEntryGroup"); } timeEntryDataList.AddRange (timeEntryGroup); timeEntryData = new TimeEntryData (timeEntryGroup.Last ()); projectData = new ProjectData (); clientData = new ClientData (); taskData = new TaskData (); }
private static async Task<ProjectData> UpdateProject (TimeEntryData newTimeEntry, ProjectData oldProjectData) { if (!newTimeEntry.ProjectId.HasValue) { return new ProjectData (); } if (oldProjectData.Id == Guid.Empty && newTimeEntry.ProjectId.HasValue) { return await GetProjectDataAsync (newTimeEntry.ProjectId.Value); } if (newTimeEntry.ProjectId.Value != oldProjectData.Id) { return await GetProjectDataAsync (newTimeEntry.ProjectId.Value); } return oldProjectData; }
public ProjectJson Export (IDataStoreContext ctx, ProjectData data) { var workspaceId = GetRemoteId<WorkspaceData> (ctx, data.WorkspaceId); var clientId = GetRemoteId<ClientData> (ctx, data.ClientId); return new ProjectJson () { Id = data.RemoteId, ModifiedAt = data.ModifiedAt.ToUtc (), Name = data.Name, Color = data.Color.ToString (), IsActive = data.IsActive, IsBillable = data.IsBillable, IsPrivate = data.IsPrivate, IsTemplate = data.IsTemplate, UseTasksEstimate = data.UseTasksEstimate, WorkspaceId = workspaceId, ClientId = clientId, }; }
private static void ImportJson (IDataStoreContext ctx, ProjectData data, ProjectJson json) { var workspaceId = GetLocalId<WorkspaceData> (ctx, json.WorkspaceId); var clientId = GetLocalId<ClientData> (ctx, json.ClientId); data.Name = json.Name; try { data.Color = Convert.ToInt32 (json.Color); } catch { data.Color = ProjectModel.DefaultColor; } data.IsActive = json.IsActive; data.IsBillable = json.IsBillable; data.IsPrivate = json.IsPrivate; data.IsTemplate = json.IsTemplate; data.UseTasksEstimate = json.UseTasksEstimate; data.WorkspaceId = workspaceId; data.ClientId = clientId; ImportCommonJson (data, json); }
public ProjectData Import (IDataStoreContext ctx, ProjectJson json, Guid? localIdHint = null, ProjectData mergeBase = null) { var log = ServiceContainer.Resolve<ILogger> (); var data = GetByRemoteId<ProjectData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new ProjectMerger (mergeBase) : null; if (merger != null && data != null) { merger.Add (new ProjectData (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 ProjectData (); 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 static ProjectData Import (this ProjectJson json, IDataStoreContext ctx, Guid? localIdHint = null, ProjectData mergeBase = null) { var converter = ServiceContainer.Resolve<ProjectJsonConverter> (); return converter.Import (ctx, json, localIdHint, mergeBase); }
public async Task SyncWidgetData () { try { // Dispathc started message. messageBus.Send<SyncWidgetMessage> (new SyncWidgetMessage (this,true)); // Query local data: var store = ServiceContainer.Resolve<IDataStore> (); var entries = await store.Table<TimeEntryData> () .OrderByDescending (r => r.StartTime) .Where (r => r.DeletedAt == null && r.State != TimeEntryState.New) .Take (4).ToListAsync ().ConfigureAwait (false); var widgetEntries = new List<WidgetEntryData>(); foreach (var entry in entries) { ProjectData project; if (entry.ProjectId != null) { var q = store.Table<ProjectData>().Where (p => p.Id == entry.ProjectId.Value); var l = await q.ToListAsync ().ConfigureAwait (false); project = l.FirstOrDefault(); } else { project = new ProjectData { Name = string.Empty, Color = ProjectModel.HexColors.Length - 1, }; } TimeSpan duration; if (entry.StopTime.HasValue) { duration = entry.StopTime.Value - entry.StartTime; } else { duration = Phoebe.Time.UtcNow - entry.StartTime; } widgetEntries.Add (new WidgetEntryData { Id = entry.Id.ToString(), ProjectName = project.Name, Description = entry.Description, Color = ProjectModel.HexColors [ project.Color % ProjectModel.HexColors.Length], IsRunning = entry.State == TimeEntryState.Running, TimeValue = GetFormattedDuration (duration), Duration = (entry.StopTime.HasValue ? entry.StopTime.Value : Time.UtcNow) - entry.StartTime, }); } widgetUpdateService.LastEntries = widgetEntries; } catch (Exception exc) { var log = ServiceContainer.Resolve<ILogger> (); log.Error (Tag, exc, "Failed to fetch time entries"); } finally { isLoading = false; // Dispathc ended message. messageBus.Send<SyncWidgetMessage> (new SyncWidgetMessage (this)); } }
public CommonProjectData (ProjectData dataObject, string clientName, TaskData task = null) : base (dataObject) { Task = task; ClientName = clientName; }
private async void OnSync (Message msg) { if (isLoading) { return; } isLoading = true; try { // Dispathc started message. messageBus.Send<SyncWidgetMessage> (new SyncWidgetMessage (this,true)); var queryStartDate = Time.UtcNow - TimeSpan.FromDays (9); // Query local data: var store = ServiceContainer.Resolve<IDataStore> (); var userId = ServiceContainer.Resolve<AuthManager> ().GetUserId (); var baseQuery = store.Table<TimeEntryData> () .OrderByDescending (r => r.StartTime) .Where (r => r.DeletedAt == null && r.UserId == userId && r.State != TimeEntryState.New && r.StartTime >= queryStartDate) .Take (4); var entries = await baseQuery.ToListAsync ().ConfigureAwait (false); var widgetEntries = new List<WidgetEntryData>(); foreach (var entry in entries) { ProjectData project; if (entry.ProjectId != null) { var q = store.Table<ProjectData>().Where (p => p.Id == entry.ProjectId.Value); var l = await q.ToListAsync ().ConfigureAwait (false); project = l.FirstOrDefault(); } else { project = new ProjectData { Name = string.Empty, Color = ProjectModel.HexColors.Length - 1, }; } widgetEntries.Add (new WidgetEntryData { Id = entry.Id.ToString(), ProjectName = project.Name, Description = entry.Description, Color = ProjectModel.HexColors [ project.Color % ProjectModel.HexColors.Length], IsRunning = entry.State == TimeEntryState.Running, TimeValue = (entry.StopTime - entry.StartTime).ToString(), Duration = (entry.StopTime.HasValue ? entry.StopTime.Value : Time.UtcNow) - entry.StartTime, }); } widgetUpdateService.LastEntries = widgetEntries; } catch (Exception exc) { var log = ServiceContainer.Resolve<ILogger> (); log.Error (Tag, exc, "Failed to fetch time entries"); } finally { isLoading = false; // Dispathc ended message. messageBus.Send<SyncWidgetMessage> (new SyncWidgetMessage (this)); } }
private static async Task<ClientData> UpdateClient (ProjectData newProjectData, ClientData oldClientData) { if (!newProjectData.ClientId.HasValue) { return new ClientData (); } if (oldClientData == null && newProjectData.ClientId.HasValue) { return await GetClientDataAsync (newProjectData.ClientId.Value); } if (newProjectData.ClientId.Value != oldClientData.Id) { return await GetClientDataAsync (newProjectData.ClientId.Value); } return oldClientData; }
public async Task UpdateAsync (IEnumerable<TimeEntryData> timeEntryGroup) { timeEntryData = new TimeEntryData (timeEntryGroup.Last ()); timeEntryDataList.Clear (); timeEntryDataList.AddRange (timeEntryGroup); projectData = await UpdateProject (timeEntryData, ProjectData); clientData = await UpdateClient (projectData, ClientData); taskData = await UpdateTask (timeEntryData, TaskData); numberOfTags = await GetNumberOfTagsAsync (timeEntryData.Id); }
public async Task LoadAsync () { numberOfTags = 0; if (timeEntryData.ProjectId.HasValue) { projectData = await GetProjectDataAsync (timeEntryData.ProjectId.Value); if (projectData.ClientId.HasValue) { clientData = await GetClientDataAsync (projectData.ClientId.Value); } } if (timeEntryData.TaskId.HasValue) { taskData = await GetTaskDataAsync (timeEntryData.TaskId.Value); } numberOfTags = await GetNumberOfTagsAsync (timeEntryData.Id); }