//=============================================================================
        private Task <object> OnBeforeAppShutdown()
        {
            if (m_CurrentDocument == null)
            {
                return(null);
            }

            // Ask for save before app close.
            if (m_CurrentDocument.HasChanges)
            {
                // undo all not completed changes
                m_CurrentDocument.SetTheLastState();

                SaveChangesDialog_ViewModel saveChangesDialogVM = new SaveChangesDialog_ViewModel();
                saveChangesDialogVM.Text = "Application session is limited by 24 hours. Application will be closed. Do you want to save changes?";
                saveChangesDialogVM.IsSaveButtonVisible   = true;
                saveChangesDialogVM.IsCancelButtonVisible = false;

                SaveChangesDialog saveChangesDialog = new SaveChangesDialog(saveChangesDialogVM);

                // Close previous dialog.
                if (DlgHost != null && DlgHost.IsOpen)
                {
                    DlgHost.IsOpen = false;
                }

                return(DialogHost.Show(saveChangesDialog).ContinueWith <object>((previousTask) =>
                {
                    var prevTaskResult = previousTask.Result;
                    // true - save
                    // false - cancel
                    // null - continue
                    if (prevTaskResult is bool && (bool)prevTaskResult)
                    {
                        // save the document
                        string strFilePath = string.Empty;
                        if (m_CurrentDocument.IsItNewDocument || m_CurrentDocument.NameWithoutExtension != m_CurrentDocument.CustomerENQ)
                        {
                            string strOldPath = null;
                            if (!m_CurrentDocument.IsItNewDocument && !string.IsNullOrEmpty(m_CurrentDocument.Path))
                            {
                                strOldPath = m_CurrentDocument.Path;
                            }

                            strFilePath = FileUtils._SaveFileDialog(DrawingDocument.FILE_FILTER, DrawingDocument.FILE_EXTENSION, m_CurrentDocument.CustomerENQ, m_CurrentDocument.CustomerENQ, strOldPath);
                            if (string.IsNullOrEmpty(strFilePath))
                            {
                                return null;
                            }
                        }

                        // Try to save in UI thread, otherwise DrawingDocument.Save throws an exception on DrawingControl.Update() method which updates UI.
                        if (DrawingControl != null)
                        {
                            DrawingControl.Dispatcher.Invoke(new Action(() =>
                            {
                                m_CurrentDocument.Save(strFilePath);
                            }
                                                                        ));

                            return true;
                        }
                        else
                        {
                            return m_CurrentDocument.Save(strFilePath);
                        }
                    }

                    return null;
                }));
            }
            else
            {
                return(this.DisplayMessageDialog("Application session is limited by 24 hours. Application will be closed."));
            }

            return(null);
        }
Exemple #2
0
 public void Save()
 {
     m_Document.Save();
 }