Esempio n. 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.FamilyTreeDSL.FamilyTreeModel modelRoot = (global::Tum.FamilyTreeDSL.FamilyTreeModel) this.RootElement;
            FamilyTreeDSLSerializationHelper.Instance.TemporarlySaveModelFamilyTreeModel(result, modelRoot, fileName, this.Encoding, false);
        }
Esempio n. 2
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
            FamilyTreeDSLSerializationPostProcessor.Instance.Reset();

            global::Tum.FamilyTreeDSL.FamilyTreeModel modelRoot = null;
            modelRoot = global::Tum.FamilyTreeDSL.FamilyTreeDSLSerializationHelper.Instance.LoadModelFamilyTreeModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

            // post process
            if (modelRoot != null && !serializationResult.Failed)
            {
                FamilyTreeDSLSerializationPostProcessor.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(
                    FamilyTreeDSLValidationMessageIds.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(FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           FamilyTreeDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));

                return(null);
            }
            else
            {
                return(modelRoot);
            }
        }
Esempio n. 3
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.FamilyTreeDSL.FamilyTreeModel modelRoot = (global::Tum.FamilyTreeDSL.FamilyTreeModel) this.RootElement;
            global::Tum.FamilyTreeDSL.FamilyTreeDSLSerializationHelper.Instance.SaveModelFamilyTreeModel(result, modelRoot, fileName, this.Encoding, false);

            // Save Diagrams
            if (this.diagramsModel != null)
            {
                string diagramsFileName = GetDiagramsFileName(fileName);
                if (this.diagramsModel.Diagrams.Count > 0)
                {
                    FamilyTreeDSLDiagramsDSLSerializationHelper.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(
                    FamilyTreeDSLValidationMessageIds.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(FamilyTreeDSLValidationMessageIds.SerializationSaveErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           FamilyTreeDSLDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"), fileName, 0, 0));
            }
        }
Esempio n. 4
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.FamilyTreeDSL.FamilyTreeModel modelRoot = null;

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

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

            try
            {
                modelRoot = global::Tum.FamilyTreeDSL.FamilyTreeDSLSerializationHelper.Instance.LoadModelFamilyTreeModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null);

                // post process
                if (modelRoot != null && !serializationResult.Failed)
                {
                    FamilyTreeDSLSerializationPostProcessor.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 = FamilyTreeDSLDiagramsDSLSerializationHelper.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(
                                                   FamilyTreeDSLValidationMessageIds.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(
                    FamilyTreeDSLValidationMessageIds.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(FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error,
                                                                                           FamilyTreeDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0));
            }
            else
            {
                this.rootModelElement = modelRoot;
            }

            if (!serializationResult.Failed && !bHasMessages)
            {
                // start validation because UseOpen=true
                ValidateAll();
            }
        }
		/// <summary>
		/// Helper method to create and initialize a new FamilyTreeModel.
		/// </summary>
		internal protected virtual global::Tum.FamilyTreeDSL.FamilyTreeModel CreateModelHelperFamilyTreeModel(DslModeling::Partition modelPartition)
		{
			global::Tum.FamilyTreeDSL.FamilyTreeModel model = new global::Tum.FamilyTreeDSL.FamilyTreeModel(modelPartition, 
				global::Tum.FamilyTreeDSL.FamilyTreeDSLDomainModelIdProvider.Instance.AssignId(null));
			if( FamilyTreeDSLElementNameProvider.Instance.HasName(model) )
				FamilyTreeDSLElementNameProvider.Instance.SetName(model, "FamilyTreeModel");
				
			return model;
		}