/// <summary>
        /// Switch model contexts.
        /// </summary>
        /// <param name="newContextVM">New model context vm.</param>
        /// <param name="oldContextVM">Old model context vm.</param>
        /// <returns>True if a switch did occur. False otherwise.</returns>
        protected virtual bool SwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM)
        {
            if (this.ModelData.CurrentModelContext.RootElement != null)
            {
                // notify that the current document will be closed
                IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                if (messageBox.ShowYesNoCancel("The currently opened document will be closed in the process of a context switch! Do you want to proceed?", CustomDialogIcons.Question) != CustomDialogResults.Yes)
                {
                    return(false);
                }
            }


            PleaseWaitHelper.Show();
            BeforeSwitchContexts(newContextVM, oldContextVM);

            if (this.ModelData.CurrentModelContext.RootElement != null)
            {
                this.ModelData.CurrentModelContext.Reset();
            }
            this.Reset();

            // update model data
            this.ModelData.CurrentModelContext = newContextVM.ModelContext;

            AfterSwitchContexts(newContextVM, oldContextVM);


            PleaseWaitHelper.Hide();
            return(true);
        }
        //internal static LongWaitMessager lwm;
        public void HandleException(Exception e)
        {
            LogExceptionDelegate logDelegate = new LogExceptionDelegate(LogException);

            if (e is System.Reflection.ReflectionTypeLoadException)
            {
                var typeLoadException = e as System.Reflection.ReflectionTypeLoadException;
                foreach (var item in typeLoadException.LoaderExceptions)
                {
                    MessageBox.Show(item.Message.ToString()); MessageBox.Show(item.Message.ToString());
                }
            }
            switch (notificationType)
            {
            case NotificationType.Ask:
                if (MessageBox.Show("An unexpected error occurred - " + e.Message +
                                    ". Do you wish to log the error?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
                logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                break;

            case NotificationType.Inform:
                if (counter == 0)
                {
                    counter++;
                    logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                    System.Windows.MessageBox.Show("An unexpected error occurred -\n " + e.Message + "\n\n" + e.StackTrace);
                    //System.Windows.MessageBox.Show("An unexpected error occurred -\n " + e.Message + "\n\n" + e.StackTrace);
                    Thread.Sleep(3);    //capture the screen
                    //lwm = new LongWaitMessager("I'am Try To Process The Exception,Please Waiting...");
                    //lwm.Show();
                    PleaseWaitHelper.Show("I'am Try To Process The Exception,Please Waiting...");
                }
                else
                {
                    textLoggerEvent.Wait(20000);
                    emailLoggerEvent.Wait(20000);
                    //if (lwm!=null)
                    //{
                    //    lwm.Close();
                    //}
                    PleaseWaitHelper.Hide();
                    System.Windows.MessageBox.Show("We Are Sorry To Show This Message To You,\nWe Will Solve The Problem As Soon As Possible, Thanks! \n");
                    Application.Current.Shutdown();
                }

                break;

            case NotificationType.Silent:
                logDelegate.BeginInvoke(e, new AsyncCallback(LogCallBack), null);
                break;
            }
            SaveOnException.SafeInvoke(this);
        }
        /// <summary>
        /// Document loaded.
        /// </summary>
        public override void OnDocumentLoaded()
        {
            base.OnDocumentLoaded();

            if (!isInitialyInitialized)
            {
                PleaseWaitHelper.Show();
                this.Initialize();
                PleaseWaitHelper.Hide();
            }
        }
 partial void HideBusyIndicator()
 {
     PleaseWaitHelper.Hide();
 }
        /// <summary>
        /// New command executed.
        /// </summary>
        protected virtual void NewModelCommandExecuted()
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return;
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return;
            }

            if (CloseModelCommandCanExecute())
            {
                if (!CloseModelCommandExecute())
                {
                    return;
                }
            }

            ISaveFileService saveFileService = this.GlobalServiceProvider.Resolve <ISaveFileService>();

            saveFileService.Filter = this.SelectedModelContextViewModel.EditorTitle + " files|*.xml|All files|*.*";
            if (saveFileService.ShowDialog(null) == true)
            {
                System.IO.StreamWriter writer = System.IO.File.CreateText(saveFileService.FileName);
                writer.Close();

                using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
                {
                    this.Reset();
                    this.SelectedModelContextViewModel.ModelContext.Load(saveFileService.FileName, false);

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

                    if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
                    {
                        // clear current error list
                        this.EventManager.GetEvent <ErrorListClearItems>().Publish(this);

                        // add serialization result items
                        List <BaseErrorListItemViewModel> items = new List <BaseErrorListItemViewModel>();
                        foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
                        {
                            SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
                            items.Add(item);
                        }

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

            if (!this.isInitialyInitialized)
            {
                PleaseWaitHelper.Show();
                this.Initialize();
                PleaseWaitHelper.Hide();
            }

            this.CloseCommand.RaiseCanExecuteChanged();
            this.SaveAsModelCommand.RaiseCanExecuteChanged();
            this.SaveModelCommand.RaiseCanExecuteChanged();
        }
Exemple #6
0
        /// <summary>
        /// Hides this please wait window.
        /// </summary>
        public virtual void Hide()
        {
            PleaseWaitHelper.Hide();

            _showCounter = 0;
        }