Exemple #1
0
        private List <TreeElement> BuildImagesSubTree(IFilesStorageProviderV40 provider, string path)
        {
            string[] dirs  = new string[0];
            string[] files = new string[0];

            if (chkImageAttachments.Checked)
            {
                // Load page attachments
                files = provider.ListPageAttachments(currentPage.FullName);
            }
            else
            {
                // Load files
                dirs  = provider.ListDirectories(path);
                files = provider.ListFiles(path);
            }

            List <TreeElement> result = new List <TreeElement>(100);

            foreach (string d in dirs)
            {
                TreeElement item = new TreeElement(d, Tools.ExtractDirectoryName(d),
                                                   BuildImagesSubTree(provider, d));
                // Do not display empty folders to reduce "noise"
                if (item.SubItems.Count > 0)
                {
                    result.Add(item);
                }
            }

            foreach (string f in files)
            {
                if (IsImage(f))
                {
                    string      name = provider.GetType().ToString() + "|" + f;
                    TreeElement item = new TreeElement(name,
                                                       @"<img src=""Thumb.aspx?Provider=" + provider.GetType().ToString() +
                                                       @"&amp;Size=Small&amp;File=" + Tools.UrlEncode(f) +
                                                       @"&amp;Page=" + (chkImageAttachments.Checked ? Tools.UrlEncode(currentPage.FullName) : "") +
                                                       @""" alt=""" + name + @""" /><span class=""imageinfo"">" + f.Substring(f.LastIndexOf("/") + 1) + "</span>",
                                                       "javascript:return SelectImage('" +
                                                       (chkImageAttachments.Checked ? "(" + Tools.UrlEncode(currentPage.FullName) + ")" : "") + "', '" + f.Replace("'", "\\\\\\'") + "', '" +
                                                       (chkImageAttachments.Checked ? currentPage.FullName : "") + "');");
                    result.Add(item);
                }
            }

            return(result);
        }
        protected void rptItems_DataBinding(object sender, EventArgs e)
        {
            provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, Tools.DetectCurrentWiki());

            if (provider == null || CurrentPage == null)
            {
                return;
            }

            // Build a DataTable containing the proper information
            DataTable table = new DataTable("Items");

            table.Columns.Add("Name");
            table.Columns.Add("Size");
            table.Columns.Add("Editable", typeof(bool));
            table.Columns.Add("Page");
            table.Columns.Add("Link");
            table.Columns.Add("CanDelete", typeof(bool));
            table.Columns.Add("CanDownload", typeof(bool));

            string[] attachments = provider.ListPageAttachments(CurrentPage.FullName);
            foreach (string s in attachments)
            {
                FileDetails details = provider.GetPageAttachmentDetails(CurrentPage.FullName, s);

                DataRow row = table.NewRow();
                string  ext = Path.GetExtension(s).ToLowerInvariant();
                row["Name"]     = s;
                row["Size"]     = Tools.BytesToString(details.Size);
                row["Editable"] = canUpload && canDelete && (ext == ".jpg" || ext == ".jpeg" || ext == ".png");
                row["Page"]     = CurrentPage.FullName;
                if (canDownload)
                {
                    row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "&#39;") + "&amp;AsStreamAttachment=1&amp;Provider=" +
                                  provider.GetType().FullName + "&amp;IsPageAttachment=1&amp;Page=" +
                                  Tools.UrlEncode(CurrentPage.FullName) + "&amp;NoHit=1";
                }
                else
                {
                    row["Link"] = "";
                }
                row["CanDelete"]   = canDelete;
                row["CanDownload"] = canDownload;
                table.Rows.Add(row);
            }

            rptItems.DataSource = table;
        }
Exemple #3
0
        private List <TreeElement> BuildFilesSubTree(IFilesStorageProviderV40 provider, string path)
        {
            string[] dirs  = new string[0];
            string[] files = new string[0];

            if (chkFilesAttachments.Checked)
            {
                // Load page attachments
                files = provider.ListPageAttachments(currentPage.FullName);
            }
            else
            {
                // Load files
                dirs  = provider.ListDirectories(path);
                files = provider.ListFiles(path);
            }

            List <TreeElement> result = new List <TreeElement>(100);

            foreach (string d in dirs)
            {
                TreeElement item = new TreeElement(d, Tools.ExtractDirectoryName(d),
                                                   BuildFilesSubTree(provider, d));
                // Do not display empty folders to reduce "noise"
                if (item.SubItems.Count > 0)
                {
                    result.Add(item);
                }
            }

            foreach (string f in files)
            {
                long        size = chkFilesAttachments.Checked ? provider.GetPageAttachmentDetails(currentPage.FullName, f).Size : provider.GetFileDetails(f).Size;
                TreeElement item = new TreeElement(f, f.Substring(f.LastIndexOf("/") + 1) + " (" + Tools.BytesToString(size) + ")",
                                                   "javascript:return SelectFile('" +
                                                   (chkFilesAttachments.Checked ? "(" + Tools.UrlEncode(currentPage.FullName) + ")" : "") + "', '" + f.Replace("'", "\\\\\\'") + "');");
                result.Add(item);
            }

            return(result);
        }
Exemple #4
0
        protected void rptIndex_ItemCommand(object sender, CommandEventArgs e)
        {
            Log.LogEntry("Index rebuild requested for " + e.CommandArgument as string, EntryType.General, SessionFacade.GetCurrentUsername(), currentWiki);

            if (e.CommandName == "PagesRebuild")
            {
                // Clear the pages search index for the current wiki
                SearchClass.ClearIndex(currentWiki);

                IPagesStorageProviderV40 pagesProvider = Collectors.CollectorsBox.PagesProviderCollector.GetProvider(e.CommandArgument as string, currentWiki);

                // Index all pages of the wiki
                List <NamespaceInfo> namespaces = new List <NamespaceInfo>(pagesProvider.GetNamespaces());
                namespaces.Add(null);
                foreach (NamespaceInfo nspace in namespaces)
                {
                    // Index pages of the namespace
                    PageContent[] pages = pagesProvider.GetPages(nspace);
                    foreach (PageContent page in pages)
                    {
                        // Index page
                        SearchClass.IndexPage(page);

                        // Index page messages
                        Message[] messages = pagesProvider.GetMessages(page.FullName);
                        foreach (Message message in messages)
                        {
                            SearchClass.IndexMessage(message, page);

                            // Search for replies
                            Message[] replies = message.Replies;
                            foreach (Message reply in replies)
                            {
                                // Index reply
                                SearchClass.IndexMessage(reply, page);
                            }
                        }
                    }
                }
            }

            else if (e.CommandName == "FilesRebuild")
            {
                // Clear the files search index for the current wiki
                SearchClass.ClearFilesIndex(currentWiki);

                IFilesStorageProviderV40 filesProvider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(e.CommandArgument as string, currentWiki);

                // Index all files of the wiki
                // 1. List all directories (add the root directory: null)
                // 2. List all files in each directory
                // 3. Index each file
                List <string> directories = new List <string>(filesProvider.ListDirectories(null));
                directories.Add(null);
                foreach (string directory in directories)
                {
                    string[] files = filesProvider.ListFiles(directory);
                    foreach (string file in files)
                    {
                        byte[] fileContent;
                        using (MemoryStream stream = new MemoryStream()) {
                            filesProvider.RetrieveFile(file, stream);
                            fileContent = new byte[stream.Length];
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Read(fileContent, 0, (int)stream.Length);
                        }

                        // Index the file
                        string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
                        if (!Directory.Exists(tempDir))
                        {
                            Directory.CreateDirectory(tempDir);
                        }
                        string tempFile = Path.Combine(tempDir, file.Substring(file.LastIndexOf('/') + 1));
                        using (FileStream writer = File.Create(tempFile)) {
                            writer.Write(fileContent, 0, fileContent.Length);
                        }
                        SearchClass.IndexFile(filesProvider.GetType().FullName + "|" + file, tempFile, currentWiki);
                        Directory.Delete(tempDir, true);
                    }
                }

                // Index all attachment of the wiki
                string[] pagesWithAttachments = filesProvider.GetPagesWithAttachments();
                foreach (string page in pagesWithAttachments)
                {
                    string[] attachments = filesProvider.ListPageAttachments(page);
                    foreach (string attachment in attachments)
                    {
                        byte[] fileContent;
                        using (MemoryStream stream = new MemoryStream()) {
                            filesProvider.RetrievePageAttachment(page, attachment, stream);
                            fileContent = new byte[stream.Length];
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Read(fileContent, 0, (int)stream.Length);
                        }

                        // Index the attached file
                        string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
                        if (!Directory.Exists(tempDir))
                        {
                            Directory.CreateDirectory(tempDir);
                        }
                        string tempFile = Path.Combine(tempDir, attachment);
                        using (FileStream writer = File.Create(tempFile)) {
                            writer.Write(fileContent, 0, fileContent.Length);
                        }
                        SearchClass.IndexPageAttachment(attachment, tempFile, Pages.FindPage(currentWiki, page));
                        Directory.Delete(tempDir, true);
                    }
                }
            }

            Log.LogEntry("Index rebuild completed for " + e.CommandArgument as string, EntryType.General, SessionFacade.GetCurrentUsername(), currentWiki);
        }