Exemple #1
0
        /// <summary>
        /// Saves the domain model to a specified filename. This serialization is treated as temporarly and as such does
        /// not change the default saving location of the current domain model.
        /// </summary>
        /// <param name="fileName">Filename to save the domain model to.</param>
        protected override void SaveDocumentTemporarly(string fileName)
        {
            DslModeling::SerializationResult result = new DslModeling.SerializationResult();

            global::Tum.StateMachineDSL.StateMachineDomainModel modelRoot = (global::Tum.StateMachineDSL.StateMachineDomainModel) this.RootElement;
            StateMachineLanguageSerializationHelper.Instance.TemporarlySaveModelStateMachineDomainModel(result, modelRoot, fileName, this.Encoding, false);
        }
Exemple #2
0
        /// <summary>
        /// Saves the domain model to a specified filename. This serialization is treated as temporarly and as such does
        /// not change the default saving location of the current domain model.
        /// </summary>
        /// <param name="fileName">Filename to save the domain model to.</param>
        protected override void SaveDocumentTemporarly(string fileName)
        {
            DslModeling::SerializationResult result = new DslModeling.SerializationResult();

            global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = (global::Tum.PDE.VSPluginDSL.DomainModel) this.RootElement;
            VSPluginDSLSerializationHelper.Instance.TemporarlySaveModelDomainModel(result, modelRoot, fileName, this.Encoding, false);
        }
Exemple #3
0
        /// <summary>
        /// Loads the pattern model file, and returns the schema.
        /// </summary>
        /// <param name="modelFilePath">Full path to the pattern model file.</param>
        public static PatternModelSchema LoadPatternModelFromFile(string modelFilePath)
        {
            var patternModel = (PatternModelSchema)null;
            var store        = new DslModeling.Store(null, new[] { typeof(PatternModelDomainModel) });

            DslModeling.Transaction tx = null;

            try
            {
                var serializationResult = new DslModeling.SerializationResult();
                tx           = store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingModel, true);
                patternModel = Instance.LoadModel(serializationResult, store, modelFilePath, null, null, null);
                if (serializationResult.Failed)
                {
                    throw new DslModeling.SerializationException(serializationResult);
                }

                tx.Commit();
            }
            finally
            {
                if ((tx != null))
                {
                    tx.Dispose();
                }
            }

            return(patternModel);
        }
Exemple #4
0
        internal void SaveModelAndDiagrams(
            DslModeling.SerializationResult serializationResult,
            PatternModelSchema modelRoot,
            string modelFileName,
            Dictionary <string, PatternModelSchemaDiagram> diagrams,
            Encoding encoding,
            bool writeOptionalPropertiesWithDefaultValue)
        {
            Guard.NotNull(() => serializationResult, serializationResult);
            Guard.NotNull(() => modelRoot, modelRoot);
            Guard.NotNullOrEmpty(() => modelFileName, modelFileName);
            Guard.NotNull(() => diagrams, diagrams);
            Guard.NotNull(() => encoding, encoding);

            if (serializationResult.Failed)
            {
                return;
            }

            using (MemoryStream modelFileContent =
                       this.InternalSaveModel2(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue))
            {
                if (serializationResult.Failed)
                {
                    return;
                }

                foreach (var diagram in diagrams)
                {
                    using (MemoryStream diagramFileContent =
                               this.InternalSaveDiagram2(serializationResult, diagram.Value, diagram.Key, encoding, writeOptionalPropertiesWithDefaultValue))
                    {
                        if (!serializationResult.Failed)
                        {
                            if (modelFileContent != null)
                            {
                                using (FileStream fileStream = new FileStream(modelFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                    using (BinaryWriter writer = new BinaryWriter(fileStream, encoding))
                                    {
                                        writer.Write(modelFileContent.ToArray());
                                    }
                                }
                            }

                            if (diagramFileContent != null)
                            {
                                using (FileStream fileStream = new FileStream(diagram.Key, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                    using (BinaryWriter writer = new BinaryWriter(fileStream, encoding))
                                    {
                                        writer.Write(diagramFileContent.ToArray());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        internal PatternModelSchema LoadModelAndDiagrams(
            DslModeling.SerializationResult serializationResult,
            DslModeling.Partition modelPartition,
            string modelFileName,
            DslModeling.Partition diagramPartition,
            IEnumerable <string> diagramFileNames,
            DslModeling.ISchemaResolver schemaResolver,
            ValidationController validationController,
            DslModeling.ISerializerLocator serializerLocator)
        {
            Guard.NotNull(() => serializationResult, serializationResult);
            Guard.NotNull(() => modelPartition, modelPartition);
            Guard.NotNullOrEmpty(() => modelFileName, modelFileName);
            Guard.NotNull(() => diagramPartition, diagramPartition);
            Guard.NotNull(() => diagramFileNames, diagramFileNames);
            Guard.NotNull(() => schemaResolver, schemaResolver);
            Guard.NotNull(() => serializerLocator, serializerLocator);

            PatternModelSchema modelRoot;

            if (!diagramPartition.Store.TransactionActive)
            {
                throw new InvalidOperationException(PatternModelDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);

            if (serializationResult.Failed)
            {
                // don't try to deserialize diagram data if model load failed.
                return(modelRoot);
            }

            var directory         = this.GetDirectory(diagramPartition.Store);
            var diagramSerializer = directory.GetSerializer(PatternModelSchemaDiagram.DomainClassId);
            var views             = modelRoot.Store.ElementDirectory.AllElements.OfType <ViewSchema>().ToList();

            foreach (var view in views)
            {
                var diagramFileName = diagramFileNames.FirstOrDefault(file => Path.GetFileNameWithoutExtension(file).Contains(view.DiagramId));

                if (diagramFileName == null)
                {
                    PatternModelSerializationHelper.CreatePatternModelSchemaDiagram(serializationResult, diagramPartition, modelRoot, view.DiagramId);
                }
                else
                {
                    this.LoadDiagram(serializationResult, diagramPartition, modelRoot, directory, diagramSerializer, diagramFileName, schemaResolver, validationController);
                }
            }

            // Set tracking properties
            ResetTrackingProperties(modelPartition.Store);

            return(modelRoot);
        }
Exemple #6
0
        /// <summary>
        /// Loads the model from a filename.
        /// </summary>
        /// <param name="serializationResult">The seriazation result.</param>
        /// <param name="partition">The state partition.</param>
        /// <param name="fileName">the filename of the model.</param>
        /// <param name="schemaResolver">The schemaresolver.</param>
        /// <param name="validationController">The validation controller.</param>
        /// <param name="serializerLocator">The serialization locator.</param>
        /// <remarks>This overload is called by teh T4Runner engine.</remarks>
        public override PatternModelSchema LoadModel(DslModeling.SerializationResult serializationResult, DslModeling.Partition partition, string fileName, DslModeling.ISchemaResolver schemaResolver, ValidationController validationController, DslModeling.ISerializerLocator serializerLocator)
        {
            var productLine = base.LoadModel(serializationResult, partition, fileName, schemaResolver, validationController, serializerLocator);

            // Set tracking properties
            if (partition != null)
            {
                ResetTrackingProperties(partition.Store);
            }

            return(productLine);
        }
Exemple #7
0
        /// <summary>
        /// Loads the domain model from a specified file.  This will not replace the currently loaded domain model.
        /// </summary>
        protected override DslModeling::ModelElement LoadDocumentInternal(string fileName)
        {
            serializationResult = new DslEditorModeling::SerializationResult();
            DslModeling::SerializationResult result = new DslModeling.SerializationResult();

            // reset post process info
            VSPluginDSLSerializationPostProcessor.Instance.Reset();

            global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = null;
            modelRoot = global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.LoadModelDomainModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

            // post process
            if (modelRoot != null && !serializationResult.Failed)
            {
                VSPluginDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List <string>(), result, modelRoot.Store);
            }

            // copy messages
            foreach (DslModeling::SerializationMessage m in result)
            {
                DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
                if (m.Kind == DslModeling.SerializationMessageKind.Info)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Message;
                }
                else if (m.Kind == DslModeling.SerializationMessageKind.Warning)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Warning;
                }

                DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
                    VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
                serializationResult.AddMessage(message);
            }
            serializationResult.Failed = result.Failed;

            if (serializationResult.Failed)
            {
                // Load failed, can't open the file.
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));

                return(null);
            }
            else
            {
                return(modelRoot);
            }
        }
Exemple #8
0
        internal static PatternModelSchemaDiagram CreatePatternModelSchemaDiagram(DslModeling.SerializationResult serializationResult, DslModeling.Partition diagramPartition, PatternModelSchema modelRoot, string diagramId)
        {
            var diagram = new PatternModelSchemaDiagram(
                diagramPartition.Store,
                new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, diagramId),
                new DslModeling.PropertyAssignment(
                    DslModeling.ElementFactory.IdPropertyAssignment,
                    !string.IsNullOrEmpty(diagramId) ? new Guid(diagramId) : Guid.NewGuid()));

            diagram.ModelElement = modelRoot;
            diagram.PostDeserialization(true);
            DoCheckForOrphanedShapes(diagram, serializationResult);

            return(diagram);
        }
Exemple #9
0
        /// <summary>
        /// Saves the domain model to a specified filename.
        /// </summary>
        /// <param name="fileName">Filename to save the domain model to.</param>
        protected override void SaveDocument(string fileName)
        {
            serializationResult = new DslEditorModeling::SerializationResult();
            DslModeling::SerializationResult result = new DslModeling.SerializationResult();

            global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = (global::Tum.PDE.VSPluginDSL.DomainModel) this.RootElement;
            global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.SaveModelDomainModel(result, modelRoot, fileName, this.Encoding, false);

            // Save Diagrams
            if (this.diagramsModel != null)
            {
                string diagramsFileName = GetDiagramsFileName(fileName);
                if (this.diagramsModel.Diagrams.Count > 0)
                {
                    VSPluginDSLDiagramsDSLSerializationHelper.Instance.SaveModel(result, this.diagramsModel, diagramsFileName, this.Encoding, false);
                }
                else if (System.IO.File.Exists(diagramsFileName))
                {
                    System.IO.File.Delete(diagramsFileName);
                }
            }

            // copy messages
            foreach (DslModeling::SerializationMessage m in result)
            {
                DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
                if (m.Kind == DslModeling.SerializationMessageKind.Info)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Message;
                }
                else if (m.Kind == DslModeling.SerializationMessageKind.Warning)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Warning;
                }

                DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
                    VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
                serializationResult.AddMessage(message);
            }
            serializationResult.Failed = result.Failed;

            if (serializationResult.Failed)
            {
                // Save failed.
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationSaveErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"), fileName, 0, 0));
            }
        }
        public PatternModelSchema LoadModel(DslModeling.Store store, Stream stream, DslModeling.ISchemaResolver schemaResolver, DslModeling.ISerializerLocator serializerLocator)
        {
            Guard.NotNull(() => store, store);
            Guard.NotNull(() => stream, stream);

            if (!store.DefaultPartition.Store.TransactionActive)
            {
                throw new InvalidOperationException(PatternModelDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            var directory = this.GetDirectory(store.DefaultPartition.Store);
            var modelRootSerializer = directory.GetSerializer(PatternModelSchema.DomainClassId);
            var serializationResult = new DslModeling.SerializationResult();

            Debug.Assert(modelRootSerializer != null, @"Cannot find serializer for PatternModel!");

            if (modelRootSerializer != null)
            {
                PatternModelSchema modelRoot = null;

                var serializationContext = new DslModeling.SerializationContext(directory, string.Empty, serializationResult);
                this.InitializeSerializationContext(store.DefaultPartition, serializationContext, true);

                var transactionContext = new DslModeling.TransactionContext();
                transactionContext.Add(DslModeling.SerializationContext.TransactionContextKey, serializationContext);

                using (var tx = store.DefaultPartition.Store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingModel, true, transactionContext))
                {
                    try
                    {
                        var settings = PatternModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);

                        using (var reader = XmlReader.Create(stream, settings))
                        {
                            reader.Read();
                            Encoding encoding;
                            if (this.TryGetEncoding(reader, out encoding))
                            {
                                serializationResult.Encoding = encoding;
                            }

                            DslModeling.SerializationUtilities.ResolveDomainModels(reader, serializerLocator, store.DefaultPartition.Store);

                            reader.MoveToContent();

                            modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, store.DefaultPartition) as PatternModelSchema;

                            if (modelRoot != null && !serializationResult.Failed)
                            {
                                this.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver);
                            }
                        }
                    }
                    catch (XmlException ex)
                    {
                        DslModeling.SerializationUtilities.AddMessage(serializationContext, DslModeling.SerializationMessageKind.Error, ex);
                    }

                    if (modelRoot == null && !serializationResult.Failed)
                    {
                        modelRoot = this.CreateModelHelper(store.DefaultPartition);
                    }

                    if (tx.IsActive)
                    {
                        tx.Commit();
                    }
                }

                // Set tracking properties
                ResetTrackingProperties(store);

                return modelRoot;
            }

            return null;
        }
Exemple #11
0
        /// <summary>
        /// Loads the domain model from a specified file.
        /// </summary>
        /// <param name="fileName">Filename to load the domain model from.</param>
        /// <param name="isReload"></param>
        protected override void LoadDocument(string fileName, bool isReload)
        {
            this.rootModelElement = null;

            serializationResult = new DslEditorModeling::SerializationResult();
            DslModeling::SerializationResult result = new DslModeling.SerializationResult();

            global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = null;

            // reset post process info
            VSPluginDSLSerializationPostProcessor.Instance.Reset();

            DslModeling::Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load model", true);

            try
            {
                modelRoot = global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.LoadModelDomainModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

                // post process
                if (modelRoot != null && !serializationResult.Failed)
                {
                    VSPluginDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List <string>(), result, modelRoot.Store);
                }


                if (!serializationResult.Failed)
                {
                    // start validation because UseLoad=true
                    ValidateAll();
                }

                // load diagramsModel
                string diagramsFileName = GetDiagramsFileName(fileName);
                if (System.IO.File.Exists(diagramsFileName))
                {
                    diagramsModel = VSPluginDSLDiagramsDSLSerializationHelper.Instance.LoadModel(result, this.ModelData.GetModelPartition(), GetDiagramsFileName(fileName), null, null, null);
                }

                if (diagramsModel == null)
                {
                    diagramsModel = new DslEditorDiagrams::DiagramsModel(this.ModelData.Store);
                }

                if (!diagramsModel.ContainsDiagram("DesignerDiagram"))
                {
                    DesignerDiagram diagramDesignerDiagram = new DesignerDiagram(this.ModelData.Store);
                    diagramDesignerDiagram.Name = "DesignerDiagram";

                    diagramsModel.Diagrams.Add(diagramDesignerDiagram);
                }
                diagramsModel.GetDiagram("DesignerDiagram").Initialize();
                OnPropertyChanged("DesignerDiagram");
                if (!diagramsModel.ContainsDiagram("SpecificElementsDiagramTemplate"))
                {
                    SpecificElementsDiagramTemplate diagramSpecificElementsDiagramTemplate = new SpecificElementsDiagramTemplate(this.ModelData.Store);
                    diagramSpecificElementsDiagramTemplate.Name = "SpecificElementsDiagramTemplate";

                    diagramsModel.Diagrams.Add(diagramSpecificElementsDiagramTemplate);
                }
                diagramsModel.GetDiagram("SpecificElementsDiagramTemplate").Initialize();
                OnPropertyChanged("SpecificElementsDiagramTemplate");

                if (result.Failed)
                {
                    transaction.Rollback();
                }
                else
                {
                    transaction.Commit();
                }
            }
            catch (System.Exception ex)
            {
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(
                                                   VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                   ex.Message, fileName, 0, 0));
                transaction.Rollback();
            }
            // copy messages
            bool bHasMessages = false;

            foreach (DslModeling::SerializationMessage m in result)
            {
                bHasMessages = true;

                DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
                if (m.Kind == DslModeling.SerializationMessageKind.Info)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Message;
                }
                else if (m.Kind == DslModeling.SerializationMessageKind.Warning)
                {
                    kind = DslEditorModeling.ModelValidationViolationType.Warning;
                }

                DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
                    VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
                serializationResult.AddMessage(message);
            }
            serializationResult.Failed = result.Failed;

            if (serializationResult.Failed)
            {
                // Load failed, can't open the file.
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
            }
            else
            {
                this.rootModelElement = modelRoot;
            }

            if (!serializationResult.Failed && !bHasMessages)
            {
                // start validation because UseOpen=true
                ValidateAll();
            }
        }
 /// <summary>
 /// Saves the domain model to a specified filename. This serialization is treated as temporarly and as such does
 /// not change the default saving location of the current domain model.
 /// </summary>
 /// <param name="fileName">Filename to save the domain model to.</param>
 protected override void SaveDocumentTemporarly(string fileName)
 {
     DslModeling::SerializationResult result = new DslModeling.SerializationResult();
     global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = (global::Tum.PDE.VSPluginDSL.DomainModel)this.RootElement;
     VSPluginDSLSerializationHelper.Instance.TemporarlySaveModelDomainModel(result, modelRoot, fileName, this.Encoding, false);
 }		
		/// <summary>
        /// Saves the domain model to a specified filename.
        /// </summary>
        /// <param name="fileName">Filename to save the domain model to.</param>
        protected override void SaveDocument(string fileName)
		{
			serializationResult = new DslEditorModeling::SerializationResult();
			DslModeling::SerializationResult result = new DslModeling.SerializationResult();
			
			global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = (global::Tum.PDE.VSPluginDSL.DomainModel)this.RootElement;
			global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.SaveModelDomainModel(result, modelRoot, fileName, this.Encoding, false);

			// Save Diagrams
			if( this.diagramsModel != null )
			{
				string diagramsFileName = GetDiagramsFileName(fileName);
				if( this.diagramsModel.Diagrams.Count > 0 )
				{
					VSPluginDSLDiagramsDSLSerializationHelper.Instance.SaveModel(result, this.diagramsModel, diagramsFileName, this.Encoding, false);
				}
				else if(System.IO.File.Exists(diagramsFileName) )
					System.IO.File.Delete(diagramsFileName);
			}

			// copy messages
			foreach (DslModeling::SerializationMessage m in result)
            {
                DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
                if( m.Kind == DslModeling.SerializationMessageKind.Info )
                    kind = DslEditorModeling.ModelValidationViolationType.Message;
                else if( m.Kind == DslModeling.SerializationMessageKind.Warning )
                    kind = DslEditorModeling.ModelValidationViolationType.Warning;

                DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
                   VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
                serializationResult.AddMessage(message);
            }	
			serializationResult.Failed = result.Failed;

			if (serializationResult.Failed)
			{	
				// Save failed.
				 serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationSaveErrorId, DslEditorModeling::ModelValidationViolationType.Error, 
                    VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"), fileName, 0, 0));
			}
		}
        /// <summary>
        /// Loads the domain model from a specified file.  This will not replace the currently loaded domain model.
        /// </summary>
        protected override DslModeling::ModelElement LoadDocumentInternal(string fileName)
		{
			serializationResult = new DslEditorModeling::SerializationResult();
			DslModeling::SerializationResult result = new DslModeling.SerializationResult();
			
			// reset post process info
			VSPluginDSLSerializationPostProcessor.Instance.Reset();

			global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = null;
			modelRoot = global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.LoadModelDomainModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

			// post process
			if( modelRoot != null && !serializationResult.Failed)
			{
				VSPluginDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List<string>(), result, modelRoot.Store);
			}

			// copy messages
			foreach (DslModeling::SerializationMessage m in result)
            {
                DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
                if( m.Kind == DslModeling.SerializationMessageKind.Info )
                    kind = DslEditorModeling.ModelValidationViolationType.Message;
                else if( m.Kind == DslModeling.SerializationMessageKind.Warning )
                    kind = DslEditorModeling.ModelValidationViolationType.Warning;

                DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
                    VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
                serializationResult.AddMessage(message);
            }	
			serializationResult.Failed = result.Failed;

			if (serializationResult.Failed)
			{	
				// Load failed, can't open the file.
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, 
                    VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
					
				return null;
			}
			else
			{
				return modelRoot;
			}
		}
		/// <summary>
        /// Loads the domain model from a specified file.
        /// </summary>
		/// <param name="fileName">Filename to load the domain model from.</param>
		/// <param name="isReload"></param>
        protected override void LoadDocument(string fileName, bool isReload)
		{
			this.rootModelElement = null;

			serializationResult = new DslEditorModeling::SerializationResult();
			DslModeling::SerializationResult result = new DslModeling.SerializationResult();
			global::Tum.PDE.VSPluginDSL.DomainModel modelRoot = null;

			// reset post process info
			VSPluginDSLSerializationPostProcessor.Instance.Reset();

			DslModeling::Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load model", true);
			try
			{
				modelRoot = global::Tum.PDE.VSPluginDSL.VSPluginDSLSerializationHelper.Instance.LoadModelDomainModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

				// post process
				if( modelRoot != null && !serializationResult.Failed)
				{
					VSPluginDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List<string>(), result, modelRoot.Store);

				}


				if( !serializationResult.Failed )
					// start validation because UseLoad=true
					ValidateAll();

				// load diagramsModel
				string diagramsFileName = GetDiagramsFileName(fileName);
				if(System.IO.File.Exists(diagramsFileName) )
					diagramsModel = VSPluginDSLDiagramsDSLSerializationHelper.Instance.LoadModel(result, this.ModelData.GetModelPartition(), GetDiagramsFileName(fileName), null, null, null);
				
				if( diagramsModel == null )
					diagramsModel = new DslEditorDiagrams::DiagramsModel(this.ModelData.Store);

				if( !diagramsModel.ContainsDiagram("DesignerDiagram") )
				{
					DesignerDiagram diagramDesignerDiagram = new DesignerDiagram(this.ModelData.Store);
					diagramDesignerDiagram.Name = "DesignerDiagram";
				
					diagramsModel.Diagrams.Add(diagramDesignerDiagram);
				}
				diagramsModel.GetDiagram("DesignerDiagram").Initialize();
				OnPropertyChanged("DesignerDiagram");
				if( !diagramsModel.ContainsDiagram("SpecificElementsDiagramTemplate") )
				{
					SpecificElementsDiagramTemplate diagramSpecificElementsDiagramTemplate = new SpecificElementsDiagramTemplate(this.ModelData.Store);
					diagramSpecificElementsDiagramTemplate.Name = "SpecificElementsDiagramTemplate";
				
					diagramsModel.Diagrams.Add(diagramSpecificElementsDiagramTemplate);
				}
				diagramsModel.GetDiagram("SpecificElementsDiagramTemplate").Initialize();
				OnPropertyChanged("SpecificElementsDiagramTemplate");

				if( result.Failed )
					transaction.Rollback();	
				else
					transaction.Commit();
			}
			catch (System.Exception ex)
			{
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(
					VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                    ex.Message, fileName, 0, 0));
				transaction.Rollback();	
			}
			// copy messages
			bool bHasMessages = false;
			foreach (DslModeling::SerializationMessage m in result)
        	{
				bHasMessages = true;
			
        	    DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error;
        	    if( m.Kind == DslModeling.SerializationMessageKind.Info )
        	        kind = DslEditorModeling.ModelValidationViolationType.Message;
        	    else if( m.Kind == DslModeling.SerializationMessageKind.Warning )
        	        kind = DslEditorModeling.ModelValidationViolationType.Warning;

        	    DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage(
        	        VSPluginDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column);
        	    serializationResult.AddMessage(message);
        	}	
			serializationResult.Failed = result.Failed;

			if (serializationResult.Failed)
			{	
				// Load failed, can't open the file.
        	    serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(VSPluginDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, 
        	        VSPluginDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
			}
			else
			{
				this.rootModelElement = modelRoot;
			}
			
			if( !serializationResult.Failed && !bHasMessages )
				// start validation because UseOpen=true
				ValidateAll();
			
		}
        /// <summary>
        /// Loads the pattern model file, and returns the schema.
        /// </summary>
        /// <param name="modelFilePath">Full path to the pattern model file.</param>
        public static PatternModelSchema LoadPatternModelFromFile(string modelFilePath)
        {
            var patternModel = (PatternModelSchema)null;
            var store = new DslModeling.Store(null, new[] { typeof(PatternModelDomainModel) });
            DslModeling.Transaction tx = null;

            try
            {
                var serializationResult = new DslModeling.SerializationResult();
                tx = store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingModel, true);
                patternModel = Instance.LoadModel(serializationResult, store, modelFilePath, null, null, null);
                if (serializationResult.Failed)
                {
                    throw new DslModeling.SerializationException(serializationResult);
                }

                tx.Commit();
            }
            finally
            {
                if ((tx != null))
                {
                    tx.Dispose();
                }
            }

            return patternModel;
        }
 /// <summary>
 /// Saves the domain model to a specified filename. This serialization is treated as temporarly and as such does
 /// not change the default saving location of the current domain model.
 /// </summary>
 /// <param name="fileName">Filename to save the domain model to.</param>
 protected override void SaveDocumentTemporarly(string fileName)
 {
     DslModeling::SerializationResult result = new DslModeling.SerializationResult();
     global::Tum.VModellXT.Musterbibliothek modelRoot = (global::Tum.VModellXT.Musterbibliothek)this.RootElement;
     VModellXTSerializationHelper.Instance.TemporarlySaveModelMusterbibliothek(result, modelRoot, fileName, this.Encoding, false);
 }		
Exemple #18
0
 /// <summary>
 /// Does the check for orphaned shapes.
 /// </summary>
 /// <param name="diagram">The diagram.</param>
 /// <param name="serializationResult">The serialization result.</param>
 internal static void DoCheckForOrphanedShapes(DslDiagrams.Diagram diagram, DslModeling.SerializationResult serializationResult)
 {
     PatternModelSerializationHelper.Instance.CheckForOrphanedShapes(diagram, serializationResult);
 }
Exemple #19
0
        private void LoadDiagram(
            DslModeling.SerializationResult serializationResult,
            DslModeling.Partition diagramPartition,
            PatternModelSchema modelRoot,
            DslModeling.DomainXmlSerializerDirectory directory,
            DslModeling.DomainClassXmlSerializer diagramSerializer,
            string diagramFileName,
            DslModeling.ISchemaResolver schemaResolver,
            ValidationController validationController)
        {
            if (diagramSerializer != null)
            {
                PatternModelSchemaDiagram diagram = null;

                using (FileStream fileStream = File.OpenRead(diagramFileName))
                {
                    var serializationContext = new DslModeling.SerializationContext(directory, fileStream.Name, serializationResult);
                    this.InitializeSerializationContext(diagramPartition, serializationContext, true);
                    var transactionContext = new DslModeling.TransactionContext();
                    transactionContext.Add(DslModeling.SerializationContext.TransactionContextKey, serializationContext);

                    using (var transaction = diagramPartition.Store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingDiagram, true, transactionContext))
                    {
                        // Ensure there is some content in the file. Blank (or almost blank, to account for encoding header bytes, etc.)
                        // files will cause a new diagram to be created and returned
                        if (fileStream.Length > 5)
                        {
                            var settings = PatternModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
                            try
                            {
                                using (var reader = XmlReader.Create(fileStream, settings))
                                {
                                    reader.MoveToContent();
                                    diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as PatternModelSchemaDiagram;
                                    if (diagram != null)
                                    {
                                        this.ReadRootElement(serializationContext, diagram, reader, schemaResolver);
                                    }
                                }
                            }
                            catch (XmlException ex)
                            {
                                DslModeling.SerializationUtilities.AddMessage(serializationContext, DslModeling.SerializationMessageKind.Error, ex);
                            }

                            if (serializationResult.Failed)
                            {
                                // Serialization error encountered, rollback the transaction.
                                diagram = null;
                                transaction.Rollback();
                            }
                        }

                        if (diagram == null && !serializationResult.Failed)
                        {
                            // Create diagram if it doesn't exist
                            if (diagramFileName.EndsWith(DesignerConstants.DiagramFileExtension, StringComparison.OrdinalIgnoreCase))
                            {
                                diagram = new PatternModelSchemaDiagram(
                                    diagramPartition.Store,
                                    new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, Guid.NewGuid()));
                            }
                            else
                            {
                                diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
                            }
                        }

                        if (transaction.IsActive)
                        {
                            transaction.Commit();
                        }
                    } // End inner Tx

                    // Do load-time validation if a ValidationController is provided.
                    if (!serializationResult.Failed && validationController != null)
                    {
                        using (new SerializationValidationObserver(serializationResult, validationController))
                        {
                            validationController.Validate(diagramPartition, ValidationCategories.Load);
                        }
                    }
                }

                if (diagram != null)
                {
                    if (!serializationResult.Failed)
                    {   // Succeeded.
                        diagram.ModelElement = modelRoot;
                        diagram.PostDeserialization(true);
                        this.CheckForOrphanedShapes(diagram, serializationResult);
                    }
                    else
                    {   // Failed.
                        diagram.PostDeserialization(false);
                    }
                }
            }
        }
 /// <summary>
 /// Saves the domain model to a specified filename. This serialization is treated as temporarly and as such does
 /// not change the default saving location of the current domain model.
 /// </summary>
 /// <param name="fileName">Filename to save the domain model to.</param>
 protected override void SaveDocumentTemporarly(string fileName)
 {
     DslModeling::SerializationResult result = new DslModeling.SerializationResult();
     global::Tum.StateMachineDSL.StateMachineDomainModel modelRoot = (global::Tum.StateMachineDSL.StateMachineDomainModel)this.RootElement;
     StateMachineLanguageSerializationHelper.Instance.TemporarlySaveModelStateMachineDomainModel(result, modelRoot, fileName, this.Encoding, false);
 }		
Exemple #21
0
        public PatternModelSchema LoadModel(DslModeling.Store store, Stream stream, DslModeling.ISchemaResolver schemaResolver, DslModeling.ISerializerLocator serializerLocator)
        {
            Guard.NotNull(() => store, store);
            Guard.NotNull(() => stream, stream);

            if (!store.DefaultPartition.Store.TransactionActive)
            {
                throw new InvalidOperationException(PatternModelDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            var directory           = this.GetDirectory(store.DefaultPartition.Store);
            var modelRootSerializer = directory.GetSerializer(PatternModelSchema.DomainClassId);
            var serializationResult = new DslModeling.SerializationResult();

            Debug.Assert(modelRootSerializer != null, @"Cannot find serializer for PatternModel!");

            if (modelRootSerializer != null)
            {
                PatternModelSchema modelRoot = null;

                var serializationContext = new DslModeling.SerializationContext(directory, string.Empty, serializationResult);
                this.InitializeSerializationContext(store.DefaultPartition, serializationContext, true);

                var transactionContext = new DslModeling.TransactionContext();
                transactionContext.Add(DslModeling.SerializationContext.TransactionContextKey, serializationContext);

                using (var tx = store.DefaultPartition.Store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingModel, true, transactionContext))
                {
                    try
                    {
                        var settings = PatternModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);

                        using (var reader = XmlReader.Create(stream, settings))
                        {
                            reader.Read();
                            Encoding encoding;
                            if (this.TryGetEncoding(reader, out encoding))
                            {
                                serializationResult.Encoding = encoding;
                            }

                            DslModeling.SerializationUtilities.ResolveDomainModels(reader, serializerLocator, store.DefaultPartition.Store);

                            reader.MoveToContent();

                            modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, store.DefaultPartition) as PatternModelSchema;

                            if (modelRoot != null && !serializationResult.Failed)
                            {
                                this.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver);
                            }
                        }
                    }
                    catch (XmlException ex)
                    {
                        DslModeling.SerializationUtilities.AddMessage(serializationContext, DslModeling.SerializationMessageKind.Error, ex);
                    }

                    if (modelRoot == null && !serializationResult.Failed)
                    {
                        modelRoot = this.CreateModelHelper(store.DefaultPartition);
                    }

                    if (tx.IsActive)
                    {
                        tx.Commit();
                    }
                }

                // Set tracking properties
                ResetTrackingProperties(store);

                return(modelRoot);
            }

            return(null);
        }