public DocumentCompositeNode CreateResource(DocumentNode newResourceNode, IPropertyId targetTypeProperty, int index)
        {
            ResourceSite currentResourceSite = this.CurrentResourceSite;

            if (currentResourceSite == null)
            {
                return((DocumentCompositeNode)null);
            }
            IDocumentContext documentContext = currentResourceSite.DocumentContext;

            if (newResourceNode.Context != documentContext)
            {
                newResourceNode = newResourceNode.Clone(documentContext);
            }
            if (this.TargetType != (Type)null)
            {
                IType type = documentContext.TypeResolver.GetType(this.TargetType);
                ((DocumentCompositeNode)newResourceNode).Properties[targetTypeProperty] = (DocumentNode)documentContext.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)type));
            }
            if (this.selectedLocation == this.thisDocumentResourceDictionaries && this.selectedResourceDictionary != null)
            {
                this.selectedResourceDictionary.Instance.EnsureResourceDictionaryNode();
                this.currentResourceSiteCacheValid = false;
            }
            DocumentNode keyNode;

            if (this.ApplyAutomatically)
            {
                keyNode = (DocumentNode)null;
            }
            else
            {
                string uniqueResourceKey = currentResourceSite.GetUniqueResourceKey(this.KeyString);
                keyNode = (DocumentNode)documentContext.CreateNode(uniqueResourceKey);
            }
            SceneDocument         externalDocument = this.ExternalDocument;
            DocumentCompositeNode resource;

            if (externalDocument != null)
            {
                using (SceneEditTransaction editTransaction = externalDocument.CreateEditTransaction(StringTable.PropertyCreateResourceInFileDescription))
                {
                    resource = currentResourceSite.CreateResource(keyNode, newResourceNode, index);
                    editTransaction.Commit();
                }
            }
            else
            {
                resource = currentResourceSite.CreateResource(keyNode, newResourceNode, index);
            }
            return(resource);
        }
        public int IndexInResourceSite(DocumentNode node)
        {
            ResourceSite currentResourceSite = this.CurrentResourceSite;

            if (currentResourceSite != null)
            {
                DocumentCompositeNode resourcesDictionary = currentResourceSite.ResourcesDictionary;
                if (resourcesDictionary != null)
                {
                    return(CreateResourceModel.IndexInResourceSite(node, resourcesDictionary));
                }
            }
            return(-1);
        }
 private void RegenerateUniqueResourceKey()
 {
     if (!this.userHasModifiedKeyString)
     {
         string name = this.TargetTypeName + (this.resourceType != (Type)null ? this.resourceType.Name : string.Empty) + "1";
         if (this.CurrentResourceSite != null && !this.applyAutomatically)
         {
             string prefix;
             int    suffixValue;
             if (!ResourceSite.ParseKeyString(name, out prefix, out suffixValue))
             {
                 suffixValue = 1;
             }
             this.keyString = prefix + suffixValue.ToString();
             while (this.AnalyzeKeyStringWorker() != CreateResourceModel.KeyStringDocumentStatus.None)
             {
                 ++suffixValue;
                 this.keyString = prefix + suffixValue.ToString((IFormatProvider)CultureInfo.InvariantCulture);
             }
         }
     }
     this.AnalyzeKeyString();
 }
Exemple #4
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?();
        }