public static bool Pack(List <string> contents, string targetpath, PackageManifest manifest) { string tempDirectory = Path.Combine(Path.GetTempPath() + "interpic_temp_package_" + Guid.NewGuid().ToString()); try { Directory.CreateDirectory(tempDirectory); } catch (Exception ex) { ErrorAlert.Show($"Could not create temporary directory '{tempDirectory}':\n{ex.Message}"); return(false); } List <AsyncTask> tasks = new List <AsyncTask>(); tasks.Add(new CreatePackageManifestTask(Path.Combine(tempDirectory, "manifest.json"), manifest)); tasks.Add(new PreparePackageContentsTask(contents, tempDirectory)); tasks.Add(new CreatePackageTask(tempDirectory, targetpath)); tasks.Add(new CleanUpAfterPackageCreationTask(tempDirectory)); ProcessTasksDialog dialog = new ProcessTasksDialog(ref tasks, "Creating package..."); dialog.ShowDialog(); return(!dialog.AllTasksCanceled); }
public void CancelAllTasks(string errorMessage = null) { foreach (AsyncTask task in TasksToExecute) { task.IsCanceled = true; if (!this.Dispatcher.CheckAccess()) { this.Dispatcher.Invoke(() => { task.Icon.Source = new BitmapImage(new Uri("/Interpic.UI;component/Icons/FailRed.png", UriKind.RelativeOrAbsolute)); }); } else { task.Icon.Source = new BitmapImage(new Uri("/Interpic.UI;component/Icons/FailRed.png", UriKind.RelativeOrAbsolute)); } task.FireCanceledEvent(this); } if (errorMessage != null) { if (!this.Dispatcher.CheckAccess()) { this.Dispatcher.Invoke(() => { ErrorAlert.Show(errorMessage); }); } else { ErrorAlert.Show(errorMessage); } } }
///<summary>Handle file->revert command from menu</summary> public void OnRevertActivated(object o, EventArgs args) { if (dataBook.NPages == 0) { return; } DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View; RevertConfirmationAlert rca = new RevertConfirmationAlert(dv.Buffer.Filename, mainWindow); ResponseType response = (ResponseType)rca.Run(); rca.Destroy(); try { if (response == ResponseType.Ok) { dv.Revert(); } } catch (FileNotFoundException ex) { string msg = string.Format(Catalog.GetString("The file '{0}' cannot be found. Perhaps it has been recently deleted."), ex.Message); ErrorAlert ea = new ErrorAlert(Catalog.GetString("Error reverting file"), msg, mainWindow); ea.Run(); ea.Destroy(); } }
private void Run() { try { Directory.CreateDirectory(Project.ProjectFolder); Directory.CreateDirectory(Project.OutputFolder); if (!Projects.SaveProject(Project)) { Dialog.CancelAllTasks(); } } catch (Exception ex) { ErrorAlert dialog = ErrorAlert.Show("Could not create project files:\n" + ex.Message + "\n\nClick on 'OK' to retry"); if (dialog.DialogResult.HasValue) { if (dialog.DialogResult.Value) { Run(); } else { IsCanceled = true; Dialog.CancelAllTasks(); } } } }
public static bool SaveAsNewProject(Project project, string path) { //TODO: Copy source directory to target and save ipp file to target directory. string projectPath = path + Path.GetFileName(project.Path); string oldPath = new string(project.Path.ToCharArray()); string oldProjectPath = new string(project.ProjectFolder.ToCharArray()); string oldOutputFolder = new string(project.OutputFolder.ToCharArray()); project.Path = projectPath; project.ProjectFolder = path; project.OutputFolder = path + "\\Output\\"; project.LastSaved = DateTime.Now; project.Changed = false; try { File.WriteAllText(project.Path, JsonConvert.SerializeObject(project)); project.Path = oldPath; project.ProjectFolder = oldProjectPath; project.OutputFolder = oldOutputFolder; return(true); } catch (Exception ex) { ErrorAlert.Show("Could not save project:\n" + ex.Message); } project.Path = oldPath; project.ProjectFolder = oldProjectPath; project.OutputFolder = oldOutputFolder; return(false); }
public static void AddToRecents(string name, string path) { List <RecentProject> recents = new List <RecentProject>(); if (File.Exists(App.EXECUTABLE_DIRECTORY + "\\" + App.RECENT_PROJECTS_FILE)) { recents.AddRange(GetRecentProjects()); } if (!recents.Any(recent => recent.Path == path)) { RecentProject newRecentProject = new RecentProject(); newRecentProject.Name = name; newRecentProject.Path = path; recents.Add(newRecentProject); try { File.WriteAllText(App.EXECUTABLE_DIRECTORY + "\\" + App.RECENT_PROJECTS_FILE, JsonConvert.SerializeObject(recents)); } catch (Exception ex) { ErrorAlert.Show("Could not save recent projects:\n" + ex.Message); } } }
///<summary>Update the search pattern from the text entry</summary> void UpdateSearchPattern() { if (!searchPatternChanged) { return; } try { byte[] ba; switch ((ComboIndex)SearchAsComboBox.Active) { case ComboIndex.Hexadecimal: ba = ByteArray.FromString(SearchPatternEntry.Text, 16); break; case ComboIndex.Decimal: ba = ByteArray.FromString(SearchPatternEntry.Text, 10); break; case ComboIndex.Octal: ba = ByteArray.FromString(SearchPatternEntry.Text, 8); break; case ComboIndex.Binary: ba = ByteArray.FromString(SearchPatternEntry.Text, 2); break; case ComboIndex.Text: ba = Encoding.ASCII.GetBytes(SearchPatternEntry.Text); break; default: ba = new byte[0]; break; } //end switch // if there is something in the text entry but nothing is parsed // it means it is full of spaces if (ba.Length == 0 && SearchPatternEntry.Text.Length != 0) { throw new FormatException(Catalog.GetString("Strings representing numbers cannot consist of whitespace characters only.")); } else { finder.Strategy.Pattern = ba; } // append string to drop-down list ListStore ls = (ListStore)SearchPatternEntry.Completion.Model; ls.AppendValues(SearchPatternEntry.Text); } catch (FormatException e) { ErrorAlert ea = new ErrorAlert(Catalog.GetString("Invalid Search Pattern"), e.Message, null); ea.Run(); ea.Destroy(); throw; } searchPatternChanged = false; }
private void LoadSettings() { try { foreach (Setting <int> setting in SettingsCollection.NumeralSettings) { if (!setting.Hidden) { RenderNumeralSetting(setting); } } foreach (Setting <string> setting in SettingsCollection.TextSettings) { if (!setting.Hidden) { RenderTextSetting(setting); } } foreach (Setting <bool> setting in SettingsCollection.BooleanSettings) { if (!setting.Hidden) { RenderBooleanSetting(setting); } } foreach (MultipleChoiceSetting setting in SettingsCollection.MultipleChoiceSettings) { if (!setting.Hidden) { RenderMultipleChoiceSetting(setting); } } foreach (PathSetting setting in SettingsCollection.PathSettings) { if (!setting.Hidden) { RenderPathSetting(setting); } } foreach (Setting <SettingsCollection> setting in SettingsCollection.SubSettings) { if (!setting.Hidden) { RenderSubSetting(setting); } } } catch (Exception ex) { ErrorAlert.Show("Error while loading settings:\n" + ex.Message); DialogResult = false; Close(); } }
private async void DisplayError(ViewModelError error) { _spinner.HideLoading(); if (_popupInputService.IsShowing) { return; } if (error.Exception is RestClient.Infrastructure.NetworkException) { DisplayNetworkError(error); return; } var showCuteError = _isError && error.Exception != null && !(error.Exception is HandledException || error.Exception is RankException); var popupErrorItems = error.ErrorItems?.ToDictionary(x => x); if (error.ErrorItems != null) { foreach (var errorItem in error.ErrorItems.ToDictionary(x => x)) { var validator = _navigationService.CurrentPage.FindByName($"{errorItem.Key}Validator"); if (validator == null) { continue; } validator.SetProperty("Text", errorItem.Value); popupErrorItems?.Remove(errorItem.Key); } } var alert = new ErrorAlert() { Description = showCuteError ? _errorDescription : error.Description, Title = showCuteError ? _errorTitle : error.Title ?? error.Severity.ToString(), ErrorItems = popupErrorItems, ViewModelType = this.GetType(), Severity = error.Severity }; if (string.IsNullOrWhiteSpace(alert.Title)) { alert.Title = "Error"; } await _popupInputService.ShowMessageOkAlertPopup(alert.Title, alert.Description, "OK"); }
internal static void SaveGlobalSettings() { try { File.WriteAllText(EXECUTABLE_DIRECTORY + "\\" + GLOBAL_SETTINGS_FILE, JsonConvert.SerializeObject(GlobalSettings)); } catch (Exception ex) { ErrorAlert.Show("Could not save global settings file.\nDefault settings are applied.\nDetails:\n" + ex.Message); } }
public static void WriteRecentProjects(List <RecentProject> projects) { try { File.WriteAllText(App.EXECUTABLE_DIRECTORY + "\\" + App.RECENT_PROJECTS_FILE, JsonConvert.SerializeObject(projects)); } catch (Exception ex) { ErrorAlert.Show("Could not save recent projects:\n" + ex.Message); } }
private void BtnRemove_Click(object sender, RoutedEventArgs e) { if (Project.Versions.Count() != 1) { Models.Version selectedVersion = Project.Versions.Single(version => version.Id == selectedVersionId); Studio.RemoveManualItem(selectedVersion, true); } else { ErrorAlert.Show("A manual must have at least 1 version!"); } }
public void OpenLog(string logfile, IStudioEnvironment environment) { try { logWriter = new StreamWriter(logfile); LogInfo("Opening log for interpic studio " + environment.GetStudioVersion(), "Studio"); } catch (Exception ex) { ErrorAlert.Show("Could not create/open log file. Details:\n" + ex.Message); } }
/// // // Replace related methods // ///<summary>Update the replace pattern from the text entry</summary> void UpdateReplacePattern() { if (!replacePatternChanged) { return; } try { switch ((ComboIndex)ReplaceAsComboBox.Active) { case ComboIndex.Hexadecimal: replacePattern = ByteArray.FromString(ReplacePatternEntry.Text, 16); break; case ComboIndex.Decimal: replacePattern = ByteArray.FromString(ReplacePatternEntry.Text, 10); break; case ComboIndex.Octal: replacePattern = ByteArray.FromString(ReplacePatternEntry.Text, 8); break; case ComboIndex.Binary: replacePattern = ByteArray.FromString(ReplacePatternEntry.Text, 2); break; case ComboIndex.Text: replacePattern = Encoding.ASCII.GetBytes(ReplacePatternEntry.Text); break; default: break; } //end switch // if there is something in the text entry but nothing is parsed // it means it is full of spaces if (replacePattern.Length == 0 && ReplacePatternEntry.Text.Length != 0) { throw new FormatException("Strings representing numbers cannot consist of only whitespace characters. Leave the text entry completely blank for deletion of matched pattern(s)."); } // append string to drop-down list ListStore ls = (ListStore)ReplacePatternEntry.Completion.Model; ls.AppendValues(ReplacePatternEntry.Text); } catch (FormatException e) { ErrorAlert ea = new ErrorAlert("Invalid Replace Pattern", e.Message, null); ea.Run(); ea.Destroy(); throw; } replacePatternChanged = false; }
private void DisplayNetworkError(ViewModelError error) { var alert = new ErrorAlert() { Description = error.Description, Title = _errorTitle, ViewModelType = this.GetType(), Severity = ViewModelError.ErrorSeverity.Warning }; ThreadingHelpers.InvokeOnMainThread(async() => await _popupInputService.ShowMessageOkAlertPopup(alert.Title, alert.Description, "OK")); }
public static bool CheckSelenium(BrowserType type) { if (Selenium.ContainsKey(type)) { return(true); } else { ErrorAlert.Show("Please wait until selenium has started."); return(false); } }
private void Run() { try { Directory.CreateDirectory(Project.OutputFolder + Path.DirectorySeparatorChar + Version.Name + Path.DirectorySeparatorChar + Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.DOCS_DIRECTORY)); Directory.CreateDirectory(Project.OutputFolder + Path.DirectorySeparatorChar + Version.Name + Path.DirectorySeparatorChar + Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.SITE_DIRECTORY)); } catch (Exception ex) { ErrorAlert.Show("Could not create directory structure.\n" + ex.Message); Dialog.CancelAllTasks(); } }
public static bool SaveAsJson(Project project, string path) { try { File.WriteAllText(path, JsonConvert.SerializeObject(project)); return(true); } catch (Exception ex) { ErrorAlert.Show("Could not export project:\n" + ex.Message); } return(false); }
private ByteBuffer OpenFileInternal(string fullPath, bool handleFileNotFound) { try { ByteBuffer bb = ByteBuffer.FromFile(fullPath); bb.UseGLibIdle = true; if (Preferences.Instance["ByteBuffer.TempDir"] != "") { bb.TempDir = Preferences.Instance["ByteBuffer.TempDir"]; } string msg = string.Format(Catalog.GetString("Loaded file '{0}'"), fullPath); Services.UI.Info.DisplayMessage(msg); History.Instance.Add(fullPath); return(bb); } catch (UnauthorizedAccessException) { string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), fullPath); ErrorAlert ea = new ErrorAlert(msg, Catalog.GetString("You do not have read permissions for the file you requested."), mainWindow); ea.Run(); ea.Destroy(); } catch (System.IO.FileNotFoundException) { if (handleFileNotFound == false) { throw; } string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), fullPath); ErrorAlert ea = new ErrorAlert(msg, Catalog.GetString("The file you requested does not exist."), mainWindow); ea.Run(); ea.Destroy(); } catch (System.IO.IOException ex) { string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), fullPath); ErrorAlert ea = new ErrorAlert(msg, ex.Message, mainWindow); ea.Run(); ea.Destroy(); } catch (System.ArgumentException ex) { string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), fullPath); ErrorAlert ea = new ErrorAlert(msg, ex.Message, mainWindow); ea.Run(); ea.Destroy(); } catch (System.NotSupportedException ex) { string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), fullPath); ErrorAlert ea = new ErrorAlert(msg, ex.Message, mainWindow); ea.Run(); ea.Destroy(); } return(null); }
private void LoadTask() { if (TaskToExecute != null) { lbTaskName.Text = TaskToExecute.TaskName; lbTaskDescription.Text = TaskToExecute.TaskDescription; ExecuteTask(); } else { ErrorAlert.Show("No task to execute"); Close(); } }
public static void UnloadExtensionDomain() { GC.Collect(); // collects all unused memory GC.WaitForPendingFinalizers(); // wait until GC has finished its work GC.Collect(); try { AppDomain.Unload(extensionDomain); } catch (Exception ex) { ErrorAlert.Show("Could not unload extensions, exiting..."); Environment.Exit(2); } }
public static bool SaveProject(Project project) { try { File.WriteAllText(project.Path, JsonConvert.SerializeObject(project)); project.LastSaved = DateTime.Now; project.Changed = false; return(true); } catch (Exception ex) { ErrorAlert.Show("Could not save project:\n" + ex.Message); } return(false); }
void OnDoOperationClicked(object o, EventArgs args) { if (dataBook.NPages == 0) { return; } DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View; // get the operands as a byte array byte[] byteArray = null; try { byteArray = ParseOperand(); } catch (FormatException e) { ErrorAlert ea = new ErrorAlert(Catalog.GetString("Error in Operand"), e.Message, null); ea.Run(); ea.Destroy(); return; } /// get the range to apply the operation to Util.Range range = dv.Selection; if (range.IsEmpty()) { Util.Range bbRange = dv.Buffer.Range; range.Start = dv.CursorOffset; range.End = range.Start + byteArray.Length - 1; range.Intersect(bbRange); } // don't allow buffer modification while the operation is perfoming dv.Buffer.ModifyAllowed = false; dv.Buffer.FileOperationsAllowed = false; BitwiseOperation bo = new BitwiseOperation(dv.Buffer, byteArray, range, (OperationType)OperationComboBox.Active, Services.UI.Progress.NewCallback(), BitwiseOperationAsyncCallback, true); // start operation thread Thread boThread = new Thread(bo.OperationThread); boThread.IsBackground = true; boThread.Start(); }
private void btnSelect_Click(object sender, RoutedEventArgs e) { if (SelectedNode == null) { ErrorAlert.Show("No node selected.\nPlease select a node."); return; } ControlIdentifier = new ControlIdentifier(); ControlIdentifier.Name = Utils.GetFriendlyHtmlName(SelectedNode); ControlIdentifier.Identifier = SelectedNode.XPath; SectionIdentifier = new SectionIdentifier(); SectionIdentifier.Name = Utils.GetFriendlyHtmlName(SelectedNode); SectionIdentifier.Identifier = SelectedNode.XPath; Close(); }
private void LoadTasks() { if (TasksToExecute != null) { if (TasksToExecute.Count > 0) { pbTotalProgress.Maximum = TasksToExecute.Count; LoadTaskList(); ExecuteTasks(); } } else { ErrorAlert.Show("No tasks to execute."); complete = true; Close(); } }
public Controller() { // Instantiate declared class objects shippingForm = new formShipping(this); location = new DataLayer.DataAccess.Location(); shipping = new DataLayer.DataAccess.Shipping(); alert = new ErrorAlert(); messageController = new MessageController(shippingForm.messageBoxControl1.ucMessageBox, Resources.loginInstructions); ScreenState = screenStates.pendingLogin; // Wire control events shippingForm.logOnOffControl1.LogOnOffChanged += new LogOnOffControl.LogOnOffChangedEventHandler(logOnOffControl1_LogOnOffChanged); shippingForm.logOnOffControl1.OperatorCodeChanged += new LogOnOffControl.OperatorCodeChangedEventHandler(logOnOffControl1_OperatorCodeChanged); shippingForm.messageBoxControl1.MessageBoxControl_ShowPrevMessage += new EventHandler <EventArgs>(messageBoxControl1_MessageBoxControl_ShowPrevMessage); shippingForm.messageBoxControl1.MessageBoxControl_ShowNextMessage += new EventHandler <EventArgs>(messageBoxControl1_MessageBoxControl_ShowNextMessage); Application.Run(shippingForm); }
private void btnOpenRecentProject_Click(object sender, RoutedEventArgs e) { if (lbsRecentProjects.SelectedItem != null) { RecentProject recentProject = (RecentProject)lbsRecentProjects.SelectedItem; if (File.Exists(recentProject.Path)) { LoadProject(recentProject.Path); } else { List <RecentProject> projects = RecentProjects.GetRecentProjects(); projects.Remove(recentProject); RecentProjects.WriteRecentProjects(projects); ErrorAlert.Show("Project doesn't exist"); LoadRecentProjects(); } } }
///<summary> /// Try to open the file as a ByteBuffer ///</summary> public ByteBuffer OpenFile(string filename) { Uri uri = null; // first try filename as a URI try { uri = new Uri(filename); } catch { } // if filename is a valid URI if (uri != null) { // try to open the URI as an unescaped path try { return(OpenFileInternal(uri.LocalPath, false)); } catch (FileNotFoundException) { } // try to open the URI as an escaped path try { return(OpenFileInternal(uri.AbsolutePath, false)); } catch (FileNotFoundException) { } } // filename is not a valid URI... (eg the path contains invalid URI characters like ':') // try to expand it as a local path try { string fullPath = Path.GetFullPath(filename); return(OpenFileInternal(fullPath, true)); } catch (Exception ex) { string msg = string.Format(Catalog.GetString("Error opening file '{0}'"), filename); ErrorAlert ea = new ErrorAlert(msg, ex.Message, mainWindow); ea.Run(); ea.Destroy(); return(null); } }
///<summary> /// Callback to call when a save operation has finished ///</summary> void SaveFileAsyncCallback(IAsyncResult ar) { ISaveState ss = (ISaveState)ar.AsyncState; if (ss.Result == ThreadedAsyncOperation.OperationResult.Finished) // save went ok { string msg; if (ss.SavePath != ss.Buffer.Filename) { msg = string.Format(Catalog.GetString("The file has been saved as '{0}'"), ss.SavePath); } else { msg = string.Format(Catalog.GetString("The file '{0}' has been saved"), ss.SavePath); } Services.UI.Info.DisplayMessage(msg); // add to history History.Instance.Add(ss.SavePath); return; } else if (ss.Result == ThreadedAsyncOperation.OperationResult.Cancelled) // save cancelled { } else if (ss.Result == ThreadedAsyncOperation.OperationResult.CaughtException) { // * UnauthorizedAccessException // * System.ArgumentException // * System.IO.IOException string msg = string.Format(Catalog.GetString("Error saving file '{0}'"), ss.SavePath); ErrorAlert ea = new ErrorAlert(msg, ss.ThreadException.Message, mainWindow); ea.Run(); ea.Destroy(); } { string msg = string.Format(Catalog.GetString("The file '{0}' has NOT been saved"), ss.SavePath); Services.UI.Info.DisplayMessage(msg); } }
///<summary> /// Create and setup a DataView ///</summary> public DataView CreateDataView(ByteBuffer bb) { DataView dv = new DataView(); string layoutFile = string.Empty; // try to load default (from user preferences) layout file try { layoutFile = Preferences.Instance["Default.Layout.File"]; string useCurrent = Preferences.Instance["Default.Layout.UseCurrent"]; if (useCurrent == "True" && dataBook.NPages > 0) { DataViewDisplay dvd = (DataViewDisplay)dataBook.CurrentPageWidget; layoutFile = dvd.Layout.FilePath; } if (layoutFile != string.Empty) { dv.Display.Layout = new Bless.Gui.Layout(layoutFile); } } catch (Exception ex) { string msg = string.Format(Catalog.GetString("Error loading layout '{0}'. Loading default layout instead."), layoutFile); ErrorAlert ea = new ErrorAlert(msg, ex.Message, mainWindow); ea.Run(); ea.Destroy(); } if (Preferences.Instance["Default.EditMode"] == "Insert") { dv.Overwrite = false; } else if (Preferences.Instance["Default.EditMode"] == "Overwrite") { dv.Overwrite = true; } dv.Buffer = bb; return(dv); }