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); } } }
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 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); } } }
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); }
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(); } }
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); } }
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 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); }
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(); } }
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(); } } }
public static List <RecentProject> GetRecentProjects() { if (File.Exists(App.EXECUTABLE_DIRECTORY + "\\" + App.RECENT_PROJECTS_FILE)) { try { List <RecentProject> recentProjects = JsonConvert.DeserializeObject <List <RecentProject> >(File.ReadAllText(App.EXECUTABLE_DIRECTORY + "\\" + App.RECENT_PROJECTS_FILE)); bool changed = false; List <RecentProject> remove = new List <RecentProject>(); foreach (RecentProject project in recentProjects) { if (!File.Exists(project.Path) || recentProjects.Count(recent => recent.Path == project.Path) > 1) { if (!remove.Any(recent => recent.Path == project.Path)) { remove.Add(project); changed = true; } } } if (changed) { foreach (RecentProject project in remove) { recentProjects.Remove(project); } WriteRecentProjects(recentProjects); } return(recentProjects); } catch (Exception ex) { ErrorAlert.Show("Could not load recent projects:\n" + ex.Message); return(new List <RecentProject>()); } } else { return(new List <RecentProject>()); } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!complete) { if (!canceling) { if (TaskToExecute.IsCancelable) { canceling = true; lbTaskName.Text += " - Canceling..."; pbProgress.IsIndeterminate = true; TaskToExecute.CancellationTokenSource.Cancel(); } else { ErrorAlert.Show("The current task cannot be canceled."); } e.Cancel = true; } } }
internal static void LoadGlobalSettings() { LoadDefaulGlobalSettings(); try { if (File.Exists(EXECUTABLE_DIRECTORY + "\\" + GLOBAL_SETTINGS_FILE)) { GlobalSettings = JsonConvert.DeserializeObject <SettingsCollection>(File.ReadAllText(EXECUTABLE_DIRECTORY + "\\" + GLOBAL_SETTINGS_FILE)); } else { GlobalSettings = DefaultGlobalSettings; SaveGlobalSettings(); } } catch (Exception ex) { ErrorAlert.Show("Could not load global settings file.\nLoading default settings.\nDetails:\n" + ex.Message); } }
public void CancelAllTasks(string errorMessage = null) { TaskToExecute.IsCanceled = true; if (errorMessage != null) { if (!this.Dispatcher.CheckAccess()) { this.Dispatcher.Invoke(() => { ErrorAlert.Show(errorMessage); WarningAlert.Show("The task has been canceled."); }); } else { ErrorAlert.Show(errorMessage); WarningAlert.Show("The task has been canceled."); } } Close(); }
private void PassThrough() { if (TaskToExecute.PassThrough) { if (TaskToExecute.GetType().GetProperties().Any((prop) => prop.Name == TaskToExecute.PassThroughSource)) { if (taskCounter != TasksToExecute.Count - 1) { AsyncTask nextTask = TasksToExecute[taskCounter + 1]; if (nextTask.GetType().GetProperties().Any((prop) => prop.Name == TaskToExecute.PassThroughTarget)) { try { nextTask.GetType().GetProperty(TaskToExecute.PassThroughTarget).SetValue(nextTask, TaskToExecute.GetType().GetProperty(TaskToExecute.PassThroughSource).GetValue(TaskToExecute)); } catch (Exception ex) { ErrorAlert.Show("Unable to pass property through:\n" + ex.Message); } } else { ErrorAlert.Show("Unknown passthrough target '" + TaskToExecute.PassThroughTarget + "'."); } } else { ErrorAlert.Show("Cannot passthrough property when there is no task to pass through to."); } } else { ErrorAlert.Show("Unknown passthrough source '" + TaskToExecute.PassThroughSource + "'."); } } }
private void Run() { MKDocsConfiguration configuration = new MKDocsConfiguration(); configuration.copyright = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.COPYRIGHT); configuration.edit_uri = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.EDIT_URL); configuration.google_analytics = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.GOOGLE_ANALYTICS); configuration.remote_branch = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.REMOTE_BRANCH); configuration.remote_name = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.REMOTE_NAME); configuration.repo_name = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.REPOSITORY_NAME); configuration.repo_url = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.REPOSITORY_URL); configuration.site_author = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.SITE_AUTHOR); configuration.site_description = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.SITE_DESCRIPTION); configuration.site_name = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.SITE_NAME); configuration.site_url = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.SITE_URL); List <KeyValuePair <string, string> > navigationConfiguration = new List <KeyValuePair <string, string> >(); foreach (Page page in Version.Pages) { string folder = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetSubSettings(Settings.ConfigurationSettings.NAVIGATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.NavigationSettings.FOLDER_SETTING_START + page.Name); if (folder == "\\") { folder = ""; } navigationConfiguration.Add(new KeyValuePair <string, string>(page.Name, folder + page.Name + ".md")); } configuration.nav = navigationConfiguration.ToArray(); StringBuilder configurationFile = new StringBuilder(); if (!string.IsNullOrWhiteSpace(configuration.copyright)) { configurationFile.Append("copyright: "); configurationFile.Append("'" + configuration.copyright + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.edit_uri)) { configurationFile.Append("edit_uri: "); configurationFile.Append("'" + configuration.edit_uri + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.google_analytics)) { configurationFile.Append("google_analytics: "); configurationFile.Append("'" + configuration.google_analytics + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.remote_branch)) { configurationFile.Append("remote_branch: "); configurationFile.Append("'" + configuration.remote_branch + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.remote_name)) { configurationFile.Append("remote_name: "); configurationFile.Append("'" + configuration.remote_name + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.repo_name)) { configurationFile.Append("repo_name: "); configurationFile.Append("'" + configuration.repo_name + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.repo_url)) { configurationFile.Append("repo_url: "); configurationFile.Append("'" + configuration.repo_url + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.site_author)) { configurationFile.Append("site_author: "); configurationFile.Append("'" + configuration.site_author + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.site_description)) { configurationFile.Append("site_description: "); configurationFile.Append("'" + configuration.site_description + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.site_name)) { configurationFile.Append("site_name: "); configurationFile.Append("'" + configuration.site_name + "'"); configurationFile.AppendLine(); } if (!string.IsNullOrWhiteSpace(configuration.site_url)) { configurationFile.Append("site_url: "); configurationFile.Append("'" + configuration.site_url + "'"); configurationFile.AppendLine(); } configurationFile.Append("nav:"); configurationFile.AppendLine(); foreach (KeyValuePair <string, string> navigation in configuration.nav) { configurationFile.Append(" - '" + navigation.Key + "': '" + navigation.Value + "'"); configurationFile.AppendLine(); } try { File.WriteAllText(Project.OutputFolder + Path.DirectorySeparatorChar + Version.Name + Path.DirectorySeparatorChar + "mkdocs.yml", configurationFile.ToString()); } catch (Exception ex) { ErrorAlert.Show("Could not create MKDocs configuration file.\n" + ex.Message); Dialog.CancelAllTasks(); } }
public static Project LoadProject(string path) { try { Project project = JsonConvert.DeserializeObject <Project>(File.ReadAllText(path)); // when the project has been moved if (project.Path != path) { project.Path = path; } if (!Directory.Exists(project.OutputFolder)) { WarningAlert.Show("Output folder not found.\nPlease specify an output folder."); System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { project.OutputFolder = dialog.SelectedPath; SaveProjectTask task = new SaveProjectTask(project); ProcessTaskDialog saveDialog = new ProcessTaskDialog(task, "Saving..."); saveDialog.ShowDialog(); if (saveDialog.TaskToExecute.IsCanceled) { throw new Exception("Could not save the project."); } } else { throw new Exception("Invalid path."); } } if (!Directory.Exists(project.OutputFolder)) { WarningAlert.Show("Project folder not found.\nPlease specify an output folder."); System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { project.ProjectFolder = dialog.SelectedPath; SaveProjectTask task = new SaveProjectTask(project); ProcessTaskDialog saveDialog = new ProcessTaskDialog(task, "Saving..."); saveDialog.ShowDialog(); if (saveDialog.TaskToExecute.IsCanceled) { throw new Exception("Could not save the project."); } } else { throw new Exception("Invalid path."); } } return(JsonConvert.DeserializeObject <Project>(File.ReadAllText(path))); } catch (Exception ex) { ErrorAlert.Show("Could not load project:\n" + ex.Message); } return(null); }
private void Run() { Image screenshot = Image.FromStream(new MemoryStream(Page.Screenshot)); StringBuilder page = new StringBuilder(); page.Append("# " + Page.Name); page.AppendLine(); page.AppendLine(); page.Append(Page.Description); page.AppendLine(); page.AppendLine(); foreach (Section section in Page.Sections) { page.Append("## " + section.Name); page.AppendLine(); page.AppendLine(); Image croppedImage = ImageUtils.CropImage(screenshot, section.ElementBounds); page.Append("<img src=\"data:image/png;base64," + ImageUtils.ImageToBase64(croppedImage, System.Drawing.Imaging.ImageFormat.Png) + "\" usemap=\"#section" + section.Name.Replace(" ", "") + "\" />"); StringBuilder imageMap = new StringBuilder(); imageMap.Append("<map name=\"section" + section.Name.Replace(" ", "") + "\">"); imageMap.AppendLine(); foreach (Control control in section.Controls) { int topLeftX = control.ElementBounds.Location.X - section.ElementBounds.Location.X; int topLeftY = control.ElementBounds.Location.Y - section.ElementBounds.Location.Y; int bottomRightX = control.ElementBounds.Location.X + control.ElementBounds.Size.Width - section.ElementBounds.Location.X; int bottomRightY = control.ElementBounds.Location.Y + control.ElementBounds.Size.Height - section.ElementBounds.Location.Y; string hrefTarget = control.Name.Replace(" ", "-").ToLower(); imageMap.Append("\t<area target=\"_self\" alt=\"" + control.Name + "\" href=\"#" + hrefTarget + "\" title=\"" + control.Name + "\" coords=\"" + topLeftX.ToString() + "," + topLeftY.ToString() + "," + bottomRightX.ToString() + "," + bottomRightY.ToString() + "\" shape=\"rect\">"); imageMap.AppendLine(); } imageMap.AppendLine(); imageMap.Append("</map>"); page.AppendLine(); page.Append(imageMap.ToString()); page.AppendLine(); page.AppendLine(); page.Append(section.Description); page.AppendLine(); page.AppendLine(); foreach (Control control in section.Controls) { page.Append("### " + control.Name); page.AppendLine(); page.AppendLine(); Image croppedControlImage = ImageUtils.CropImage(screenshot, control.ElementBounds); page.Append("<img src=\"data:image/png;base64," + ImageUtils.ImageToBase64(croppedControlImage, System.Drawing.Imaging.ImageFormat.Png) + "\" />"); page.AppendLine(); page.AppendLine(); page.Append(control.Description); page.AppendLine(); page.AppendLine(); } } try { string docsFolder = Options.BuildSettings.GetSubSettings(Settings.CONFIGURATION_SETTINGS).GetTextSetting(Settings.ConfigurationSettings.DOCS_DIRECTORY); File.WriteAllText(Project.OutputFolder + Path.DirectorySeparatorChar + Version.Name + Path.DirectorySeparatorChar + docsFolder + Path.DirectorySeparatorChar + Page.Name + ".md", page.ToString()); } catch (Exception ex) { ErrorAlert.Show("Could not create page file.\n" + ex.Message); Dialog.CancelAllTasks(); } }