/// <summary> /// Starts editing a new wiki page. The page will not be created in the wiki until the fisrt save. /// </summary> /// <param name="spaceName">The name of the wiki space.</param> /// <param name="pageName">The name of page.</param> /// <param name="pageTitle">The title of the page.</param> /// <param name="sender"> /// The instance of the form that started the action. /// This form need to be closed before swithing the Active Word Document. /// </param> public void AddNewPage(string spaceName, string pageName, string pageTitle, Form sender) { //Any modal dialog nust be closed before opening or closing active documents. if (sender != null) { //hide the form before closing to prevent reactivation and focus request. sender.Hide(); sender.Close(); Application.DoEvents(); } try { if (!this.Client.LoggedIn) { Client.Login(addin.Username, addin.Password); } String pageFullName = spaceName + "." + pageName; String localFileName = pageFullName.Replace(".", "-"); String folder = addin.PagesRepository + "TempPages"; new FolderAttributesCleaner(folder).Perform(); //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content); ConversionManager pageConverter = new ConversionManager(addin.ServerURL, folder, pageFullName, localFileName, addin.Client); localFileName = folder + "\\" + localFileName + ".html"; addin.CurrentLocalFilePath = localFileName; //Save the file if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } String pageContent = "<h1>" + pageTitle + "</h1>" + Environment.NewLine; pageContent = pageContent + newPageText; FileStream stream = new FileStream(localFileName, FileMode.Create); //byte[] buffer = UTF8Encoding.UTF8.GetBytes(pageContent.ToString()); Encoding iso = Client.ServerEncoding; byte[] buffer = iso.GetBytes(pageContent); stream.Write(buffer, 0, buffer.Length); stream.Close(); addin.CurrentPageFullName = pageFullName; //Since it's a new page, it's not published addin.CurrentPagePublished = false; addin.PublishedStatus.Add(pageFullName, false); addin.EditedPages.Add(localFileName, pageFullName); //Open the file with Word HTMLDocumentOpener htmlDocOpener = new HTMLDocumentOpener(addin, localFileName); htmlDocOpener.Perform(); Word.Document doc = htmlDocOpener.GetResults(); doc.Activate(); newDoc = doc; //If it's a new space, add it to the wiki structure and mark it as unpublished List<Space> spaces = Globals.XWord2003AddIn.Wiki.spaces; Space space = null; foreach (Space sp in spaces) { if (sp.name == spaceName) { space = sp; //Add the new page to the wiki structure and mark it as unpublished XWikiDocument xwdoc = new XWikiDocument(); xwdoc.name = pageName; xwdoc.published = false; xwdoc.space = spaceName; space.documents.Add(xwdoc); break; } } if (space == null) { space = new Space(); space.name = spaceName; space.published = false; Globals.XWord2003AddIn.Wiki.spaces.Add(space); //Add the new page to the wiki structure and mark it as unpublished XWikiDocument xwdoc = new XWikiDocument(); xwdoc.name = pageName; xwdoc.published = false; xwdoc.space = spaceName; space.documents.Add(xwdoc); } } catch (IOException ex) { UserNotifier.Error(ex.Message); } }
/// <summary> /// Starts editing a new wiki page. The page will not be created in the wiki until the fisrt save. /// </summary> /// <param name="spaceName">The name of the wiki space.</param> /// <param name="pageName">The name of page.</param> /// <param name="pageTitle">The title of the page.</param> /// <param name="sender"> /// The instance of the form that started the action. /// This form need to be closed before swithing the Active Word Document. /// </param> public void AddNewPage(string spaceName, string pageName, string pageTitle, Form sender) { //Any modal dialog nust be closed before opening or closing active documents. if (sender != null) { //hide the form before closing to prevent reactivation and focus request. sender.Hide(); sender.Close(); Application.DoEvents(); } try { if (!this.Client.LoggedIn) { Client.Login(addin.Username, addin.Password); } String pageFullName = spaceName + "." + pageName; String localFileName = pageFullName.Replace(".", "-"); String folder = addin.PagesRepository + "TempPages"; new FolderAttributesCleaner(folder).Perform(); //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content); ConversionManager pageConverter = new ConversionManager(addin.ServerURL, folder, pageFullName, localFileName, addin.Client); localFileName = folder + "\\" + localFileName + ".html"; addin.CurrentLocalFilePath = localFileName; //Save the file if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } String pageContent = "<h1>" + pageTitle + "</h1>" + Environment.NewLine; pageContent = pageContent + newPageText; FileStream stream = new FileStream(localFileName, FileMode.Create); //byte[] buffer = UTF8Encoding.UTF8.GetBytes(pageContent.ToString()); Encoding iso = Client.ServerEncoding; byte[] buffer = iso.GetBytes(pageContent); stream.Write(buffer, 0, buffer.Length); stream.Close(); addin.CurrentPageFullName = pageFullName; //Since it's a new page, it's not published addin.CurrentPagePublished = false; addin.PublishedStatus.Add(pageFullName, false); addin.EditedPages.Add(localFileName, pageFullName); //Open the file with Word HTMLDocumentOpener htmlDocOpener = new HTMLDocumentOpener(addin, localFileName); htmlDocOpener.Perform(); Word.Document doc = htmlDocOpener.GetResults(); doc.Activate(); newDoc = doc; //If it's a new space, add it to the wiki structure and mark it as unpublished List <Space> spaces = Globals.XWord2003AddIn.Wiki.spaces; Space space = null; foreach (Space sp in spaces) { if (sp.name == spaceName) { space = sp; //Add the new page to the wiki structure and mark it as unpublished XWikiDocument xwdoc = new XWikiDocument(); xwdoc.name = pageName; xwdoc.published = false; xwdoc.space = spaceName; space.documents.Add(xwdoc); break; } } if (space == null) { space = new Space(); space.name = spaceName; space.published = false; Globals.XWord2003AddIn.Wiki.spaces.Add(space); //Add the new page to the wiki structure and mark it as unpublished XWikiDocument xwdoc = new XWikiDocument(); xwdoc.name = pageName; xwdoc.published = false; xwdoc.space = spaceName; space.documents.Add(xwdoc); } } catch (IOException ex) { UserNotifier.Error(ex.Message); } }
/// <summary> /// Saves the currently edited page or document to the server. /// </summary> public void SaveToServer() { string msgSaving = "Saving to server ..."; string msgPublished = "Page published!"; addin.StatusMessage = msgSaving; addin.Application.StatusBar = msgSaving; if (addin.CurrentPageFullName == "" || addin.CurrentPageFullName == null) { UserNotifier.Exclamation(UIMessages.NOT_A_WIKI_PAGE); return; } SaveToXWiki(); if (!addin.CurrentPagePublished) { //mark page as published addin.CurrentPagePublished = true; if (addin.PublishedStatus.ContainsKey(addin.CurrentPageFullName)) { addin.PublishedStatus[addin.CurrentPageFullName] = true; } else { addin.PublishedStatus.Add(addin.CurrentPageFullName, true); } char[] separator = { '.' }; string[] pageFullName = addin.CurrentPageFullName.Split(separator, StringSplitOptions.RemoveEmptyEntries); string spaceName = pageFullName[0].Trim(); string pageName = pageFullName[1].Trim(); XWiki.Space currentSpace = null; //if it's a new space add it to the local wiki structure bool spaceExists = false; foreach (XWiki.Space space in addin.Wiki.spaces) { if (space.name == spaceName) { spaceExists = true; currentSpace = space; break; } } if (!spaceExists) { currentSpace = new Space(); currentSpace.name = spaceName; currentSpace.documents = new List<XWikiDocument>(); currentSpace.hidden = false; currentSpace.published = true; } //add the new page to the space in the local wiki structure bool pageExists = false; foreach (XWiki.XWikiDocument page in currentSpace.documents) { if (page.name == pageName) { pageExists = true; break; } } if (!pageExists) { XWiki.XWikiDocument currentPage = new XWikiDocument(); currentPage.name = pageName; currentPage.published = true; currentPage.space = spaceName; currentSpace.documents.Add(currentPage); } } addin.StatusMessage = msgPublished; addin.Application.StatusBar = msgPublished; }
/// <summary> /// Saves the currently edited page or document to the server. /// </summary> public void SaveToServer() { string msgSaving = "Saving to server ..."; string msgPublished = "Page published!"; addin.StatusMessage = msgSaving; addin.Application.StatusBar = msgSaving; if (addin.CurrentPageFullName == "" || addin.CurrentPageFullName == null) { UserNotifier.Exclamation(UIMessages.NOT_A_WIKI_PAGE); return; } SaveToXWiki(); if (!addin.CurrentPagePublished) { //mark page as published addin.CurrentPagePublished = true; if (addin.PublishedStatus.ContainsKey(addin.CurrentPageFullName)) { addin.PublishedStatus[addin.CurrentPageFullName] = true; } else { addin.PublishedStatus.Add(addin.CurrentPageFullName, true); } char[] separator = { '.' }; string[] pageFullName = addin.CurrentPageFullName.Split(separator, StringSplitOptions.RemoveEmptyEntries); string spaceName = pageFullName[0].Trim(); string pageName = pageFullName[1].Trim(); XWiki.Space currentSpace = null; //if it's a new space add it to the local wiki structure bool spaceExists = false; foreach (XWiki.Space space in addin.Wiki.spaces) { if (space.name == spaceName) { spaceExists = true; currentSpace = space; break; } } if (!spaceExists) { currentSpace = new Space(); currentSpace.name = spaceName; currentSpace.documents = new List <XWikiDocument>(); currentSpace.hidden = false; currentSpace.published = true; } //add the new page to the space in the local wiki structure bool pageExists = false; foreach (XWiki.XWikiDocument page in currentSpace.documents) { if (page.name == pageName) { pageExists = true; break; } } if (!pageExists) { XWiki.XWikiDocument currentPage = new XWikiDocument(); currentPage.name = pageName; currentPage.published = true; currentPage.space = spaceName; currentSpace.documents.Add(currentPage); } } addin.StatusMessage = msgPublished; addin.Application.StatusBar = msgPublished; }