static void ThrowIfMapsIncompatible(EnvironmentUpdateMap first, EnvironmentUpdateMap second,
                                     DynamicUpdateMap.MergeErrorContext errorContext)
 {
     if (first.NewArgumentCount != second.OldArgumentCount ||
         first.NewVariableCount != second.OldVariableCount ||
         first.NewPrivateVariableCount != second.OldPrivateVariableCount)
     {
         errorContext.Throw(SR.InvalidMergeMapEnvironmentCount(
                                first.NewArgumentCount, first.NewVariableCount, first.NewPrivateVariableCount,
                                second.OldArgumentCount, second.OldVariableCount, second.OldPrivateVariableCount));
     }
 }
Esempio n. 2
0
        internal static DynamicUpdateMapEntry Merge(DynamicUpdateMapEntry first, DynamicUpdateMapEntry second,
                                                    DynamicUpdateMapEntry newParent, DynamicUpdateMap.MergeErrorContext errorContext)
        {
            Fx.Assert(first.NewActivityId == second.OldActivityId, "Merging mismatched entries");
            Fx.Assert((first.Parent == null && second.Parent == null) || (first.Parent.NewActivityId == second.Parent.OldActivityId), "Merging mismatched parents");

            var result = new DynamicUpdateMapEntry(first.OldActivityId, second.NewActivityId)
            {
                Parent = newParent
            };

            if (second.IsRemoval)
            {
                if (!result.IsParentRemovedOrBlocked)
                {
                    result.DisplayName = second.DisplayName;
                }
            }
            else
            {
                result.SavedOriginalValues          = Merge(first.SavedOriginalValues, second.SavedOriginalValues);
                result.SavedOriginalValueFromParent = first.SavedOriginalValueFromParent ?? second.SavedOriginalValueFromParent;
                if (first.BlockReason == UpdateBlockedReason.NotBlocked)
                {
                    result.BlockReason        = second.BlockReason;
                    result.BlockReasonMessage = second.BlockReasonMessage;
                }
                else
                {
                    result.BlockReason        = first.BlockReason;
                    result.BlockReasonMessage = second.BlockReasonMessage;
                }
                result.IsUpdateBlockedByUpdateAuthor = first.IsUpdateBlockedByUpdateAuthor || second.IsUpdateBlockedByUpdateAuthor;

                errorContext.PushIdSpace(result.NewActivityId);
                result.EnvironmentUpdateMap = EnvironmentUpdateMap.Merge(first.EnvironmentUpdateMap, second.EnvironmentUpdateMap, errorContext);
                if (!result.IsRuntimeUpdateBlocked && !result.IsUpdateBlockedByUpdateAuthor && !result.IsParentRemovedOrBlocked)
                {
                    result.ImplementationUpdateMap = DynamicUpdateMap.Merge(first.ImplementationUpdateMap, second.ImplementationUpdateMap, errorContext);
                }
                errorContext.PopIdSpace();
            };

            return(result);
        }
        internal static EnvironmentUpdateMap Merge(EnvironmentUpdateMap first, EnvironmentUpdateMap second,
                                                   DynamicUpdateMap.MergeErrorContext errorContext)
        {
            if (first == null || second == null)
            {
                return(first ?? second);
            }

            ThrowIfMapsIncompatible(first, second, errorContext);

            EnvironmentUpdateMap result = new EnvironmentUpdateMap
            {
                OldArgumentCount        = first.OldArgumentCount,
                NewArgumentCount        = second.NewArgumentCount,
                OldVariableCount        = first.OldVariableCount,
                NewVariableCount        = second.NewVariableCount,
                OldPrivateVariableCount = first.OldPrivateVariableCount,
                NewPrivateVariableCount = second.NewPrivateVariableCount,
            };

            result.variableEntries        = Merge(result.NewVariableCount, first.VariableEntries, second.VariableEntries);
            result.privateVariableEntries = Merge(result.NewPrivateVariableCount, first.PrivateVariableEntries, second.PrivateVariableEntries);
            result.argumentEntries        = Merge(result.NewArgumentCount, first.ArgumentEntries, second.ArgumentEntries);

            if (result.OldArgumentCount != result.NewArgumentCount ||
                result.OldVariableCount != result.NewVariableCount ||
                result.OldPrivateVariableCount != result.NewPrivateVariableCount ||
                result.HasArgumentEntries || result.HasVariableEntries || result.HasPrivateVariableEntries)
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
 static void ThrowIfMapsIncompatible(EnvironmentUpdateMap first, EnvironmentUpdateMap second,
     DynamicUpdateMap.MergeErrorContext errorContext)
 {
     if (first.NewArgumentCount != second.OldArgumentCount ||
         first.NewVariableCount != second.OldVariableCount ||
         first.NewPrivateVariableCount != second.OldPrivateVariableCount)
     {
         errorContext.Throw(SR.InvalidMergeMapEnvironmentCount(
             first.NewArgumentCount, first.NewVariableCount, first.NewPrivateVariableCount,
             second.OldArgumentCount, second.OldVariableCount, second.OldPrivateVariableCount));
     }
 }
        internal static EnvironmentUpdateMap Merge(EnvironmentUpdateMap first, EnvironmentUpdateMap second,
            DynamicUpdateMap.MergeErrorContext errorContext)
        {
            if (first == null || second == null)
            {
                return first ?? second;
            }

            ThrowIfMapsIncompatible(first, second, errorContext);

            EnvironmentUpdateMap result = new EnvironmentUpdateMap
            {
                OldArgumentCount = first.OldArgumentCount,
                NewArgumentCount = second.NewArgumentCount,
                OldVariableCount = first.OldVariableCount,
                NewVariableCount = second.NewVariableCount,
                OldPrivateVariableCount = first.OldPrivateVariableCount,
                NewPrivateVariableCount = second.NewPrivateVariableCount,
            };

            result.variableEntries = Merge(result.NewVariableCount, first.VariableEntries, second.VariableEntries);
            result.privateVariableEntries = Merge(result.NewPrivateVariableCount, first.PrivateVariableEntries, second.PrivateVariableEntries);
            result.argumentEntries = Merge(result.NewArgumentCount, first.ArgumentEntries, second.ArgumentEntries);

            if (result.OldArgumentCount != result.NewArgumentCount ||
                result.OldVariableCount != result.NewVariableCount ||
                result.OldPrivateVariableCount != result.NewPrivateVariableCount ||
                result.HasArgumentEntries || result.HasVariableEntries || result.HasPrivateVariableEntries)
            {
                return result;
            }
            else
            {
                return null;
            }
        }