コード例 #1
0
        public string DeleteFolder(int folderNumber)
        {
            string currentUser = User.Identity.GetUserId();

            var trash = db.Folders.Where(f => f.UserId == currentUser && f.FolderName == "Trash");
            int trId  = 0;

            foreach (var item in trash)
            {
                trId = item.Id;
            }

            var notes = db.Notes.Where(n => n.UserId == currentUser && n.FolderId == folderNumber);

            foreach (var nt in notes)
            {
                nt.FolderId        = trId;
                db.Entry(nt).State = EntityState.Modified;
            }

            //db.SaveChanges();


            Models.Folder fld = db.Folders.Find(folderNumber);
            if (fld == null)
            {
                return("Fail");
            }

            db.Folders.Remove(fld);
            db.SaveChanges();

            return("Ok");
        }
コード例 #2
0
        //creates task with attachment
        public ActionResult CreateWithFile(TaskViewModel task, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var currentUserId = GetCurrentUserId();

                string pathToFile = SaveUploadedFile(file);

                TaskToDo taskToDo = task.TaskToDo;
                taskToDo.Id = Guid.NewGuid();
                Models.Folder folder = db.Folders.Find(task.FolderId);

                taskToDo.Folder             = folder;
                taskToDo.StartDate          = DateTime.Now;
                taskToDo.AppUserId          = currentUserId;
                taskToDo.PathToAttachedFile = pathToFile;

                db.TaskToDoes.Add(taskToDo);

                if (taskToDo.Description.Contains("#"))
                {
                    ManageHashtags(taskToDo);
                }

                db.SaveChanges();
                return(RedirectToAction("IndexWithFolders"));
            }

            return(View(task));
        }
コード例 #3
0
        /// <summary>
        /// Upload contents recursively
        /// </summary>
        private void UploadRecursive(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target, ActionType actionType)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder()
                {
                    Name = source.Name
                };
                bool isExist = false;

                if (Synchronize)
                {
                    try
                    {
                        string path = String.Format("/{0}", source.Name);
                        Item   item = null;
                        try
                        {
                            item = client.Items.ByPath(target.url, path).Execute();
                        }
                        catch (ODataException e)
                        {
                            if (e.Code != System.Net.HttpStatusCode.NotFound)
                            {
                                throw e;
                            }
                        }

                        if (item != null && item is Folder)
                        {
                            isExist   = true;
                            newFolder = (Folder)item;
                        }
                    }
                    catch { }
                }

                if (!isExist)
                {
                    newFolder = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                }

                ActionManager actionManager = new ActionManager(this, source.Name);

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo && Recursive)
                    {
                        UploadRecursive(client, uploadId, fsInfo, newFolder, actionType);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                        actionManager.AddAction(uploadAction);
                    }
                }

                actionManager.Execute();
            }
        }
コード例 #4
0
        /// <summary>
        /// Start Upload to Sharefile location
        /// </summary>
        private void StartUpload(ShareFileClient client, int uploadId, Models.Item target, ICollection <string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            Logger.Instance.Info("Uploading files to ShareFile server.");

            ActionManager actionManager  = new ActionManager();
            bool          firstIteration = true;

            foreach (string path in resolvedPaths)
            {
                FileAttributes attr   = System.IO.File.GetAttributes(path);
                FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                // create an extra parent folder if CreateRoot flag is specified on target location
                if (firstIteration && CreateRoot)
                {
                    DirectoryInfo parentFolder = Directory.GetParent(path);
                    var           newFolder    = new Models.Folder()
                    {
                        Name = parentFolder.Name
                    };
                    target         = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                    firstIteration = false;
                }

                if (source is DirectoryInfo)
                {
                    UploadRecursive(client, uploadId, source, target, actionType);
                }
                else
                {
                    IAction uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
            }

            actionManager.Execute();

            if (Move)
            {
                foreach (string path in resolvedPaths)
                {
                    FileAttributes attr   = System.IO.File.GetAttributes(path);
                    FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                    if (Strict && source is DirectoryInfo)
                    {
                        DeleteSharefileStrictRecursive(client, source as DirectoryInfo, target);
                    }

                    DeleteLocalItemRecursive(source, Recursive);
                }
            }
        }
コード例 #5
0
        private Models.Folder CreateDefaultFolder(string userId)
        {
            Models.Folder defaultFolder = new Models.Folder
            {
                Name      = "Default",
                Id        = Guid.NewGuid(),
                AppUserId = userId
            };
            db.Folders.Add(defaultFolder);
            db.SaveChanges();

            return(defaultFolder);
        }
コード例 #6
0
        public ActionResult CreateFolder(Models.Folder folder)
        {
            if (ModelState.IsValid)
            {
                folder.Id        = Guid.NewGuid();
                folder.AppUserId = GetCurrentUserId();
                db.Folders.Add(folder);
                db.SaveChanges();

                return(RedirectToAction("IndexWithFolders"));
            }

            return(View(folder));
        }
コード例 #7
0
        public ActionResult Folder(string folderName)
        {
            Models.Folder folder = db.Folders.Where(f => f.Name == folderName).FirstOrDefault();

            if (folder == null)
            {
                return(HttpNotFound());
            }

            var tasksInFolder = db.TaskToDoes
                                .Where(task => task.Folder.Name == folderName)
                                .ToList();

            InsertHashtagReferences(tasksInFolder);
            return(View(tasksInFolder));
        }
コード例 #8
0
ファイル: Mother.cs プロジェクト: KyleGobel/DailyEZ
 public static Page CreateInMemorySamplePage()
 {
     var folder = new Models.Folder() {Id = 2};
     return new JetNettApi.Models.Page()
                {
                    AutoOrdering = false,
                    CanonicalUrl = "",
                    Folder = folder,
                    FooterHtml = "",
                    HeaderHtml = "",
                    MetaDesc = "",
                    MetaKeys = "",
                    Route = "",
                    Title = "Test Page"
                };
 }
コード例 #9
0
 public void Delete(int id)
 {
     if (_userPermissions.IsAuthorized(User, EntityNames.Folder, id, PermissionNames.Edit))
     {
         Models.Folder _folder = _folders.GetFolder(id, false);
         if (Directory.Exists(GetFolderPath(_folder)))
         {
             Directory.Delete(GetFolderPath(_folder));
         }
         _folders.DeleteFolder(id);
         _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Folder Deleted {FolderId}", id);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Delete, "User Not Authorized To Delete Folder {FolderId}", id);
         HttpContext.Response.StatusCode = 401;
     }
 }
コード例 #10
0
        private void RecursiveUpload(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder()
                {
                    Name = source.Name
                };
                newFolder = client.Items.CreateFolder(target.url, newFolder, Force || ResumeSupport.IsPending, false).Execute();

                ActionManager actionManager = new ActionManager(this, source.Name);
                ActionType    actionType    = Force ? ActionType.Force : ActionType.None;

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo)
                    {
                        RecursiveUpload(client, uploadId, fsInfo, newFolder);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(fsInfo.Name))
                        {
                            IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                            actionManager.AddAction(uploadAction);
                        }
                    }
                }

                actionManager.Execute();
            }
            else if (source is FileInfo)
            {
                ActionManager actionManager = new ActionManager(this, source.Name);
                if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(source.Name))
                {
                    ActionType actionType   = Force || ResumeSupport.IsPending ? ActionType.Force : ActionType.None;
                    IAction    uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
                actionManager.Execute();
            }
        }
コード例 #11
0
        public Folder Put(int id, [FromBody] Folder folder)
        {
            if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, folder.FolderId, PermissionNames.Edit))
            {
                if (folder.IsPathValid())
                {
                    if (folder.ParentId != null)
                    {
                        Folder parent = _folders.GetFolder(folder.ParentId.Value);
                        folder.Path = Utilities.PathCombine(parent.Path, folder.Name);
                    }
                    folder.Path = Utilities.PathCombine(folder.Path, Path.DirectorySeparatorChar.ToString());

                    Models.Folder _folder = _folders.GetFolder(id, false);
                    if (_folder.Path != folder.Path && Directory.Exists(GetFolderPath(_folder)))
                    {
                        Directory.Move(GetFolderPath(_folder), GetFolderPath(folder));
                    }

                    folder = _folders.UpdateFolder(folder);
                    _logger.Log(LogLevel.Information, this, LogFunction.Update, "Folder Updated {Folder}", folder);
                }
                else
                {
                    _logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Name Not Valid {Folder}", folder);
                    HttpContext.Response.StatusCode = 401;
                    folder = null;
                }
            }
            else
            {
                _logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Folder {Folder}", folder);
                HttpContext.Response.StatusCode = 401;
                folder = null;
            }
            return(folder);
        }
コード例 #12
0
        protected override void NewItem(string path, string itemTypeName, object newItemValue)
        {
            var di       = (ShareFileDriveInfo)this.PSDriveInfo;
            var p        = this.DynamicParameters as NewItemParameters;
            var itemName = GetChildName(path);
            var parent   = GetShareFileItem(di, GetParentPath(path, PSDriveInfo.Root), new string[] { "Id", "url" });

            Models.Item newItem     = null;
            var         isContainer = false;

            if (itemTypeName == null || itemTypeName.ToLower().Equals("folder") || itemTypeName.ToLower().Equals("directory"))
            {
                var folder = new Models.Folder()
                {
                    Name = itemName, Description = p.Details
                };
                newItem     = di.Client.Items.CreateFolder(parent.url, folder, Force.ToBool()).Execute();
                isContainer = true;
            }
            else if (itemTypeName.ToLower().Equals("symboliclink"))
            {
                if (p.Uri != null)
                {
                    var symlink = new Models.SymbolicLink()
                    {
                        Name = itemName, Link = p.Uri, Description = p.Details
                    };
                    newItem     = di.Client.Items.CreateSymbolicLink(parent.url, symlink, Force.ToBool()).Execute();
                    isContainer = false;
                }
            }
            if (newItem != null)
            {
                WriteItemObject(newItem, path, isContainer);
            }
        }
コード例 #13
0
 public Folder(Models.Folder folder)
 {
     Id   = folder.Id;
     Name = folder.Name?.Decrypt();
 }
コード例 #14
0
        /// <summary>
        /// Start download process
        /// </summary>
        private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection <string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            ActionManager actionManager  = new ActionManager(this, string.Empty);
            bool          firstIteration = true;

            var shareFileItems = new List <Item>();

            foreach (string path in resolvedPaths)
            {
                var item = Utility.ResolveShareFilePath(driveInfo, path);

                if (item == null)
                {
                    throw new FileNotFoundException(string.Format("Source path '{0}' not found on ShareFile server.", path));
                }

                var target = new DirectoryInfo(LocalPath);

                if (!target.Exists)
                {
                    throw new Exception(string.Format("Destination '{0}' path not found on local drive.", LocalPath));
                }

                // if create root folder flag is specified then create a container folder first
                if (firstIteration && CreateRoot)
                {
                    Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder;

                    target         = CreateLocalFolder(target, parentFolder);
                    firstIteration = false;
                }

                if (item is Models.Folder)
                {
                    // if user downloading the root drive then download its root folders
                    if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault())
                    {
                        var children = client.Items.GetChildren(item.url)
                                       .Select("Id")
                                       .Select("url")
                                       .Select("FileName")
                                       .Select("FileSizeBytes")
                                       .Select("Hash")
                                       .Select("Info")
                                       .Execute();

                        foreach (var child in children.Feed)
                        {
                            if (child is Models.Folder)
                            {
                                DownloadRecursive(client, transactionId, child, target, actionType);

                                shareFileItems.Add(child);
                            }
                        }
                    }
                    else
                    {
                        DownloadRecursive(client, transactionId, item, target, actionType);

                        shareFileItems.Add(item);
                    }
                }
                else if (item is Models.File)
                {
                    DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType);
                    actionManager.AddAction(downloadAction);

                    shareFileItems.Add(item);
                }
            }

            actionManager.Execute();

            // if strict flag is specified then also clean the target files which are not in source
            if (Strict)
            {
                var target      = new DirectoryInfo(LocalPath);
                var directories = target.GetDirectories();

                foreach (string path in resolvedPaths)
                {
                    var item = Utility.ResolveShareFilePath(driveInfo, path);

                    if (item is Folder)
                    {
                        foreach (DirectoryInfo directory in directories)
                        {
                            if (directory.Name.Equals(item.Name))
                            {
                                DeleteLocalStrictRecursive(client, item, directory);
                                break;
                            }
                        }
                    }
                }
            }

            // on move remove source files
            if (Move)
            {
                foreach (var item in shareFileItems)
                {
                    DeleteShareFileItemRecursive(client, item, Recursive);
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Start download process
        /// </summary>
        private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection <string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            Logger.Instance.Info("Downloading files from ShareFile server.");

            ActionManager actionManager  = new ActionManager();
            bool          firstIteration = true;

            foreach (string path in resolvedPaths)
            {
                var item = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, path, null, null);

                // if user didn't specify the Sharefile HomeFolder in path then append in path
                // e.g. if user tries sf:/Folder1 as sharefile source then resolve this path to sf:/My Files & Folders/Folder1
                if (item == null && !path.StartsWith(String.Format(@"\{0}\", DefaultSharefileFolder)))
                {
                    string updatedPath = String.Format(@"\{0}\{1}", DefaultSharefileFolder, path);
                    item = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, updatedPath, null, null);
                }

                var target = new DirectoryInfo(LocalPath);

                // if create root folder flag is specified then create a container folder first
                if (firstIteration && CreateRoot)
                {
                    Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder;

                    target         = CreateLocalFolder(target, parentFolder);
                    firstIteration = false;
                }

                if (item is Models.Folder)
                {
                    // if user downloading the root drive then download its root folders
                    if ((item as Folder).Info.IsAccountRoot == true)
                    {
                        var children = client.Items.GetChildren(item.url).Execute();
                        foreach (var child in children.Feed)
                        {
                            if (child is Models.Folder)
                            {
                                DownloadRecursive(client, transactionId, child, target, actionType);
                            }
                        }
                    }
                    else
                    {
                        DownloadRecursive(client, transactionId, item, target, actionType);
                    }
                }
                else if (item is Models.File)
                {
                    DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType);
                    actionManager.AddAction(downloadAction);
                }
            }

            actionManager.Execute();

            // on move remove source files
            if (Move)
            {
                foreach (string path in resolvedPaths)
                {
                    var item   = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, path, null, null);
                    var target = new DirectoryInfo(LocalPath);

                    // if strict flag is specified then also clean the target files which are not in source
                    if (Strict)
                    {
                        DeleteLocalStrictRecursive(client, item, target);
                    }

                    DeleteShareFileItemRecursive(client, item, CreateRoot && Recursive);
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Start download process
        /// </summary>
        private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection<string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            ActionManager actionManager = new ActionManager(this, string.Empty);
            bool firstIteration = true;

            var shareFileItems = new List<Item>();
            foreach (string path in resolvedPaths)
            {
                var item = Utility.ResolveShareFilePath(driveInfo, path);

                if (item == null)
                {
                    throw new FileNotFoundException(string.Format("Source path '{0}' not found on ShareFile server.", path));
                }

                var target = new DirectoryInfo(LocalPath);

                if (!target.Exists)
                {
                    throw new Exception(string.Format("Destination '{0}' path not found on local drive.", LocalPath));
                }

                // if create root folder flag is specified then create a container folder first
                // KA - Fix. When CreateRoot is used and the source item is a folder we should NOT create the parent of that folder.
                //      This possibly fixes another unknown scenario when the root folder is specified as the source.
                if (firstIteration && CreateRoot && !(item is Models.Folder))
                {
                    Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder;

                    target = CreateLocalFolder(target, parentFolder);
                    firstIteration = false;
                }

                if (item is Models.Folder)
                {
                    // if user downloading the root drive then download its root folders
                    // KA - Fix. We should also process only subfolders and files if CreateRoot is not used and source is a folder.
                    //      This prevents DownloadRecursive from creating the parent folder in conditions where CreateRoot is not specified.
                    //      Code adapted from DownloadRecursive function and processes both file sources and folder sources appropriately now.
                    // if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault())
                    if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault() || !CreateRoot)
                    {
                        var children = client.Items.GetChildren(item.url)
                            .Select("Id")
                            .Select("url")
                            .Select("FileName")
                            .Select("FileSizeBytes")
                            .Select("Hash")
                            .Select("Info")
                            .Execute();

                        if (children != null)
                        {
                            (item as Folder).Children = children.Feed;

                            foreach (var child in children.Feed)
                            {
                                child.Parent = item;

                                if (child is Models.Folder && ((item as Folder).Info.IsAccountRoot.GetValueOrDefault() || Recursive))
                                {
                                    DownloadRecursive(client, transactionId, child, target, actionType);

                                    shareFileItems.Add(child);
                                }
                                else if (child is Models.File)
                                {
                                    DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)child, target, actionType);
                                    actionManager.AddAction(downloadAction);
                                }
                            }
                            if (!(item as Folder).Info.IsAccountRoot.GetValueOrDefault()) { shareFileItems.Add(item); }
                        }
                    }
                    else
                    {
                        DownloadRecursive(client, transactionId, item, target, actionType);

                        shareFileItems.Add(item);
                    }
                }
                else if (item is Models.File)
                {
                    DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType);
                    actionManager.AddAction(downloadAction);

                    shareFileItems.Add(item);
                }
            }

            actionManager.Execute();

            // if strict flag is specified then also clean the target files which are not in source
            if (Strict)
            {
                var target = new DirectoryInfo(LocalPath);
                var directories = target.GetDirectories();

                foreach (string path in resolvedPaths)
                {
                    var item = Utility.ResolveShareFilePath(driveInfo, path);
                    
                    if (item is Folder)
                    {
                        foreach (DirectoryInfo directory in directories)
                        {
                            if (directory.Name.Equals(item.Name))
                            {
                                DeleteLocalStrictRecursive(client, item, directory);
                                break;
                            }
                        }
                    }
                }
            }

            // on move remove source files
            if (Move)
            {
                foreach(var item in shareFileItems)
                {
                    // KA - Fix. Replaced 'Recursive' with '!KeepFolders'. This prevents "Move" from deleting folders even when KeepFolders is specified.
                    //      This fixes the bug that causes the source folder to be deleted in all scenarios where "Move" is specified and it does not contain children.
                    // DeleteShareFileItemRecursive(client, item, Recursive);
                    DeleteShareFileItemRecursive(client, item, !KeepFolders);
                }
            }
        }