Пример #1
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.TestLanguage.DomainModel modelRoot = null;

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

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

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

                // post process
                if (modelRoot != null && !serializationResult.Failed)
                {
                    TestLanguageSerializationPostProcessor.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 = TestLanguageDiagramsDSLSerializationHelper.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 (result.Failed)
                {
                    transaction.Rollback();
                }
                else
                {
                    transaction.Commit();
                }
            }
            catch (System.Exception ex)
            {
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(
                                                   TestLanguageValidationMessageIds.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(
                    TestLanguageValidationMessageIds.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(TestLanguageValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           TestLanguageDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
            }
            else
            {
                this.rootModelElement = modelRoot;
            }

            if (!serializationResult.Failed && !bHasMessages)
            {
                // start validation because UseOpen=true
                ValidateAll();
            }
        }
		/// <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.TestLanguage.DomainModel modelRoot = null;

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

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

				// post process
				if( modelRoot != null && !serializationResult.Failed)
				{
					TestLanguageSerializationPostProcessor.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 = TestLanguageDiagramsDSLSerializationHelper.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( result.Failed )
					transaction.Rollback();	
				else
					transaction.Commit();
			}
			catch (System.Exception ex)
			{
                serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(
					TestLanguageValidationMessageIds.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(
        	        TestLanguageValidationMessageIds.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(TestLanguageValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, 
        	        TestLanguageDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
			}
			else
			{
				this.rootModelElement = modelRoot;
			}
			
			if( !serializationResult.Failed && !bHasMessages )
				// start validation because UseOpen=true
				ValidateAll();
			
		}