Esempio n. 1
0
        public TagData Import (IDataStoreContext ctx, TagJson json, Guid? localIdHint = null, TagData mergeBase = null)
        {
            var data = GetByRemoteId<TagData> (ctx, json.Id.Value, localIdHint);

            var merger = mergeBase != null ? new TagMerger (mergeBase) : null;
            if (merger != null && data != null)
                merger.Add (new TagData (data));

            if (json.DeletedAt.HasValue) {
                if (data != null) {
                    ctx.Delete (data);
                    data = null;
                }
            } else if (merger != null || ShouldOverwrite (data, json)) {
                data = ImportJson (ctx, data, json);

                if (merger != null) {
                    merger.Add (data);
                    data = merger.Result;
                }

                data = ctx.Put (data);
            }

            return data;
        }
Esempio n. 2
0
        public TagJson Export (IDataStoreContext ctx, TagData data)
        {
            var workspaceId = GetRemoteId<WorkspaceData> (ctx, data.WorkspaceId);

            return new TagJson () {
                Id = data.RemoteId,
                ModifiedAt = data.ModifiedAt.ToUtc (),
                Name = data.Name,
                WorkspaceId = workspaceId,
            };
        }
Esempio n. 3
0
        private static TagData ImportJson (IDataStoreContext ctx, TagData data, TagJson json)
        {
            var workspaceId = GetLocalId<WorkspaceData> (ctx, json.WorkspaceId);

            if (data == null) {
                // Fallback to name lookup for unsynced tags:
                var rows = ctx.Connection.Table<TagData> ().Take (1)
                    .Where (r => r.WorkspaceId == workspaceId && r.Name == json.Name && r.RemoteId == null);
                data = rows.FirstOrDefault ();
            }

            // As a last chance create new tag:
            data = data ?? new TagData ();

            data.Name = json.Name;
            data.WorkspaceId = workspaceId;

            ImportCommonJson (data, json);

            return data;
        }
Esempio n. 4
0
        public TagData Import (IDataStoreContext ctx, TagJson json, Guid? localIdHint = null, TagData mergeBase = null)
        {
            var log = ServiceContainer.Resolve<ILogger> ();

            var data = GetByRemoteId<TagData> (ctx, json.Id.Value, localIdHint);

            var merger = mergeBase != null ? new TagMerger (mergeBase) : null;
            if (merger != null && data != null) {
                merger.Add (new TagData (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 = 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;
        }
        private async Task CreateTestData ()
        {
            var workspace = await DataStore.PutAsync (new WorkspaceData () {
                RemoteId = 1,
                Name = "Unit Testing",
            });

            var user = await DataStore.PutAsync (new UserData () {
                RemoteId = 1,
                Name = "Tester",
                DefaultWorkspaceId = workspace.Id,
            });

            tag1 = await DataStore.PutAsync (new TagData () {
                RemoteId = 1,
                Name = DefaultTag,
                WorkspaceId = workspace.Id,
            });

            tag2 = await DataStore.PutAsync (new TagData () {
                RemoteId = 2,
                Name = "Tag #2",
                WorkspaceId = workspace.Id,
            });

            tag3 = await DataStore.PutAsync (new TagData () {
                RemoteId = 3,
                Name = "Tag #3",
                WorkspaceId = workspace.Id,
            });

            timeEntry = await DataStore.PutAsync (new TimeEntryData () {
                RemoteId = 1,
                Description = "Initial concept",
                State = TimeEntryState.Finished,
                StartTime = MakeTime (09, 12),
                StopTime = MakeTime (10, 1),
                WorkspaceId = workspace.Id,
                UserId = user.Id,
            });

            await DataStore.PutAsync (new TimeEntryTagData () {
                RemoteId = 1,
                TimeEntryId = timeEntry.Id,
                TagId = tag1.Id,
            });

            await DataStore.PutAsync (new TimeEntryTagData () {
                RemoteId = 2,
                TimeEntryId = timeEntry.Id,
                TagId = tag2.Id,
            });
        }
 public void OnCreateNewTag (TagData newTagData)
 {
     ViewModel.AddTag (newTagData);
     NavigationController.PopToViewController (this, true);
 }
 public void OnCreateNewTag (TagData newTagData)
 {
     ViewModel.AddTag (newTagData);
 }
Esempio n. 8
0
        private static void ResetTags (IDataStoreContext ctx, TimeEntryData timeEntryData, TimeEntryJson json)
        {
            // Don't touch the tags when the field is null
            if (json.Tags == null) {
                return;
            }

            var con = ctx.Connection;

            // Resolve tags to IDs:
            var tagIds = new List<Guid> ();
            foreach (var tagName in json.Tags) {
                // Prevent importing empty (invalid) tags:
                if (String.IsNullOrWhiteSpace (tagName)) {
                    continue;
                }

                var id = ctx.GetTagIdFromName (timeEntryData.WorkspaceId, tagName);

                if (id == Guid.Empty) {
                    // Need to create a new tag:
                    var tagData = new TagData () {
                        Name = tagName,
                        WorkspaceId = timeEntryData.WorkspaceId,
                    };
                    con.Insert (tagData);

                    id = timeEntryData.Id;
                }

                tagIds.Add (id);
            }

            // Iterate over TimeEntryTags and determine which to keep and which to discard:
            var inters = con.Table<TimeEntryTagData> ().Where (m => m.TimeEntryId == timeEntryData.Id);
            var toDelete = new List<TimeEntryTagData> ();
            foreach (var inter in inters) {
                if (tagIds.Contains (inter.TagId)) {
                    tagIds.Remove (inter.TagId);
                } else {
                    toDelete.Add (inter);
                }
            }

            // Delete unused tags intermediate rows:
            foreach (var inter in toDelete) {
                ctx.Delete (inter);
            }

            // Create new intermediate rows:
            foreach (var tagId in tagIds) {
                ctx.Put (new TimeEntryTagData () {
                    TagId = tagId,
                    TimeEntryId = timeEntryData.Id,
                });
            }
        }
 private View GetTagView (int position, TagData tagData, View convertView)
 {
     View view = convertView ?? LayoutInflater.FromContext (Activity).Inflate (Resource.Layout.TagListItem, null);
     var nameCheckedTextView = view.FindViewById<CheckedTextView> (Resource.Id.NameCheckedTextView).SetFont (Font.Roboto);
     nameCheckedTextView.Text = tagData.Name;
     return view;
 }
Esempio n. 10
0
 public static TagData Import (this TagJson json, IDataStoreContext ctx,
                               Guid? localIdHint = null, TagData mergeBase = null)
 {
     var converter = ServiceContainer.Resolve<TagJsonConverter> ();
     return converter.Import (ctx, json, localIdHint, mergeBase);
 }
Esempio n. 11
0
 public TagData (TagData other) : base (other)
 {
     Name = other.Name;
     WorkspaceId = other.WorkspaceId;
 }
Esempio n. 12
0
 public void AddTag (TagData tagData)
 {
     TagList.Add (tagData);
     RaisePropertyChanged (() => TagList);
 }
Esempio n. 13
0
 public TagData(TagData other) : base(other)
 {
     Name        = other.Name;
     WorkspaceId = other.WorkspaceId;
 }