Exemplo n.º 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;
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public AttachmentUploader(XWord2003AddIn addin, string pageFullName, IXWikiClient client, string[] fileNames)
        {
            this.addin     = addin;
            this.client    = client;
            this.fileNames = fileNames;

            if (pageFullName != null)
            {
                if (!this.client.LoggedIn)
                {
                    client.Login(addin.Username, addin.Password);
                }
                int index = pageFullName.IndexOf(".");
                space = pageFullName.Substring(0, index);
                page  = pageFullName.Substring(index + 1);
            }
            else
            {
                result = false;
            }
        }
Exemplo n.º 4
0
        public void Perform()
        {
            if (!client.LoggedIn)
            {
                client.Login(addin.Username, addin.Password);
            }
            if (path == null)
            {
                path = addin.DownloadedAttachmentsRepository;
                if (new FileInfo(path).Exists)
                {
                    File.Create(path);
                }
                path = path + "\\" + UtilityClass.GenerateUniqueFileName(attachmentName, path);
            }
            fileInfo = new FileInfo(path);
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            byte[]     binaryContent = client.GetAttachmentContent(pageFullName, attachmentName);
            FileStream fileStream    = fileInfo.Create();

            fileStream.Write(binaryContent, 0, binaryContent.Length);
            fileStream.Close();
        }