コード例 #1
0
        public IHttpActionResult Blob(string path, string accountName)
        {
            if (String.IsNullOrEmpty(path) ||
                String.IsNullOrEmpty(accountName))
            {
                return(Unauthorized());
            }

            // When linking to a blob, we must resolve the account name to handle cases
            // where multiple storage accounts are being used.
            CloudStorageAccount account = AccountProvider.GetAccountByName(accountName);

            if (account == null)
            {
                return(Unauthorized());
            }

            BlobPath            parsed     = BlobPath.Parse(path);
            LocalBlobDescriptor descriptor = new LocalBlobDescriptor
            {
                ContainerName = parsed.ContainerName,
                BlobName      = parsed.BlobName
            };
            var blob = descriptor.GetBlockBlob(account);

            // Get a SAS for the next 10 mins
            string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions            = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10)
            });

            // Redirect to it
            return(Redirect(blob.Uri.AbsoluteUri + sas));
        }
コード例 #2
0
        public IHttpActionResult Blob(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(Unauthorized());
            }

            if (_account == null)
            {
                return(Unauthorized());
            }

            BlobPath            parsed     = BlobPath.Parse(path);
            LocalBlobDescriptor descriptor = new LocalBlobDescriptor
            {
                ContainerName = parsed.ContainerName,
                BlobName      = parsed.BlobName
            };
            var blob = descriptor.GetBlockBlob(_account);

            // Get a SAS for the next 10 mins
            string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions            = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10)
            });

            // Redirect to it
            return(Redirect(blob.Uri.AbsoluteUri + sas));
        }
コード例 #3
0
        public IHttpActionResult Output(string id, int start = 0)
        {
            // Parse the ID
            Guid funcId;

            if (!Guid.TryParse(id, out funcId))
            {
                return(BadRequest());
            }

            // Get the invocation log
            var instance = _functionInstanceLookup.Lookup(funcId);

            if (instance == null)
            {
                return(NotFound());
            }

            if (instance.InlineOutputText != null)
            {
                return(new TextResult(instance.InlineOutputText, Request));
            }

            LocalBlobDescriptor outputBlobDescriptor = instance.OutputBlob;

            if (outputBlobDescriptor == null)
            {
                return(NotFound());
            }

            CloudBlockBlob blob = outputBlobDescriptor.GetBlockBlob(_account);

            var sb     = new StringBuilder();
            var stream = blob.OpenRead();

            try
            {
                using (var sr = new StreamReader(stream))
                {
                    stream = null;
                    string line = sr.ReadLine();
                    for (int i = 0; line != null; i++, line = sr.ReadLine())
                    {
                        if (i >= start)
                        {
                            sb.AppendLine(line);
                        }
                    }
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            return(new TextResult(sb.ToString(), Request));
        }
コード例 #4
0
 public BlobFunctionOutputDefinition(IStorageBlobClient client, LocalBlobDescriptor outputBlob,
                                     LocalBlobDescriptor parameterLogBlob)
 {
     _client           = client;
     _outputBlob       = outputBlob;
     _parameterLogBlob = parameterLogBlob;
 }
コード例 #5
0
 public BlobFunctionOutputDefinition(IStorageBlobClient client, LocalBlobDescriptor outputBlob,
     LocalBlobDescriptor parameterLogBlob)
 {
     _client = client;
     _outputBlob = outputBlob;
     _parameterLogBlob = parameterLogBlob;
 }
コード例 #6
0
        public async Task <IFunctionOutputDefinition> CreateAsync(IFunctionInstance instance, CancellationToken cancellationToken)
        {
            await _outputLogDirectory.Container.CreateIfNotExistsAsync(cancellationToken);

            string namePrefix = instance.Id.ToString("N");
            LocalBlobDescriptor outputBlob       = CreateDescriptor(_outputLogDirectory, namePrefix + ".txt");
            LocalBlobDescriptor parameterLogBlob = CreateDescriptor(_outputLogDirectory, namePrefix + ".params.txt");

            return(new BlobFunctionOutputDefinition(_outputLogDirectory.ServiceClient, outputBlob, parameterLogBlob));
        }
コード例 #7
0
        private void DeleteParameterLogBlob(LocalBlobDescriptor blobDescriptor)
        {
            if (blobDescriptor == null)
            {
                return;
            }

            CloudBlockBlob blob = blobDescriptor.GetBlockBlob(_cloudStorageAccount);

            blob.DeleteIfExists();
        }
コード例 #8
0
        public static CloudBlockBlob GetBlockBlob(this LocalBlobDescriptor descriptor, string connectionString)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            if (connectionString == null)
            {
                return(null);
            }

            CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);

            return(GetBlockBlob(descriptor, account));
        }
コード例 #9
0
        public static CloudBlockBlob GetBlockBlob(this LocalBlobDescriptor descriptor, CloudStorageAccount account)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            if (account == null)
            {
                return(null);
            }

            CloudBlobClient    client    = account.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference(descriptor.ContainerName);

            return(container.GetBlockBlobReference(descriptor.BlobName));
        }
コード例 #10
0
        private void DeleteParameterLogBlob(LocalBlobDescriptor blobDescriptor)
        {
            if (blobDescriptor == null)
            {
                return;
            }

            CloudBlockBlob blob = blobDescriptor.GetBlockBlob(_cloudStorageAccount);
            blob.DeleteIfExists();
        }
コード例 #11
0
        public ActionResult SearchBlob(string path)
        {
            ViewBag.Path = path;

            if (String.IsNullOrEmpty(path))
            {
                return(View());
            }

            if (_account == null)
            {
                TempData["Message.Text"]  = "Account not found";
                TempData["Message.Level"] = "danger";
                return(View());
            }

            ICloudBlob blob = null;

            try
            {
                BlobPath            parsed     = BlobPath.Parse(path);
                LocalBlobDescriptor descriptor = new LocalBlobDescriptor
                {
                    ContainerName = parsed.ContainerName,
                    BlobName      = parsed.BlobName
                };

                IReadOnlyDictionary <string, CloudStorageAccount> accounts = AccountProvider.GetAccounts();
                foreach (var account in accounts.Values)
                {
                    blob = descriptor.GetBlockBlob(account);
                    if (blob.Exists())
                    {
                        break;
                    }
                    else
                    {
                        blob = null;
                    }
                }
            }
            catch (FormatException e)
            {
                TempData["Message.Text"]  = e.Message;
                TempData["Message.Level"] = "danger";
                return(View());
            }
            catch
            {
                blob = null;
            }

            if (blob == null)
            {
                TempData["Message.Text"]  = "No invocation found for: " + path;
                TempData["Message.Level"] = "warning";
                return(View());
            }

            Guid?guid;

            try
            {
                guid = BlobCausalityReader.GetParentId(blob);
            }
            catch
            {
                guid = null;
            }

            if (!guid.HasValue)
            {
                TempData["Message.Text"]  = "No invocation found for: " + path;
                TempData["Message.Level"] = "warning";
                return(View());
            }

            TempData["Message.Text"]  = "Invocation found for: " + path;
            TempData["Message.Level"] = "info";

            return(Redirect("~/#/functions/invocations/" + guid));
        }
コード例 #12
0
        public IHttpActionResult Blob(string path, string accountName)
        {
            if (String.IsNullOrEmpty(path) ||
                String.IsNullOrEmpty(accountName))
            {
                return Unauthorized();
            }

            // When linking to a blob, we must resolve the account name to handle cases
            // where multiple storage accounts are being used.
            CloudStorageAccount account = AccountProvider.GetAccountByName(accountName);
            if (account == null)
            {
                return Unauthorized();
            }

            BlobPath parsed = BlobPath.Parse(path);
            LocalBlobDescriptor descriptor = new LocalBlobDescriptor
            {
                ContainerName = parsed.ContainerName,
                BlobName = parsed.BlobName
            };
            var blob = descriptor.GetBlockBlob(account);

            // Get a SAS for the next 10 mins
            string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10)
            });

            // Redirect to it
            return Redirect(blob.Uri.AbsoluteUri + sas);
        }
コード例 #13
0
        private IStorageBlockBlob GetBlockBlobReference(LocalBlobDescriptor descriptor)
        {
            IStorageBlobContainer container = _client.GetContainerReference(descriptor.ContainerName);

            return(container.GetBlockBlobReference(descriptor.BlobName));
        }
コード例 #14
0
 private IStorageBlockBlob GetBlockBlobReference(LocalBlobDescriptor descriptor)
 {
     IStorageBlobContainer container = _client.GetContainerReference(descriptor.ContainerName);
     return container.GetBlockBlobReference(descriptor.BlobName);
 }
コード例 #15
0
        public ActionResult SearchBlob(string path)
        {
            ViewBag.Path = path;

            if (String.IsNullOrEmpty(path))
            {
                return View();
            }

            if (_account == null)
            {
                TempData["Message.Text"] = "Account not found";
                TempData["Message.Level"] = "danger";
                return View();
            }

            ICloudBlob blob = null;

            try
            {
                BlobPath parsed = BlobPath.Parse(path);
                LocalBlobDescriptor descriptor = new LocalBlobDescriptor
                {
                    ContainerName = parsed.ContainerName,
                    BlobName = parsed.BlobName
                };

                IReadOnlyDictionary<string, CloudStorageAccount> accounts = AccountProvider.GetAccounts();
                foreach (var account in accounts.Values)
                {
                    blob = descriptor.GetBlockBlob(account);
                    if (blob.Exists())
                    {
                        break;
                    }
                    else
                    {
                        blob = null;
                    }
                }
            }
            catch (FormatException e)
            {
                TempData["Message.Text"] = e.Message;
                TempData["Message.Level"] = "danger";
                return View();
            }
            catch
            {
                blob = null;
            }

            if (blob == null)
            {
                TempData["Message.Text"] = "No invocation found for: " + path;
                TempData["Message.Level"] = "warning";
                return View();
            }

            Guid? guid;

            try
            {
                guid = BlobCausalityReader.GetParentId(blob);
            }
            catch
            {
                guid = null;
            }

            if (!guid.HasValue)
            {
                TempData["Message.Text"] = "No invocation found for: " + path;
                TempData["Message.Level"] = "warning";
                return View();
            }

            TempData["Message.Text"] = "Invocation found for: " + path;
            TempData["Message.Level"] = "info";

            return Redirect("~/#/functions/invocations/" + guid);
        }
コード例 #16
0
        public IHttpActionResult Blob(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return Unauthorized();
            }

            if (_account == null)
            {
                return Unauthorized();
            }

            BlobPath parsed = BlobPath.Parse(path);
            LocalBlobDescriptor descriptor = new LocalBlobDescriptor
            {
                ContainerName = parsed.ContainerName,
                BlobName = parsed.BlobName
            };
            var blob = descriptor.GetBlockBlob(_account);

            // Get a SAS for the next 10 mins
            string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10)
            });

            // Redirect to it
            return Redirect(blob.Uri.AbsoluteUri + sas);
        }