Ejemplo n.º 1
0
        /// <summary>
        /// Get the id of a function invocation that wrote a given blob.
        /// </summary>
        /// <returns>The function invocation's id, or Guid.Empty if no owner is specified, or null if the blob is missing.</returns>
        private static Guid?GetBlobWriter(ICloudBlob blob)
        {
            if (blob == null)
            {
                return(null);
            }

            try
            {
                return(BlobCausalityReader.GetParentId(blob) ?? Guid.Empty);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404 || e.RequestInformation.HttpStatusCode == 400)
                {
                    // NoBlob
                    return(null);
                }
                else
                {
                    throw;
                }
            }
        }
        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));
        }