예제 #1
0
        private static IList <ResourceEvaluation> EvaluateResourcesInternal(IList <DictionaryEntryNode> resources, SceneNode destination)
        {
            SceneViewModel            viewModel = destination.ViewModel;
            List <ResourceEvaluation> list      = new List <ResourceEvaluation>();

            foreach (DictionaryEntryNode originalResource in (IEnumerable <DictionaryEntryNode>)resources)
            {
                DocumentNode documentNode = (DocumentNode)null;
                SceneNode    keyNode      = originalResource.KeyNode;
                if (keyNode != null)
                {
                    documentNode = new ExpressionEvaluator(viewModel.DocumentRootResolver).EvaluateResource(destination.DocumentNodePath, keyNode.DocumentNode);
                }
                if (documentNode == null)
                {
                    list.Add(new ResourceEvaluation(originalResource, (DocumentNode)null, ResourceEvaluationResult.NoExistingResource));
                }
                else
                {
                    ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(destination.DocumentNode);
                    bool flag = resourcesCollection != null && resourcesCollection.Resources == documentNode.Parent.Parent;
                    if (ResourceHelper.NodeTreesAreEquivalent(viewModel, originalResource.Value.DocumentNode, documentNode))
                    {
                        list.Add(new ResourceEvaluation(originalResource, documentNode, flag ? ResourceEvaluationResult.IdenticalResourceExists : ResourceEvaluationResult.IdenticalResourceIsMasked));
                    }
                    else
                    {
                        list.Add(new ResourceEvaluation(originalResource, documentNode, flag ? ResourceEvaluationResult.ConflictingResourceExists : ResourceEvaluationResult.ConflictingResourceIsMasked));
                    }
                }
            }
            return((IList <ResourceEvaluation>)list);
        }
예제 #2
0
        public void FixupIndividualReference(DocumentCompositeNode resource, SceneNode reference)
        {
            switch (this.updateMethod)
            {
            case ReferencesFoundModel.UpdateMethod.UpdateReferences:
                DocumentNode node = reference.DocumentContext.CreateNode(this.newKey.GetType(), this.newKey);
                ResourceNodeHelper.SetResourceKey((DocumentCompositeNode)reference.DocumentNode, node);
                IPropertyId propertyId1 = (IPropertyId)reference.Parent.GetPropertyForChild(reference);
                reference.Parent.SetValue(new PropertyReference((ReferenceStep)propertyId1), (object)reference.DocumentNode.Clone(reference.DocumentContext));
                break;

            case ReferencesFoundModel.UpdateMethod.ConvertToLocal:
                DocumentNode documentNode = resource.Properties[DictionaryEntryNode.ValueProperty].Clone(reference.DocumentContext);
                IPropertyId  propertyId2  = (IPropertyId)reference.Parent.GetPropertyForChild(reference);
                reference.Parent.SetValue(new PropertyReference((ReferenceStep)propertyId2), (object)documentNode);
                break;

            case ReferencesFoundModel.UpdateMethod.ResetToDefault:
                if (PlatformTypes.Setter.IsAssignableFrom((ITypeId)reference.Parent.Type))
                {
                    reference.Parent.Remove();
                    break;
                }
                IPropertyId propertyKey = (IPropertyId)reference.Parent.GetPropertyForChild(reference);
                reference.Parent.ClearLocalValue(propertyKey);
                break;
            }
        }
예제 #3
0
        private void ResolveTemplate(SetterSceneNode setter)
        {
            DocumentNode node1 = ((DocumentCompositeNode)setter.DocumentNode).Properties[SetterSceneNode.ValueProperty];

            if (node1 != null && !PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)node1.Type))
            {
                DocumentCompositeNode node2 = node1 as DocumentCompositeNode;
                if (node2 != null)
                {
                    DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node2);
                    if (resourceKey != null)
                    {
                        node1 = this.CreateNode(this.ViewModel.FindResource(this.ViewModel.CreateInstance(new DocumentNodePath(resourceKey, resourceKey))));
                    }
                }
            }
            if (node1 == null)
            {
                return;
            }
            ControlTemplateElement controlTemplateElement = this.ViewModel.GetSceneNode(node1) as ControlTemplateElement;

            if (controlTemplateElement != null)
            {
                controlTemplateElement.RenameTemplateIDs();
            }
            ((DocumentCompositeNode)setter.DocumentNode).Properties[SetterSceneNode.ValueProperty] = node1;
        }
예제 #4
0
 private void OnViewUpdated(SceneUpdatePhaseEventArgs args)
 {
     if (this.view != null && this.Document != null && this.Document.IsEditable)
     {
         ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(this.Document.RootNode);
         if (resourcesCollection != null)
         {
             DocumentNode node = (DocumentNode)resourcesCollection.Resources;
             if (node != null)
             {
                 this.resourceSubscription.SetBasisNodes(this.ViewModel, (IEnumerable <SceneNode>) new List <SceneNode>()
                 {
                     this.ViewModel.GetSceneNode(node)
                 });
                 this.resourceSubscription.Update(this.ViewModel, args.DocumentChanges, args.DocumentChangeStamp);
             }
         }
     }
     else
     {
         this.needsRebuild = true;
         this.resourceSubscription.SetBasisNodes(this.ViewModel, (IEnumerable <SceneNode>) new List <SceneNode>());
     }
     if (!this.needsRebuild)
     {
         return;
     }
     this.OnItemsChanged();
 }
 public static string GetUserFriendlyDescription(DocumentCompositeNode expressionNode, DocumentNode parentNode)
 {
     if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)expressionNode) || DocumentNodeUtilities.IsStaticResource((DocumentNode)expressionNode))
     {
         DocumentNode          resourceKey           = ResourceNodeHelper.GetResourceKey(expressionNode);
         DocumentPrimitiveNode documentPrimitiveNode = resourceKey as DocumentPrimitiveNode;
         DocumentCompositeNode expressionNode1       = resourceKey as DocumentCompositeNode;
         if (documentPrimitiveNode != null && documentPrimitiveNode.Value != null)
         {
             return(documentPrimitiveNode.Value.ToString());
         }
         if (expressionNode1 != null && DocumentNodeUtilities.IsMarkupExtension((DocumentNode)expressionNode1))
         {
             return(XamlExpressionSerializer.GetUserFriendlyDescription(expressionNode1, (DocumentNode)expressionNode));
         }
     }
     else if (DocumentNodeUtilities.IsStaticResource((DocumentNode)expressionNode))
     {
         DocumentPrimitiveNode documentPrimitiveNode = expressionNode.Properties[StaticExtensionProperties.MemberProperty] as DocumentPrimitiveNode;
         if (documentPrimitiveNode != null)
         {
             return(documentPrimitiveNode.Value.ToString());
         }
     }
     return(XamlExpressionSerializer.GetStringFromExpression((DocumentNode)expressionNode, parentNode));
 }
예제 #6
0
        private static RawDataSourceInfoBase GetDataSourceInfoFromResourceReference(DocumentCompositeNode resourceReferenceNode)
        {
            if (resourceReferenceNode.DocumentRoot == null)
            {
                return((RawDataSourceInfoBase)RawDataSourceInfo.Invalid);
            }
            DocumentNode          resourceKey        = ResourceNodeHelper.GetResourceKey(resourceReferenceNode);
            ResourceReferenceType resourceType       = ResourceNodeHelper.GetResourceType((DocumentNode)resourceReferenceNode);
            DocumentNodePath      nodePath           = new DocumentNodePath(resourceReferenceNode.DocumentRoot.RootNode, (DocumentNode)resourceReferenceNode);
            DocumentNode          sourceNode         = new ExpressionEvaluator((IDocumentRootResolver)resourceReferenceNode.Context).EvaluateResource(nodePath, resourceType, resourceKey);
            RawDataSourceInfoBase dataSourceInfoBase = (RawDataSourceInfoBase) new RawDataSourceInfo(sourceNode, (string)null);

            if (sourceNode != null && PlatformTypes.XmlDataProvider.IsAssignableFrom((ITypeId)sourceNode.Type))
            {
                DocumentNode node = ((DocumentCompositeNode)sourceNode).Properties[XmlDataProviderSceneNode.XPathProperty];
                if (node != null)
                {
                    string valueAsString = DocumentPrimitiveNode.GetValueAsString(node);
                    if (!string.IsNullOrEmpty(valueAsString))
                    {
                        dataSourceInfoBase.XmlPath = valueAsString;
                    }
                }
            }
            return(dataSourceInfoBase);
        }
예제 #7
0
        protected void InitializeCurrentValueConverter()
        {
            if (this.TargetProperty == null)
            {
                return;
            }
            BindingSceneNode binding = this.TargetElement.GetBinding((IPropertyId)this.TargetProperty);

            if (binding == null)
            {
                return;
            }
            string str = binding.ConverterParameter as string;

            if (str != null)
            {
                this.ValueConverterParameter = str;
            }
            DocumentCompositeNode node = binding.Converter as DocumentCompositeNode;

            if (node == null)
            {
                return;
            }
            ValueConverterModel valueConverterModel = (ValueConverterModel)null;

            if (node.Type.IsResource)
            {
                string key = DocumentPrimitiveNode.GetValueAsString(ResourceNodeHelper.GetResourceKey(node));
                if (string.IsNullOrEmpty(key))
                {
                    return;
                }
                valueConverterModel = Enumerable.FirstOrDefault <ValueConverterModel>((IEnumerable <ValueConverterModel>) this.ValueConverters, (Func <ValueConverterModel, bool>)(vc => vc.DisplayName == key));
            }
            else
            {
                SceneNode sceneNode = this.ViewModel.GetSceneNode((DocumentNode)node);
                if (sceneNode != null)
                {
                    valueConverterModel = ValueConverterModelFactory.CreateValueConverterModel(sceneNode);
                    if (valueConverterModel != null)
                    {
                        this.ValueConverters.Add(valueConverterModel);
                    }
                }
            }
            if (valueConverterModel == null)
            {
                return;
            }
            this.CurrentValueConverter = valueConverterModel;
        }
예제 #8
0
 private object InternalGetAmbientValue(ReferenceStep property, SceneNode targetNode)
 {
     AmbientPropertyManager.AmbientPropertyValue ambientPropertyValue = this.GetAmbientPropertyValue(property);
     if (ambientPropertyValue != null)
     {
         if (ambientPropertyValue.Value == DependencyProperty.UnsetValue)
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentNode node = ambientPropertyValue.Value as DocumentNode;
         if (node == null)
         {
             return(DependencyProperty.UnsetValue);
         }
         if (targetNode == null && (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node) || DocumentNodeUtilities.IsTemplateBinding(node)))
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;
         if (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node))
         {
             DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(documentCompositeNode);
             bool         flag        = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext).EvaluateResource(targetNode.DocumentNodePath, DocumentNodeUtilities.IsStaticResource(node) ? ResourceReferenceType.Static : ResourceReferenceType.Dynamic, resourceKey) != null;
             if (!flag)
             {
                 object instance = targetNode.ViewModel.CreateInstance(new DocumentNodePath(resourceKey, resourceKey));
                 if (instance != null)
                 {
                     flag = targetNode.ViewModel.FindResource(instance) != null;
                 }
             }
             if (!flag)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         else if (DocumentNodeUtilities.IsTemplateBinding(node))
         {
             ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext);
             if (documentCompositeNode == null || expressionEvaluator.EvaluateTemplateBinding(targetNode.DocumentNodePath, documentCompositeNode) == null)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         return((object)node);
     }
     if (targetNode == null || !object.Equals(ambientPropertyValue.DefaultValue, targetNode.GetDefaultValueAsWpf((IPropertyId)property)))
     {
         return(ambientPropertyValue.DefaultValue);
     }
     return(DependencyProperty.UnsetValue);
 }
예제 #9
0
        private void SetExistingBindingValues(BindingSceneNode existingBinding)
        {
            string                path  = existingBinding.PathOrXPath;
            DocumentNode          node1 = (DocumentNode)null;
            DocumentCompositeNode node2 = existingBinding.SupportsSource ? existingBinding.Source as DocumentCompositeNode : (DocumentCompositeNode)null;

            if (node2 != null && node2.Type.IsResource)
            {
                node1 = ResourceNodeHelper.GetResourceKey(node2);
            }
            if (node1 != null)
            {
                this.InitializeDataSource(DocumentPrimitiveNode.GetValueAsString(node1), path);
            }
            else if (existingBinding.SupportsElementName && existingBinding.ElementName != null && this.elementPropertyModel != null)
            {
                this.InitializeElementName(existingBinding.ElementName, path);
            }
            else
            {
                this.InitializeExplicitDataContext(path);
            }
            if (this.bindingSourcesProxy.Value.Path != path)
            {
                if (this.CurrentBindingSource.Schema is EmptySchema && existingBinding.SupportsXPath && !string.IsNullOrEmpty(existingBinding.XPath))
                {
                    path = "XPath=" + path;
                }
                this.CustomBindingExpression    = path;
                this.UseCustomBindingExpression = true;
            }
            DocumentNode node3 = existingBinding.SupportsFallbackValue ? existingBinding.FallbackValue : (DocumentNode)null;

            if (node3 != null)
            {
                string valueAsString = DocumentPrimitiveNode.GetValueAsString(node3);
                if (valueAsString != null)
                {
                    this.BindingFallbackValue = valueAsString;
                }
            }
            if (existingBinding.IsModeSet)
            {
                this.CurrentBindingMode = existingBinding.Mode;
            }
            if (!existingBinding.SupportsUpdateSourceTrigger)
            {
                return;
            }
            this.CurrentUpdateSourceTrigger = existingBinding.UpdateSourceTrigger;
        }
예제 #10
0
        internal static DocumentCompositeNode LookupResource(SceneViewModel viewModel, DocumentCompositeNode findMe)
        {
            DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(findMe);

            if (resourceKey != null)
            {
                DocumentNode documentNode = new ExpressionEvaluator(viewModel.DocumentRootResolver).EvaluateResource(viewModel.GetSceneNode((DocumentNode)findMe).DocumentNodePath, DocumentNodeUtilities.IsDynamicResource((DocumentNode)findMe) ? ResourceReferenceType.Dynamic : ResourceReferenceType.Static, resourceKey);
                if (documentNode != null)
                {
                    return(documentNode.Parent);
                }
            }
            return((DocumentCompositeNode)null);
        }
        private static void ReplaceTemplateTargetType(DocumentNode root, IList <DocumentCompositeNode> resources, IType targetType)
        {
            DocumentCompositeNode node = root as DocumentCompositeNode;

            if (node == null)
            {
                return;
            }
            DocumentCompositeNode parent = root.Parent;

            if (parent != null && PlatformTypes.Setter.IsAssignableFrom((ITypeId)parent.Type) && (parent.TypeResolver.ResolveProperty(SetterSceneNode.TargetNameProperty) == null || parent.Properties[SetterSceneNode.TargetNameProperty] == null) && (ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)root.GetValueProperty()) && parent.Properties[SetterSceneNode.ValueProperty] == root))
            {
                if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)root.Type))
                {
                    node.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)node.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                }
                else if (DocumentNodeUtilities.IsDynamicResource(root) || DocumentNodeUtilities.IsStaticResource(root))
                {
                    DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                    if (resourceKey != null && resources != null)
                    {
                        foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)resources)
                        {
                            if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                            {
                                DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                if (documentCompositeNode != null)
                                {
                                    if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                                    {
                                        documentCompositeNode.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                                        break;
                                    }
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (parent != null && DocumentNodeUtilities.IsStyleOrTemplate(root.Type))
            {
                return;
            }
            foreach (DocumentNode root1 in node.ChildNodes)
            {
                ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(root1, resources, targetType);
            }
        }
예제 #12
0
        internal static string TargetNameFromDocumentNode(DocumentCompositeNode node)
        {
            DocumentCompositeNode node1 = node.Properties[BeginActionNode.StoryboardProperty] as DocumentCompositeNode;

            if (node1 != null && node1.Type.IsResource)
            {
                DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node1);
                if (resourceKey != null)
                {
                    return(DocumentPrimitiveNode.GetValueAsString(resourceKey));
                }
            }
            return((string)null);
        }
예제 #13
0
        public DocumentNode CreateResourceReference(IDocumentContext documentContext, DocumentCompositeNode resourceNode, bool useStaticResource)
        {
            DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(resourceNode);

            if (resourceEntryKey == null)
            {
                return((DocumentNode)null);
            }
            DocumentNode keyNode = resourceEntryKey.Clone(documentContext);

            if (useStaticResource)
            {
                return((DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode));
            }
            return((DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode));
        }
예제 #14
0
        protected virtual ObservableCollectionWorkaround <LocalResourceModel> ProvideLocalResources(List <ResourceContainer> activeContainers)
        {
            ObservableCollectionWorkaround <LocalResourceModel> collectionWorkaround = new ObservableCollectionWorkaround <LocalResourceModel>();

            foreach (DocumentCompositeNode entryNode in this.DesignerContext.ResourceManager.GetResourcesInElementsScope((IList <ResourceContainer>)activeContainers, PlatformTypes.Object, ResourceResolutionFlags.IncludeApplicationResources | ResourceResolutionFlags.UniqueKeysOnly))
            {
                DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                DocumentNode node             = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                if (resourceEntryKey != null)
                {
                    DelayedEvaluationLocalResourceModel localResourceModel = new DelayedEvaluationLocalResourceModel(this.DocumentContext, this.DesignerContext, resourceEntryKey, node.TargetType, node);
                    collectionWorkaround.Add((LocalResourceModel)localResourceModel);
                }
            }
            collectionWorkaround.Sort((Comparison <LocalResourceModel>)((left, right) => string.Compare(left.ResourceName, right.ResourceName, StringComparison.CurrentCulture)));
            return(collectionWorkaround);
        }
예제 #15
0
        private void UpdateAsync()
        {
            SelectedElementsResourceObserver.UpdateState updateState = this.updateState;
            this.updateState = SelectedElementsResourceObserver.UpdateState.None;
            List <DocumentNode> list1 = this.oldNodesAsync;
            List <DocumentNode> list2 = this.newNodesAsync;

            this.oldNodesAsync = new List <DocumentNode>();
            this.newNodesAsync = new List <DocumentNode>();
            if (updateState == SelectedElementsResourceObserver.UpdateState.Catastrophic)
            {
                this.Update(this.ViewModel, SceneViewModel.ViewStateBits.EntireScene);
            }
            foreach (DocumentNode documentNode in list2)
            {
                foreach (ResourceContainer resourceContainer in this.ResourceManager.ActiveSceneViewModel == null || documentNode.DocumentRoot != this.ResourceManager.ActiveSceneViewModel.DocumentRoot ? (IEnumerable)this.ResourceManager.DocumentResourceContainers : (IEnumerable)this.ResourceManager.LocalResourceContainers)
                {
                    if (resourceContainer.DocumentNode != null && ResourceNodeHelper.GetResourcesCollection(resourceContainer.DocumentNode).Resources == documentNode.Parent)
                    {
                        foreach (ResourceItem resourceItem in (Collection <ResourceItem>)resourceContainer.ResourceItems)
                        {
                            if (resourceItem.DocumentNode == documentNode)
                            {
                                this.AddRefItem(resourceItem);
                                break;
                            }
                        }
                    }
                }
            }
            foreach (DocumentNode documentNode in list1)
            {
                foreach (ResourceItem resourceItem in (Collection <ResourceItem>) this.ResourceItems)
                {
                    if (resourceItem.DocumentNode == documentNode)
                    {
                        this.RemoveItem(resourceItem);
                        break;
                    }
                }
            }
        }
        public DataStorePropertyEntry FindMatchDataStorePropertyEntry(SceneNodeProperty property, string propertyName)
        {
            if (property == null)
            {
                return((DataStorePropertyEntry)null);
            }
            bool         isMixed             = false;
            DocumentNode valueAsDocumentNode = property.GetLocalValueAsDocumentNode(false, out isMixed);

            if (valueAsDocumentNode != null && property.SceneNodeObjectSet.ViewModel.IsExternal(valueAsDocumentNode))
            {
                return((DataStorePropertyEntry)null);
            }
            BindingSceneNode bindingSceneNode = property.SceneNodeObjectSet.ViewModel.GetSceneNode(valueAsDocumentNode) as BindingSceneNode;

            if (bindingSceneNode == null)
            {
                return((DataStorePropertyEntry)null);
            }
            string path                = propertyName ?? bindingSceneNode.Path;
            string dataStore           = (string)null;
            DocumentCompositeNode node = bindingSceneNode.Source as DocumentCompositeNode;

            if (node != null && PlatformTypes.StaticResource.IsAssignableFrom((ITypeId)node.Type))
            {
                DocumentPrimitiveNode documentPrimitiveNode = ResourceNodeHelper.GetResourceKey(node) as DocumentPrimitiveNode;
                if (documentPrimitiveNode != null)
                {
                    dataStore = documentPrimitiveNode.GetValue <string>();
                }
            }
            return(Enumerable.FirstOrDefault <DataStorePropertyEntry>(Enumerable.Where <DataStorePropertyEntry>((IEnumerable <DataStorePropertyEntry>) this.Properties, (Func <DataStorePropertyEntry, bool>)(entry =>
            {
                if (entry.Name == path)
                {
                    return entry.DataSetName == dataStore;
                }
                return false;
            }))));
        }
예제 #17
0
 private static void ChangeKey(IList <SceneNode> elements, DictionaryEntryNode resource, DocumentNode oldKey, DocumentNode newKey)
 {
     resource.KeyNode = resource.ViewModel.GetSceneNode(newKey);
     if (elements == null)
     {
         return;
     }
     foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)elements)
     {
         foreach (DocumentNode expression in sceneNode.DocumentNode.SelectDescendantNodes(new Predicate <DocumentNode>(ResourceHelper.FilterResources)))
         {
             DocumentCompositeNode node = expression as DocumentCompositeNode;
             if (node != null)
             {
                 DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                 if (resourceKey != null && resourceKey.Equals(oldKey) && new ExpressionEvaluator((IDocumentRootResolver)null).EvaluateExpression(sceneNode.DocumentNodePath, expression) == null)
                 {
                     ResourceNodeHelper.SetResourceKey(node, newKey.Clone(sceneNode.DocumentContext));
                 }
             }
         }
     }
 }
예제 #18
0
        protected void DoDrop(DragEventArgs eventArgs, int destinationIndex)
        {
            IDataObject data = eventArgs.Data;

            if (this.ResourceManager.IsFiltering)
            {
                return;
            }
            ResourceEntryItem resourceEntry = (ResourceEntryItem)null;

            if (!this.CanDrop(eventArgs, out resourceEntry) || resourceEntry == this)
            {
                return;
            }
            ResourceContainer dropTargetContainer = this.DragDropTargetContainer;

            if (resourceEntry.Container == dropTargetContainer)
            {
                if ((eventArgs.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey)
                {
                    using (SceneEditTransaction editTransaction = resourceEntry.Container.ViewModel.CreateEditTransaction(StringTable.UndoUnitCopyResource))
                    {
                        DocumentCompositeNode entryNode = resourceEntry.Resource.ResourceNode.Clone(dropTargetContainer.ViewModel.Document.DocumentContext) as DocumentCompositeNode;
                        DocumentNode          keyNode   = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.GenerateUniqueResourceKey(resourceEntry.Key.ToString(), dropTargetContainer.Node);
                        ResourceNodeHelper.SetResourceEntryKey(entryNode, keyNode);
                        Microsoft.Expression.DesignSurface.Utility.ResourceHelper.AddResource((DictionaryEntryNode)dropTargetContainer.ViewModel.GetSceneNode((DocumentNode)entryNode), dropTargetContainer.ResourceDictionaryNode, destinationIndex);
                        editTransaction.Commit();
                    }
                }
                else
                {
                    resourceEntry.Container.MoveItem(resourceEntry, destinationIndex);
                }
            }
            else
            {
                ObservableCollection <string> observableCollection = new ObservableCollection <string>();
                observableCollection.Add(dropTargetContainer.DocumentContext.DocumentUrl);
                bool skipReferencedResourceCopy = this.IsContainerReachable((IEnumerable <string>)observableCollection, resourceEntry.Container);
                if ((eventArgs.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey)
                {
                    this.CopyItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy);
                }
                else
                {
                    ReferencesFoundModel referencingResources = resourceEntry.InteractiveGetReferencingResources(ReferencesFoundModel.UseScenario.DeleteResource);
                    if (referencingResources == null)
                    {
                        return;
                    }
                    bool doReferenceFixup = false;
                    if (referencingResources.ReferenceNames.Count > 0 && !this.IsContainerReachable((IEnumerable <string>)referencingResources.ScenesWithReferences, dropTargetContainer))
                    {
                        if (!new ReferencesFoundDialog(referencingResources).ShowDialog().GetValueOrDefault(false))
                        {
                            return;
                        }
                        doReferenceFixup = referencingResources.SelectedUpdateMethod != ReferencesFoundModel.UpdateMethod.DontFix;
                    }
                    if (dropTargetContainer.ViewModel == resourceEntry.Container.ViewModel)
                    {
                        using (SceneEditTransaction editTransaction = dropTargetContainer.ViewModel.CreateEditTransaction(StringTable.UndoUnitMoveResource))
                        {
                            if (this.MoveItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy, referencingResources, doReferenceFixup))
                            {
                                editTransaction.Commit();
                            }
                            else
                            {
                                editTransaction.Cancel();
                            }
                        }
                    }
                    else
                    {
                        this.MoveItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy, referencingResources, doReferenceFixup);
                    }
                }
            }
        }
예제 #19
0
        private static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, bool allowInsertionPointChange, out bool canceledPasteOperation)
        {
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.PasteElements);
            canceledPasteOperation = false;
            List <SceneNode> list         = new List <SceneNode>();
            PastePackage     pastePackage = PastePackage.FromData(viewModel, dataObject);

            if (pastePackage != null)
            {
                if (allowInsertionPointChange)
                {
                    insertionPoint = PasteCommand.ComputeNewInsertionPoint(viewModel, insertionPoint, pastePackage);
                }
                if (!PasteCommand.CanAddMultipleElements(insertionPoint.SceneElement, pastePackage.Elements.Count))
                {
                    string name = insertionPoint.SceneElement.TargetType.Name;
                    viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteMultipleInSingleContainerError, new object[1]
                    {
                        (object)name
                    }));
                }
                else if (pastePackage.Elements.Count == 0 && pastePackage.Storyboards.Count == 0 && pastePackage.Resources.Count > 0)
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedNoElementsDialogMessage);
                }
                else
                {
                    IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>();
                    foreach (SceneNode sceneNode in pastePackage.Elements)
                    {
                        foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel))
                        {
                            imageMap.Add(keyValuePair);
                        }
                    }
                    foreach (SceneNode sceneNode in pastePackage.Resources)
                    {
                        foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel))
                        {
                            imageMap.Add(keyValuePair);
                        }
                    }
                    int index = 0;
                    ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(viewModel.RootNode.DocumentNode);
                    if (resourcesCollection != null && resourcesCollection.Resources != null && resourcesCollection.Resources.SupportsChildren)
                    {
                        index = resourcesCollection.Resources.Children.Count;
                    }
                    if (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, viewModel.RootNode, index, false))
                    {
                        ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(insertionPoint.SceneElement, true);
                        List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater = new List <PasteCommand.DelayedElementTranslationInfo>(pastePackage.Elements.Count);
                        string copyElementToken = pastePackage.ClipboardCopyElementToken;
                        foreach (SceneElement element in pastePackage.Elements)
                        {
                            SceneElement sceneElement = PasteCommand.PasteElement(viewModel, element, elementsToTranslateLater, insertionPoint);
                            if (sceneElement != null)
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.UpdateImageReferences(sceneElement.DocumentNode, imageMap, pastePackage, viewModel);
                                list.Add((SceneNode)sceneElement);
                                sceneElement.ClearValue(DesignTimeProperties.CopyTokenProperty);
                            }
                        }
                        if (copyElementToken != null)
                        {
                            pastePackage.SetGlobalCopyElementToken(copyElementToken);
                            PastePackage.PasteSelectionChangePending = true;
                        }
                        foreach (SceneNode childProperty in pastePackage.ChildPropertyNodes)
                        {
                            PasteCommand.PasteChildProperty(viewModel, childProperty, (IList <SceneNode>)list);
                        }
                        foreach (StoryboardTimelineSceneNode storyboard in pastePackage.Storyboards)
                        {
                            PasteCommand.PasteStoryboard(viewModel, storyboard, (IList <SceneNode>)list);
                        }
                        viewModel.Document.OnUpdatedEditTransaction();
                        viewModel.DefaultView.UpdateLayout();
                        using (viewModel.ForceBaseValue())
                        {
                            Rect empty = Rect.Empty;
                            foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater)
                            {
                                empty.Union(elementTranslationInfo.Bounds);
                            }
                            foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater)
                            {
                                elementTranslationInfo.UpdateTranslation(designerForParent, empty);
                            }
                        }
                    }
                    else
                    {
                        canceledPasteOperation = true;
                    }
                }
            }
            else if (dataObject.GetDataPresent(DataFormats.FileDrop))
            {
                DesignerContext designerContext = viewModel.DesignerContext;
                string[]        supportedFiles  = FileDropToolBehavior.CreateImageOrMediaDrop(designerContext).GetSupportedFiles(ClipboardService.GetDataObject());
                if (supportedFiles.Length > 0)
                {
                    IEnumerable <IProjectItem> importedItems = designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo()
                    {
                        SourcePath = file
                    })));
                    FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, importedItems, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint);
                }
                else
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
                }
            }
            else if (dataObject.GetDataPresent(DataFormats.Bitmap))
            {
                DesignerContext designerContext = viewModel.DesignerContext;
                IProjectItem    projectItem     = CutBuffer.AddImageDataFromClipboard(designerContext.ProjectManager, designerContext.ActiveProject);
                if (projectItem != null)
                {
                    FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, (IEnumerable <IProjectItem>) new List <IProjectItem>()
                    {
                        projectItem
                    }, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint);
                }
                else
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
                }
            }
            else
            {
                viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
            }
            return((ICollection <SceneNode>)list);
        }
        protected override void Work()
        {
            IProjectDocument projectDocument1 = this.projectDocuments[this.currentProjectDocument];

            if (projectDocument1 == null || projectDocument1.Document != null)
            {
                return;
            }
            IProjectDocument projectDocument2 = this.model.ResourceEntryNode.ProjectContext.OpenDocument(projectDocument1.Path);

            if (projectDocument2 == null)
            {
                return;
            }
            SceneDocument document = projectDocument2.Document as SceneDocument;

            if (document == null || !document.IsEditable)
            {
                return;
            }
            IDocumentRoot documentRoot = document.DocumentRoot;
            DocumentNode  searchKey    = (DocumentNode)null;
            SceneNode     keyNode      = this.model.ResourceEntryNode.KeyNode;

            if (keyNode != null)
            {
                searchKey = keyNode.DocumentNode;
            }
            foreach (DocumentNode documentNode1 in documentRoot.RootNode.SelectDescendantNodes((Predicate <DocumentNode>)(node =>
            {
                DocumentCompositeNode node1 = node as DocumentCompositeNode;
                return(node1 != null && node1.Type.IsResource && ResourceNodeHelper.GetResourceKey(node1).Equals(searchKey));
            })))
            {
                ITypeMetadataFactory metadataFactory = this.model.ResourceEntryNode.ProjectContext.MetadataFactory;
                IType type = documentNode1.TypeResolver.ResolveType(PlatformTypes.FrameworkElement);
                DocumentCompositeNode documentCompositeNode = documentNode1.SelectFirstAncestorNode(type.RuntimeType) as DocumentCompositeNode;
                string caption = document.Caption;
                string str;
                if (documentCompositeNode != null)
                {
                    IPropertyId  index         = (IPropertyId)metadataFactory.GetMetadata(documentCompositeNode.TargetType).NameProperty;
                    DocumentNode documentNode2 = documentCompositeNode.Properties[index];
                    if (documentNode2 != null)
                    {
                        DocumentPrimitiveNode documentPrimitiveNode = documentNode2 as DocumentPrimitiveNode;
                        str = documentPrimitiveNode == null?documentNode2.ToString() : documentPrimitiveNode.Value.ToString();
                    }
                    else
                    {
                        str = documentCompositeNode.ToString();
                    }
                }
                else
                {
                    str = documentNode1.ToString();
                }
                this.model.ReferenceNames.Add(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ReferencesFoundFormat, new object[2]
                {
                    (object)str,
                    (object)caption
                }));
                this.model.AddReferencesFile(document);
            }
            this.model.ResourceEntryNode.ViewModel.DesignerContext.DocumentService.CloseDocument((IDocument)document);
        }
        protected DocumentNode ProvideCurrentStyle(SceneElement targetElement, IType targetType, PropertyReference targetPropertyReference, bool allowDefaultStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            DocumentNode currentStyle = (DocumentNode)null;
            bool         isThemeStyle = false;
            IType        targetType1  = targetType;

            if (!this.TargetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                IDocumentContext documentContext    = this.SceneViewModel.Document.DocumentContext;
                Type             propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
                targetType1 = propertyTargetType == (Type)null ? (IType)null : this.SceneViewModel.ProjectContext.GetType(propertyTargetType);
            }
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference);
                if (valueAsDocumentNode != null && valueAsDocumentNode.Node is DocumentCompositeNode && PlatformTypes.Style.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type) && (!StyleNode.IsDefaultValue(valueAsDocumentNode.Node) || allowDefaultStyle))
                {
                    StyleNode styleNode = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as StyleNode;
                    if (styleNode != null)
                    {
                        currentStyle       = styleNode.DocumentNode;
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(valueAsDocumentNode.Node);
                    }
                }
            }
            if (currentStyle == null)
            {
                object obj = this.ResolveCurrentStyle(targetElement, targetPropertyReference, allowDefaultStyle);
                if (obj != null)
                {
                    DocumentNode correspondingDocumentNode = this.SceneView.GetCorrespondingDocumentNode(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(obj), true);
                    if (correspondingDocumentNode != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)correspondingDocumentNode.Type))
                    {
                        currentStyle = correspondingDocumentNode;
                    }
                    else if (obj is Style)
                    {
                        StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(obj);
                        if (targetType1 != null)
                        {
                            styleNode.StyleTargetTypeId = targetType1;
                        }
                        currentStyle = styleNode.DocumentNode;
                    }
                }
                if (currentStyle != null && !allowDefaultStyle && StyleNode.IsDefaultValue(currentStyle))
                {
                    currentStyle = (DocumentNode)null;
                }
            }
            if (currentStyle == null)
            {
                object defaultStyleKey = this.GetDefaultStyleKey(targetElement, (ITypeId)targetType1, (IPropertyId)this.TargetProperty);
                if (defaultStyleKey != null)
                {
                    this.ResolveDefaultStyle(targetElement, defaultStyleKey, allowDefaultStyle, out currentStyle, out isThemeStyle, out auxillaryResources);
                }
            }
            if (currentStyle != null && !allowDefaultStyle)
            {
                List <DocumentCompositeNode> list = new List <DocumentCompositeNode>();
                DocumentCompositeNode        node = currentStyle as DocumentCompositeNode;
                IProperty property = this.SceneViewModel.ProjectContext.ResolveProperty(StyleNode.BasedOnProperty);
                while (node != null && property != null && (node.Type.Equals((object)PlatformTypes.Style) && node.Properties.Count == 2) && (node.Properties[(IPropertyId)property] != null && node.Properties[StyleNode.TargetTypeProperty] != null))
                {
                    node = node.Properties[StyleNode.BasedOnProperty] as DocumentCompositeNode;
                    if (node != null)
                    {
                        if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)node) || DocumentNodeUtilities.IsStaticResource((DocumentNode)node))
                        {
                            DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                            if (resourceKey != null && auxillaryResources != null)
                            {
                                foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                                {
                                    if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                                    {
                                        node = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                        break;
                                    }
                                }
                            }
                        }
                        if (PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type))
                        {
                            currentStyle = (DocumentNode)node;
                            list.Add(node);
                        }
                    }
                }
                if (auxillaryResources != null)
                {
                    foreach (DocumentNode documentNode in list)
                    {
                        DocumentCompositeNode parent = documentNode.Parent;
                        if (parent != null && parent.Type.Equals((object)PlatformTypes.DictionaryEntry))
                        {
                            auxillaryResources.Remove(parent);
                        }
                    }
                }
                if (currentStyle != null && (list.Count > 0 || currentStyle.DocumentRoot != null))
                {
                    currentStyle = currentStyle.Clone(targetElement.DocumentContext);
                }
                if (auxillaryResources != null)
                {
                    for (int index = 0; index < auxillaryResources.Count; ++index)
                    {
                        if (auxillaryResources[index].DocumentRoot != null)
                        {
                            auxillaryResources[index] = (DocumentCompositeNode)auxillaryResources[index].Clone(targetElement.DocumentContext);
                        }
                    }
                }
                if (isThemeStyle)
                {
                    ReplaceStyleTemplateCommand.StripFormatting(currentStyle);
                    if (auxillaryResources != null)
                    {
                        for (int index = 0; index < auxillaryResources.Count; ++index)
                        {
                            ReplaceStyleTemplateCommand.StripFormatting((DocumentNode)auxillaryResources[index]);
                        }
                    }
                }
                DocumentCompositeNode documentCompositeNode = currentStyle as DocumentCompositeNode;
                if (documentCompositeNode != null && targetType1 != null)
                {
                    documentCompositeNode.Properties[StyleNode.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType1));
                }
                if (targetType1 != null)
                {
                    ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(currentStyle, auxillaryResources, targetType1);
                }
            }
            return(currentStyle);
        }
예제 #22
0
        private static DocumentNode FindResource(ResourceDictionaryContentProvider themeContent, string originalThemePath, Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> > provideInstanceForThemeContent, Func <Uri, string, string> provideResolvedUriForMergedDictionary, Func <string, ResourceDictionaryContentProvider> provideContentForMergedDictionary, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            DocumentNode root = (DocumentNode)null;

            auxillaryResources = (IList <DocumentCompositeNode>)null;
            Func <DocumentNode, object> func = provideInstanceForThemeContent(themeContent);

            foreach (DocumentNode documentNode1 in themeContent.Items)
            {
                DocumentCompositeNode entryNode = documentNode1 as DocumentCompositeNode;
                if (entryNode != null)
                {
                    DocumentNode documentNode2 = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                    if (documentNode2 == null)
                    {
                        DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                        if (documentCompositeNode != null)
                        {
                            if (documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty != null)
                            {
                                documentNode2 = documentCompositeNode.Properties[documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty];
                            }
                            if (documentNode2 == null && documentCompositeNode.TypeResolver.IsCapabilitySet(PlatformCapability.NameSupportedAsKey))
                            {
                                documentNode2 = documentCompositeNode.Properties[(IPropertyId)documentCompositeNode.Type.Metadata.NameProperty];
                            }
                        }
                    }
                    if (documentNode2 != null)
                    {
                        object objB = func(documentNode2);
                        if (object.Equals(resourceKey, objB))
                        {
                            root = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                            break;
                        }
                    }
                }
            }
            if (root == null && originalThemePath != null)
            {
                foreach (DocumentNode documentNode in themeContent.Items)
                {
                    DocumentCompositeNode documentCompositeNode = documentNode as DocumentCompositeNode;
                    if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                    {
                        Uri uriValue = documentCompositeNode.GetUriValue(ResourceDictionaryNode.SourceProperty);
                        if (uriValue != (Uri)null)
                        {
                            string originalThemePath1 = provideResolvedUriForMergedDictionary(uriValue, originalThemePath);
                            if (originalThemePath1 != null)
                            {
                                ResourceDictionaryContentProvider themeContent1 = provideContentForMergedDictionary(originalThemePath1);
                                if (themeContent1 != null)
                                {
                                    root = ThemeContentProvider.FindResource(themeContent1, originalThemePath1, provideInstanceForThemeContent, provideResolvedUriForMergedDictionary, provideContentForMergedDictionary, resourceKey, out auxillaryResources);
                                    if (root != null)
                                    {
                                        return(root);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (root != null)
            {
                auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root);
            }
            return(root);
        }
예제 #23
0
        public override void Execute()
        {
            SceneElement targetElement = this.TargetElement;

            if (targetElement is StyleNode)
            {
                this.useStyle = new bool?(false);
            }
            else
            {
                IList <DocumentCompositeNode> auxillaryResources1;
                DocumentNode documentNode1 = this.ProvideCurrentStyle(targetElement, this.Type, new PropertyReference((ReferenceStep)targetElement.ProjectContext.ResolveProperty(BaseFrameworkElement.StyleProperty)), false, out auxillaryResources1);
                IList <DocumentCompositeNode> auxillaryResources2;
                DocumentNode other = this.ProvideCurrentTemplate(targetElement, new PropertyReference(this.ActiveTemplateProperty), out auxillaryResources2);
                bool         flag  = false;
                if ((other == null || other.DocumentRoot == null) && documentNode1 != null)
                {
                    using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitEditCopyStyle, true))
                    {
                        if (auxillaryResources1 != null && auxillaryResources1.Count > 0)
                        {
                            ResourceSite resourceSite = new ResourceSite(targetElement.DocumentNode);
                            resourceSite.EnsureResourceCollection();
                            foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources1)
                            {
                                DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                                DocumentNode documentNode2    = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                                if (resourceEntryKey != null && documentNode2 != null)
                                {
                                    DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.DictionaryEntry);
                                    dictionaryEntryNode.KeyNode = this.SceneViewModel.GetSceneNode(resourceEntryKey.Clone(this.SceneViewModel.Document.DocumentContext));
                                    dictionaryEntryNode.Value   = this.SceneViewModel.GetSceneNode(documentNode2.Clone(this.SceneViewModel.Document.DocumentContext));
                                    resourceSite.ResourcesDictionary.Children.Add(dictionaryEntryNode.DocumentNode);
                                }
                            }
                        }
                        documentNode1 = documentNode1.Clone(this.SceneViewModel.Document.DocumentContext);
                        DocumentCompositeNode documentCompositeNode = documentNode1 as DocumentCompositeNode;
                        if (documentCompositeNode != null && documentCompositeNode.NameProperty != null && documentCompositeNode.Properties.Contains(documentCompositeNode.NameProperty))
                        {
                            documentCompositeNode.ClearValue((IPropertyId)documentCompositeNode.NameProperty);
                        }
                        targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1);
                        DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(this.TargetPropertyReference);
                        documentNode1 = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                        editTransaction.Update();
                        object computedValue = targetElement.GetComputedValue(new PropertyReference(this.ActiveTemplateProperty));
                        if (computedValue != null)
                        {
                            DocumentNodePath correspondingNodePath = this.SceneView.GetCorrespondingNodePath(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(computedValue), true);
                            if (correspondingNodePath != null)
                            {
                                flag  = valueAsDocumentNode.IsAncestorOf(correspondingNodePath);
                                other = correspondingNodePath != null ? correspondingNodePath.Node : other;
                            }
                        }
                        editTransaction.Cancel();
                    }
                }
                this.useStyle = new bool?(flag || other != null && documentNode1 != null && documentNode1.IsAncestorOf(other));
            }
            base.Execute();
            this.useStyle = new bool?();
        }