Example #1
0
        /// <summary>
        /// When activated saves current experiment from associated application view model.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        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 = null;
                if (String.IsNullOrEmpty(experiment.ExperimentInfo.FilePath))
                {
                    // if file path is not set show save as dialog
                    file = FileDialogs.ShowSaveAsDialog(m_applicationContext.MainWindow.WindowShell);
                }
                else
                {
                    file = experiment.ExperimentInfo.FilePath;
                }

                if (file != null)
                {
                    try
                    {
                        string extension = file.Substring(file.Length - 6);

                        if (extension.Equals(".temlx"))
                        {
                            ExperimentManager.SaveToCrypt(experiment, file);
                        }
                        else
                        {
                            ExperimentManager.Save(experiment, file);
                        }
                    }
                    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 (Exception e)
                    {
                        FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file);
                    }
                }
            }
        }
        public void passwordPickerDestroyed(object sender, EventArgs e)
        {
            if (pwdPicker.passwordChanged)
            {
                this.Modal = true;
                //update passwords in the metadata
                this.m_applicationViewModel.Experiment.ExperimentInfo.ChallengePassword  = pwdPicker.challengePwd;
                this.m_applicationViewModel.Experiment.ExperimentInfo.ExperimentPassword = pwdPicker.experimentPwd;
                string oldPath   = m_applicationViewModel.Experiment.ExperimentInfo.FilePath;
                string extension = System.IO.Path.GetFileNameWithoutExtension(oldPath);

                if (!string.IsNullOrEmpty(pwdPicker.challengePwd) || !string.IsNullOrEmpty(pwdPicker.experimentPwd))
                {
                    //there is AT LEAST one password
                    //call the procedure to save a locked esxperiment in TEMLX format
                    string path;
                    if (!extension.Equals(".temlx"))
                    {
                        path = addExt(m_applicationViewModel.Experiment.ExperimentInfo.FilePath, ".temlx");
                    }
                    else
                    {
                        //save an updated version of the experiment
                        path = m_applicationViewModel.Experiment.ExperimentInfo.FilePath;
                    }
                    ExperimentManager.SaveToCrypt(this.m_applicationViewModel.Experiment, path);
                }
                else
                {
                    //there are no password so we should decrypt the file, if this is a TEMLX
                    //save the experiment decrypted and delete the .temlx file
                    string uniquePat = GetUniqueName(m_applicationViewModel.Experiment.ExperimentInfo.FilePath, ".teml");
                    ExperimentManager.Save(this.m_applicationViewModel.Experiment, uniquePat);
                }

                //delete old file TEML
                ExperimentManager.DeleteFile(oldPath);
            }
            pwdPicker = null;
        }