/// <summary> /// Creates new page with new project. Project info must be passed /// </summary> /// <param name="projectInfo"></param> /// <param name="url">Url of file (which project will be saved in)</param> /// <returns></returns> internal static CanvasTabPage createPage(CProjectInfo projectInfo, String url) { CanvasTabPage tabPage = new CanvasTabPage(); tabPage.projectInfo = projectInfo; tabPage.activeProjectContent = projectInfo.projectXml; tabPage.Text = System.IO.Path.GetFileName(url); tabPage.url = url; return tabPage; }
/// <summary> /// Creates new page with new project. Project info must be passed /// </summary> /// <param name="projectInfo"></param> /// <param name="url">Url of file (which project will be saved in)</param> /// <returns></returns> internal static CanvasTabPage createNewPage(CProjectInfo projectInfo, String url) { CanvasTabPage tabPage = new CanvasTabPage(); tabPage.projectInfo = projectInfo; tabPage.activeProjectContent = ProjectResources.new_file.ToString(); tabPage.Text = System.IO.Path.GetFileName(url); tabPage.url = url; return tabPage; }
/// <summary> /// Generates complete page to specified path /// Project content of the page is in projectInfo.projectXml, language /// which to generate to is in projectInfo.languageID /// </summary> /// <param name="projectInfo">ProjectInfo instance</param> /// <param name="path">Path of HTML index</param> /// <returns>Boolean of success</returns> public static bool generatePage(CProjectInfo projectInfo, String path) { List<AModule> moduleList; String index = CXMLParser.Instance.GetHTMLFromProjectXML(projectInfo.projectXml, out moduleList); // Save html file if (!saveFile(index, path)) return false; // Generate all the templates in module directory foreach (AModule module in moduleList) { // Get module name String moduleName = (String)module.GetType().GetField("name", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty).GetValue(null); // Create directory for each module String newDirPath = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + module.setup.id; DirectoryInfo di = null; String[] moduleResources = module.GetType().Assembly.GetManifestResourceNames(); foreach (String resource in moduleResources) { // There are more resources - preview one, html one, // but just those in given language are needed String nspace = "Modules." + moduleName + "_Templates." + projectInfo.languageID; if (resource.StartsWith(nspace)) { // Create directory only if needed if (di == null) { di = Directory.CreateDirectory(newDirPath); } String name = resource.Substring(nspace.Length + 1); String renderedTemplate = module.renderTemplate(projectInfo.languageID + "." + name); if (!saveFile(renderedTemplate, newDirPath + Path.DirectorySeparatorChar + name)) return false; } } } return true; }
/// <summary> /// Saves serialized ProjectInfo to file /// </summary> /// <param name="projectInfo">ProjectInfo to get serialized</param> /// <param name="url">Url of file to save to</param> /// <returns>Boolean of success</returns> public static bool saveProject(CProjectInfo projectInfo, String url) { // Init serializer DataContractSerializer serializer = new DataContractSerializer(typeof(CProjectInfo)); StreamWriter sw = null; try { // Init stream to file sw = new StreamWriter(url); // Serialize projectInfo to file serializer.WriteObject(sw.BaseStream, projectInfo); } catch (IOException) { return false; } finally { // Whatever happened, try to close the file if (sw != null) sw.Close(); } return true; }
private void ShowNewForm(object sender, EventArgs e) { SaveFileDialog saveFileDialog = CFileDialogFactory.createNewFileDialog(); if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { // Get variables needed for canvastabpage string fileURL = saveFileDialog.FileName; // New form - new info CProjectInfo projectInfo = new CProjectInfo(); projectInfo.languageID = ((CLanguageInfo)CFormController.Instance.languageBox.SelectedItem).Value; // Create tabpage from them CanvasTabPage tabPage = CCanvasTabPageFactory.createNewPage(projectInfo, fileURL); // And add it to tabControl pageContainerControl.TabPages.Add(tabPage); pageContainerControl.SelectedTab = tabPage; // Manually cast selectindexchanged, since it doesnt fire when the first tab // is opened this.pageContainerControl_SelectedIndexChanged(null, null); // Save it also CFileHelper.saveProject(tabPage.projectInfo, tabPage.url); CFormController.Instance.mainForm.setStatus("Project Created"); showToolBox(); } }