示例#1
0
 /// <summary>
 /// Removes a XWikiDocument instance from the wiki structure.
 /// This has no effect on the server. It only affects the document list
 /// Word works with.
 /// </summary>
 public void RemoveXWikiDocument(XWikiDocument doc)
 {
     foreach (Space space in spaces)
     {
         if (space.name == doc.space)
         {
             space.documents.Remove(doc);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Adds a collection of XWiki documents to the space instance.
 /// </summary>
 /// <param name="_documents">A collection containing XWiki documents names.</param>
 public void AddDocuments(IEnumerable <String> _documents)
 {
     foreach (String documentName in _documents)
     {
         XWikiDocument doc = new XWikiDocument();
         doc.name      = documentName;
         doc.space     = this.name;
         doc.published = true;
         documents.Add(doc);
     }
 }
示例#3
0
 /// <summary>
 /// Adds a collection of XWiki documents to the space instance.
 /// </summary>
 /// <param name="_documents">A collection containing XWiki documents names.</param>
 public void AddDocuments(IEnumerable<String> _documents)
 {
     foreach (String documentName in _documents)
     {
         XWikiDocument doc = new XWikiDocument();
         doc.name = documentName;
         doc.space = this.name;
         doc.published = true;
         documents.Add(doc);
     }
 }
示例#4
0
 /// <summary>
 /// Removes a XWikiDocument instance from the wiki structure.
 /// This has no effect on the server. It only affects the document list
 /// Word works with.
 /// </summary>
 public void RemoveXWikiDocument(XWikiDocument doc)
 {
     foreach (Space space in spaces)
     {
         if (space.name == doc.space)
         {
             space.documents.Remove(doc);
         }
     }
 }
        /// <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 fprm 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)
            {
                sender.Hide();
                Application.DoEvents();
                sender.Close();
            }
            try
            {
                if (!this.Client.LoggedIn)
                {
                    Client.Login(addin.username, addin.password);
                }
                String pageFullName = spaceName + "." + pageName;
                String localFileName = pageFullName.Replace(".", "-");
                String folder = addin.AddinSettings.PagesRepository + "TempPages";
                ConvertToNormalFolder(folder);
                //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content);
                ConversionManager pageConverter = new ConversionManager(addin.AddinSettings, 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 encoding = Client.ServerEncoding;
                byte[] buffer = encoding.GetBytes(pageContent);
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();
                addin.currentPageFullName = pageFullName;
                addin.EditedPages.Add(localFileName, pageFullName);

                //Open the file with Word
                Word.Document doc = OpenHTMLDocument(localFileName);
                Application.DoEvents();
                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.XWikiAddIn.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.XWikiAddIn.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);
            }
        }