/// <summary> /// Downloads page content, opens the page in word and marks the documents as saved. /// </summary> /// <param name="_pageFullName">Page full name.</param> private void GetPage(Object _pageFullName) { try { //Download page content string pageFullName = _pageFullName.ToString(); PageContentDownloader pageContentDownloader = new PageContentDownloader(ref addin, _pageFullName.ToString(), Client, pageConverters); pageContentDownloader.Perform(); string localFileName = pageContentDownloader.GetResults(); //Register new local filename as a wiki page. addin.EditedPages.Add(localFileName, pageFullName); addin.CurrentPageFullName = pageFullName; //Since the page exists on server, consider it published addin.CurrentPagePublished = true; if (addin.PublishedStatus.ContainsKey(pageFullName)) { addin.PublishedStatus[pageFullName] = true; } else { addin.PublishedStatus.Add(pageFullName, true); } //Open the file with Word HTMLDocumentOpener htmlDocOpener = new HTMLDocumentOpener(addin, localFileName); try { htmlDocOpener.Perform(); } catch { } //MS Word might thing some modal forms are still opened Word.Document doc = htmlDocOpener.GetResults(); doc.Activate(); newDoc = doc; if (doc != null) { //Mark just-opened document as saved. This prevents a silly confirmation box that //warns about unsaved changes when closing an unchanged document. doc.Saved = true; } } catch (Exception 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> /// Downloads page content, opens the page in word and marks the documents as saved. /// </summary> /// <param name="_pageFullName">Page full name.</param> private void GetPage(Object _pageFullName) { try { //Download page content string pageFullName = _pageFullName.ToString(); PageContentDownloader pageContentDownloader = new PageContentDownloader(ref addin, _pageFullName.ToString(), Client, pageConverters); pageContentDownloader.Perform(); string localFileName = pageContentDownloader.GetResults(); //Register new local filename as a wiki page. addin.EditedPages.Add(localFileName, pageFullName); addin.CurrentPageFullName = pageFullName; //Since the page exists on server, consider it published addin.CurrentPagePublished = true; if (addin.PublishedStatus.ContainsKey(pageFullName)) { addin.PublishedStatus[pageFullName] = true; } else { addin.PublishedStatus.Add(pageFullName, true); } //Open the file with Word HTMLDocumentOpener htmlDocOpener = new HTMLDocumentOpener(addin, localFileName); try { htmlDocOpener.Perform(); } catch { } //MS Word might thing some modal forms are still opened Word.Document doc = htmlDocOpener.GetResults(); doc.Activate(); newDoc = doc; if (doc != null) { //Mark just-opened document as saved. This prevents a silly confirmation box that //warns about unsaved changes when closing an unchanged document. doc.Saved = true; } } catch (Exception 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); } }