Пример #1
0
 //
 // GET: /Folder/Delete/5
 public ActionResult Delete(Folder f)
 {
     if (f == null) {
         return HttpNotFound();
     }
     return View(f);
 }
Пример #2
0
        // Builds the Treeview recursively
        protected void BuildTreeView(IFileSystemComponent fsc, TreeNodeCollection nodes)
        {
            //Checks if its a document
            if (fsc.FileType == SliceOfPie.DocType.Document)
            {
                // Makes a new TreeNode with the correct title and adds it to nodes
                TreeNode n = new TreeNode(fsc.Title);
                nodes.Add(n);
                n.Value = ((DocumentStruct)fsc).Id;
            }
            // else its a folder
            else
            {
                TreeNode n = new TreeNode(fsc.Title);
                nodes.Add(n);
                if (fsc.FileType == DocType.Project)
                {
                    // We save the value of the id for later use
                    n.Value = ((Project)fsc).Id;
                }

                // We make the folder object and check its children recursively
                SliceOfPie.Folder folder = (SliceOfPie.Folder)fsc;
                foreach (SliceOfPie.IFileSystemComponent f in (folder.Children))
                {
                    BuildTreeView(f, n.ChildNodes);
                }
            }
        }
Пример #3
0
 public ActionResult CreateInProject(Folder newFolder, string text)
 {
     if (ModelState.IsValid) {
         Project parent = controller.GetProjectDirectly((int)newFolder.ProjectId);
         Folder result = controller.CreateFolder(newFolder.Title, User.Identity.Name, parent);
         return RedirectToAction("Index", "Folder", result);
     }
     return View();
 }
Пример #4
0
 /**
  * Add all structs in folder to list of structs.
  * If component is a folder, do the same to that recursively.
  */
 public static List<DocumentStruct> GetAllStructs(Folder folder, List<DocumentStruct> structs)
 {
     foreach (IFileSystemComponent component in folder.Children)
     {
         if (component.FileType == DocType.Folder)
         {
             GetAllStructs((Folder)component, structs);
         }
         if (component.FileType == DocType.Document)
         {
             structs.Add((DocumentStruct)component);
         }
     }
     return structs;
 }
Пример #5
0
        /// <summary>
        /// Initializes the engine class.
        /// </summary>
        private void Initialize()
        {
            // Initializes all other classes.
            dbCon = DBConnector.Instance;
            folder = new Folder();
            userhandler = new UserHandler();

            //Thread hostThread = new Thread(() => OpenHost());
            //hostThread.Start();

            //docHandler = new DocumentHandler();

            // Check if root directory exists
            /*if (!Directory.Exists("root"))
            {
                Directory.CreateDirectory("root");
            }*/
        }
Пример #6
0
 public override Folder AddFolder(IItemContainer parent, string title, int id = 0, bool db = false)
 {
     if (title == null || parent == null) throw new ArgumentNullException();
     Folder f = new Folder() {
         Title = title,
         Parent = parent
     };
     if (parent is Folder) f.FolderId = parent.Id;
     else f.ProjectId = parent.Id;
     using (var dbContext = new sliceofpieEntities2()) {
         dbContext.Folders.AddObject(f);
         dbContext.SaveChanges();
     }
     return new Folder() {
         Title = title,
         Parent = parent,
         Id = f.Id,
         ProjectId = f.ProjectId,
         FolderId = f.FolderId
     };
 }
Пример #7
0
 /**
  * Recursive function,
  * filling out the treeView with folders and documents
  * 'tag' is a property referencing the object itself.
  *
  * Don't add the document to the tree if it is marked for deletion.
  */
 private void BuildDocumentTree(TreeNodeCollection nodes, IFileSystemComponent fsc)
 {
     if (fsc.FileType == SliceOfPie.DocType.Document) // If it's a document
     {
         if (!((DocumentStruct)fsc).Deleted)
         {
             TreeNode n = new TreeNode(fsc.Title);
             n.Tag = fsc;
             nodes.Add(n);
         }
     }
     else // else, if it's a folder
     {
         TreeNode n = new TreeNode(fsc.Title);
         n.Tag = fsc;
         nodes.Add(n);
         SliceOfPie.Folder folder = (SliceOfPie.Folder)fsc;
         foreach (IFileSystemComponent f in (folder.Children))
         {
             BuildDocumentTree(n.Nodes, f);
         }
     }
 }
Пример #8
0
 public ActionResult CreateInProject(Folder f)
 {
     return View(f);
 }
Пример #9
0
        /// <summary>
        /// Start removing a folder asynchronously in accordance to the Asynchronous Programming Model.
        /// </summary>
        /// <param name="f">Folder to remove</param>
        /// <param name="callback">Callback called when folder has been removed</param>
        /// <param name="state">State object (passed to callback)</param>
        /// <returns>IAsyncResult for EndRemoveFolder</returns>
        /// <seealso cref="EndRemoveFolder"/>
        public IAsyncResult BeginRemoveFolder(Folder f, AsyncCallback callback, object state)
        {
            AsyncResultNoResult<Folder> ar = new AsyncResultNoResult<Folder>(callback, state, f);
            ThreadPool.QueueUserWorkItem(RemoveFolderAsyncHelper, ar);

            return ar;
        }
Пример #10
0
        /// <summary>
        /// Upload folders to db for project or folder.
        /// </summary>
        /// <param name="parentPath"></param>
        /// <param name="parentId"></param>
        /// <param name="container"></param>
        public void UploadFolders(string parentPath, int parentId, Container container = Container.Folder)
        {
            string[] folders = Directory.GetDirectories(parentPath);
            foreach (string folderName in folders) {
                Folder dbFolder = null;
                using (var dbContext = new sliceofpieEntities2()) {
                    string pathName = Path.GetFileName(folderName);
                    string[] parts = pathName.Split('-');
                    int id = int.Parse(parts[0]);
                    string title = pathName.Replace(parts[0] + "-", "");

                    var dbFolders = from dFolder in dbContext.Folders
                                    where dFolder.Id == id
                                    select dFolder;
                    if (id > 0 && dbFolders.Count() == 0) {
                        if (Directory.Exists(Path.Combine(parentPath, Helper.GenerateName(id, title)))) {
                            Directory.Move(Path.Combine(parentPath, Helper.GenerateName(id, title)), Path.Combine(parentPath, Helper.GenerateName(0, title)));
                        }
                        id = 0;
                    }
                    if (id > 0) {
                        // Updating folder
                        dbFolder = dbFolders.First();
                        dbFolder.Title = title;
                        if (container == Container.Project) {
                            dbFolder.ProjectId = parentId;
                            dbFolder.FolderId = null;
                        } else {
                            dbFolder.ProjectId = null;
                            dbFolder.FolderId = parentId;
                        }
                    } else {
                        // Creating folder
                        dbFolder = new Folder {
                            Title = title
                        };
                        if (container == Container.Project) {
                            dbFolder.ProjectId = parentId;
                            dbFolder.FolderId = null;
                        } else {
                            dbFolder.ProjectId = null;
                            dbFolder.FolderId = parentId;
                        }
                        dbContext.Folders.AddObject(dbFolder);
                    }
                    dbContext.SaveChanges();
                }
                // Rename folder directory
                string folderPath = Path.Combine(parentPath, Helper.GenerateName(dbFolder.Id, dbFolder.Title));
                if (Directory.Exists(Path.Combine(parentPath, Helper.GenerateName(0, dbFolder.Title)))) {
                    Directory.Move(Path.Combine(parentPath, Helper.GenerateName(0, dbFolder.Title)), folderPath);
                }
                // Recursively
                UploadFolders(folderPath, dbFolder.Id);
                UploadDocuments(folderPath, dbFolder.Id);
            }
        }
Пример #11
0
 public override void RemoveFolder(Folder folder)
 {
     if (!Directory.Exists(folder.GetPath())) {
         throw new ArgumentException("Folder does not exist (" + folder.GetPath() + ")");
     }
     Document[] removeDocuments = folder.Documents.ToArray();
     foreach (Document document in removeDocuments) {
         RemoveDocument(document);
     }
     Folder[] removeFolders = folder.Folders.ToArray();
     foreach (Folder subFolder in removeFolders) {
         RemoveFolder(subFolder);
     }
     Directory.Delete(folder.GetPath());
     folder.Parent.Folders.Remove(folder);
 }
Пример #12
0
 /// <summary>
 /// Remove the folder from the model
 /// </summary>
 /// <param name="f">Folder to remove</param>
 public abstract void RemoveFolder(Folder f);
Пример #13
0
        public void GetHierachyTest()
        {
            Project project = new Project("Projekt1", new User("NotKewin2"), new List<User>() { new User("Karsten") });
            Storage.SaveProjectToFile(project);

            Storage.WriteToFile(project, testDoc);
            Storage.WriteToFile(project, testDoc1);
            Storage.WriteToFile(project, testDoc2);

            Folder root = new Folder("root");
            Folder cuteanimals = new Folder("cuteanimalsxoxo");
            Folder reptiles = new Folder("reptiles");

            DocumentStruct testStruct0 = new DocumentStruct(testDoc.Title, testDoc.Owner, testDoc.Id, testDoc.Path,true,true);
            DocumentStruct testStruct1 = new DocumentStruct(testDoc1.Title, testDoc1.Owner, testDoc1.Id, testDoc1.Path,true,true);
            DocumentStruct testStruct2 = new DocumentStruct(testDoc2.Title, testDoc2.Owner, testDoc2.Id, testDoc2.Path,true,true);

            reptiles.AddChild(testStruct2);
            cuteanimals.AddChild(testStruct0);
            root.AddChild(testStruct1);

            cuteanimals.AddChild(reptiles);
            root.AddChild(cuteanimals);
            project.AddChild(root);
            Project expected = project;
            Project actual = Storage.GetHierachy(project.Id);

            Assert.AreEqual(expected, actual);
        }
Пример #14
0
        /**
         * Called when something is selected, expanded or collapsed in the treeview
         * Sets the selected folder/document here
         */
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            IFileSystemComponent fsc = (IFileSystemComponent)e.Node.Tag;
            if (fsc.FileType == DocType.Document) // If it's a document
            {
                isDocument = true;
                selectedDocument = (DocumentStruct)fsc;
                selectedFolder = (Folder)e.Node.Parent.Tag;
            }
            else // else, if it's a folder
            {
                isDocument = false;
                selectedFolder = (Folder)e.Node.Tag;
            }

            // If a document was not selected, grey out the button
            if (isDocument)
            {
                openButton.Enabled = true;
            }
            else
            {
                openButton.Enabled = false;
            }

            // You can't rename, move or delete projects in the offline client
            if (selectedFolder.FileType == DocType.Project && !isDocument)
            {
                renameButton.Enabled = false;
                moveButton.Enabled = false;
                deleteButton.Enabled = false;
            }
            else
            {
                renameButton.Enabled = true;
                moveButton.Enabled = true;
                deleteButton.Enabled = true;
            }

            createDocumentButton.Enabled = true;
        }
Пример #15
0
        /**
         * Recursively move the contents of a folder to somewhere new
         */
        private void MoveFolder(Folder folder, string path)
        {
            foreach (IFileSystemComponent component in folder.Children)
            {
                if (component.FileType == DocType.Document)
                {
                    DocumentStruct docStruct = (DocumentStruct)component;
                    moveDocument(path, docStruct.Id);
                }
                else if (component.FileType == DocType.Folder)
                {
                    Folder fold = (Folder)component;
                    MoveFolder(fold, path + @"/" + component.Title);
                }

            }
        }
Пример #16
0
 /**
  * Recursively call delete on the contents of a folder
  */
 private void DeleteFolder(Folder folder, Project project)
 {
     foreach (IFileSystemComponent component in folder.Children)
     {
         if (component.FileType == DocType.Document)
         {
             DocumentStruct doc = (DocumentStruct)component;
             DeleteDocument(selectedProject, ((DocumentStruct)component));
         }
         else if (component.FileType == DocType.Folder)
         {
             Folder fold = (Folder)component;
             DeleteFolder(fold, project);
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Synchronizes a users local Documents with Documents owned and shared with him on the server
        /// </summary>
        /// <param name="incDocuments">All of the users Documents</param>
        /// <param name="user">the documents user</param>
        /// <returns>A list of all the newest documents the user either owns, have rights to watch or edit.</returns>
        public List<Document> OfflineSynchronization(List<Document> incDocuments, User user)
        {
            List<Document> usersIncDocuments = new List<Document>();

            foreach (Document d in incDocuments)
            {
                string pathTmp = d.path;

                string[] folderPath = pathTmp.Split('/');
                string folder = "";

                for (int i = 0; i < folderPath.Length - 1; i++)
                {
                    folder += folderPath[i] + "/";
                }

                if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

                if (!File.Exists(pathTmp)) File.Create(pathTmp);

                dbCon.InsertSyncDocument(d.owner.username, d.path);
                usersIncDocuments.Add(GetDocumentByPath(d.owner, d.path));
            }

            List<Document> newDocumentList = new List<Document>();
            List<Document> usersDocumentOnServer = GetAllUsersDocuments(user);

            newDocumentList = usersDocumentOnServer;
            CopyNewEntities(usersIncDocuments, newDocumentList);

            return newDocumentList;
        }
Пример #18
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Folders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFolders(Folder folder)
 {
     base.AddObject("Folders", folder);
 }
Пример #19
0
        /// <summary>
        /// Find all folders in project folder and subfolders in file system and create them in internal system.
        /// </summary>
        /// <param name="parent"></param>
        public void FindFolders(IItemContainer parent)
        {
            string[] folders = Directory.GetDirectories(parent.GetPath());
            foreach (string folderName in folders) {
                string pathName = Path.GetFileName(folderName);
                string[] parts = pathName.Split('-');
                Folder folder = new Folder {
                    Id = int.Parse(parts[0]),
                    Title = pathName.Replace(parts[0] + "-", ""),
                    Parent = parent
                };
                parent.Folders.Add(folder);

                FindFolders(folder);
                FindDocuments(folder);
            }
        }
Пример #20
0
 /// <summary>
 /// Create a new Folder object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static Folder CreateFolder(global::System.Int32 id)
 {
     Folder folder = new Folder();
     folder.Id = id;
     return folder;
 }
Пример #21
0
 /// <summary>
 /// Rename folder both in file system and internal system.
 /// </summary>
 /// <param name="folder"></param>
 /// <param name="title"></param>
 public void RenameFolder(Folder folder, string title)
 {
     string folderPath = Path.Combine(folder.Parent.GetPath(), Helper.GenerateName(folder.Id, GetAvailableName(title, folder.Id, folder.Parent.GetPath())));
     try {
         Directory.Move(folder.GetPath(), folderPath);
     } catch (IOException e) {
         // Should not be accesible
         Console.WriteLine(e.Message);
     }
     folder.Title = title;
 }
Пример #22
0
        public override Folder GetFolder(int id)
        {
            Folder result;
            try {
                using (var dbContext = new sliceofpieEntities2()) {
                    Folder dbFolder = dbContext.Folders.First(f => f.Id == id);
                    result = new Folder() {
                        Id = dbFolder.Id,
                        Title = dbFolder.Title
                    };

                }
            } catch (InvalidOperationException e) {
                return null;
            }
            GetFolders(result);
            GetDocuments(result);
            return result;
        }
Пример #23
0
 /// <summary>
 /// Add folder to system. If db is set to true, only create folder.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public override Folder AddFolder(IItemContainer parent, string title, int id = 0, bool db = false)
 {
     if (!db) title = GetAvailableName(title, id, parent.GetPath());
     string folderPath = Path.Combine(parent.GetPath(), Helper.GenerateName(id, title));
     try {
         Directory.CreateDirectory(folderPath);
     } catch (IOException e) {
         // Should not be accesible
         Console.WriteLine(e.Message);
     }
     if (db) return null;
     Folder folder = new Folder();
     folder.Title = title;
     folder.Parent = parent;
     parent.Folders.Add(folder);
     return folder;
 }
Пример #24
0
        public override void RemoveFolder(Folder folder)
        {
            if (folder == null) throw new ArgumentNullException();
            IEnumerable<Document> documents;
            IEnumerable<Folder> folders;
            using (var dbContext = new sliceofpieEntities2()) {
                Folder folderToGetFrom = dbContext.Folders.First(fold => folder.Id == fold.Id);
                documents = folderToGetFrom.Documents.ToList();
                folders = folderToGetFrom.Folders.ToList();
            }

            foreach (Document d in documents) {
                RemoveDocument(d);
            }

            foreach (Folder f in folders) {
                RemoveFolder(f);
            }

            using (var dbContext = new sliceofpieEntities2()) {
                Folder f = dbContext.Folders.First(fold => fold.Id == folder.Id);
                dbContext.Folders.DeleteObject(f);
                dbContext.SaveChanges();
            }
        }
Пример #25
0
 /// <summary>
 /// Remove a folder
 /// </summary>
 /// <param name="f">Folder to remove</param>
 public void RemoveFolder(Folder f)
 {
     fileModel.RemoveFolder(f);
 }
Пример #26
0
 public ActionResult CreateInFolder(Folder f)
 {
     return View(f);
 }