예제 #1
0
        public static async Task <bool> UploadStream(UploadFileConfig _fileConfig, AzureStorageConfig _storageConfig)
        {
            // Get reference to the blob container by passing the name by reading the value from the configuration (appsettings.json)
            CloudBlobContainer container = GetBlobContainer(_storageConfig);

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(_fileConfig.StrageFilename);

            await blockBlob.UploadFromStreamAsync(_fileConfig.Stream);

            return(await Task.FromResult(true));
        }
예제 #2
0
        //public string GetInfomationLog()
        //{
        //    return GetLogText("Infomation");
        //}
        public string GetLogText(AzureStorageConfig _storageConfig)
        {
            string log = "";

            CloudBlobContainer container = GetBlobContainer(_storageConfig);
            CloudBlockBlob     blob      = container.GetBlockBlobReference(string.Format("{0}_log.txt", _storageConfig.Container));

            try
            {
                log = blob.DownloadTextAsync().Result;
            }
            catch { };
            return(log);
        }
예제 #3
0
        //public Task<TdsDataObject> GetTable(AzureStorageConfig _storageConfig)
        //{
        //    return Task<TdsDataObject>.Run(() => {
        //        TdsDataObject tableObject = new TdsDataObject();
        //        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_storageConfig.ConnectionString);

        //        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        //        tableObject.InitTables(_storageConfig.Container, tableClient);

        //        return tableObject;
        //    });
        //}
        static public string SaveInfoLog(AzureStorageConfig _storageConfig, string content)
        {
            string log = "";

            CloudBlobContainer container = GetBlobContainer(_storageConfig);
            CloudBlockBlob     blob      = container.GetBlockBlobReference(string.Format("{0}_log.txt", _storageConfig.Container));

            try
            {
                blob.UploadTextAsync(content).Wait();
            }
            catch { };
            return(log);
        }
예제 #4
0
        private static CloudBlobContainer GetBlobContainer(AzureStorageConfig _storageConfig)
        {
            // Create cloudstorage account by passing the storageconnectionstring
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_storageConfig.ConnectionString);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Get reference to the blob container by passing the name by reading the value from the configuration (appsettings.json)
            CloudBlobContainer container = blobClient.GetContainerReference(_storageConfig.Container);

            container.CreateIfNotExistsAsync();

            return(container);
        }
예제 #5
0
        public Task <List <string> > GetInfotext(AzureStorageConfig _storageConfig)
        {
            return(Task <List <string> > .Run(async() => {
                List <string> blobs = null;
                CloudBlobContainer container = GetBlobContainer(_storageConfig);
                CloudBlockBlob blob = container.GetBlockBlobReference("_Info.txt");

                try
                {
                    string text = await blob.DownloadTextAsync(Encoding.UTF8, null, null, null);
                    blobs = new List <string>(text.Split(new string[] { "\r\n" }, StringSplitOptions.None));
                }
                catch { };

                return blobs;
            }));
        }
예제 #6
0
        public Task <List <CloudBlob> > GetGraphsUrlAsync(AzureStorageConfig _storageConfig)
        {
            return(Task <List <CloudBlob> > .Run(() => {
                CloudBlobContainer container = GetBlobContainer(_storageConfig);
                List <CloudBlob> blobs = new List <CloudBlob>();
                try
                {
                    BlobResultSegment resultSegment = container.ListBlobsSegmentedAsync(null).Result;

                    foreach (IListBlobItem item in resultSegment.Results)
                    {
                        if (item.GetType() == typeof(CloudBlockBlob))
                        {
                            CloudBlockBlob blob = (CloudBlockBlob)item;
                            if (blob.Properties.ContentType.Contains("text"))
                            {
                                continue;
                            }

                            blobs.Add(blob);
                            //blobs.Add(blob.StorageUri.PrimaryUri.AbsoluteUri);
                        }
                        else if (item.GetType() == typeof(CloudPageBlob))
                        {
                            CloudPageBlob blob = (CloudPageBlob)item;
                            blobs.Add(blob);
                            //blobs.Add(blob.StorageUri.PrimaryUri.AbsoluteUri);
                        }
                        // else if (item.GetType() == typeof(CloudBlobDirectory))
                        // {
                        //    CloudBlobDirectory dir = (CloudBlobDirectory)item;
                        //    blobs.Add(dir.Uri.ToString());
                        //}
                    }
                }
                catch { }
                return blobs;
            }));
        }
예제 #7
0
 public string GetGraphsLog(AzureStorageConfig _storageConfig)
 {
     return(GetLogText(_storageConfig));
 }