Beispiel #1
0
 private void ClearChildren(ITreeNode TN)
 {
     if (items.Contains(TN))
     {
         int indexToRemove = this.items.IndexOf(TN) + 1;
         while ((indexToRemove < this.items.Count) && (this.items[indexToRemove].Level > TN.Level))
         {
             items[indexToRemove].PropertyChanged -= new PropertyChangedEventHandler(TN_PropertyChanged);
             items.RemoveAt(indexToRemove);
         }
     }
 }
Beispiel #2
0
        private async Task GetAllNotesAndUpdate()
        {
            Offline = !App.Cloud.IsConnected();
            if (Offline)
            {
                return;
            }

            GettingLatestNotes = true;

            var notes = await App.Cloud.GetAllNotes();

            if (notes == null) // null if we time out trying to connect
            {
                return;
            }

            string cloudKey = SelectedNote?.CloudKey;

            // Loop through the notes backwards so as to remove them if needed
            for (int i = _notes.Count - 1; i >= 0; i--)
            {
                // Note exists in cloud - update if necessary
                if (notes.ContainsKey(_notes[i]?.CloudKey ?? ""))
                {
                    if (notes[_notes[i].CloudKey].LastModified > _notes[i].LastModified) // Cloud note is newer
                    {
                        await App.Cloud.GetNoteWithContent(_notes[i].NoteData);

                        await App.Local.UpdateNote(_notes[i].NoteData);
                    }
                    else if (notes[_notes[i].CloudKey].LastModified < _notes[i].LastModified) // Local note is newer
                    {
                        await App.Cloud.UpdateNote(_notes[i].NoteData);
                    }

                    notes.Remove(_notes[i].CloudKey);
                }
                // Note no longer exists in cloud, delete locally and in localDB
                else if (!notes.ContainsKey(_notes[i]?.CloudKey ?? ""))
                {
                    await App.Local.DeleteNote(_notes[i].NoteData);

                    _notes.RemoveAt(i);
                }
            }

            // These are the new notes coming from the cloud
            foreach (Note note in notes.Values)
            {
                await App.Cloud.GetNoteWithContent(note);

                _notes.Add(new NoteViewModel(note));
                await App.Local.AddNote(note);
            }

            if (String.IsNullOrEmpty(cloudKey) && _notes.Count > 0)
            {
                SelectedNote = _notes[0];
            }
            else
            {
                SelectedNote = _notes.Where(x => x.CloudKey == cloudKey).FirstOrDefault();
            }

            // Forces a refresh on the converter!
            foreach (var note in _notes)
            {
                note.ForceLastModifiedConverterRefresh();
            }

            GettingLatestNotes = false;
        }