示例#1
0
        public static DynamicUpdateMap CreateUpdateMap(ActivityBuilder updatedActivityDefinition, IEnumerable <Activity> disallowUpdateInsideActivities, out IList <ActivityBlockingUpdate> activitiesBlockingUpdate)
        {
            if (updatedActivityDefinition == null)
            {
                throw FxTrace.Exception.ArgumentNull("updatedActivityDefinition");
            }

            ActivityBuilder originalActivityDefinition = DynamicUpdateInfo.GetOriginalActivityBuilder(updatedActivityDefinition);

            if (originalActivityDefinition == null)
            {
                throw FxTrace.Exception.Argument("updatedActivityDefinition", SR.MustCallPrepareBeforeFinalize);
            }

            Activity originalBuiltRoot = GetDynamicActivity(originalActivityDefinition);
            Activity updatedBuiltRoot  = GetDynamicActivity(updatedActivityDefinition);

            DynamicUpdateMap result = InternalTryCreateUpdateMap(updatedBuiltRoot, originalBuiltRoot, disallowUpdateInsideActivities, true, out activitiesBlockingUpdate);

            // Remove the DynamicUpdateMapItems now that the update is finalized
            // Calling CalculateMapItems is actually an unnecessary perf hit since it calls CacheMetadata
            // again; but we do it so that Finalize is implemented purely in terms of other public APIs.
            DynamicUpdateInfo.SetOriginalActivityBuilder(updatedActivityDefinition, null);
            IDictionary <object, DynamicUpdateMapItem> mapItems = DynamicUpdateMap.CalculateImplementationMapItems(updatedBuiltRoot);

            foreach (object matchObject in mapItems.Keys)
            {
                DynamicUpdateInfo.SetMapItem(matchObject, null);
            }

            return(result);
        }
示例#2
0
        private static void InternalPrepareForUpdate(object definitionToBeUpdated, bool forImplementation)
        {
            // Clone the definition
            object clone;

            using (XamlObjectReader reader = new XamlObjectReader(definitionToBeUpdated))
            {
                using (XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext))
                {
                    XamlServices.Transform(reader, writer);
                    clone = writer.Result;
                }
            }

            // Calculate the match info
            // Set the match info as attached properties so it is serializable,
            // and available when the user calls CreateUpdateMap

            IDictionary <object, DynamicUpdateMapItem> mapItems;

            if (!forImplementation)
            {
                DynamicUpdateInfo.SetOriginalDefinition(definitionToBeUpdated, (Activity)clone);
                mapItems = DynamicUpdateMap.CalculateMapItems((Activity)definitionToBeUpdated);
            }
            else
            {
                DynamicUpdateInfo.SetOriginalActivityBuilder(definitionToBeUpdated, (ActivityBuilder)clone);
                mapItems = DynamicUpdateMap.CalculateImplementationMapItems(GetDynamicActivity((ActivityBuilder)definitionToBeUpdated));
            }

            foreach (KeyValuePair <object, DynamicUpdateMapItem> objectInfo in mapItems)
            {
                DynamicUpdateInfo.SetMapItem(objectInfo.Key, objectInfo.Value);
            }
        }