public void OnFileExportImageAsCommand()
        {
            var dlg = new SaveFileDialog();

            dlg.AddExtension     = true;
            dlg.CheckPathExists  = true;
            dlg.Filter           = "Portable Network Graphics (*.png)|*.png|Portable Document Format (*.pdf)|*.pdf|Scalable Vector Graphics (*.svg)|*.svg";
            dlg.FilterIndex      = this._settings.Get("FileExportImageAsFilterIndex", 1);
            dlg.InitialDirectory = this._settings.Get("CurrentDirectory", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
            dlg.OverwritePrompt  = true;

            if ((Boolean)dlg.ShowDialog())
            {
                try
                {
                    var format = "";
                    switch (dlg.FilterIndex)
                    {
                    case 1:
                        format = "png";
                        break;

                    case 2:
                        format = "pdf";
                        break;

                    case 3:
                        format = "svg";
                        break;

                    default:
                        throw new ArgumentException("Unsupported output format");
                    }

                    var webSequenceDiagramsResult = WebSequenceDiagrams.DownloadDiagram(this._wsdScript, this.Style.ToString().ToLower().Replace('_', '-'), format, this.ApiKey);
                    webSequenceDiagramsResult.SaveFile(dlg.FileName);

                    this._settings.Set("CurrentDirectory", Path.GetDirectoryName(dlg.FileName));
                    this._settings.Set("FileExportImageAsFilterIndex", dlg.FilterIndex);
                }
                catch (Exception ex)
                {
                    MsgBox.Error(ex, "Cannot export image to\n{0}", dlg.FileName);
                }
            }
        }
        private void Refresh()
        {
            RefreshStatus = "Updating image...";

            var task = Task.Factory.StartNew(() => this._webSequenceDiagramsResult = WebSequenceDiagrams.DownloadDiagram(this._wsdScript, this.Style.ToString().ToLower().Replace('_', '-'), "png", this.ApiKey));

            task.ContinueWith(t =>
            {
                this.Errors.Clear();

                if (task.Exception != null)
                {
                    RefreshStatus = "Error(s) detected";

                    var ex = task.Exception.InnerException;
                    if (ex is WebSequenceDiagramsException)
                    {
                        foreach (var error in (ex as WebSequenceDiagramsException).Errors)
                        {
                            this.Errors.Add(new ErrorViewModel(error.Line, error.Message));
                        }
                    }
                    else
                    {
                        this.Errors.Add(new ErrorViewModel(0, ex.Message));
                    }
                }
                else
                {
                    RefreshStatus = "Ready";
                }

                this.WsdImage = this._webSequenceDiagramsResult.GetBitmapImage();
                this.OnPropertyChanged(() => this.WsdImage);

                this.ActualWsdImageWidth = this._webSequenceDiagramsResult.ActualImageWidth;
            });
        }
 private void DownloadImage()
 {
     this._webSequenceDiagramsResult = WebSequenceDiagrams.DownloadDiagram(this._wsdScript, this.Style.ToString().ToLower().Replace('_', '-'), "png", this.ApiKey);
 }