Exemplo n.º 1
0
        /// <summary>
        /// Return OSFolder object of directory that was given via
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private object GetOSFolder(string folder)
        {
            OSFolder dir = this.Bind();

            if (!String.IsNullOrEmpty(dir.full_path))
            {
                System.IO.DirectoryInfo dir_info = new DirectoryInfo(dir.full_path);
                dir.dir    = dir_info.Name;
                dir.subdir = new List <OSFolder>();

                foreach (DirectoryInfo info in dir_info.GetDirectories())
                {
                    OSFolder subdir = new OSFolder
                    {
                        full_path = info.FullName,
                        dir       = info.Name
                    };
                    dir.subdir.Add(subdir);
                }
                return(dir);
            }
            else
            {
                return(new APIMessage(400, "full_path missing"));
            }
        }
Exemplo n.º 2
0
        public void Load(OpenStackAPI OSAPI, OSContainer container, OSFolder folder)
        {
            this.OSAPI       = OSAPI;
            this.OSContainer = container;
            this.OSFolder    = folder;

            HubicDriveForm form = this.GetForm();

            this.Items.Clear();
            form.downloadToolButton.Enabled = true;

            ListViewItem item;

            ListViewItem.ListViewSubItem[] subItems;

            OSFile file;

            foreach (KeyValuePair <string, OSFile> entry in this.OSFolder.Files)
            {
                file = entry.Value;

                item     = new ListViewItem(file.Name, 1);
                item.Tag = file;
                subItems = new ListViewItem.ListViewSubItem[] {
                    new ListViewItem.ListViewSubItem(item, file.Size),
                    new ListViewItem.ListViewSubItem(item, file.LastModified)
                };

                item.SubItems.AddRange(subItems);
                this.Items.Add(item);
            }

            this.Enabled = true;
        }
Exemplo n.º 3
0
        public async void Create(string name)
        {
            HubicDriveForm form = this.GetForm();

            form.GetConnectionStatus().SetStatus("Status: creating folder " + name + "...", true);

            TreeNode selectedNode   = this.GetSelectedNode();
            OSFolder selectedFolder = this.GetSelectedFolder();

            if (!await OSAPI.CreateObject(this.OSContainer.Name, selectedFolder.Path + "/" + name))
            {
                MessageBox.Show("Failed creating the folder " + name, "Communication error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                form.GetConnectionStatus().SetStatus("Status: connected");
                return;
            }

            OSFolder folder = new OSFolder("", "", "0", selectedFolder.Path + "/" + name, "application/folder");

            selectedFolder.Subfolders.Add(folder.Name, folder);

            TreeNode node = new TreeNode(folder.Name);

            node.Name = folder.Name;
            node.Tag  = folder;
            selectedNode.Nodes.Add(node);

            this.SelectedNode = node;

            form.GetConnectionStatus().SetStatus("Status: connected");
        }
Exemplo n.º 4
0
        private void DeleteFolderToolStripButton_Click(object sender, EventArgs e)
        {
            OSFolder folder = foldersTreeView.GetSelectedFolder();

            ConfirmationForm cForm = new ConfirmationForm("Do you really want to delete the folder " + folder.Name, foldersTreeView.Delete);

            cForm.Show();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Return OSFolder with subdirs as every driver on local system
        /// </summary>
        /// <returns></returns>
        private object GetOSDrives()
        {
            string[] drives = System.IO.Directory.GetLogicalDrives();
            OSFolder dir    = new OSFolder();

            dir.dir       = "/";
            dir.full_path = "/";
            dir.subdir    = new List <OSFolder>();
            foreach (string str in drives)
            {
                OSFolder driver = new OSFolder();
                driver.dir       = str;
                driver.full_path = str;
                dir.subdir.Add(driver);
            }

            return(dir);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Return OSFolder object that is a folder from which jmmserver is running
        /// </summary>
        /// <returns></returns>
        private object GetOSBaseFolder()
        {
            OSFolder dir = new OSFolder();

            dir.full_path = Environment.CurrentDirectory;
            System.IO.DirectoryInfo dir_info = new DirectoryInfo(dir.full_path);
            dir.dir    = dir_info.Name;
            dir.subdir = new List <OSFolder>();

            foreach (DirectoryInfo info in dir_info.GetDirectories())
            {
                OSFolder subdir = new OSFolder();
                subdir.full_path = info.FullName;
                subdir.dir       = info.Name;
                dir.subdir.Add(subdir);
            }
            return(dir);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Return OSFolder with subdirs as every driver on local system
        /// </summary>
        /// <returns></returns>
        private object GetOSDrives()
        {
            string[] drives = Directory.GetLogicalDrives();
            OSFolder dir    = new OSFolder
            {
                dir       = "/",
                full_path = "/",
                subdir    = new List <OSFolder>()
            };

            foreach (string str in drives)
            {
                OSFolder driver = new OSFolder
                {
                    dir       = str,
                    full_path = str
                };
                dir.subdir.Add(driver);
            }

            return(dir);
        }
Exemplo n.º 8
0
        public async void Delete(bool confirmed = false)
        {
            if (confirmed == false)
            {
                return;
            }

            HubicDriveForm form = this.GetForm();

            TreeNode selectedNode   = this.GetSelectedNode();
            OSFolder selectedFolder = this.GetSelectedFolder();

            if (selectedFolder.Name == "")
            {
                MessageBox.Show("Can not delete root folder, maybe you want to delete container", "Not allowed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                form.GetConnectionStatus().SetStatus("Status: connected");
                return;
            }

            form.GetConnectionStatus().SetStatus("Status: deleting folder " + selectedFolder.Name + "...", true);

            string path = this.OSContainer.Name + "/" + selectedFolder.Path;

            if (!await OSAPI.DeleteObject(path))
            {
                MessageBox.Show("Failed deleting the folder " + selectedFolder.Name, "Communication error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                form.GetConnectionStatus().SetStatus("Status: connected");
                return;
            }

            this.Nodes.Remove(selectedNode);
            form.GetFilesListView().Items.Clear();
            form.GetFolderInfoLabel().Visible = false;

            form.GetConnectionStatus().SetStatus("Status: connected");
        }
Exemplo n.º 9
0
        private async void FoldersTreeView_AfterSelect(Object sender, TreeViewEventArgs e)
        {
            HubicDriveForm form = this.GetForm();

            TreeNode selectedNode   = this.GetSelectedNode();
            OSFolder selectedFolder = this.GetSelectedFolder();

            if (selectedFolder.Loaded == false)
            {
                form.GetConnectionStatus().SetStatus("Status: reading content...", true);

                selectedFolder.Subfolders = new Dictionary <string, OSFolder>();
                selectedFolder.Files      = new Dictionary <string, OSFile>();

                JArray jsonObjects = await this.OSAPI.GetObjects(this.OSContainer.Name, selectedFolder.Path);

                OSFolder folder;
                OSFile   file;
                TreeNode node;

                for (int i = 0; i < jsonObjects.Count; i++)
                {
                    if (jsonObjects[i]["content_type"].ToString() == "application/directory")
                    {
                        folder = new OSFolder(
                            jsonObjects[i]["hash"].ToString(),
                            jsonObjects[i]["last_modified"].ToString(),
                            jsonObjects[i]["bytes"].ToString(),
                            jsonObjects[i]["name"].ToString(),
                            jsonObjects[i]["content_type"].ToString()
                            );

                        selectedFolder.Subfolders.Add(folder.Name, folder);

                        node      = new TreeNode(folder.Name);
                        node.Name = folder.Name;
                        node.Tag  = folder;
                        selectedNode.Nodes.Add(node);
                    }
                    else
                    {
                        file = new OSFile(
                            jsonObjects[i]["hash"].ToString(),
                            jsonObjects[i]["last_modified"].ToString(),
                            jsonObjects[i]["bytes"].ToString(),
                            jsonObjects[i]["name"].ToString(),
                            jsonObjects[i]["content_type"].ToString()
                            );

                        selectedFolder.Bytes += file.Bytes;
                        selectedFolder.Files.Add(file.Name, file);
                    }
                }

                selectedFolder.Loaded = true;
                selectedNode.Expand();
                form.GetConnectionStatus().SetStatus("Status: connected");
            }

            form.createFolderToolButton.Enabled = true;
            form.deleteFolderToolButton.Enabled = selectedFolder.Name.Length > 0;
            form.uploadToolButton.Enabled       = true;

            Label folderInfoLabel = form.GetFolderInfoLabel();

            folderInfoLabel.Visible = true;
            folderInfoLabel.Text    = selectedFolder.Files.Count.ToString() + " files (" + selectedFolder.Size + ")";

            FilesListView filesListView = form.GetFilesListView();

            filesListView.Load(this.OSAPI, this.OSContainer, selectedFolder);
        }