protected override void ExecuteCore(SelectedItemCollection selection) { ActivationRequestAction action = new ActivationRequestAction(_request); action.Completed += action_Completed; action.RunAsync(); }
void action_Completed(ActionBase sender) { ActivationRequestAction action = (ActivationRequestAction)sender; if (action.Succeeded) { Program.OpenURL(string.Format(InvisibleMessages.ACTIVATION_FORM_URL, InvisibleMessages.ACTIVATION_SERVER, action.Result)); } else { if (DialogResult.Cancel == ShowSaveDialog()) { throw action.Exception; } SaveFileDialog fd = new SaveFileDialog(); Program.Invoke(Program.MainWindow, delegate() { fd.AddExtension = true; fd.DefaultExt = "txt"; fd.Filter = string.Format("{0} (*.*)|*.*", Messages.ALL_FILES); fd.FilterIndex = 0; fd.RestoreDirectory = true; if (DialogResult.Cancel == fd.ShowDialog(Program.MainWindow)) { throw action.Exception; } using (FileStream fs = File.Open(fd.FileName, FileMode.Create)) { byte[] bytes = Encoding.UTF8.GetBytes(_request); fs.Write(bytes, 0, bytes.Length); } }); //Description = string.Format(Messages.ACTIVATION_REQUEST_SAVED, fd.FileName); } }