none
Always getting exception error when ConflictResolutionAction.SkipChange

    Question

  • Hi. I kept getting exception errors when I tried to use my program to sync files which create a concurrency conflict. 

    I want the files to remain unchanged, instead gets propagated to the other side, and vice versa. Anyone has a solution for this? Thanks!


    using System;

    using System.IO;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    using Microsoft.Synchronization;

    using Microsoft.Synchronization.Files;

     

    namespace nsync_test

    {

        class SyncEngine

        {

            ////////////////////

            // Private variables

            ////////////////////

     

            private static Form2 _summary;

            private string path1;

            private string path2;

     

            ////////////////////

            // Private methods

            ////////////////////

     

            private static void DetectChangesonFileSystemReplica(

                string replicaRootPath,

                FileSyncScopeFilter filter, FileSyncOptions options)

            {

                FileSyncProvider provider = null;

     

                try

                {

                    provider = new FileSyncProvider(replicaRootPath, filter, options);

                    provider.DetectChanges();

                }

                finally

                {

                    // Release resources/memory

                    if (provider != null)

                        provider.Dispose();

                }

            }

     

            private void SyncFileSystemReplicasOneWay(string sourcePath, string destPath,

                FileSyncScopeFilter filter, FileSyncOptions options)

            {

                FileSyncProvider sourceProvider = null;

                FileSyncProvider destProvider = null;

     

                try

                {

                    sourceProvider = new FileSyncProvider(sourcePath, filter, options);

                    destProvider = new FileSyncProvider(destPath, filter, options);

     

                    SyncCallbacks destinationCallBacks = destProvider.DestinationCallbacks;

                    destinationCallBacks.ItemConflicting += new EventHandler<ItemConflictingEventArgs>(OnItemConflicting);

                    destinationCallBacks.ItemConstraint += new EventHandler<ItemConstraintEventArgs>(OnItemConstraint);

     

                    destProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);

     

                    SyncOrchestrator agent = new SyncOrchestrator();

                    agent.LocalProvider = sourceProvider;

                    agent.RemoteProvider = destProvider;

                    agent.Direction = SyncDirectionOrder.Upload;

     

                    agent.Synchronize();

                }

                finally

                {

                    if (sourceProvider != null) sourceProvider.Dispose();

                    if (destProvider != null) destProvider.Dispose();

                }

            }

     

            // Setting conflicting rules

            private static void OnItemConflicting(object sender, ItemConflictingEventArgs args)

            {

                args.SetResolutionAction(ConflictResolutionAction.SkipChange); 

            }

     

            private static void OnItemConstraint(object sender, ItemConstraintEventArgs args)

            {

                args.SetResolutionAction(ConstraintConflictResolutionAction.RenameSource);

            }

     

            private static void OnAppliedChange(object sender, AppliedChangeEventArgs args)

            {

                switch (args.ChangeType)

                {

                    case ChangeType.Create:

                        _summary.InsertMsg("-- Applied CREATE for file " + args.NewFilePath);

                        break;

                    case ChangeType.Delete:

                        _summary.InsertMsg("-- Applied DELETE for file " + args.OldFilePath);

                        break;

                    case ChangeType.Update:

                        _summary.InsertMsg("-- Applied OVERWRITE for file " + args.OldFilePath);

                        break;

                    case ChangeType.Rename:

                        _summary.InsertMsg("-- Applied RENAME for file " + args.OldFilePath +

                                          " as " + args.NewFilePath);

                        break;

                }

            }

     

            ////////////////////

            // Public methods

            ////////////////////

     

            // Return paths

            public string[] GetPath()

            {

                string[] listOfPaths = new string[2];

                listOfPaths[0] = path1;

                listOfPaths[1] = path2;

                return listOfPaths;

            }

     

            // Check if paths are valid

            public bool SetPath(string p1, string p2)

            {

                if (string.IsNullOrEmpty(p1) || string.IsNullOrEmpty(p2) ||

                    !Directory.Exists(p1) || !Directory.Exists(p2))

                {

                    return false;

                }

                else

                {

                    path1 = p1;

                    path2 = p2;

                    return true;

                }

            }

     

            // Start the sync process

            public void StartSync(Form2 summary)

            {

                try

                {

                    _summary = summary;

                    // Configure sync options

                    FileSyncOptions options = FileSyncOptions.ExplicitDetectChanges |

                        FileSyncOptions.RecycleConflictLoserFiles |

                        FileSyncOptions.RecycleDeletedFiles |

                        FileSyncOptions.RecyclePreviousFileOnUpdates;

     

                    // Configure sync filters

                    // This example will exclude shortcut links during sync

                    FileSyncScopeFilter filter = new FileSyncScopeFilter();

                    filter.FileNameExcludes.Add("*.lnk");

     

                    // Update metadata of the folders before sync to

                    // check for any changes or modifications

                    DetectChangesonFileSystemReplica(path1, filter, options);

                    DetectChangesonFileSystemReplica(path2, filter, options);

     

                    // Start the 2-way sync

                    SyncFileSystemReplicasOneWay(path1, path2, null, options);

                    SyncFileSystemReplicasOneWay(path2, path1, null, options);

                }

                catch (Exception e)

                {

                    throw e;

                }

            }

     

     

        }

    }


    Thursday, February 04, 2010 12:56 PM

Answers

  • What is the exception you are seeing.
    We believe that the skipchange action does not apply to file sync provider. Please post back the exception you are seeing.
    Also what is the need for you to skip a change rather than use a source or destination wins resolution?
    This posting is provided AS IS with no warranties, and confers no rights
    Sunday, February 07, 2010 11:53 PM

All replies

  • What is the exception you are seeing.
    We believe that the skipchange action does not apply to file sync provider. Please post back the exception you are seeing.
    Also what is the need for you to skip a change rather than use a source or destination wins resolution?
    This posting is provided AS IS with no warranties, and confers no rights
    Sunday, February 07, 2010 11:53 PM
  • Hello,

    I also receive an exception when I am trying to use SkipChange.

    The exception is SyncException: "An incorrect conflict resolution action was set on the OnConflict callback."

    My need is the following: I am making a program which allows to the user (during files synchronization) to preview the changes, decide what to do with conflicts and apply the changes. So I think it is useful for the user to postpone a decision to the next sync session - for example, I am synchronizing 1000 files and 2 files are in conflict - I do not know what is the best decision, so I want to synchronize 998 files first and come back later to finish the operation with those 2 files.

    If this is somehow not supported by FileSyncProvider I would like to know what could be your recommendations for the case implementation.

    Regards,

    Nikolay.

    Saturday, September 28, 2013 10:27 PM