/// <summary>
        /// Extract the path portion for the Storage URI -- e.g. from
        /// https://htestseq.blob.core.windows.net/hli-0008-vhd-backups/myFolder/myblob.dat
        /// to
        /// /myFlder/myblob.dat
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static string ExtractBlobPath(IListBlobItem b)
        {
            return(BlobUtilities.ExtractBlobPath(b));

            /*
             * // remove the storage prefix + the container from the URI
             * var parts = b.Uri.LocalPath.Split('/');
             * // remove the container in [0]
             * var pathPortion = String.Join("/", parts, 2, parts.Length - 2);
             *
             * return pathPortion;
             */
        }
예제 #2
0
        private static bool processFilesFromResponse(ButlerResponse jobResponse, Configuration.WorkflowStatus jobStatus, CloudStorageAccount account)
        {
            bool               returnValue         = true;
            CloudBlockBlob     baseBlob            = new CloudBlockBlob(new Uri(jobResponse.MezzanineFiles[0]), account.Credentials);
            CloudBlobContainer container           = baseBlob.Container;
            string             directoryTo         = (jobStatus == Configuration.WorkflowStatus.Failed) ? Configuration.DirectoryFailed : Configuration.DirectoryCompleted;
            string             timestampFileAppend = (string.IsNullOrEmpty(jobResponse.TimeStampProcessingStarted)) ? "" : jobResponse.TimeStampProcessingStarted.Replace(':', '-');

            // fix: substitute / with - in date to avoid file being treated as series of dirs
            timestampFileAppend = timestampFileAppend.Replace('/', '-');
            try
            {
                foreach (string videoUri in jobResponse.MezzanineFiles)
                {
                    CloudBlockBlob fileToMove            = new CloudBlockBlob(new Uri(videoUri), account.Credentials);
                    var            blobContinuationToken = new BlobContinuationToken();

                    string blobTarget        = BlobUtilities.AdjustPath(fileToMove, directoryTo);
                    int    trimEnd           = blobTarget.LastIndexOf('.');
                    string blobTargetFileExt = blobTarget.Substring(trimEnd, blobTarget.Length - trimEnd);
                    blobTarget = string.Concat(blobTarget, ".", timestampFileAppend, ".", blobTargetFileExt);
                    BlobUtilities.RenameBlobWithinContainer(container, BlobUtilities.ExtractBlobPath(fileToMove), blobTarget);
                }


                // write log file
                string blobUriString = BlobUtilities.AdjustPath(baseBlob, directoryTo);
                // remove file ext
                // append .log
                blobUriString = string.Concat(blobUriString, ".", timestampFileAppend, ".log");
                CloudBlockBlob logBlob = container.GetBlockBlobReference(blobUriString);
                logBlob.Properties.ContentType = "text/plain";
                logBlob.UploadText(jobResponse.Log);
            }
            catch (Exception)
            {
                throw;
            }


            return(returnValue);
        }