private void HandleConflict(SynchronisationResults results,
                                    TType localEntry, TType remoteEntry,
                                    ICollection <TType> saveLocal, ICollection <TType> saveRemote)
        {
            var resolution = ConflcitResolver.Resolve(localEntry, remoteEntry);

            if (resolution.SaveLocal != null)
            {
                if (_syncDirection == SyncDirection.Upload)
                {
                    throw new InvalidOperationException("Sync direction is upload, but conflict resolved as saving locally.");
                }
                saveLocal.Add(resolution.SaveLocal);
            }
            if (resolution.SaveRemote != null)
            {
                if (_syncDirection == SyncDirection.Download)
                {
                    throw new InvalidOperationException("Sync direction is download, but conflict resolved as saving remotely.");
                }
                saveRemote.Add(resolution.SaveRemote);
            }

            results.NumberConflicts++;
        }
        private SynchronisationResults PopulateItemsToSave(
            IEnumerable <TType> remoteModifications, IEnumerable <TType> localModifications,
            out List <TType> saveLocal, out List <TType> saveRemote)
        {
            var remoteModified = remoteModifications.ToDictionary(_keySelector);
            var localModified  = localModifications.ToDictionary(_keySelector);
            var results        = new SynchronisationResults();

            saveLocal  = new List <TType>();
            saveRemote = new List <TType>();
            foreach (var remoteEntry in remoteModified)
            {
                var entry = remoteEntry;
                var localMatchingModifications = localModified.Where(t => Equals(t.Key, entry.Key)).Select(e => e.Value).ToList();

                switch (localMatchingModifications.Count)
                {
                case 0:
                    saveLocal.Add(remoteEntry.Value);
                    break;

                case 1:
                    HandleConflict(results, localMatchingModifications[0], remoteEntry.Value,
                                   saveLocal, saveRemote);
                    break;
                }
            }

            saveRemote.AddRange(localModified.Where(modifiedEntry => !remoteModified.Keys.Contains(modifiedEntry.Key)).Select(l => l.Value).ToList());
            return(results);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SynchronisationCompleteEventArgs"/> class.
 /// </summary>
 /// <param name="results">The results.</param>
 public SynchronisationCompleteEventArgs(SynchronisationResults results)
 {
     SynchronisationResults = results;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SynchronisationCompleteEventArgs"/> class.
 /// </summary>
 /// <param name="results">The results.</param>
 public SynchronisationCompleteEventArgs(SynchronisationResults results)
 {
     SynchronisationResults = results;
 }