Ejemplo n.º 1
0
        /// <summary>
        /// Closing this instance.
        /// </summary>
        /// <param name="e">The <see cref="CancelEventArgs" /> instance containing the event data.</param>
        /// <returns><c>true</c> if the application is closing, <c>false</c> otherwise</returns>
        public virtual bool Closing(CancelEventArgs e)
        {
            for (int i = 0; i < Documents.Count; i++)
            {
                ContentViewModel vm = Documents[i];
                if (vm.Model.IsDirty)
                {
                    ActiveDocument = vm;

                    //Execute the close command
                    vm.CloseCommand.Execute(e);

                    //If canceled
                    if (e.Cancel == true)
                    {
                        return(false);
                    }

                    //If it was a new view model with no location to save, we have removed the view model from documents - so reduce the count
                    if (vm.Model.Location == null)
                    {
                        i--;
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 private void ContentChanged(ContentViewModel model)
 {
     _document = model == null ? "" : model.Title;
     RaisePropertyChanged("Title");
     if(model != null)
     {
         Logger.Log("Active document changed to " + model.Title, LogCategory.Info, LogPriority.None);
     }
 }
        private void ContentChanged(ContentViewModel cvm)
        {
            var converter = this.Resources["RegistryConverter"] as TestRegistryToToolboxConverter;
            converter.Content = cvm;

            //Rebind
            object dc = this.DataContext;
            this.DataContext = null;
            this.DataContext = dc;
        }
 private void SaveAs(ContentViewModel cvm)
 {
     if (cvm != null)
     {
         Header = "Save " + cvm.Title + " As...";
     }
     else
     {
         Header = "Save As...";
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves the content of the TextViewModel
        /// </summary>
        /// <param name="contentViewModel">This needs to be a TextViewModel that needs to be saved</param>
        /// <param name="saveAs">Pass in true if you need to Save As?</param>
        /// <returns>true, if successful - false, otherwise</returns>
        public virtual bool SaveContent(ContentViewModel contentViewModel, bool saveAs = false)
        {
            var textViewModel = contentViewModel as TextViewModel;

            if (textViewModel == null)
            {
                _loggerService.Log("ContentViewModel needs to be a TextViewModel to save details", LogCategory.Exception,
                                   LogPriority.High);
                throw new ArgumentException("ContentViewModel needs to be a TextViewModel to save details");
            }

            var textModel = textViewModel.Model as TextModel;

            if (textModel == null)
            {
                _loggerService.Log("TextViewModel does not have a TextModel which should have the text",
                                   LogCategory.Exception, LogPriority.High);
                throw new ArgumentException("TextViewModel does not have a TextModel which should have the text");
            }

            var location = textModel.Location as string;

            if (location == null)
            {
                //If there is no location, just prompt for Save As..
                saveAs = true;
            }

            if (saveAs)
            {
                if (location != null)
                    _dialog.InitialDirectory = Path.GetDirectoryName(location);

                _dialog.CheckPathExists = true;
                _dialog.DefaultExt = "txt";
                _dialog.Filter = "All files (*.*)|*.*";

                if (_dialog.ShowDialog() == true)
                {
                    location = _dialog.FileName;
                    textModel.SetLocation(location);
                    textViewModel.Title = Path.GetFileName(location);
                    try
                    {
                        File.WriteAllText(location, textModel.Document.Text);
                        textModel.IsDirty = false;
                        _loggerService.Log("Saved active document as " + textModel.Document.Text, LogCategory.Info, LogPriority.Low);
                        return true;
                    }
                    catch (Exception exception)
                    {
                        _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                        _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                        return false;
                    }
                }
            }
            else
            {
                try
                {
                    File.WriteAllText(location, textModel.Document.Text);
                    textModel.IsDirty = false;
                    _loggerService.Log("Saved active document as " + textModel.Document.Text, LogCategory.Info, LogPriority.Low);
                    return true;
                }
                catch (Exception exception)
                {
                    _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                    _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                    return false;
                }
            }

            return false;
        }
 private void CurrentContent(ContentViewModel cvm)
 {
 }
Ejemplo n.º 7
0
        public void Update(ContentViewModel viewModel)
        {
            RecentViewItem item = new RecentViewItem();
            item.ContentID = viewModel.ContentId;
            item.DisplayValue = viewModel.Model.Location.ToString();

            if (ActualRecentItems.Contains(item))
            {
                ActualRecentItems.Remove(item);
            }
            ActualRecentItems.Add(item);
            this.Save();
            RecentMenu.Refresh();
        }
 /// <summary>
 ///     Saves the content of the WebTestResultHandler
 /// </summary>
 /// <param name="contentViewModel">This needs to be a WebTestResultHandler that needs to be saved</param>
 /// <param name="saveAs">Pass in true if you need to Save As?</param>
 /// <returns>true, if successful - false, otherwise</returns>
 public virtual bool SaveContent(ContentViewModel contentViewModel, bool saveAs = false)
 {
     return false;
 }
        /// <summary>
        ///     Saves the content of the WebTestScenarioViewModel
        /// </summary>
        /// <param name="contentViewModel">This needs to be a WebTestScenarioViewModel that needs to be saved</param>
        /// <param name="saveAs">Pass in true if you need to Save As?</param>
        /// <returns>true, if successful - false, otherwise</returns>
        public virtual bool SaveContent(ContentViewModel contentViewModel, bool saveAs = false)
        {
            var scenarioViewModel = contentViewModel as WebTestScenarioViewModel;

            if (scenarioViewModel == null)
            {
                _loggerService.Log("ContentViewModel needs to be a Web test scenario to save details",
                    LogCategory.Exception, LogPriority.High);
                throw new ArgumentException("ContentViewModel needs to be a WebTestScenarioViewModel to save details");
            }

            var scenario = scenarioViewModel.Model as WebTestScenario;

            if (scenario == null)
            {
                _loggerService.Log(
                    "WebTestScenarioViewModel does not have a WebTestScenario which should have the content",
                    LogCategory.Exception, LogPriority.High);
                throw new ArgumentException(
                    "WebTestScenarioViewModel does not have a WebTestScenario which should have the text");
            }

            var location = scenario.Location as string;

            if (location == null)
            {
                //If there is no location, just prompt for Save As..
                saveAs = true;
            }

            if (saveAs)
            {
                if (location != null)
                    _dialog.InitialDirectory = Path.GetDirectoryName(location);

                _dialog.CheckPathExists = true;
                _dialog.DefaultExt = "wts";
                _dialog.Filter = "Web test scenario files (*.wts)|*.wts";

                if (_dialog.ShowDialog() == true)
                {
                    location = _dialog.FileName;
                    scenario.SetLocation(location);
                    scenarioViewModel.Title = Path.GetFileName(location);
                    try
                    {
                        using (var writer = new FileStream(location, FileMode.Create, FileAccess.Write))
                        {
                            var ser = new DataContractSerializer(typeof (WebTestScenario),
                                _testRegistry.Tests);
                            ser.WriteObject(writer, scenario);
                            scenario.SetDirty(false);
                        }
                        return true;
                    }
                    catch (Exception exception)
                    {
                        _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                        _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                        return false;
                    }
                }
            }
            else
            {
                try
                {
                    using (var writer = new FileStream(location, FileMode.Create, FileAccess.Write))
                    {
                        var ser = new DataContractSerializer(typeof (WebTestScenario), _testRegistry.Tests);
                        ser.WriteObject(writer, scenario);
                        scenario.SetDirty(false);
                    }
                    return true;
                }
                catch (Exception exception)
                {
                    _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                    _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                    return false;
                }
            }

            return false;
        }
Ejemplo n.º 10
0
        public bool SaveContent(ContentViewModel contentViewModel, bool saveAs = false)
        {
            var textViewModel = contentViewModel as TextViewModel;

            if (textViewModel == null)
            {
                _loggerService.Log("ContentViewModel needs to be a TextViewModel to save details", LogCategory.Exception,
                                   LogPriority.High);
                throw new ArgumentException("ContentViewModel needs to be a TextViewModel to save details");
            }

            var textModel = textViewModel.Model as TextModel;

            if (textModel == null)
            {
                _loggerService.Log("TextViewModel does not have a TextModel which should have the text",
                                   LogCategory.Exception, LogPriority.High);
                throw new ArgumentException("TextViewModel does not have a TextModel which should have the text");
            }

            if (saveAs)
            {
                //TODO: Save as...?
            }
            else
            {
                //Regular save
                var location = textModel.Location as string;
                try
                {
                    File.WriteAllText(location, textModel.Document.Text);
                    textModel.IsDirty = false;
                    return true;
                }
                catch (Exception exception)
                {
                    _loggerService.Log(exception.Message, LogCategory.Exception, LogPriority.High);
                    _loggerService.Log(exception.StackTrace, LogCategory.Exception, LogPriority.High);
                    return false;
                }
            }

            return false;
        }