Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
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);
        }