示例#1
0
        /// <summary>
        /// Deletes and de-indexes a file.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="fullName">The full name of the file to delete.</param>
        /// <returns><c>true</c> if the file was deleted, <c>false</c> otherwise.</returns>
        public static bool DeleteFile(IFilesStorageProviderV40 provider, string fullName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            if (fullName.Length == 0)
            {
                throw new ArgumentException("Full Name cannot be empty", "fullName");
            }

            fullName = NormalizeFullName(fullName);

            bool done = provider.DeleteFile(fullName);

            if (!done)
            {
                return(false);
            }

            SearchClass.UnindexFile(provider.GetType().FullName + "|" + fullName, provider.CurrentWiki);

            Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, null, FileActivity.FileDeleted);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Gets all the actions for a directory that are denied to a subject.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <returns>The denied actions.</returns>
        private string[] RetrieveDenialsForDirectory(string subject, IFilesStorageProviderV40 provider, string directory)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (directory.Length == 0)
            {
                throw new ArgumentException("Directory cannot be empty", "directory");
            }

            string resourceName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(provider, directory);

            AclEntry[] entries = _settingsProvider.AclManager.RetrieveEntriesForSubject(subject);

            List <string> result = new List <string>(entries.Length);

            foreach (AclEntry entry in entries)
            {
                if (entry.Value == Value.Deny && entry.Resource == resourceName)
                {
                    result.Add(entry.Action);
                }
            }

            return(result.ToArray());
        }
示例#3
0
        /// <summary>
        /// Processes the renaming of a directory.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="oldName">The old directory name (full path).</param>
        /// <param name="newName">The new directory name (full path).</param>
        /// <returns><c>true</c> if the operation completed successfully, <c>false</c> otherwise.</returns>
        /// <remarks>The method <b>does not</b> recurse in sub-directories.</remarks>
        public bool ProcessDirectoryRenaming(IFilesStorageProviderV40 provider, string oldName, string newName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (oldName == null)
            {
                throw new ArgumentNullException("oldName");
            }
            if (oldName.Length == 0)
            {
                throw new ArgumentException("Old Name cannot be empty", "oldName");
            }

            if (newName == null)
            {
                throw new ArgumentNullException("newName");
            }
            if (newName.Length == 0)
            {
                throw new ArgumentException("New Name cannot be empty", "newName");
            }

            return(_settingsProvider.AclManager.RenameResource(
                       Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(provider, oldName),
                       Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(provider, newName)));
        }
示例#4
0
        /// <summary>
        /// Adds some ACL entries for a subject.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <param name="grants">The granted actions.</param>
        /// <param name="denials">The denies actions.</param>
        /// <returns><c>true</c> if the operation succeeded, <c>false</c> otherwise.</returns>
        private bool AddAclEntriesForDirectory(string subject, IFilesStorageProviderV40 provider, string directory, string[] grants, string[] denials)
        {
            bool isGroup = subject.StartsWith("G.");

            subject = subject.Substring(2);

            UserGroup group = null;
            UserInfo  user  = null;

            if (isGroup)
            {
                group = Users.FindUserGroup(currentWiki, subject);
            }
            else
            {
                user = Users.FindUser(currentWiki, subject);
            }

            AuthWriter authWriter = new AuthWriter(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            foreach (string action in grants)
            {
                bool done = false;
                if (isGroup)
                {
                    done = authWriter.SetPermissionForDirectory(AuthStatus.Grant,
                                                                provider, directory, action, group);
                }
                else
                {
                    done = authWriter.SetPermissionForDirectory(AuthStatus.Grant,
                                                                provider, directory, action, user);
                }
                if (!done)
                {
                    return(false);
                }
            }

            foreach (string action in denials)
            {
                bool done = false;
                if (isGroup)
                {
                    done = authWriter.SetPermissionForDirectory(AuthStatus.Deny,
                                                                provider, directory, action, group);
                }
                else
                {
                    done = authWriter.SetPermissionForDirectory(AuthStatus.Deny,
                                                                provider, directory, action, user);
                }
                if (!done)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#5
0
        /// <summary>
        /// Deletes a directory and de-indexes all its contents.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory to delete.</param>
        public static bool DeleteDirectory(IFilesStorageProviderV40 provider, string directory)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (directory.Length == 0 || directory == "/")
            {
                throw new ArgumentException("Cannot delete the root directory", "directory");
            }

            directory = NormalizeFullPath(directory);

            // This must be done BEFORE deleting the directory, otherwise there wouldn't be a way to list contents
            DeletePermissions(provider, directory);
            DeindexDirectory(provider, directory);

            // Delete Directory
            bool done = provider.DeleteDirectory(directory);

            if (!done)
            {
                return(false);
            }

            Host.Instance.OnDirectoryActivity(provider.GetType().FullName, directory, null, FileActivity.DirectoryDeleted);

            return(true);
        }
示例#6
0
        /// <summary>
        /// Retrieves the subjects that have ACL entries set for a directory.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <returns>The subjects.</returns>
        public SubjectInfo[] RetrieveSubjectsForDirectory(IFilesStorageProviderV40 provider, string directory)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (directory.Length == 0)
            {
                throw new ArgumentException("Directory cannot be empty", "directory");
            }

            AclEntry[] entries = _settingsProvider.AclManager.RetrieveEntriesForResource(Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(provider, directory));

            List <SubjectInfo> result = new List <SubjectInfo>(entries.Length);

            for (int i = 0; i < entries.Length; i++)
            {
                SubjectType type = AuthTools.IsGroup(entries[i].Subject) ? SubjectType.Group : SubjectType.User;

                // Remove the subject qualifier ('U.' or 'G.')
                string name = entries[i].Subject.Substring(2);

                if (result.Find(delegate(SubjectInfo x) { return(x.Name == name && x.Type == type); }) == null)
                {
                    result.Add(new SubjectInfo(name, type));
                }
            }

            return(result.ToArray());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentWiki = Tools.DetectCurrentWiki();

            if (!Page.IsPostBack)
            {
                // Localized strings for JavaScript
                StringBuilder sb = new StringBuilder();
                sb.Append(@"<script type=""text/javascript"">" + "\r\n<!--\n");
                sb.Append("var ConfirmMessage = '");
                sb.Append(Properties.Messages.ConfirmOperation);
                sb.Append("';\r\n");
                sb.AppendFormat("var UploadControl = '{0}';\r\n", fileUpload.ClientID);
                //sb.AppendFormat("var RefreshCommandParameter = '{0}';\r\n", btnRefresh.UniqueID);
                sb.AppendFormat("var OverwriteControl = '{0}';\r\n", chkOverwrite.ClientID);
                sb.Append("// -->\n</script>\n");
                lblStrings.Text = sb.ToString();

                // Setup upload information (max file size, allowed file types)
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$1", Tools.BytesToString(GlobalSettings.MaxFileSize * 1024));
                sb = new StringBuilder();
                string[] aft = Settings.GetAllowedFileTypes(currentWiki);
                for (int i = 0; i < aft.Length; i++)
                {
                    sb.Append(aft[i].ToUpper());
                    if (i != aft.Length - 1)
                    {
                        sb.Append(", ");
                    }
                }
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$2", sb.ToString());

                // Load Providers
                foreach (IFilesStorageProviderV40 prov in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(currentWiki))
                {
                    ListItem item = new ListItem(prov.Information.Name, prov.GetType().FullName);
                    if (item.Value == GlobalSettings.DefaultFilesProvider)
                    {
                        item.Selected = true;
                    }
                    lstProviders.Items.Add(item);
                }

                if (CurrentPage == null)
                {
                    btnUpload.Enabled = false;
                }
            }

            // Set provider
            provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, currentWiki);

            if (!Page.IsPostBack)
            {
                rptItems.DataBind();
            }

            DetectPermissions();
            SetupControls();
        }
示例#8
0
        private float GetCurrentAverage(string fullPageName)
        {
            float average = 0;

            try {
                IFilesStorageProviderV40 filesStorageProvider = GetDefaultFilesStorageProvider();

                MemoryStream stream      = new MemoryStream();
                string       fileContent = "";

                if (FileExists(filesStorageProvider, DefaultDirectoryName(), ratingFileName))
                {
                    filesStorageProvider.RetrieveFile(DefaultDirectoryName() + ratingFileName, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    fileContent = Encoding.UTF8.GetString(stream.ToArray());
                }

                string[] plugins = fileContent.Split(new String[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

                // If the plugin is found return the posizion in the plugins array
                // otherwise return -1
                int pluginIndex = SearchPlugin(plugins, fullPageName);
                if (pluginIndex != -1)
                {
                    string[] pluginDetails = plugins[pluginIndex].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                    average = (float)int.Parse(pluginDetails[2]) / (float)100;
                }
            }
            catch (Exception ex) {
                LogWarning(String.Format("Exception occurred {0}", ex.ToString()));
            }
            return(average);
        }
示例#9
0
        /// <summary>
        /// Removes all the ACL Entries for a directory that are bound to a subject.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <returns><c>true</c> if the operation succeeded, <c>false</c> otherwise.</returns>
        private bool RemoveEntriesForDirectory(string subject, IFilesStorageProviderV40 provider, string directory)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (directory.Length == 0)
            {
                throw new ArgumentException("Directory cannot be empty", "directory");
            }

            string resourceName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(provider, directory);

            AclEntry[] entries = _settingsProvider.AclManager.RetrieveEntriesForSubject(subject);

            foreach (AclEntry entry in entries)
            {
                if (entry.Resource == resourceName)
                {
                    // This call automatically logs the operation result
                    bool done = SetPermissionForDirectory(AuthStatus.Delete, provider, directory, entry.Action, subject);
                    if (!done)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#10
0
        /// <summary>
        /// Recursively re-indexes all the contents of the old (renamed) directory to the new one.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="oldDirectory">The old directory.</param>
        /// <param name="newDirectory">The new directory.</param>
        private static void ReindexDirectory(IFilesStorageProviderV40 provider, string oldDirectory, string newDirectory)
        {
            oldDirectory = NormalizeFullPath(oldDirectory);
            newDirectory = NormalizeFullPath(newDirectory);

            // At this point the directory has been already renamed,
            // thus we must list on the new directory and construct the old name
            // Example: /directory/one/ renamed to /directory/two-two/
            // List on /directory/two-two/
            //     dir1
            //     dir2
            // oldSub = /directory/one/dir1/

            foreach (string sub in provider.ListDirectories(newDirectory))
            {
                string oldSub = oldDirectory + sub.Substring(newDirectory.Length);
                ReindexDirectory(provider, oldSub, sub);
            }

            foreach (string file in provider.ListFiles(newDirectory))
            {
                string oldFile = oldDirectory + file.Substring(newDirectory.Length);
                SearchClass.RenameFile(provider.CurrentWiki, provider.GetType().FullName + "|" + oldFile, provider.GetType().FullName + "|" + file);
            }
        }
示例#11
0
        public void Init()
        {
            IFilesStorageProviderV40 prov = GetProvider();

            prov.Init(MockHost(), ConfigurationManager.AppSettings["AzureConnString"], "wiki1");

            Assert.IsNotNull(prov.Information, "Information should not be null");
        }
        public void Init()
        {
            IFilesStorageProviderV40 prov = GetProvider();

            prov.Init(MockHost(), ConnString + InitialCatalog, null);

            Assert.IsNotNull(prov.Information, "Information should not be null");
        }
示例#13
0
        /// <summary>
        /// Sets a permission for a directory.
        /// </summary>
        /// <param name="status">The authorization status.</param>
        /// <param name="provider">The provider that handles the directory.</param>
        /// <param name="directory">The directory.</param>
        /// <param name="action">The action of which to modify the authorization status.</param>
        /// <param name="user">The user subject of the authorization change.</param>
        /// <returns><c>true</c> if the authorization status is changed, <c>false</c> otherwise.</returns>
        public bool SetPermissionForDirectory(AuthStatus status, IFilesStorageProviderV40 provider, string directory, string action, UserInfo user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            return(SetPermissionForDirectory(status, provider, directory, action, AuthTools.PrepareUsername(user.Username)));
        }
示例#14
0
        /// <summary>
        /// Gets all the actions for a directory that are denied to a group.
        /// </summary>
        /// <param name="group">The user group.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <returns>The denied actions.</returns>
        public string[] RetrieveDenialsForDirectory(UserGroup group, IFilesStorageProviderV40 provider, string directory)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            return(RetrieveDenialsForDirectory(AuthTools.PrepareGroup(group.Name), provider, directory));
        }
示例#15
0
        /// <summary>
        /// Sets a permission for a directory.
        /// </summary>
        /// <param name="status">The authorization status.</param>
        /// <param name="provider">The provider that handles the directory.</param>
        /// <param name="directory">The directory.</param>
        /// <param name="action">The action of which to modify the authorization status.</param>
        /// <param name="group">The group subject of the authorization change.</param>
        /// <returns><c>true</c> if the authorization status is changed, <c>false</c> otherwise.</returns>
        public bool SetPermissionForDirectory(AuthStatus status, IFilesStorageProviderV40 provider, string directory, string action, UserGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            return(SetPermissionForDirectory(status, provider, directory, action, AuthTools.PrepareGroup(group.Name)));
        }
示例#16
0
        /// <summary>
        /// Gets all the actions for a directory that are denied to a user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        /// <returns>The denied actions.</returns>
        public string[] RetrieveDenialsForDirectory(UserInfo user, IFilesStorageProviderV40 provider, string directory)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            return(RetrieveDenialsForDirectory(AuthTools.PrepareUsername(user.Username), provider, directory));
        }
示例#17
0
        /// <summary>
        /// Renames and re-indexes a page attachment.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="pageFullName">The page full name.</param>
        /// <param name="name">The attachment name.</param>
        /// <param name="newName">The new attachment name.</param>
        /// <returns><c>true</c> if the attachment was rename, <c>false</c> otherwise.</returns>
        public static bool RenamePageAttachment(IFilesStorageProviderV40 provider, string pageFullName, string name, string newName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (pageFullName == null)
            {
                throw new ArgumentNullException("pageFullName");
            }
            if (pageFullName.Length == 0)
            {
                throw new ArgumentException("Page Full Name cannot be empty", "pageFullName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }
            if (newName == null)
            {
                throw new ArgumentNullException("newName");
            }
            if (newName.Length == 0)
            {
                throw new ArgumentException("New Name cannot be empty", "newName");
            }

            if (name.ToLowerInvariant() == newName.ToLowerInvariant())
            {
                return(false);
            }

            PageContent page = Pages.FindPage(provider.CurrentWiki, pageFullName);

            if (page == null)
            {
                return(false);
            }

            bool done = provider.RenamePageAttachment(pageFullName, name, newName);

            if (!done)
            {
                return(false);
            }

            SearchClass.RenamePageAttachment(page, name, newName);

            Host.Instance.OnAttachmentActivity(provider.GetType().FullName, newName, pageFullName, name, FileActivity.AttachmentRenamed);

            return(true);
        }
示例#18
0
        private void SetProvider()
        {
            string p = Request["Provider"];

            if (string.IsNullOrEmpty(p))
            {
                p = GlobalSettings.DefaultFilesProvider;
            }
            provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(p, currentWiki);
        }
示例#19
0
 private bool DirectoryExists(IFilesStorageProviderV40 filesStorageProvider, string directoryName)
 {
     string[] directoryList = filesStorageProvider.ListDirectories("/");
     foreach (string dir in directoryList)
     {
         if (dir == directoryName)
         {
             return(true);
         }
     }
     return(false);
 }
示例#20
0
 private bool FileExists(IFilesStorageProviderV40 filesStorageProvider, string directory, string fileName)
 {
     string[] filesList = filesStorageProvider.ListFiles(directory);
     foreach (string file in filesList)
     {
         if (file == directory + fileName)
         {
             return(true);
         }
     }
     return(false);
 }
示例#21
0
        /// <summary>
        /// Stores and indexes a file.
        /// </summary>
        /// <param name="provider">The destination provider.</param>
        /// <param name="fullName">The full name.</param>
        /// <param name="source">The source stream.</param>
        /// <param name="overwrite"><c>true</c> to overwrite the existing file, <c>false</c> otherwise.</param>
        /// <returns><c>true</c> if the file was stored, <c>false</c> otherwise.</returns>
        public static bool StoreFile(IFilesStorageProviderV40 provider, string fullName, Stream source, bool overwrite)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            if (fullName.Length == 0)
            {
                throw new ArgumentException("Full Name cannot be empty", "fullName");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            fullName = NormalizeFullName(fullName);

            bool done = provider.StoreFile(fullName, source, overwrite);

            if (!done)
            {
                return(false);
            }

            if (overwrite)
            {
                SearchClass.UnindexFile(provider.GetType().FullName + "|" + fullName, provider.CurrentWiki);
            }

            // 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, Path.GetFileName(fullName));

            source.Seek(0, SeekOrigin.Begin);
            using (FileStream temp = File.Create(tempFile)) {
                source.CopyTo(temp);
            }
            SearchClass.IndexFile(provider.GetType().FullName + "|" + fullName, tempFile, provider.CurrentWiki);
            Directory.Delete(tempDir, true);

            Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, null, FileActivity.FileUploaded);

            return(true);
        }
示例#22
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string subject = lstSubjects.SelectedValue;

            bool done = false;

            switch (CurrentResourceType)
            {
            case AclResources.Namespaces:
                // Remove old values, add new ones
                done = RemoveAllAclEntriesForNamespace(subject, CurrentResourceName);
                if (done)
                {
                    done = AddAclEntriesForNamespace(subject, CurrentResourceName,
                                                     aclActionsSelector.GrantedActions, aclActionsSelector.DeniedActions);
                }
                break;

            case AclResources.Pages:
                // Remove old values, add new ones
                done = RemoveAllAclEntriesForPage(subject, CurrentResourceName);
                if (done)
                {
                    done = AddAclEntriesForPage(subject, CurrentResourceName,
                                                aclActionsSelector.GrantedActions, aclActionsSelector.DeniedActions);
                }
                break;

            case AclResources.Directories:
                // Remove old values, add new ones
                IFilesStorageProviderV40 prov = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(CurrentFilesProvider, currentWiki);
                done = RemoveAllAclEntriesForDirectory(subject, prov, CurrentResourceName);
                if (done)
                {
                    done = AddAclEntriesForDirectory(subject, prov, CurrentResourceName,
                                                     aclActionsSelector.GrantedActions, aclActionsSelector.DeniedActions);
                }
                break;

            default:
                throw new NotSupportedException();
            }

            if (done)
            {
                PopulateSubjectsList();
            }
            else
            {
                lblSaveResult.CssClass = "resulterror";
                lblSaveResult.Text     = Properties.Messages.CouldNotStorePermissions;
            }
        }
示例#23
0
        /// <summary>
        /// Deletes the permissions of a directory.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        private static void DeletePermissions(IFilesStorageProviderV40 provider, string directory)
        {
            directory = NormalizeFullPath(directory);

            foreach (string sub in provider.ListDirectories(directory))
            {
                DeletePermissions(provider, sub);
            }

            AuthWriter authWriter = new AuthWriter(Collectors.CollectorsBox.GetSettingsProvider(provider.CurrentWiki));

            authWriter.ClearEntriesForDirectory(provider, directory);
        }
示例#24
0
        /// <summary>
        /// De-indexes all contents of a directory.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="directory">The directory.</param>
        private static void DeindexDirectory(IFilesStorageProviderV40 provider, string directory)
        {
            directory = NormalizeFullPath(directory);

            foreach (string sub in provider.ListDirectories(directory))
            {
                DeindexDirectory(provider, sub);
            }

            foreach (string file in provider.ListFiles(directory))
            {
                SearchClass.UnindexFile(provider.GetType().FullName + "|" + file, provider.CurrentWiki);
            }
        }
示例#25
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);
        }
示例#26
0
        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;
        }
示例#27
0
        /// <summary>
        /// Gets the proper full name for a directory.
        /// </summary>
        /// <param name="prov">The provider.</param>
        /// <param name="name">The directory name.</param>
        /// <returns>The full name (<b>not</b> prepended with <see cref="Actions.ForDirectories.ResourceMasterPrefix" />.</returns>
        public static string GetDirectoryName(IFilesStorageProviderV40 prov, string name)
        {
            if (prov == null)
            {
                throw new ArgumentNullException("prov");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }

            return("(" + prov.GetType().FullName + ")" + name);
        }
示例#28
0
        private void AddRating(string fullPageName, int rate)
        {
            IFilesStorageProviderV40 filesStorageProvider = GetDefaultFilesStorageProvider();

            MemoryStream stream = new MemoryStream();

            if (FileExists(filesStorageProvider, DefaultDirectoryName(), ratingFileName))
            {
                filesStorageProvider.RetrieveFile(DefaultDirectoryName() + ratingFileName, stream);
                stream.Seek(0, SeekOrigin.Begin);
            }
            string fileContent = Encoding.UTF8.GetString(stream.ToArray());

            string[] plugins = fileContent.Split(new String[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

            StringBuilder sb = new StringBuilder();

            // If the plugin is found return the posizion in the plugins array
            // otherwise return -1
            int pluginIndex = SearchPlugin(plugins, fullPageName);

            if (pluginIndex != -1)
            {
                int numRates   = int.Parse(plugins[pluginIndex].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1]);
                int average    = int.Parse(plugins[pluginIndex].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2]);
                int newAverage = ((average * numRates) + (rate * 100)) / (numRates + 1);
                numRates++;
                plugins[pluginIndex] = fullPageName + "|" + numRates + "|" + newAverage;
                foreach (string plugin in plugins)
                {
                    sb.Append(plugin + "||");
                }
            }
            else
            {
                foreach (string plugin in plugins)
                {
                    sb.Append(plugin + "||");
                }
                sb.Append(fullPageName + "|1|" + (rate * 100));
            }

            stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));

            filesStorageProvider.StoreFile(DefaultDirectoryName() + ratingFileName, stream, true);
        }
示例#29
0
        /// <summary>
        /// Renames and re-indexes a file.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="fullName">The full name of the file to rename.</param>
        /// <param name="newName">The new name of the file (without namespace).</param>
        /// <returns><c>true</c> if the file was renamed, <c>false</c> otherwise.</returns>
        public static bool RenameFile(IFilesStorageProviderV40 provider, string fullName, string newName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            if (fullName.Length == 0)
            {
                throw new ArgumentException("Full Name cannot be empty", "fullName");
            }
            if (newName == null)
            {
                throw new ArgumentNullException("newName");
            }
            if (newName.Length == 0)
            {
                throw new ArgumentException("New Name cannot be empty", "newName");
            }

            fullName = NormalizeFullName(fullName);
            string newFullName = GetDirectory(fullName) + newName;

            newFullName = NormalizeFullName(newFullName);

            if (newFullName.ToLowerInvariant() == fullName.ToLowerInvariant())
            {
                return(false);
            }

            bool done = provider.RenameFile(fullName, newFullName);

            if (!done)
            {
                return(false);
            }

            SearchClass.RenameFile(provider.CurrentWiki, provider.GetType().FullName + "|" + fullName, provider.GetType().FullName + "|" + newFullName);

            Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, newFullName, FileActivity.FileRenamed);

            return(true);
        }
示例#30
0
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <param name="wiki">The wiki.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
        public void Init(IHostV40 host, string config, string wiki)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            _host = host;
            _wiki = wiki;

            IFilesStorageProviderV40 filesStorageProvider = GetDefaultFilesStorageProvider();

            if (!DirectoryExists(filesStorageProvider, DefaultDirectoryName()))
            {
                filesStorageProvider.CreateDirectory("/", DefaultDirectoryName().Trim('/'));
            }

            string[] configEntries = config.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < configEntries.Length; i++)
            {
                string[] configEntryDetails = configEntries[i].Split(new string[] { "=" }, 2, StringSplitOptions.None);
                switch (configEntryDetails[0].ToLowerInvariant())
                {
                case "logoptions":
                    if (configEntryDetails[1] == "nolog")
                    {
                        _enableLogging = false;
                    }
                    else
                    {
                        LogWarning("Unknown value in 'logOptions' configuration string: " + configEntries[i] + "; supported values are: 'nolog'.");
                    }
                    break;

                default:
                    LogWarning("Unknown value in configuration string: " + configEntries[i]);
                    break;
                }
            }
        }