Exemple #1
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 #2
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));
            }
        }
Exemple #3
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.
        /// </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();
			
		}