Amazon.Glacier.Transfer.Internal.DownloadFileCommand.getJobIdFromMessage C# (CSharp) Method

getJobIdFromMessage() private method

Parse the sqs message to make sure it contains the right job id and that the job was successful
private getJobIdFromMessage ( Message message ) : string
message Message
return string
        string getJobIdFromMessage(Message message)
        {
            string json;

            // Some older AWS accounts send messages base 64 encoded.  Do a check to 
            // see if this is the start of a json document.  If not then base 64 decode the message.
            if (message.Body.Trim().StartsWith("{", StringComparison.OrdinalIgnoreCase))
                json = message.Body;
            else
                json = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(message.Body));

            Dictionary<string, string> outerLayer = JsonMapper.ToObject<Dictionary<string, string>>(json);
            Dictionary<string, object> fields = JsonMapper.ToObject<Dictionary<string, object>>(outerLayer["Message"]);

            string jobId = fields["JobId"] as string;

            string statusCode = fields["StatusCode"] as string;
            if (!string.Equals(statusCode, GlacierUtils.JOB_STATUS_SUCCEEDED, StringComparison.OrdinalIgnoreCase))
            {
                object statusMessage = "";
                fields.TryGetValue("StatusMessage", out statusMessage);
                throw new AmazonGlacierException(
                    string.Format(CultureInfo.InvariantCulture, "Failed to download {0}: {1}",
                        this.filePath, Convert.ToString(statusMessage, CultureInfo.InvariantCulture)));
            }

            return jobId;
        }