示例#1
0
 /// <summary>
 /// Called to save options when the application exits.
 /// </summary>
 public override void SaveOptions(DslEditorViewModelServices::IMessageBoxService messageBox)
 {
     // save options
     try
     {
         string directory = this.ModelData.GetDomainModelServices().ModelDataOptions.AppDataDirectory;
         string path      = directory + System.IO.Path.DirectorySeparatorChar + TestLanguageViewModelOptions.OptionsFileName;
         this.Options.Serialize(path);
     }
     catch (System.Exception ex)
     {
         messageBox.ShowError("Couldn't save options: " + ex.Message);
     }
 }
示例#2
0
        /// <summary>
        /// Called to load options when the application starts.
        /// </summary>
        public override void LoadOptions(DslEditorViewModelServices::IMessageBoxService messageBox)
        {
            this.Options = new VModellXTViewModelOptions();

            try
            {
                string directory = this.ModelData.GetDomainModelServices().ModelDataOptions.AppDataDirectory;
                string path      = directory + System.IO.Path.DirectorySeparatorChar + VModellXTViewModelOptions.OptionsFileName;
                this.Options.Deserialize(path);
            }
            catch (System.Exception ex)
            {
                messageBox.ShowError("Couldn't open options: " + ex.Message);
            }
        }
        /// <summary>
        /// Loads the model from the given file path and sets it to its appropriate element.
        /// </summary>
        /// <param name="filePath">File path to load the model from. Can be null to indicate that there is no referenced domain model.</param>
        protected override void SetReferencedModel(string filePath)
        {
            using (new Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                global::Tum.VModellXT.Musterbibliothek model = this.Elements[0] as global::Tum.VModellXT.Musterbibliothek;
                string file = filePath;

                DslEditorModeling::IParentModelElement parent = model.GetDomainModelServices().ElementParentProvider.GetParentModelElement(model);
                if (parent == null)
                {
                    throw new System.ArgumentNullException("Parent of element " + model.ToString() + " can not be null");
                }

                string path             = parent.DomainFilePath;
                string vModellDirectory = new System.IO.FileInfo(path).DirectoryName;
                //string curPath = Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions.Path.PathHelper.EvaluateRelativePath(
                //	vModellDirectory, file);

                // load model
                try
                {
                    if (!System.IO.File.Exists(file))
                    {
                        System.IO.FileStream s = System.IO.File.Create(file);
                        s.Close();
                    }

                    using (DslModeling::Transaction transaction = this.Store.TransactionManager.BeginTransaction("Set referenced model"))
                    {
                        global::Tum.VModellXT.VModellXTDocumentData data = this.ViewModelStore.ModelData as global::Tum.VModellXT.VModellXTDocumentData;
                        global::Tum.VModellXT.VModell referenceModel     = data.ModelContextVModellXT.LoadInternal(file) as  global::Tum.VModellXT.VModell;
                        model.VModell = referenceModel;

                        transaction.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    DslEditorViewModelServices::IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <DslEditorViewModelServices::IMessageBoxService>();
                    messageBox.ShowError(ex.Message);
                }

                this.ModelData.FlushUndoRedoStacks();
            }
        }
示例#4
0
        /// <summary>
        /// Save command executed.
        /// </summary>
        /// <remarks>
        /// This was generated because of Validation.UseSave = true.
        /// </remarks>
        protected override void SaveModelCommandExecuted()
        {
            this.ValidateAllCommandExecuted();

            if (this.ErrorListModel != null)
            {
                if (this.ErrorListModel.ErrorsCount > 0)
                {
                    DslEditorViewModelServices::IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <DslEditorViewModelServices::IMessageBoxService>();
                    if (messageBox.ShowYesNoCancel("Validation founds errors. Are you sure you want to save the model?", DslEditorViewModelServices.CustomDialogIcons.Exclamation) != DslEditorViewModelServices.CustomDialogResults.Yes)
                    {
                        return;
                    }
                }
            }

            base.SaveModelCommandExecuted();
        }
示例#5
0
 /// <summary>
 /// Called to save options when the application exits.
 /// </summary>
 public override void SaveOptions(DslEditorViewModelServices::IMessageBoxService messageBox)
 {
 }
        /// <summary>
        /// Ensures that the user can open the selected file and refence the domain model.
        /// </summary>
        /// <returns>True to reference; False otherwise.</returns>
        protected override bool EnsureOpening(string filePath)
        {
            try
            {
                HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument.Load(filePath);

                HtmlAgilityPack.HtmlNodeCollection nodes = htmlDocument.DocumentNode.SelectNodes("//@id");

                // verify that none of the ids is present at the moment
                if (nodes != null)
                {
                    foreach (HtmlAgilityPack.HtmlNode node in nodes)
                    {
                        string value = node.Attributes["id"].Value;
                        if (VModellXTDomainModelIdProvider.Instance.HasVModellKey(value))
                        {
                            DslEditorViewModelServices::IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <DslEditorViewModelServices::IMessageBoxService>();
                            messageBox.ShowInformation("Can not reference the selected model because some of its elements are already included in the currently opened model. (Failed on element '" + node.Name + "').\r\n\r\nHint: This could also be caused by a referenced model in the domain model selected to be referenced.");

                            return(false);
                        }
                    }
                }

                // proceed with referenced models
                HtmlAgilityPack.HtmlNode refNode = htmlDocument.DocumentNode.SelectSingleNode("//v-modellvariante/referenzmodell");
                if (refNode != null)
                {
                    foreach (HtmlAgilityPack.HtmlNode n in refNode.ChildNodes)
                    {
                        if (n.Name != "xi:include")
                        {
                            continue;
                        }

                        string href    = n.Attributes["href"].Value;
                        string curPath = href;
                        if (!curPath.Contains(System.IO.Path.VolumeSeparatorChar.ToString()))
                        {
                            curPath = new System.IO.FileInfo(filePath).DirectoryName + System.IO.Path.DirectorySeparatorChar + curPath;
                        }

                        if (System.IO.File.Exists(curPath))
                        {
                            if (!EnsureOpening(curPath))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                DslEditorViewModelServices::IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <DslEditorViewModelServices::IMessageBoxService>();
                messageBox.ShowInformation("Couldnt parse file: " + ex.Message);

                return(false);
            }
            return(true);
        }