Ejemplo n.º 1
0
    /// <summary>
    /// Called when the note synchronization thread completes.
    /// </summary>
    private void OnSynchronizeNotesComplete(bool showUserInterface) {
      try {
        if (synchronizer_.Exception != null) {
          // Only show a network exception if we are doing a non-passive
          // operation (as opposed to our timer-based passive synchronization).
          // Otherwise, we would end up showing a bunch of exceptions when the
          // computer is not connected to the net.
          if (synchronizer_.Exception is System.Net.WebException && !showUserInterface) {
            return;
          }
          Debug.WriteLine(synchronizer_.Exception.Message);
          ShowError(String.Format(Messages.SynchronizationError, synchronizer_.Exception.Message));
          return;
        }

        // Load new notes and reload modified notes
        bool newNotesFound = false;
        foreach (Note note in synchronizer_.Notes) {
          bool skip = false;
          foreach (NoteForm form in noteForms_) {
            if (form.Note.Guid == note.Guid) {
              if (form.Note.Modified >= note.Modified) {
                skip = true;
              } else {
                // Replace this note with a new note. Since the note has the
                // same GUID, it will have the same path.
                form.Delete();
              }
              break;
            }
          }
          if (skip) continue;
          newNotesFound = true;
          ShowNote(new NoteForm(this, note, false));
          note.Save(false);
        }

        // Update our last sync time
        if (preferences_.SynchronizeSettings != null) {
          preferences_.SynchronizeSettings.LastSync = DateTime.UtcNow;
          preferences_.Save();
        }

        if (newNotesFound) {
          ShowMessage(Messages.SynchronizationNotesUpdated);
        }
      } catch (Exception e) {
        ShowError(String.Format(Messages.SynchronizationError, e.Message));
      } finally {
        synchronizer_ = null;
      }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Synchronizes the notes with the online data store.
    /// </summary>
    private void SynchronizeOnlineNotes(bool showUserInterface) {
      if (synchronizer_ != null) return;
      if (preferences_.SynchronizeSettings == null) return;

      // Load the note objects from the note forms
      List<Note> notes = new List<Note>();
      foreach (NoteForm form in noteForms_) {
        // TODO: Copy note to avoid synchronization problems
        notes.Add(form.Note);
      }

      // Synchronize the notes with or without a user interface
      synchronizer_ = new SynchronizeNotesOperation(preferences_.SynchronizeSettings, notes);
      if (showUserInterface) {
        NetworkActivityDialog dialog = new NetworkActivityDialog(Messages.SynchronizationProgress, synchronizer_);
        dialog.StartPosition = FormStartPosition.Manual;
        dialog.Location = Control.MousePosition;
        if (dialog.ShowDialog() == DialogResult.OK) {
          OnSynchronizeNotesComplete(true);
        } else {
          synchronizer_ = null;
        }
      } else {
        synchronizer_.RunAsynchronously(this, new System.Threading.ThreadStart(this.OnSynchronizeNotesComplete));
      }
    }