public async void DeleteSelected() { if (this.SelectedItems.Count == 0) { return; } HubicDriveForm form = this.GetForm(); foreach (ListViewItem selectedItem in this.SelectedItems) { OSFile selectedFile = (OSFile)selectedItem.Tag; form.GetConnectionStatus().SetStatus("Status: deleting file " + selectedFile.Name + "...", true); string path = this.OSContainer.Name + "/" + selectedFile.Path; if (!await OSAPI.DeleteObject(path)) { MessageBox.Show("Failed deleting the file " + selectedFile.Name, "Communication error", MessageBoxButtons.OK, MessageBoxIcon.Error); form.GetConnectionStatus().SetStatus("Status: connected"); return; } this.Items.Remove(selectedItem); this.OSFolder.Files.Remove(selectedFile.Name); form.GetConnectionStatus().SetStatus("Status: connected"); } }
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; }
public async void Delete(bool confirmed = false) { if (confirmed == false) { return; } HubicDriveForm form = this.GetForm(); string name = this.GetSelectedContainer().Name; form.GetConnectionStatus().SetStatus("Status: deleting container " + name + "...", true); if (!await OSAPI.DeleteObject(name)) { MessageBox.Show("Failed deleting the container " + name, "Communication error", MessageBoxButtons.OK, MessageBoxIcon.Error); form.GetConnectionStatus().SetStatus("Status: connected"); return; } this.OSContainers.Remove(name); this.Items.Remove(name); form.GetFoldersTreeView().Nodes.Clear(); form.GetFilesListView().Items.Clear(); form.GetFolderInfoLabel().Visible = false; form.GetConnectionStatus().SetStatus("Status: connected"); }
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"); }
private void ContainersComboBox_SelectedIndexChanged(object sender, EventArgs e) { HubicDriveForm form = this.GetForm(); form.deleteContainerToolButton.Enabled = this.GetSelectedContainer().Name != "default"; FoldersTreeView foldersTreeView = form.GetFoldersTreeView(); foldersTreeView.Load(this.OSAPI, this.GetSelectedContainer(), true); }
public async void Load(OpenStackAPI OSAPI, bool reload = false) { this.OSAPI = OSAPI; HubicDriveForm form = this.GetForm(); form.GetConnectionStatus().SetStatus("Status: reading containers...", true); OSContainer container; if (this.OSContainers == null || reload) { this.Items.Clear(); JArray jsonObjects = await this.OSAPI.GetObjects(); this.OSContainers = new Dictionary <string, OSContainer>(); for (int i = 0; i < jsonObjects.Count; i++) { container = new OSContainer( jsonObjects[i]["count"].ToString(), jsonObjects[i]["bytes"].ToString(), jsonObjects[i]["name"].ToString() ); this.OSContainers.Add(container.Name, container); if (container.Name.IndexOf("_segments") != -1) { continue; } this.Items.Add(container.Name); } } this.Enabled = true; this.SelectedIndex = this.FindStringExact("default"); form.GetConnectionStatus().SetStatus("Status: connected"); }
public void Upload() { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = false; ofd.ValidateNames = false; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { HubicDriveForm form = this.GetForm(); foreach (string file in ofd.FileNames) { form.queueForm.Add(this.OSContainer.Name, this.GetSelectedFolder().Path, file, Helper.HumanReadableSize(new FileInfo(file).Length), "upload"); } form.queueForm.Show(); } }
public async void Create(string name) { HubicDriveForm form = this.GetForm(); form.GetConnectionStatus().SetStatus("Status: creating container " + name + "...", true); if (!await OSAPI.CreateObject(name)) { MessageBox.Show("Failed creating the container " + name, "Communication error", MessageBoxButtons.OK, MessageBoxIcon.Error); form.GetConnectionStatus().SetStatus("Status: connected"); return; } OSContainer container = new OSContainer("0", "0", name); this.OSContainers.Add(name, container); this.Items.Add(name); this.SelectedItem = name; form.GetConnectionStatus().SetStatus("Status: connected"); }
public void DownloadSelected() { if (this.SelectedItems.Count == 0) { return; } HubicDriveForm form = this.GetForm(); if (this.SelectedItems.Count == 1) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save as.."; OSFile selectedFile = this.GetSelectedFile(); sfd.FileName = selectedFile.Name; if (sfd.ShowDialog() == DialogResult.OK) { form.queueForm.Add(this.OSContainer.Name, selectedFile.Path, sfd.FileName, selectedFile.Size, "download"); form.queueForm.Show(); } } else { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { foreach (ListViewItem fileItem in this.SelectedItems) { OSFile selectedFile = (OSFile)fileItem.Tag; form.queueForm.Add(this.OSContainer.Name, selectedFile.Path, fbd.SelectedPath + "\\" + selectedFile.Name, selectedFile.Size, "download"); } form.queueForm.Show(); } } }
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"); }
public void FileSelectedIndexChanged_Click(object sender, EventArgs e) { HubicDriveForm form = this.GetForm(); form.downloadToolButton.Enabled = true; }
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); }