public void ImportProject() { // Make sure we give the user a chance to // save the project if they need too. if (!AskSaveProject()) { return; } if (!View.AskImportProject(out string projectFilePath)) { return; } CloseProject(); OnProjectLoading?.Invoke(); #if SHIPPING try #endif { _actionStack.Clear(); _project = new PipelineProject(); var parser = new PipelineProjectParser(this, _project); parser.ImportProject(projectFilePath); ResolveTypes(); ProjectOpen = true; ProjectDirty = true; } #if SHIPPING catch (Exception e) { View.ShowError("Open Project", "Failed to open project!"); return; } #endif UpdateTree(); View.UpdateTreeItem(_project); OnProjectLoaded?.Invoke(); UpdateMenu(); }
public void OpenProject(string projectFilePath) { CloseProject(); OnProjectLoading?.Invoke(); var errortext = "Failed to open the project due to an unknown error."; try { _actionStack.Clear(); _project = new PipelineProject(); var parser = new PipelineProjectParser(this, _project); var errorCallback = new MGBuildParser.ErrorCallback((msg, args) => { errortext = string.Format(msg, args); throw new Exception(); }); parser.OpenProject(projectFilePath, errorCallback); ResolveTypes(); ProjectOpen = true; ProjectDirty = false; PipelineSettings.Default.AddProjectHistory(projectFilePath); PipelineSettings.Default.StartupProject = projectFilePath; PipelineSettings.Default.Save(); View.UpdateRecentList(PipelineSettings.Default.ProjectHistory); } catch (Exception) { View.ShowError("Error Opening Project", Path.GetFileName(projectFilePath) + ": " + errortext); return; } UpdateTree(); View.UpdateTreeItem(_project); OnProjectLoaded?.Invoke(); UpdateMenu(); }
public void NewProject() { // Make sure we give the user a chance to // save the project if they need too. if (!AskSaveProject()) { return; } // A project needs a root directory or it is impossible to resolve relative paths. // So we need the user to choose that location even though the project has not // yet actually been saved to disk. var projectFilePath = Environment.CurrentDirectory; if (!View.AskSaveName(ref projectFilePath, "New Project")) { return; } CloseProject(); OnProjectLoading?.Invoke(); // Clear existing project data, initialize to a new blank project. _actionStack.Clear(); _project = new PipelineProject(); PipelineTypes.Load(_project); // Save the new project. _project.OriginalPath = projectFilePath; ProjectOpen = true; ProjectDirty = true; UpdateTree(); OnProjectLoaded?.Invoke(); UpdateMenu(); }
//Loads the project from the specified filepath //filepath - Directory, name and file extension (Example './My Project.xml') //Returns a flag indicating whether the project loaded successfully public bool Load(string filepath) { //If the filepath is valid if (File.Exists(filepath)) { try { //Create XML serializer XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Task>)); //Create stream reader using (StreamReader streamReader = new StreamReader(filepath)) { //Deserialize project tasks Tasks = (List <Task>)xmlSerializer.Deserialize(streamReader); } //If at least one subscription to the on project loaded event exists if (OnProjectLoaded != null) { //Invoke the on project loaded event OnProjectLoaded.Invoke(this); } //Successfully loaded return(true); } catch (Exception exception) { //Display exception message MessageBox.Show(exception.Message); } } //Failed to load return(false); }