예제 #1
0
 public static IMergeResult <T> ResolveWithResolutionChoice <T>(T proposal, T yours, T theirs, T ancestor, MergeResolutionChoice resolutionChoice)
 {
     if (resolutionChoice.HasFlag(MergeResolutionChoice.ResolveConflict))
     {
         return(MergeResult <T> .IsSuccess(proposal, yours, theirs, ancestor));
     }
     else
     {
         return(MergeResult <T> .IsConflict(proposal, yours, theirs, ancestor));
     }
 }
예제 #2
0
        public static IMergeResult <T> Resolve <T>(T yours, T theirs, T ancestor, Func <T, IDictionary <string, dynamic>, object[]> getConstructorArguments, IDictionary <string, IMergeResult> mergeresults, MergeResolutionChoice resolutionOption)
        {
            MergeResolution mergeResolution = MergeResolutionHelpers.GetResolutionMinimum(mergeresults.Values);

            switch (mergeResolution)
            {
            case MergeResolution.Equal:
                return(MergeResult <T> .IsEqual(yours, theirs, ancestor));

            case MergeResolution.Theirs:
                return(MergeResult <T> .IsTheirs(yours, theirs, ancestor));
            }

            if (mergeresults.Any(result => result.Value.Conflict))
            {
                IDictionary <string, dynamic> parameterResults = null;

                if (resolutionOption.HasFlag(MergeResolutionChoice.ChooseYours))
                {
                    // is yours hier kiezen (geen conflict) niet gevaarlijk? de audit trail van theirs (server) raak je kwijt
                    // en TBH lijkt hier nu niet tegen te kunnen omdat administratieve locatie van klant dan niet meer gevonden kan worden.
                    parameterResults = mergeresults
                                       .Select(kvp => new { kvp.Key, Value = kvp.Value.Conflict ? kvp.Value.Yours : kvp.Value.Result })
                                       .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }
                else if (resolutionOption.HasFlag(MergeResolutionChoice.ChooseTheirs))
                {
                    parameterResults = mergeresults
                                       .Select(kvp => new { kvp.Key, Value = kvp.Value.Conflict ? kvp.Value.Theirs : kvp.Value.Result })
                                       .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }
                else if (resolutionOption.HasFlag(MergeResolutionChoice.ChooseAncestor))
                {
                    parameterResults = mergeresults
                                       .Select(kvp => new { kvp.Key, Value = kvp.Value.Conflict ? kvp.Value.Ancestor : kvp.Value.Result })
                                       .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }
                else
                {
                    parameterResults = mergeresults
                                       .Select(kvp => new { kvp.Key, Value = kvp.Value.Result })
                                       .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }

                if (resolutionOption.HasFlag(MergeResolutionChoice.ResolveConflict))
                {
                    return(MergeResult <T> .IsSuccess((T)Activator.CreateInstance(typeof(T), getConstructorArguments(theirs, parameterResults)), yours, theirs, ancestor));
                }
                else
                {
                    return(MergeResult <T> .IsConflict((T)Activator.CreateInstance(typeof(T), getConstructorArguments(theirs, parameterResults)), yours, theirs, ancestor));
                }
            }
            else
            {
                IDictionary <string, dynamic> parameterResults = mergeresults
                                                                 .Select(kvp => new { kvp.Key, Value = kvp.Value.Result })
                                                                 .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                return(MergeResult <T> .IsSuccess((T)Activator.CreateInstance(typeof(T), getConstructorArguments(theirs, parameterResults)), yours, theirs, ancestor));
            }
        }