Exemple #1
0
        /// <summary>
        /// Determines whether the currently logged on user has edit permissions on the specific item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>
        ///     <c>true</c> if the currently logged on user has edit permissions on the specific item; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanEdit(VirtualFileBase item)
        {
            if (item == null)
            {
                return(false);
            }

            UnifiedDirectory dir = item as UnifiedDirectory;

            if (dir != null)
            {
                return(PrincipalInfo.HasAdminAccess || dir.QueryDistinctAccess(AccessLevel.Edit));
            }

            UnifiedFile file = item as UnifiedFile;

            if (file != null && (PrincipalInfo.HasAdminAccess || file.QueryDistinctAccess(AccessLevel.Edit)))
            {
                IVersioningFile versioningFile = file as IVersioningFile;
                return(versioningFile == null || !IsCheckedOutBySomeoneElse(versioningFile));
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Renames a virtual file or folder.
        /// </summary>
        /// <param name="sourceItem">The item to rename.</param>
        /// <param name="newName">The new name.</param>
        public static void RenameItem(VirtualFileBase sourceItem, string newName)
        {
            // Get the parent directory of the source item.
            string           sourceItemParentPath = VirtualPathUtility.GetDirectory(sourceItem.VirtualPath);
            UnifiedDirectory targetDirectory      = HostingEnvironment.VirtualPathProvider.GetDirectory(sourceItemParentPath) as UnifiedDirectory;

            MoveItem(sourceItem, targetDirectory, newName);
        }
Exemple #3
0
        /// <summary>
        /// Gets the username for the user the file is checked out to.
        /// </summary>
        /// <param name="fileItem">The file item.</param>
        /// <returns>The user name, or an epmty string if the file is not checked out.</returns>
        protected static string GetCheckedOutString(VirtualFileBase fileItem)
        {
            IVersioningFile versioningFile = fileItem as IVersioningFile;

            if (versioningFile != null && versioningFile.IsCheckedOut)
            {
                return(versioningFile.CheckedOutBy);
            }
            return(String.Empty);
        }
Exemple #4
0
 /// <summary>
 /// Moves a virtual file or folder to a new location, optionally renaming it at the same time.
 /// </summary>
 /// <param name="sourceItem">The source item to be moved.</param>
 /// <param name="targetDirectory">The destination directory.</param>
 /// <param name="newName">An optional new name. Supply <c>null</c> to use the original name of the source folder.</param>
 public static void MoveItem(VirtualFileBase sourceItem, UnifiedDirectory targetDirectory, string newName)
 {
     if (sourceItem.IsDirectory)
     {
         MoveDirectory((VirtualDirectory)sourceItem, targetDirectory, newName);
     }
     else
     {
         MoveFile((VirtualFile)sourceItem, targetDirectory, newName);
     }
 }
Exemple #5
0
 /// <summary>
 /// Copies a virtual file or folder to the target directory.
 /// </summary>
 /// <param name="sourceItem">The item to copy.</param>
 /// <param name="targetDirectory">The target directory.</param>
 public static void CopyItem(VirtualFileBase sourceItem, UnifiedDirectory targetDirectory)
 {
     if (sourceItem.IsDirectory)
     {
         CopyDirectory((VirtualDirectory)sourceItem, targetDirectory);
     }
     else
     {
         CopyFile((VirtualFile)sourceItem, targetDirectory);
     }
 }
Exemple #6
0
        /// <summary>
        /// Determines whether the currently logged on user can undo a check out of the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>
        ///     <c>true</c> if the user is allowed to undo check out of the specified file; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Administrators are always allowed to undo a check out files</remarks>
        public static bool CanUndoCheckOut(VirtualFileBase file)
        {
            Validate.RequiredParameter("file", file);
            IVersioningFile versioningFile = file as IVersioningFile;

            if (versioningFile != null)
            {
                // Admins are allowed to undo other users check outs
                return((versioningFile.IsCheckedOut && PrincipalInfo.HasAdminAccess) || IsCheckedOutByCurrentUser(versioningFile));
            }
            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Determines whether the currently logged on user can check out the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>
        ///     <c>true</c> if the currently logged on user is permitted to check out the specified file; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanCheckOut(VirtualFileBase file)
        {
            Validate.RequiredParameter("virtualFileBase", file);
            if (!CanEdit(file))
            {
                return(false);
            }

            IVersioningFile versioningFile = file as IVersioningFile;

            return(versioningFile == null ? false : !versioningFile.IsCheckedOut);
        }
Exemple #8
0
        private void UpdateSelectedFilesList(VirtualFileBase file)
        {
            int currentIndex = FileManager.SelectedItems.IndexOf(file);

            if (currentIndex >= 0)
            {
                FileManager.SelectedItems.RemoveAt(currentIndex);
            }
            else
            {
                FileManager.SelectedItems.Add(file);
            }
        }
        // ReSharper disable RedundantNameQualifier
        private ContentRegistration RenderViewForRegistration(VirtualFileBase file, Type modelType, ControllerContext cctx, ViewEngineResult result, List <ContentRegistration> registrations)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            // ReSharper disable once UseObjectOrCollectionInitializer
            var fileName = N2.Web.Url.RemoveAnyExtension(file.Name);
            var re       = registrations.FirstOrDefault(cr => cr.Definition.ItemType == modelType && cr.Definition.TemplateKey == fileName)
                           ?? new ContentRegistration(map.CreateDefinition(modelType, fileName))
            {
                IsDefined = false
            };

            re.Context.TouchedPaths.Add(file.VirtualPath);

            using (var sw = new StringWriter())
            {
                var vdd = new ViewDataDictionary();
                cctx.Controller.ViewData = vdd;
                N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);

                try
                {
                    logger.DebugFormat("Rendering view {0} for registrations", file.VirtualPath);
                    result.View.Render(new ViewContext(cctx, result.View, vdd, new TempDataDictionary(), sw), sw);
                    logger.DebugFormat("Rendered view {0}, editables = {1}, defined = {2}", file.VirtualPath, re.Definition.Editables.Count, re.IsDefined);

                    if (!registrations.Contains(re))
                    {
                        registrations.Add(re);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(file.VirtualPath, ex);
                    if (re.IsDefined)
                    {
                        throw new Exception(String.Format("Failed to render view {0} for registrations", file.VirtualPath), ex);
                    }
                    return(null);
                }
                finally
                {
                    N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, null);
                }

                return(re.IsDefined ? re : null);
            }
        }
Exemple #10
0
        private static VirtualFileBase GetVirtualFileByPath(string virtualPath)
        {
            VirtualFileBase file = null;

            if (virtualPath.EndsWith("/", StringComparison.Ordinal))
            {
                file = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath) as VirtualFileBase;
            }
            else
            {
                file = HostingEnvironment.VirtualPathProvider.GetFile(virtualPath) as VirtualFileBase;
            }
            return(file);
        }
Exemple #11
0
        private IEnumerable <SkinTemplate> GetSkinTemplatesFromDir(VirtualFileBase virtualDirectory)
        {
            string skinConfigPath = string.Format("{0}/{1}/skin.config", RootSkinsVirtualPath, virtualDirectory.Name);

            if (VirtualPathProvider.FileExists(skinConfigPath))
            {
                IEnumerable <SkinTemplate> deserializedTemplates = GetSkinTemplates(VirtualPathProvider, skinConfigPath);
                deserializedTemplates.ForEach(t => t.TemplateFolder = virtualDirectory.Name);
                return(deserializedTemplates);
            }
            return(new[] { new SkinTemplate {
                               Name = virtualDirectory.Name, TemplateFolder = virtualDirectory.Name
                           } });
        }
Exemple #12
0
        IEnumerator IEnumerable.GetEnumerator()
        {
            IEnumerable <VirtualFileBase> files = new VirtualFileBase[0];

            if (_requestedEntryType.HasFlag(RequestedEntryType.Files))
            {
                files = files.Concat(this._dirInfo.EnumerateFiles().Select(_ => new RenderingVirtualFile(Path.Combine(virtualPath, _.Name), _.FullName, _)));
            }
            if (_requestedEntryType.HasFlag(RequestedEntryType.Directories))
            {
                files = files.Concat(this._dirInfo.EnumerateDirectories().Select(_ => new RenderingVirtualDirectory(Path.Combine(virtualPath, _.Name), _.FullName, _)));
            }
            return(files.GetEnumerator());
        }
Exemple #13
0
        protected void FileTree_TreeNodeDataBound(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e)
        {
            VirtualFileBase virtualFile = e.Node.DataItem as VirtualFileBase;

            if (virtualFile.IsDirectory)
            {
                e.Node.SelectAction = TreeNodeSelectAction.Expand;
            }
            else
            {
                e.Node.NavigateUrl = e.Node.DataPath;
            }
            e.Node.Text = Server.HtmlEncode(virtualFile.Name);
        }
Exemple #14
0
        /// <summary>
        /// Gets the css for a folder or a file extension
        /// </summary>
        /// <param name="fileItem">The file item.</param>
        /// <returns>The folder or a file extension css string or an empty string if the input is not a <see cref="UnifiedFile"/></returns>
        protected static string GetFileExtensionCss(object fileItem)
        {
            UnifiedFile unifiedFile = fileItem as UnifiedFile;

            if (unifiedFile != null)
            {
                string extension = String.Empty;
                if (!String.IsNullOrEmpty(unifiedFile.Extension))
                {
                    extension = unifiedFile.Extension.Substring(1);
                }
                return(String.Format("document {0}Extension", extension.ToLowerInvariant()));
            }

            VirtualFileBase fileBase = fileItem as VirtualFileBase;

            if (fileBase != null && fileBase.IsDirectory)
            {
                return("document folder");
            }

            return(string.Empty);
        }
Exemple #15
0
 /// <summary>
 /// Moves a virtual file or folder to a new location.
 /// </summary>
 /// <param name="sourceItem">The source item to be moved.</param>
 /// <param name="targetDirectory">The destination directory.</param>
 public static void MoveItem(VirtualFileBase sourceItem, UnifiedDirectory targetDirectory)
 {
     MoveItem(sourceItem, targetDirectory, null);
 }
Exemple #16
0
        /// <summary>
        /// Gets the file size as a string in human readable format.
        /// </summary>
        /// <param name="fileItem">The file item.</param>
        /// <returns>The file size, or an empty string if the input is not a <see cref="UnifiedFile"/></returns>
        protected static string GetFileSizeString(VirtualFileBase fileItem)
        {
            UnifiedFile unifiedFile = fileItem as UnifiedFile;

            return(unifiedFile != null?GetFileSizeString(unifiedFile.Length) : String.Empty);
        }