Exemplo n.º 1
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="serializationMessage">Serialization message.</param>
        public SerializationErrorListItemViewModel(ViewModelStore viewModelStore, SerializationMessage serializationMessage)
            : base(viewModelStore, serializationMessage.MessageId, ModelErrorListItemViewModel.ConvertCategory(serializationMessage.Type), serializationMessage.Description)
        {
            this.serializationMessage = serializationMessage;

            this.SourceDisplayName = serializationMessage.Source + " - Line: " + serializationMessage.Line.ToString() + " , Column: " + serializationMessage.Column;
        }
        /// <summary>
        /// Validate command executed.
        /// </summary>
        protected override void OnValidateCommandExecuted()
        {
            if (this.SelectedItemViewModel == null)
                return;

            using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                // clear error list
                this.EventManager.GetEvent<ErrorListClearItems>().Publish(this);

                List<IValidationMessage> messages = this.ModelData.CurrentModelContext.Validate(this.SelectedItemViewModel.Element);
                List<BaseErrorListItemViewModel> items = new List<BaseErrorListItemViewModel>();
                foreach (IValidationMessage message in messages)
                {
                    if (message is ModelValidationMessage)
                    {
                        ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
                        items.Add(item);
                    }
                    else if (message is ValidationMessage)
                    {
                        StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
                        items.Add(item);
                    }
                }

                // notify of change
                this.EventManager.GetEvent<ErrorListAddItems>().Publish(items);
            }
        }
        /// <summary>
        /// Document loaded.
        /// </summary>
        public override void OnDocumentLoaded()
        {
            base.OnDocumentLoaded();


            // clear current error list
            this.EventManager.GetEvent<ErrorListClearItems>().Publish(this);

            List<BaseErrorListItemViewModel> items = new List<BaseErrorListItemViewModel>();
            if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
            {
                // add serialization result items

                foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
                {
                    SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
                    items.Add(item);
                }
            }

            if (this.SelectedModelContextViewModel.ModelContext.ValidationResult.Count > 0)
            {
                foreach (IValidationMessage message in this.SelectedModelContextViewModel.ModelContext.ValidationResult)
                {
                    if (message is ModelValidationMessage)
                    {
                        ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
                        items.Add(item);
                    }
                    else if (message is ValidationMessage)
                    {
                        StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
                        items.Add(item);
                    }
                }
            }

            // notify of change
            if (items.Count > 0)
                this.EventManager.GetEvent<ErrorListAddItems>().Publish(items);
        }
        /// <summary>
        /// Open model.
        /// </summary>
        /// <param name="fileName">File to open.</param>
        public virtual void OpenModel(string fileName)
        {
            if (this.SelectedModelContextViewModel == null)
                return;
            if (this.SelectedModelContextViewModel.ModelContext == null)
                return;
            
            if (CloseModelCommandCanExecute())
                if (!CloseModelCommandExecute())
                    return;

            if (this.Ribbon != null)
                this.Ribbon.IsBackstageOpen = false;

            if (!System.IO.File.Exists(fileName))
            {
                IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve<IMessageBoxService>();
                messageBox.ShowError("File does not exists: " + fileName);
                return;
            }

            // LOAD model in background thread
            // in main UI thread, load avalondock
            // --> wait on ui thread for model load to finish...
            /*if (!this.isInitialyInitialized)
            {
                #region MT-Load
                PleaseWaitHelper.Show();

                loadingModelEvent.Reset();

                this.ViewModelStore.InLoad = true;
                this.Reset();

                System.ComponentModel.BackgroundWorker loadModel = new System.ComponentModel.BackgroundWorker();
                loadModel.DoWork += new System.ComponentModel.DoWorkEventHandler(loadModel_DoWork);
                loadModel.RunWorkerAsync(fileName);

                this.Initialize();
                this.loadingModelEvent.WaitOne();

                // add to mru list
                this.MRUFilesViewModel.AddMRUEntry(fileName);

                // clear current error list
                this.EventManager.GetEvent<ErrorListClearItems>().Publish(this);

                List<BaseErrorListItemViewModel> items = new List<BaseErrorListItemViewModel>();
                if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
                {
                    // add serialization result items

                    foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
                    {
                        SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
                        items.Add(item);
                    }
                }

                if (this.SelectedModelContextViewModel.ModelContext.ValidationResult.Count > 0)
                {
                    foreach (IValidationMessage message in this.SelectedModelContextViewModel.ModelContext.ValidationResult)
                    {
                        if (message is ModelValidationMessage)
                        {
                            ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
                            items.Add(item);
                        }
                        else if (message is ValidationMessage)
                        {
                            StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
                            items.Add(item);
                        }
                    }
                }

                this.ViewModelStore.InLoad = false;

                // Open views based on the configuration in the layout manager
                if (this.LayoutManager != null)
                    if (this.LayoutManager.ConfigurationManager != null)
                        foreach (string paneName in this.LayoutManager.CurrentConfiguration.Configurations.Keys)
                        {
                            DockingPaneConfiguration paneConfig = this.LayoutManager.CurrentConfiguration.Configurations[paneName];
                            if (paneConfig.IsRestorable && paneConfig.RestoreInformation != null && paneConfig.DockingPaneType != null)
                            {
                                if (!this.LayoutManager.HasWindow(paneConfig.PaneName))
                                {
                                    // create new modal window
                                    BaseDiagramSurfaceViewModel vm = this.ViewModelStore.TopMostStore.Factory.CreateRestorableViewModel(paneConfig.DockingPaneType);
                                    if (vm != null && vm is IRestorableDockableViewModel)
                                    {
                                        if ((vm as IRestorableDockableViewModel).Restore(paneConfig.RestoreInformation))
                                        {
                                            OpenViewModelEventArgs args = new OpenViewModelEventArgs(vm);
                                            args.DockingPaneStyle = PDE.ToolFramework.Modeling.Visualization.ViewModel.DockingPaneStyle.DockedInDocumentPane;
                                            this.EventManager.GetEvent<OpenViewModelEvent>().Publish(args);
                                        }
                                        else
                                        {
                                            vm.Dispose();
                                        }
                                    }
                                }
                            }


                            // notify of change
                            if (items.Count > 0)
                                this.EventManager.GetEvent<ErrorListAddItems>().Publish(items);
                        }

                PleaseWaitHelper.Hide();
                #endregion
            }
            else
            {*/
                #region Normal Load
            using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                this.ViewModelStore.InLoad = true;
                
                this.Reset();
                this.SelectedModelContextViewModel.ModelContext.Load(fileName, false);

                // add to mru list
                this.MRUFilesViewModel.AddMRUEntry(fileName);

                // clear current error list
                this.EventManager.GetEvent<ErrorListClearItems>().Publish(this);

                List<BaseErrorListItemViewModel> items = new List<BaseErrorListItemViewModel>();

                if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
                {
                    // add serialization result items

                    foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
                    {
                        SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
                        items.Add(item);
                    }
                }

                if (this.SelectedModelContextViewModel.ModelContext.ValidationResult.Count > 0)
                {
                    foreach (IValidationMessage message in this.SelectedModelContextViewModel.ModelContext.ValidationResult)
                    {
                        if (message is ModelValidationMessage)
                        {
                            ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
                            items.Add(item);
                        }
                        else if (message is ValidationMessage)
                        {
                            StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
                            items.Add(item);
                        }
                    }
                }

                this.ViewModelStore.InLoad = false;

                // Open views based on the configuration in the layout manager
                    if (this.LayoutManager != null)
                        if (this.LayoutManager.ConfigurationManager != null)
                foreach (string paneName in this.LayoutManager.CurrentConfiguration.Configurations.Keys)
                {
                    DockingPaneConfiguration paneConfig = this.LayoutManager.CurrentConfiguration.Configurations[paneName];
                    if (paneConfig.IsRestorable && paneConfig.RestoreInformation != null && paneConfig.DockingPaneType != null)
                    {
                        if (!this.LayoutManager.HasWindow(paneConfig.PaneName))
                        {
                            // create new modal window
                            BaseDiagramSurfaceViewModel vm = this.ViewModelStore.TopMostStore.Factory.CreateRestorableViewModel(paneConfig.DockingPaneType);
                            if (vm != null && vm is IRestorableDockableViewModel)
                            {
                                if ((vm as IRestorableDockableViewModel).Restore(paneConfig.RestoreInformation))
                                {
                                    OpenViewModelEventArgs args = new OpenViewModelEventArgs(vm);
                                    args.DockingPaneStyle = PDE.ToolFramework.Modeling.Visualization.ViewModel.DockingPaneStyle.DockedInDocumentPane;
                                    this.EventManager.GetEvent<OpenViewModelEvent>().Publish(args);
                                }
                                else
                                {
                                    vm.Dispose();
                                }
                            }
                        }
                    }
                }

                // notify of change
                if (items.Count > 0)
                    this.EventManager.GetEvent<ErrorListAddItems>().Publish(items);
            }
                #endregion
            //}

        }