示例#1
0
        /// <summary>
        /// Tries to upload attachments to an xwiki page.
        /// Stops when one upload fails.
        /// </summary>
        public void Perform()
        {
            if (space == null || page == null)
            {
                Log.Error("Trying to attach a file to a page with an invalid name!");
                result = false;
            }
            if (!this.client.LoggedIn)
            {
                client.Login(addin.Username, addin.Password);
            }
            bool operationCompleted = false;

            if (addin.Application.ActiveDocument == null)
            {
                UserNotifier.Message(UIMessages.NO_OPENED_DOCUMENT);
            }
            operationCompleted = false;
            int totalUploadedAttachments = 0;

            foreach (string fileName in fileNames)
            {
                if (client.AddAttachment(space, page, fileName))
                {
                    totalUploadedAttachments++;
                }
                else
                {
                    break;
                }
            }
            operationCompleted = (totalUploadedAttachments == fileNames.Length);

            result = operationCompleted;
        }
示例#2
0
        /// <summary>
        /// Edits a wiki page.
        /// The LoadingDialog is shown during the operation.
        /// <see cref="EditPage"/>
        /// </summary>
        /// <param name="pageFullName">The full name of the wiki page that is being opened for editing.</param>
        public void EditPage(String pageFullName)
        {
            if (IsOpened(pageFullName))
            {
                UserNotifier.Message("You are already editing this page.");
                return;
            }
            if (!this.Client.LoggedIn)
            {
                Client.Login(addin.username, addin.password);
            }
            if (IsProtectedPage(pageFullName, addin.ProtectedPages))
            {
                String message = "You cannot edit this page." + Environment.NewLine;
                message += "This page contains scrips that provide functionality to the wiki.";
                UserNotifier.StopHand(message);
                return;
            }
            LoadingDialog loadingDialog = new LoadingDialog("Opening page...");

            ThreadPool.QueueUserWorkItem(new WaitCallback(loadingDialog.ShowSyncDialog));

            GetPage(pageFullName);
            loadingDialog.CloseSyncDialog();
        }
        /// <summary>
        /// Attaches the current Word document to the selected wiki page.
        /// <remarks>Event triggered when the "Attach file" button in the context menu is pressed.</remarks>
        /// </summary>
        /// <param name="sender">The control that triggered the event.</param>
        /// <param name="e">The event parameters.</param>
        private void cmnuAttachFile_Click(object sender, EventArgs e)
        {
            String page     = Globals.XWikiAddIn.AddinStatus.TaskPaneSelectedPage.Get("page");
            bool   finished = Globals.XWikiAddIn.AddinActions.AttachCurrentFile(page);

            if (finished)
            {
                UserNotifier.Message("Upload finished.");
            }
        }
示例#4
0
        /// <summary>
        /// Saves the document and attaches it to a wiki page
        /// </summary>
        /// <param name="space">The name of the wiki space.</param>
        /// <param name="page">The name of the page.</param>
        public bool AttachCurrentFile(String space, String page)
        {
            if (space == null || page == null)
            {
                Log.Error("Trying to attach a file to a page with an invalid name!");
                return(false);
            }
            if (!this.Client.LoggedIn)
            {
                Client.Login(addin.username, addin.password);
            }
            bool operationCompleted = false;;

            if (addin.Application.ActiveDocument == null)
            {
                UserNotifier.Message("This command is not available because no document is open.");
            }
            try
            {
                addin.Application.ActiveDocument.Save();
            }
            catch (System.Runtime.InteropServices.COMException) { }
            //Test if the user doesnt cancel the saving process.
            if (addin.Application.ActiveDocument.Saved && (!addin.Application.ActiveDocument.FullName.Equals("Document1")))
            {
                String docFullName = addin.Application.ActiveDocument.FullName;
                String docName     = addin.Application.ActiveDocument.Name;
                Directory.CreateDirectory(addin.AddinSettings.PagesRepository);
                try
                {
                    String targetFile = addin.AddinSettings.PagesRepository + "\\" + docName;
                    File.Copy(docFullName, targetFile, true);
                    Client.AddAttachment(space, page, targetFile);
                    operationCompleted = true;
                }
                catch (IOException ioex)
                {
                    Log.ExceptionSummary(ioex);
                }
                catch (Exception ex)
                {
                    Log.ExceptionSummary(ex);
                }
            }
            return(operationCompleted);
        }
示例#5
0
 private void downloadAtt_Click(object sender, RibbonControlEventArgs e)
 {
     if (Addin.XWikiTaskPane.treeView.SelectedNode != null)
     {
         String page           = Globals.XWikiAddIn.AddinStatus.TaskPaneSelectedPage.Get("page");
         String attachmentName = Addin.XWikiTaskPane.treeView.SelectedNode.Name;
         String path           = Globals.XWikiAddIn.AddinActions.SaveFileDialog(attachmentName);
         if (path != null)
         {
             FileInfo attachmentInfo = Addin.AddinActions.DownloadAttachment(page, attachmentName, path);
             UserNotifier.Message("Download finised.");
         }
     }
     else
     {
         UserNotifier.Exclamation("You need to select an attachment in the wiki explorer.");
     }
 }
        /// <summary>
        /// Downloads the selected file to the local disk and openes it(optional).
        /// </summary>
        /// <param name="sender">The control that triggered the event.</param>
        /// <param name="e">The arguments of the event.</param>
        private void cmnuDownloadOpenFile_Click(object sender, EventArgs e)
        {
            String page           = Globals.XWikiAddIn.AddinStatus.TaskPaneSelectedPage.Get("page");
            String attachmentName = treeView.SelectedNode.Name;
            String path           = AddinActions.SaveFileDialog(attachmentName);

            if (path != null)
            {
                FileInfo attachmentInfo = AddinActions.DownloadAttachment(page, attachmentName, null);
                if (sender == cmnuDownloadOpenFile)
                {
                    AddinActions.StartProcess(attachmentInfo.FullName);
                }
                else
                {
                    UserNotifier.Message("Download finised.");
                }
            }
        }
示例#7
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");
            }
        }
        /// <summary>
        /// Edits a wiki page.
        /// </summary>
        /// <param name="pageFullName">The full name of the wiki page that is being opened for editing.</param>
        public void EditPage(string pageFullName)
        {
            if (IsOpened(pageFullName))
            {
                UserNotifier.Message(UIMessages.ALREADY_EDITING_PAGE);
                return;
            }
            if (!this.Client.LoggedIn)
            {
                Client.Login(addin.Username, addin.Password);
            }

            if (IsProtectedPage(pageFullName, addin.ProtectedPages))
            {
                UserNotifier.StopHand(UIMessages.PROTECTED_PAGE);
                return;
            }


            GetPage(pageFullName);
        }