示例#1
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;
        }
示例#2
0
        /// <summary>
        /// Process message Back fro success and Fial queues
        /// </summary>
        /// <param name="storageAccountString">Storage account</param>
        /// <param name="queueName">Queue Name</param>
        /// <param name="status">Workflow status</param>
        private static void processMessageBack(string storageAccountString, string queueName,  Configuration.WorkflowStatus status)
        {
            string erroMsg;
            Trace.TraceInformation("reading from workflow results queue: " + status.ToString());
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccountString);
            CloudQueueClient inQueueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue inQueue = inQueueClient.GetQueueReference(queueName);
            inQueue.CreateIfNotExists();
            CloudQueueMessage retrievedMessage = inQueue.GetMessage();
            if (retrievedMessage != null)
            {
                try
                {
                    if (retrievedMessage.DequeueCount > Configuration.maxDequeueCount)
                    {
                        //Poison Message
                        erroMsg = String.Format("[0]Error: Max DequeueCount Messsage : {1}", "getWorkflowOperations_" + status.ToString(), retrievedMessage.AsString);
                        SendMessageToDeadLetterQueue(erroMsg, inQueueClient, retrievedMessage);
                    }
                    else
                    {
                        ButlerResponse messageResponse = DeserializeRsponseMessage(retrievedMessage.AsString);
                        if (messageResponse != null)
                        {
                            //Process the message
                            Configuration.WorkflowStatus messageStatus = status;
                            processFilesFromResponse(messageResponse, messageStatus, storageAccount);
                        }
                        else
                        {
                            //Message bad format ccopu to deadletter 
                            erroMsg = String.Format("[0]Error: invalid Response message : {1}", "getWorkflowOperations_" + status.ToString(), retrievedMessage.AsString);
                            SendMessageToDeadLetterQueue(erroMsg, inQueueClient, retrievedMessage);
                        }
                    }
                    // TODO: updateQueuemessage if it is taking longer
                    //Process the message in less than 30 seconds, and then delete the message
                    inQueue.DeleteMessage(retrievedMessage);
                }
                catch (Exception X)
                {
                    //Trace the error but don't break the proccess or delete the message.
                    //dequeue control is running too.
                    Trace.TraceError(string.Format("[{0}] Error: {1}", "getWorkflowOperations_" + status.ToString(), X.Message));
                }
            }

            
        }