コード例 #1
0
ファイル: FrameMain.cs プロジェクト: dantheman213/CloudMount
        private void loadListFilesAtDirPath(string path)
        {
            var node = fs.FindNodeAtAbsolutePath(path);

            if (node != null && node.Children != null && node.Children.Count > 0)
            {
                currentDirectoryNode = node;

                listFiles.Items.Clear();
                foreach (var child in node.Children)
                {
                    int imageIndex = 0;
                    if (child.Type == CloudFileSystemNodeTypeEnum.BUCKET || child.Type == CloudFileSystemNodeTypeEnum.DIRECTORY)
                    {
                        imageIndex = 0;
                    }
                    else if (child.Type == CloudFileSystemNodeTypeEnum.FILE)
                    {
                        imageIndex = 1;
                    }

                    var listItem = new ListViewItem(child.Name, imageIndex);
                    listItem.Tag = child;
                    listFiles.Items.Add(listItem);
                }

                updatePathUi();
            }
        }
コード例 #2
0
ファイル: FrameMain.cs プロジェクト: dantheman213/CloudMount
        private void connectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var d = new FrameConnect();

            if (d.ShowDialog() == DialogResult.OK)
            {
                cloudType = d.type;
                if (cloudType == CloudTypeEnum.AWS)
                {
                    // TODO
                    aws = new AwsDataModel();
                }
                else if (cloudType == CloudTypeEnum.GCP)
                {
                    try
                    {
                        gcp = new GcpDataModel();
                        gcp.credentialsFilePath = d.gcpCredsPath;
                        gcp.projectId           = d.gcpProjectId;

                        var creds = GoogleCredential.FromFile(gcp.credentialsFilePath);
                        gcp.client = StorageClient.Create(creds);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    fs = CloudFileSystemIngestor.IngestGcp(gcp);
                    currentDirectoryNode = fs.GetRootNode();
                    loadListFilesAtDirPath(currentDirectoryNode.AbsolutePath);
                }
            }
        }
コード例 #3
0
        public static CloudFileSystem IngestGcp(GcpDataModel gcp)
        {
            var fs      = new CloudFileSystem();
            var buckets = gcp.client.ListBuckets(gcp.projectId);

            foreach (var bucket in buckets)
            {
                var root  = fs.GetRootNode();
                var child = new CloudFileSystemNode
                {
                    Name         = bucket.Name,
                    AbsolutePath = String.Format("{0}{1}", root.AbsolutePath, bucket.Name),
                    Type         = CloudFileSystemNodeTypeEnum.BUCKET
                };
                fs.AddChild(root, child);

                foreach (var file in gcp.client.ListObjects(child.Name))
                {
                    var path = String.Format("cloud://{0}/{1}", bucket.Name, file.Name);
                    fs.AddFileWithAbsolutePath(path);
                }
            }

            return(fs);
        }
コード例 #4
0
        // Should only be used externally for inserting buckets onto root
        public void AddChild(CloudFileSystemNode parent, CloudFileSystemNode child)
        {
            if (parent.Children == null)
            {
                parent.Children = new List <CloudFileSystemNode>();
            }

            parent.Children.Add(child);
        }
コード例 #5
0
        public CloudFileSystem()
        {
            string prefix = "cloud://";

            root = new CloudFileSystemNode
            {
                AbsolutePath = prefix,
                Name         = prefix,
                Type         = CloudFileSystemNodeTypeEnum.ROOT
            };
        }
コード例 #6
0
ファイル: FrameMain.cs プロジェクト: dantheman213/CloudMount
 private void toolStripTextCloudPath_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         var path = toolStripTextCloudPath.Text.Trim();
         var node = fs.FindNodeAtAbsolutePath(path);
         if (node != null)
         {
             currentDirectoryNode = node;
             loadListFilesAtDirPath(path);
         }
     }
 }
コード例 #7
0
ファイル: FrameMain.cs プロジェクト: dantheman213/CloudMount
        private void listFiles_DoubleClick(object sender, EventArgs e)
        {
            if (listFiles.SelectedItems.Count == 1)
            {
                var selectedItem = listFiles.SelectedItems[0];
                var node         = (CloudFileSystemNode)selectedItem.Tag;
                if (node != null)
                {
                    currentDirectoryNode = node;

                    if (currentDirectoryNode.Type == CloudFileSystemNodeTypeEnum.BUCKET || currentDirectoryNode.Type == CloudFileSystemNodeTypeEnum.DIRECTORY)
                    {
                        loadListFilesAtDirPath(currentDirectoryNode.AbsolutePath);
                    }
                    else if (currentDirectoryNode.Type == CloudFileSystemNodeTypeEnum.FILE)
                    {
                        // TODO
                    }
                }
            }
        }
コード例 #8
0
        // Create file in FS by automatically finding the correct node to place under.
        // If directories do not exist in path to file, create them and manage nodes.
        public void AddFileWithAbsolutePath(string path)
        {
            // TODO
            if (!String.IsNullOrEmpty(path))
            {
                path = RemovePrefix(path);
                var parts = path.Split('/');

                if (parts.Length > 0)
                {
                    var file = parts[parts.Length - 1];
                    // the last element is always the file. remove it from list
                    Array.Resize(ref parts, parts.Length - 1);

                    var currentNode = root;
                    var currentPath = root.AbsolutePath;
                    foreach (var part in parts)
                    {
                        currentPath += part;
                        var node = FindNodeAtAbsolutePath(currentPath);
                        if (node != null)
                        {
                            currentNode = node;
                        }
                        else
                        {
                            var newNode = new CloudFileSystemNode
                            {
                                AbsolutePath = currentPath,
                                Name         = part,
                                Type         = CloudFileSystemNodeTypeEnum.DIRECTORY
                            };
                            if (currentNode.Children == null)
                            {
                                currentNode.Children = new List <CloudFileSystemNode>();
                            }
                            currentNode.Children.Add(newNode);
                            currentNode = newNode;
                        }

                        currentPath += "/";
                    }

                    currentPath += file;
                    if (!FileExists(currentPath))
                    {
                        var newNode = new CloudFileSystemNode
                        {
                            AbsolutePath = currentPath,
                            Name         = file,
                            Type         = CloudFileSystemNodeTypeEnum.FILE
                        };

                        if (currentNode.Children == null)
                        {
                            currentNode.Children = new List <CloudFileSystemNode>();
                        }
                        currentNode.Children.Add(newNode);
                    }
                }
            }
        }