예제 #1
0
        /// <summary>
        /// Action to be performed on form load.
        /// If the wiki structure is loaded, populates the spaces ListBox, selects the first space
        /// and populates the pages ListBox with pages names from selected space.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        protected override void ActionFormLoad(object sender, EventArgs e)
        {
            if (Globals.XWord2003AddIn.Wiki != null)
            {
                spacesNames = new List <string>();
                pagesNames  = new List <string>();

                foreach (XWiki.Space space in Globals.XWord2003AddIn.Wiki.spaces)
                {
                    spacesNames.Add(space.name);
                }

                XWiki.Space firstSpace = Globals.XWord2003AddIn.Wiki.spaces[0];

                foreach (XWiki.XWikiDocument page in firstSpace.documents)
                {
                    pagesNames.Add(page.name);
                }

                editPageForm.ListBoxPagesDataSource     = pagesNames;
                editPageForm.ListBoxPagesSelectedIndex  = 0;
                editPageForm.ListBoxSpacesDataSource    = spacesNames;
                editPageForm.ListBoxSpacesSelectedIndex = 0;
            }
            else
            {
                UserNotifier.Error(UIMessages.WIKI_STRUCTURE_NOT_LOADED);
            }
        }
예제 #2
0
 /// <summary>
 /// Copies a document to a specified path.
 /// </summary>
 /// <param name="document">The Document instance.</param>
 /// <param name="path">The path where the new file will be saved.</param>
 /// <param name="saveFormat">The save format.</param>
 /// <exception cref="IOException">When the file cannot be saved.</exception>
 /// <remarks>The document is saved in Unicode little endian encoding.</remarks>
 /// <returns>True if the operation succedes. False otherwise.</returns>
 public bool ShadowCopyDocument(Word.Document document, string path, Word.WdSaveFormat saveFormat)
 {
     try
     {
         Object format               = saveFormat;
         Object copyPath             = path;
         Object encoding             = MsoEncoding.msoEncodingUTF8;
         Object missing              = Type.Missing;
         Object originalFilePath     = document.FullName;
         Object initialDocSaveFormat = document.SaveFormat;
         document.SaveAs(ref copyPath, ref format, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref encoding,
                         ref missing, ref missing, ref missing, ref missing);
         //Refresh the active instance(required after acquiring chart data from Excel)
         document = addin.Application.ActiveWindow.Document;
         document.SaveAs(ref originalFilePath, ref initialDocSaveFormat, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing);
     }
     catch (IOException ioex)
     {
         Log.Exception(ioex);
         UserNotifier.Error(ioex.Message);
         return(false);
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
         return(false);
     }
     return(true);
 }
예제 #3
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXWiki()
        {
            try
            {
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath        = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    UserNotifier.Error(UIMessages.ERROR_SAVING_PAGE);
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr          = new StreamReader(contentFilePath);
                String       fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.CurrentPageFullName))
                {
                    pageConverter = pageConverters[addin.CurrentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.ServerURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.CurrentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);
                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }


                //Convert the source to the propper encoding.
                Encoding iso         = Client.ServerEncoding;
                byte[]   content     = Encoding.Unicode.GetBytes(cleanHTML);
                byte[]   wikiContent = null;
                wikiContent = Encoding.Convert(Encoding.Unicode, iso, content);
                cleanHTML   = iso.GetString(wikiContent);
                SavePage(addin.CurrentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax);
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }
 /// <summary>
 /// Opens the URL if the selected page in the default browser.
 /// </summary>
 public void ViewInBrowser()
 {
     if (treeView.SelectedNode != null)
     {
         if (treeView.SelectedNode.Level == TREE_PAGE_LEVEL)
         {
             try
             {
                 String pageFullName = treeView.SelectedNode.Name;
                 String url          = Client.GetURL(pageFullName);
                 //url = Addin.serverURL + url;
                 Process p = new Process();
                 p.StartInfo = new ProcessStartInfo(url);
                 p.Start();
             }
             catch (Win32Exception ex)
             {
                 UserNotifier.Error(ex.Message);
             }
             catch (WebException webex)
             {
                 UserNotifier.Error(webex.Message);
             }
         }
         else
         {
             UserNotifier.Exclamation("No page is selected");
         }
     }
     else
     {
         UserNotifier.Exclamation("Please select a page in the Wiki Explorer first.");
     }
 }
예제 #5
0
 public void Perform()
 {
     result = true;
     try
     {
         Object format               = saveFormat;
         Object copyPath             = path;
         Object encoding             = MsoEncoding.msoEncodingUnicodeLittleEndian;
         Object missing              = Type.Missing;
         Object originalFilePath     = document.FullName;
         Object initialDocSaveFormat = document.SaveFormat;
         document.SaveAs(ref copyPath, ref format, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref encoding,
                         ref missing, ref missing, ref missing, ref missing);
         document.SaveAs(ref originalFilePath, ref initialDocSaveFormat, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing);
     }
     catch (IOException ioex)
     {
         Log.Exception(ioex);
         UserNotifier.Error(ioex.Message);
         result = false;
     }
 }
 /// <summary>
 /// Loads the wiki data using a background thread.
 /// </summary>
 /// <param name="e">Event parameters. 'e.Argument' contains the </param>
 /// <param name="sender">The control that triggered the event.</param>
 private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         if (Client.LoggedIn)
         {
             LoadWikiStructure();
             Addin.ProtectedPages = GetProtectedPages();
             //The pages will be displayed, and the user will be prompted
             //when trying to edit a protected page.
             //AddinActions.HideProtectedPages(wiki, addin.ProtectedPages);
         }
     }
     catch (Exception ex)
     {
         if (System.Diagnostics.Debugger.IsAttached)
         {
             System.Diagnostics.Debugger.Break();
             Log.Exception(ex);
         }
         else
         {
             treeView.Nodes.Clear();
             loadingWikiData = false;
             Log.Exception(ex);
             UserNotifier.Error(ex.Message);
         }
     }
     backgroundWorker.ReportProgress(100, e.Argument);
 }
예제 #7
0
        private void ReportSaveProblem()
        {
            String error   = Log.GetLastException().Message;
            String message = "There was an error on the server when trying to save the page";

            message += Environment.NewLine + "Details:" + Environment.NewLine + error;
            UserNotifier.Error(message);
        }
예제 #8
0
        /// <summary>
        /// Event triggered when the textbox loses the focus.
        /// </summary>
        /// <param name="sender">The control that triggered the event.</param>
        /// <param name="e">The event parameters.</param>
        private void txtAttachmentsRepo_Leave(object sender, EventArgs e)
        {
            bool isValid = ValidatePath(txtAttachmentsRepo.Text);

            if (!isValid)
            {
                UserNotifier.Error("The path you provided is not valid. Please select a valid path");
            }
        }
예제 #9
0
 public static void ActionNewSpaceOrPage()
 {
     if (Globals.XWord2003AddIn.Wiki != null)
     {
         AddPageForm addPageForm = new AddPageForm(ref Globals.XWord2003AddIn.Wiki);
         new AddPageFormManager(ref addPageForm).EnqueueAllHandlers();
         addPageForm.ShowDialog();
     }
     else
     {
         UserNotifier.Error(UIMessages.WIKI_STRUCTURE_NOT_LOADED);
     }
 }
예제 #10
0
 public static void ActionOpenWikiPage()
 {
     if (Globals.XWord2003AddIn.Wiki != null)
     {
         EditPageForm editPageForm = new EditPageForm();
         new EditPageFormManager(ref editPageForm).EnqueueAllHandlers();
         editPageForm.ShowDialog();
     }
     else
     {
         UserNotifier.Error(UIMessages.WIKI_STRUCTURE_NOT_LOADED);
     }
 }
예제 #11
0
        /// <summary>
        /// Searches the server response for error strings.
        /// </summary>
        /// <param name="content">The server response.</param>
        /// <returns>True if the response contains error reports. False if the response does not ocntain error reports.</returns>
        public bool CheckForErrors(string content)
        {
            bool hasErrors = false;

            if (content.Contains(HTTPResponses.NO_PROGRAMMING_RIGHTS))
            {
                Log.Error("Server " + addin.serverURL + " has no programming rights on getPageservice");
                UserNotifier.Error("There was an error on the server. The pages in MSOffice space don't have programming rights");
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.WRONG_REQUEST))
            {
                Log.Error("Server " + addin.serverURL + " wrong request");
                UserNotifier.Error("Server error: Wrong request");
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.NO_EDIT_RIGHTS))
            {
                Log.Information("User tried to edit a page on " + addin.serverURL + " whithout edit rights");
                UserNotifier.Error("You dont have the right to edit this page");
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.NO_GROOVY_RIGHTS))
            {
                Log.Error("Server " + addin.serverURL + " error on parsing groovy - no groovy rights");
                String message = "There was an error on the server." + Environment.NewLine;
                message += "Please contact your server adminitrator. Error on executing groovy page in MSOffice space";
                UserNotifier.Error(message);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.INSUFFICIENT_MEMMORY))
            {
                Log.Error("Server " + addin.serverURL + " reported OutOfMemmoryException");
                String message = "There was an error on the server." + Environment.NewLine;
                message += "The server has insufficient memmory to execute the current tasks.";
                UserNotifier.Error(message);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.VELOCITY_PARSER_ERROR))
            {
                Log.Error("Server " + addin.serverURL + " error when parsing page. ");
                String message = "There was an error on the server" + Environment.NewLine;
                message += "'Error while parsing velocity page'";
                UserNotifier.Error(message);
                hasErrors = true;
            }
            return(hasErrors);
        }
예제 #12
0
 /// <summary>
 /// Event triggered when the "Add page" button is pressed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAddPage_Click(object sender, EventArgs e)
 {
     if (ValidateFormData())
     {
         try
         {
             this.Close();
             this.OnAdd(sender, e);
         }
         catch (COMException) { }
         catch (Exception ex)
         {
             UserNotifier.Error(ex.Message);
         }
     }
 }
 /// <summary>
 /// Reloads the wiki structure displayed in the wiki explorer.
 /// </summary>
 public void RefreshWikiExplorer()
 {
     pictureBox.Visible = true;
     treeView.Nodes.Clear();
     pictureBox.BringToFront();
     loadingWikiData = true;
     timerUI.Start();
     try
     {
         backgroundWorker.RunWorkerAsync(this);
     }
     catch (InvalidOperationException)
     {
         UserNotifier.Error("This operation is already in progress");
     }
 }
예제 #14
0
        /// <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);
            }
        }
예제 #15
0
        /// <summary>
        /// Saves the page to the wiki. Shows a message box with an error if the operation fails.
        /// </summary>
        /// <param name="pageName">The full name of the wiki page.</param>
        /// <param name="pageContent">The contant to be saved.</param>
        /// <param name="syntax">The wiki syntax of the saved page.</param>
        /// <returns>TRUE if the page was saved successfully.</returns>
        private bool SavePage(String pageName, ref string pageContent, string syntax)
        {
            bool saveSucceeded = false;

            GrammarAndSpellingSettings.Save(ref addin);
            GrammarAndSpellingSettings.Disable();

            if (!this.Client.LoggedIn)
            {
                Client.Login(addin.Username, addin.Password);
            }


            if (!Client.SavePageHTML(pageName, pageContent, syntax))
            {
                Log.Error("Failed to save page " + pageName + "on server " + addin.ServerURL);
                UserNotifier.Error(UIMessages.SERVER_ERROR_SAVING_PAGE);
                saveSucceeded = false;
            }
            else
            {
                saveSucceeded = true;
                //mark the page from wiki structure as published
                bool markedDone = false;
                foreach (Space sp in addin.Wiki.spaces)
                {
                    foreach (XWikiDocument xwdoc in sp.documents)
                    {
                        if ((xwdoc.space + "." + xwdoc.name) == pageName)
                        {
                            sp.published    = true;
                            xwdoc.published = true;
                            markedDone      = true;
                            break;//inner foreach
                        }
                    }
                    if (markedDone)
                    {
                        break;//outer foreach
                    }
                }
            }

            GrammarAndSpellingSettings.Restore();
            return(saveSucceeded);
        }
예제 #16
0
        public void Perform()
        {
            try
            {
                if (!client.LoggedIn)
                {
                    client.Login(addin.Username, addin.Password);
                }
                string content = client.GetRenderedPageContent(pageFullName);
                localFileName = pageFullName.Replace(".", "-");
                string folder = addin.PagesRepository + "TempPages";
                new FolderAttributesCleaner(folder).Perform();

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(pageFullName))
                {
                    pageConverter = pageConverters[pageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.ServerURL, folder, pageFullName, localFileName, addin.Client);
                    pageConverters.Add(pageFullName, pageConverter);
                }

                content       = pageConverter.ConvertFromWebToWord(content);
                localFileName = folder + "\\" + localFileName + ".html";
                addin.CurrentLocalFilePath = localFileName;

                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                FileStream stream = new FileStream(localFileName, FileMode.Create);
                byte[]     buffer = UTF8Encoding.UTF8.GetBytes(content);
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();
            }
            catch (IOException ex)
            {
                UserNotifier.Error(ex.Message);
            }
        }
예제 #17
0
        /// <summary>
        /// Searches the server response for error strings.
        /// </summary>
        /// <param name="content">The server response.</param>
        /// <returns>True if the response contains error reports. False if the response does not ocntain error reports.</returns>
        public bool CheckForErrors(string content)
        {
            bool hasErrors = false;

            if (content.Contains(HTTPResponses.NO_PROGRAMMING_RIGHTS))
            {
                Log.Error("Server " + addin.ServerURL + " has no programming rights on getPageservice");
                UserNotifier.Error(UIMessages.SERVER_ERROR_NO_PROGRAMMING_RIGHTS);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.WRONG_REQUEST))
            {
                Log.Error("Server " + addin.ServerURL + " wrong request");
                UserNotifier.Error(UIMessages.SERVER_ERROR_WRONG_REQUEST);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.NO_EDIT_RIGHTS))
            {
                Log.Information("User tried to edit a page on " + addin.ServerURL + " whithout edit rights");
                UserNotifier.Error(UIMessages.SERVER_ERROR_NO_EDIT_RIGHTS);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.NO_GROOVY_RIGHTS))
            {
                Log.Error("Server " + addin.ServerURL + " error on parsing groovy - no groovy rights");
                UserNotifier.Error(UIMessages.SERVER_ERROR_NO_GROOVY_RIGHTS);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.INSUFFICIENT_MEMMORY))
            {
                Log.Error("Server " + addin.ServerURL + " reported OutOfMemmoryException");
                UserNotifier.Error(UIMessages.SERVER_ERROR_INSUFFICIENT_MEMORY);
                hasErrors = true;
            }
            else if (content.Contains(HTTPResponses.VELOCITY_PARSER_ERROR))
            {
                Log.Error("Server " + addin.ServerURL + " error when parsing page. ");
                UserNotifier.Error(UIMessages.SERVER_ERROR_VELOCITY_PARSER);
                hasErrors = true;
            }
            return(hasErrors);
        }
예제 #18
0
        private void UploadAttToPage_Click(object sender, RibbonControlEventArgs e)
        {
            String page = Globals.XWikiAddIn.AddinStatus.TaskPaneSelectedPage.Get("page");

            if (page == null)
            {
                UserNotifier.Exclamation("You need to select a page in the wiki explorer first.");
                return;
            }
            bool finished = Globals.XWikiAddIn.AddinActions.AttachCurrentFile(page);

            if (finished)
            {
                UserNotifier.Message("Upload finished.");
            }
            else
            {
                UserNotifier.Error("Upload failed. Make sure you have selected a page before uploading");
            }
        }
예제 #19
0
        /// <summary>
        /// Uploads attachments to a page.
        /// </summary>
        /// <param name="pageFullName">The full name of the wiki page.</param>
        public bool AttachFiles(String pageFullName)
        {
            string[] fileNames = SelectLocalFiles();
            addin.Application.StatusBar = "Adding " + fileNames.Length + " attachments to " + pageFullName + " ...";
            AttachmentUploader attachmentUploader = new AttachmentUploader(addin, pageFullName, Client, fileNames);

            attachmentUploader.Perform();
            bool attached = attachmentUploader.GetResults();

            if (attached)
            {
                addin.Application.StatusBar = "Attachments uploaded!";
            }
            else
            {
                addin.Application.StatusBar = "Error uploading attachments!";
                UserNotifier.Error(UIMessages.ERROR_UPLOADING_ATTACHMENTS);
            }
            return(attached);
        }
예제 #20
0
 protected override void ActionFormLoad(object sender, EventArgs e)
 {
     pageFullName = viewPageAttachmentsForm.PageFullName;
     try
     {
         attachments = client.GetDocumentAttachmentList(pageFullName);
     }
     catch
     {
         UserNotifier.Error(UIMessages.ERROR_GET_ATTACHMENTS_LIST);
         viewPageAttachmentsForm.Close();
         return;
     }
     viewPageAttachmentsForm.LabelPageNameText            = pageFullName;
     viewPageAttachmentsForm.ListBoxAttachmentsDataSource = attachments;
     if (attachments.Count > 0)
     {
         viewPageAttachmentsForm.ListBoxAttachmentsIndex = 0;
         attachmentName = attachments[0];
     }
 }
        /// <summary>
        /// Loads the wiki structure(Spaces and pages).
        /// </summary>
        private void LoadWikiStructure()
        {
            try
            {
                Wiki wiki = RequestWikiStructure();
                //keep unpublished spaces and pages
                Wiki oldWikiStruct = null;
                if (Addin.wiki != null)
                {
                    oldWikiStruct = Addin.wiki.GetUnpublishedWikiStructure();
                    AddUnpublishedData(ref wiki, ref oldWikiStruct);
                }

                //Attach the newest data to the addin
                Addin.wiki = wiki;
            }
            catch (Exception ex)
            {
                UserNotifier.Error(ex.Message);
                Log.Exception(ex);
            }
        }
예제 #22
0
 /// <summary>
 /// Removes all XWiki task panes.
 /// <see cref="RemoveTaskPane"/>
 /// </summary>
 private void RemoveAllTaskPanes()
 {
     try
     {
         if (this.Application.Documents.Count > 0)
         {
             for (int i = this.CustomTaskPanes.Count; i > 0; i--)
             {
                 Tools.CustomTaskPane ctp = this.CustomTaskPanes[i - 1];
                 String tag = (String)ctp.Control.Tag;
                 if (tag.Contains(XWikiNavigationPane.XWIKI_EXPLORER_TAG))
                 {
                     this.CustomTaskPanes.Remove(ctp);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         UserNotifier.Error(ex.Message);
     }
 }
예제 #23
0
 /// <summary>
 /// Event triggered when a new word instance is starting.
 /// </summary>
 /// <param name="sender">The control/application that triggers the event.</param>
 /// <param name="e">The event parameters.</param>
 private void ThisAddIn_Startup(object sender, System.EventArgs e)
 {
     try
     {
         InitializeAddin();
         this.Application.DocumentBeforeClose += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);
         this.Application.DocumentChange      += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentChangeEventHandler(Application_DocumentChange);
         this.Application.DocumentOpen        += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
         ((Word.ApplicationEvents4_Event) this.Application).NewDocument += new Microsoft.Office.Interop.Word.ApplicationEvents4_NewDocumentEventHandler(ThisAddIn_NewDocument);
     }
     catch (Exception ex)
     {
         if (System.Diagnostics.Debugger.IsAttached)
         {
             System.Diagnostics.Debugger.Break();
         }
         else
         {
             UserNotifier.Error(ex.Message);
         }
     }
 }
예제 #24
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXwiki()
        {
            try
            {
                addin.AnnotationMaintainer.ClearComments();
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath        = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    ReportSaveProblem();
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr          = new StreamReader(contentFilePath, Client.ServerEncoding);
                String       fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.currentPageFullName))
                {
                    pageConverter = pageConverters[addin.currentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.currentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);

                SSXManager ssxManager = SSXManager.BuildFromLocalHTML(pageConverter, cleanHTML);

                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                //openHTMLDocument(addin.currentLocalFilePath);
                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }

                if (SavePage(addin.currentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax))
                {
                    ssxManager.UploadStyleSheetExtensions();
                    pageConverter.UploadAttachments();
                    addin.AnnotationMaintainer.UpdateAnnotations();
                }
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }
예제 #25
0
        /// <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);
            }
        }
예제 #26
0
        /// <summary>
        /// Edits a wiki page.
        /// </summary>
        /// <param name="_pageFullName">The full name of the wiki page that is being opened for editing.</param>
        private void GetPage(Object _pageFullName)
        {
            try
            {
                if (!this.Client.LoggedIn)
                {
                    Client.Login(addin.username, addin.password);
                }
                String pageFullName = (String)_pageFullName;
                //Read from server
                String content = Client.GetRenderedPageContent(pageFullName);

                //TODO: Add versioniong info to the xmlrpc Page model
                IndexPageHistory(pageFullName);

                String localFileName = pageFullName.Replace(".", "-");
                String folder        = addin.AddinSettings.PagesRepository + "TempPages";
                ConvertToNormalFolder(folder);
                //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content);
                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(pageFullName))
                {
                    pageConverter = pageConverters[pageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, folder, pageFullName, localFileName, addin.Client);
                    pageConverters.Add(pageFullName, pageConverter);
                }
                content       = pageConverter.ConvertFromWebToWord(content);
                localFileName = folder + "\\" + localFileName + ".html";
                addin.currentLocalFilePath = localFileName;
                StringBuilder pageContent = new StringBuilder(content);
                //Process the content
                pageContent.Insert(0, startDocument);
                pageContent.Append(endDocument);
                //Save the file
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                StreamWriter writer = new StreamWriter(localFileName, false, Encoding.UTF8);
                writer.Write(pageContent.ToString());
                writer.Close();

                #region OpenLocalDocument
                //Register new local filename as a wiki page.
                addin.EditedPages.Add(localFileName, pageFullName);
                addin.currentPageFullName = pageFullName;
                //Open the file with Word
                Word.Document doc = OpenHTMLDocument(localFileName);
                #endregion//Open local document

                //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;

                //The opened doc becomes the newest doc used for window reactivation.
                newDoc = doc;
                if (addin.ActiveDocumentInstance != doc)
                {
                    doc.Activate();
                }
            }
            catch (IOException ex)
            {
                UserNotifier.Error(ex.Message);
            }
        }