public static CommonData Import (this CommonJson json, IDataStoreContext ctx, Guid? localIdHint = null, CommonData mergeBase = null) { var type = json.GetType (); if (type == typeof (ClientJson)) { return Import ((ClientJson)json, ctx, localIdHint, (ClientData)mergeBase); } else if (type == typeof (ProjectJson)) { return Import ((ProjectJson)json, ctx, localIdHint, (ProjectData)mergeBase); } else if (type == typeof (ProjectUserJson)) { return Import ((ProjectUserJson)json, ctx, localIdHint, (ProjectUserData)mergeBase); } else if (type == typeof (TagJson)) { return Import ((TagJson)json, ctx, localIdHint, (TagData)mergeBase); } else if (type == typeof (TaskJson)) { return Import ((TaskJson)json, ctx, localIdHint, (TaskData)mergeBase); } else if (type == typeof (TimeEntryJson)) { return Import ((TimeEntryJson)json, ctx, localIdHint, (TimeEntryData)mergeBase); } else if (type == typeof (UserJson)) { return Import ((UserJson)json, ctx, localIdHint, (UserData)mergeBase); } else if (type == typeof (WorkspaceJson)) { return Import ((WorkspaceJson)json, ctx, localIdHint, (WorkspaceData)mergeBase); } else if (type == typeof (WorkspaceUserJson)) { return Import ((WorkspaceUserJson)json, ctx, localIdHint, (WorkspaceUserData)mergeBase); } throw new InvalidOperationException (String.Format ("Unknown type of {0}", type)); }
private Node GetOrCreateNode (CommonData dataObject) { var node = GetNode (dataObject); if (node == null) { nodes.Add (node = new Node (dataObject)); } return node; }
/// <summary> /// Initializes a new instance of the <see cref="Toggl.Phoebe.Data.DataObjects.CommonData"/> class copying /// the data from the other object. /// </summary> /// <param name="other">Instance to copy data from.</param> protected CommonData (CommonData other) { Id = other.Id; ModifiedAt = other.ModifiedAt; DeletedAt = other.DeletedAt; IsDirty = other.IsDirty; RemoteId = other.RemoteId; RemoteRejected = other.RemoteRejected; }
public IEnumerable<CommonData> Remove (CommonData dataObject) { var node = GetNode (dataObject); if (node == null) return Enumerable.Empty<CommonData> (); var removedNodes = new List<Node> (); Remove (node, removedNodes); return removedNodes.Select (n => n.Data); }
public void Add (CommonData dataObject, CommonData parent = null) { if (parent != null) Add (parent); var node = GetOrCreateNode (dataObject); if (parent != null) { var parentNode = GetOrCreateNode (parent); node.Parents.Add (parentNode); parentNode.Children.Add (node); } }
private void OnItemSelected (CommonData m) { // TODO: valorate to work only with IDs. Guid projectId = Guid.Empty; Guid taskId = Guid.Empty; if (m is ProjectData) { if (! ((ProjectsCollection.SuperProjectData)m).IsEmpty) { projectId = m.Id; } } else if (m is TaskData) { var task = (TaskData)m; projectId = task.ProjectId; taskId = task.Id; } // Return selected data inside the // intent. var resultIntent = new Intent (); resultIntent.PutExtra (BaseActivity.IntentProjectIdArgument, projectId.ToString ()); resultIntent.PutExtra (BaseActivity.IntentTaskIdArgument, taskId.ToString ()); Activity.SetResult (Result.Ok, resultIntent); Activity.Finish(); }
private Node GetNode (CommonData dataObject) { return nodes.FirstOrDefault (n => n.Data.Matches (dataObject)); }
private static async Task<IEnumerable<CommonData>> GetRelatedData (CommonData data, List<CommonData> cache) { var dataObjects = new List<CommonData> (); foreach (var relation in data.GetRelations ()) { if (relation.Id == null) { continue; } // Query data in a synchronous manner to guarantee exclusive access to cache (without locking) // and give other code chance to have intermediate queries. var relatedObject = cache.FirstOrDefault (d => d.Id == relation.Id && d.GetType () == relation.Type); if (relatedObject == null) { relatedObject = await relation.ToListAsync ().ConfigureAwait (false); if (relatedObject != null) { cache.Add (relatedObject); } } if (relatedObject != null) { dataObjects.Add (relatedObject); } } return dataObjects; }
public Node (CommonData data) { Data = data; }
public IEnumerable<CommonData> RemoveBranch (CommonData dataObject) { var node = GetNode (dataObject); if (node == null) { return Enumerable.Empty<CommonData> (); } var removedNodes = new List<Node> (); // Find elders (highest parents): var elders = new HashSet<Node> (); var parentStack = new Stack<Node> (); parentStack.Push (node); while (parentStack.Count > 0) { var parentNode = parentStack.Pop (); if (parentNode.Parents.Count == 0) { elders.Add (parentNode); } else { foreach (var grandparent in parentNode.Parents) { parentStack.Push (grandparent); } } } // Remove elders from graph: foreach (var elder in elders) { Remove (elder, removedNodes); } return removedNodes.Select (n => n.Data); }