Example #1
0
        /// <summary>
        /// Saves the given file.
        /// </summary>
        protected override void Save(string fileName)
        {
            DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult();

            global::DSLFactory.Candle.SystemModel.CandleModel modelRoot = (global::DSLFactory.Candle.SystemModel.CandleModel) this.RootElement;


            global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement);
            if (diagrams.Count > 0)
            {
                global::DSLFactory.Candle.SystemModel.ComponentModelDiagram diagram = diagrams[0] as global::DSLFactory.Candle.SystemModel.ComponentModelDiagram;
                if (diagram != null)
                {
                    string diagramFileName = fileName + this.DiagramExtension;

                    try
                    {
                        this.SuspendFileChangeNotification(diagramFileName);

                        global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false);
                        if (!serializationResult.Failed)
                        {
                            // fileName != this.FileName is false in the case of Save As.  Allow OnFileNameChanged() below to handle this case.
                            if (global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) == 0 && global::System.IO.File.Exists(diagramFileName))
                            {
                                DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName);
                            }
                        }
                    }
                    finally
                    {
                        this.ResumeFileChangeNotification(diagramFileName);
                    }
                }
            }
            if (!serializationResult.Failed)
            {
                global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false);
            }
            // Report serialization messages.
            this.SuspendErrorListRefresh();
            try
            {
                foreach (DslModeling::SerializationMessage serializationMessage in serializationResult)
                {
                    this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage));
                }
            }
            finally
            {
                this.ResumeErrorListRefresh();
            }

            if (serializationResult.Failed)
            {                   // Save failed.
                throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
Example #2
0
        /// <summary>
        /// Called on both document load and reload.
        /// </summary>
        protected virtual void OnDocumentLoaded()
        {
            // Validate the document
            this.ValidationController.Validate(this.Store, DslValidation::ValidationCategories.Open);

            // Enable CompartmentItems events.
            global::DSLFactory.Candle.SystemModel.CandleModel modelRoot = this.RootElement as global::DSLFactory.Candle.SystemModel.CandleModel;
            if (modelRoot != null)
            {
                global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot);
                if (diagrams.Count > 0)
                {
                    global::DSLFactory.Candle.SystemModel.ComponentModelDiagram diagram = diagrams[0] as global::DSLFactory.Candle.SystemModel.ComponentModelDiagram;
                    if (diagram != null)
                    {
                        diagram.SubscribeCompartmentItemsEvents();
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Loads the given file.
        /// </summary>
        protected override void Load(string fileName, bool isReload)
        {
            DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult();

            global::DSLFactory.Candle.SystemModel.CandleModel modelRoot = null;
            DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider);

            // Enable diagram fixup rules in our store, because we will load diagram data.
            global::DSLFactory.Candle.SystemModel.CandleDomainModel.EnableDiagramRules(this.Store);
            string diagramFileName = fileName + this.DiagramExtension;

            // Ensure that subordinate diagram file is named properly; handles the case where a rename occurs while the designer was closed.
            if (this.Hierarchy != null)
            {
                uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension);
                if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL)
                {
                    global::System.Diagnostics.Debug.Assert(!this.IsLoaded);
                    // Make sure the name is right before we lock the item in the RDT.
                    DslShell::SubordinateFileHelper.EnsureChildFileName(this.ServiceProvider, this.Hierarchy, itemId, diagramFileName);

                    // Found the diagram file, lock it in the running documents table.
                    this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId);
                    if (this.diagramDocumentLockHolder == null)
                    {
                        throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"));
                    }
                }
            }

            try
            {
                modelRoot = global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */);
            }
            finally
            {
                if (this.diagramDocumentLockHolder != null && (modelRoot == null || serializationResult.Failed))
                {
                    // Load failed, release the document lock if we added one above.
                    this.diagramDocumentLockHolder.UnregisterSubordinateDocument();
                    this.diagramDocumentLockHolder = null;
                }
            }

            // Report serialization messages.
            this.SuspendErrorListRefresh();
            try
            {
                foreach (DslModeling::SerializationMessage serializationMessage in serializationResult)
                {
                    this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage));
                }
            }
            finally
            {
                this.ResumeErrorListRefresh();
            }

            if (serializationResult.Failed)
            {
                // Load failed, can't open the file.
                throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"));
            }
            else
            {
                this.SetRootElement(modelRoot);
                if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName))
                {
                    DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName);

                    // Should have a subordinate diagram file now. If we didn't add a lock above, add one now.
                    if (this.diagramDocumentLockHolder == null)
                    {
                        uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension);
                        this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId);
                        if (this.diagramDocumentLockHolder == null)
                        {
                            throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"));
                        }
                    }

                    // Connect to events on the RDT in order to allow delayed rename handling.
                    this.eventsCookie = DslShell::SubordinateFileHelper.AdviseRunningDocumentTableEvents(this.ServiceProvider, this);
                }
            }
        }