Ejemplo n.º 1
0
        private void SaveAsFunc(object param)
        {
            //save the experiment of this application view model
            Experiment experiment = m_viewModel.Experiment;

            if (experiment != null)
            {
                ReferencedFiles referencedFilesProcessing;
                string          rootDrive = System.IO.Path.GetPathRoot(experiment.ExperimentInfo.FilePath);
                string          file      = FileDialogs.GetExperimentFilenameSaveAsDialog(rootDrive, out referencedFilesProcessing);
                if (file != null)
                {
                    //remember old guid in case save fails
                    Guid oldId          = experiment.ExperimentInfo.GuidId;
                    bool successfulSave = false;
                    try
                    {
                        experiment.ExperimentInfo.GuidId = Guid.NewGuid();
                        //try save
                        successfulSave = ExperimentManager.SaveAs(experiment, file, referencedFilesProcessing);
                    }
                    catch (System.IO.IOException e)
                    {
                        NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                        System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                        System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                    }
                    catch (TraceLab.Core.Exceptions.FilesCopyFailuresException e)
                    {
                        //some referenced files failed to be copied... note the experiment still might have been saved as correctly
                        NLog.LogManager.GetCurrentClassLogger().Warn(String.Format("Failed to Save File {0}. {1}", file, e.Message));

                        DisplayCopyErrorsWindow(e);
                    }
                    catch (Exception e)
                    {
                        NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e);
                        System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK);
                    }

                    if (successfulSave == true)
                    {
                        //reset the workspace view and logView to the new experiment id
                        //so that both workspace and log view shows the data of the experiment with new id
                        m_viewModel.WorkspaceViewModel = new WorkspaceViewModel((TraceLab.Core.Workspaces.Workspace)m_viewModel.WorkspaceViewModel, experiment.ExperimentInfo.Id);
                        m_viewModel.LogViewModel       = new LogViewModel(experiment.ExperimentInfo.Id, m_viewModel.LogViewModel);
                    }
                    else
                    {
                        //otherwise don't change the views, but reset the experiment id back to old ID
                        experiment.ExperimentInfo.GuidId = oldId;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Activated(object sender, EventArgs args)
        {
            //save the experiment of this application view model
            Experiment experiment = m_applicationContext.Application.Experiment;

            if (experiment != null)
            {
                string file = FileDialogs.ShowSaveAsDialog(m_applicationContext.MainWindow.WindowShell,
                                                           experiment.ExperimentInfo.FilePath);

                if (file != null)
                {
                    //remember old guid in case save fails
                    Guid oldId          = experiment.ExperimentInfo.GuidId;
                    bool successfulSave = false;
                    try
                    {
                        experiment.ExperimentInfo.GuidId = Guid.NewGuid();

                        //TODO: allow user to set whether referenced files should be copied or not
                        ReferencedFiles referencedFilesProcessing = ReferencedFiles.IGNORE;
                        //try save
                        successfulSave = ExperimentManager.SaveAs(experiment, file, referencedFilesProcessing);
                    }
                    catch (System.IO.IOException e)
                    {
                        FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file);
                    }
                    catch (TraceLab.Core.Exceptions.FilesCopyFailuresException e)
                    {
                        //some referenced files failed to be copied... note the experiment still might have been saved as correctly
                        NLog.LogManager.GetCurrentClassLogger().Warn(String.Format("Failed to Save File {0}. {1}", file, e.Message));

                        //TODO
                        //DisplayCopyErrorsWindow(e);
                    }
                    catch (Exception e)
                    {
                        FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file);
                    }

                    if (successfulSave == true)
                    {
                        //reset the workspace view and logView to the new experiment id
                        //so that both workspace and log view shows the data of the experiment with new id
                        ApplicationViewModel.CreateNewApplicationViewModel(m_applicationContext.Application, experiment);

                        //create new workspace view for the new experiment id
                        m_applicationContext.Application.WorkspaceViewModel =
                            new WorkspaceViewModel((TraceLab.Core.Workspaces.Workspace)m_applicationContext.Application.WorkspaceViewModel,
                                                   experiment.ExperimentInfo.Id);

                        m_applicationContext.Application.LogViewModel = new LogViewModel(experiment.ExperimentInfo.Id,
                                                                                         m_applicationContext.Application.LogViewModel);
                    }
                    else
                    {
                        //otherwise don't change the views, but reset the experiment id back to old ID
                        experiment.ExperimentInfo.GuidId = oldId;
                    }
                }
            }
        }