ResolveConflict() public static method

The GUI should call this after having the user resolve a conflict so the synchronization thread can continue.
public static ResolveConflict ( SyncTitleConflictResolution resolution ) : void
resolution SyncTitleConflictResolution
return void
Example #1
0
 public void NoteConflictDetected(NoteManager manager, Note localConflictNote, NoteUpdate remoteNote, IList <string> noteUpdateTitles)
 {
     Logger.Debug("SilentUI: NoteConflictDetected, overwriting without a care");
     // TODO: At least respect conflict prefs
     // TODO: Implement more useful conflict handling
     if (localConflictNote.Id != remoteNote.UUID)
     {
         manager.Delete(localConflictNote);
     }
     SyncManager.ResolveConflict(SyncTitleConflictResolution.OverwriteExisting);
 }
Example #2
0
        public void NoteConflictDetected(NoteManager manager,
                                         Note localConflictNote,
                                         NoteUpdate remoteNote,
                                         IList <string> noteUpdateTitles)
        {
            SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel;
            object dlgBehaviorPref = Preferences.Get(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR);

            if (dlgBehaviorPref != null && dlgBehaviorPref is int)             // TODO: Check range of this int
            {
                savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref;
            }

            SyncTitleConflictResolution resolution = SyncTitleConflictResolution.OverwriteExisting;
            // This event handler will be called by the synchronization thread
            // so we have to use the delegate here to manipulate the GUI.
            // To be consistent, any exceptions in the delgate will be caught
            // and then rethrown in the synchronization thread.
            Exception mainThreadException = null;

            Gtk.Application.Invoke(delegate {
                try {
                    SyncTitleConflictDialog conflictDlg =
                        new SyncTitleConflictDialog(localConflictNote, noteUpdateTitles);
                    Gtk.ResponseType reponse = Gtk.ResponseType.Ok;

                    bool noteSyncBitsMatch =
                        SyncManager.SynchronizedNoteXmlMatches(localConflictNote.GetCompleteNoteXml(),
                                                               remoteNote.XmlContent);

                    // If the synchronized note content is in conflict
                    // and there is no saved conflict handling behavior, show the dialog
                    if (!noteSyncBitsMatch && savedBehavior == 0)
                    {
                        reponse = (Gtk.ResponseType)conflictDlg.Run();
                    }


                    if (reponse == Gtk.ResponseType.Cancel)
                    {
                        resolution = SyncTitleConflictResolution.Cancel;
                    }
                    else
                    {
                        if (noteSyncBitsMatch)
                        {
                            resolution = SyncTitleConflictResolution.OverwriteExisting;
                        }
                        else if (savedBehavior == 0)
                        {
                            resolution = conflictDlg.Resolution;
                        }
                        else
                        {
                            resolution = savedBehavior;
                        }

                        switch (resolution)
                        {
                        case SyncTitleConflictResolution.OverwriteExisting:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            // No need to delete if sync will overwrite
                            if (localConflictNote.Id != remoteNote.UUID)
                            {
                                manager.Delete(localConflictNote);
                            }
                            break;

                        case SyncTitleConflictResolution.RenameExistingAndUpdate:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            RenameNote(localConflictNote, conflictDlg.RenamedTitle, true);
                            break;

                        case SyncTitleConflictResolution.RenameExistingNoUpdate:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            RenameNote(localConflictNote, conflictDlg.RenamedTitle, false);
                            break;
                        }
                    }

                    Preferences.Set(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
                                    (int)savedBehavior);                       // TODO: Clean up

                    conflictDlg.Hide();
                    conflictDlg.Destroy();

                    // Let the SyncManager continue
                    SyncManager.ResolveConflict(/*localConflictNote, */ resolution);
                } catch (Exception e) {
                    mainThreadException = e;
                }
            });
            if (mainThreadException != null)
            {
                throw mainThreadException;
            }
        }