Beispiel #1
0
        public static ObjectStat FromResponseHeaders(string objectName, IList <Parameter> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            foreach (Parameter parameter in responseHeaders)
            {
                switch (parameter.Name.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(parameter.Value.ToString());
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(parameter.Value.ToString(), CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = parameter.Value.ToString().Replace("\"", string.Empty);
                    break;

                case "Content-Type":
                    objInfo.ContentType = parameter.Value.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = parameter.Value.ToString();
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = parameter.Value.ToString().Equals("true");
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(parameter.Name))
                    {
                        objInfo.MetaData[parameter.Name] = parameter.Value.ToString();
                    }
                    else if (parameter.Name.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[parameter.Name.Substring("x-amz-meta-".Length)] = parameter.Value.ToString();
                    }
                    else
                    {
                        objInfo.ExtraHeaders[parameter.Name] = parameter.Value.ToString();
                    }
                    break;
                }
            }

            return(objInfo);
        }
Beispiel #2
0
        public static ObjectStat FromResponseHeaders(string objectName, Dictionary <string, string> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            objInfo.ObjectName = objectName;
            foreach (var paramName in responseHeaders.Keys)
            {
                string paramValue = responseHeaders[paramName];
                switch (paramName.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(paramValue);
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(paramValue, CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = paramValue.Replace("\"", string.Empty);
                    break;

                case "content-type":
                    objInfo.ContentType = paramValue.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = paramValue;
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = paramValue.Equals("true");
                    break;

                case "x-amz-archive-status":
                    objInfo.ArchiveStatus = paramValue.ToString();
                    break;

                case "x-amz-tagging-count":
                    if (Int32.TryParse(paramValue.ToString(), out int tagCount) && tagCount >= 0)
                    {
                        objInfo.TaggingCount = (uint)tagCount;
                    }
                    break;

                case "x-amz-expiration":
                    // x-amz-expiration header includes the expiration date and the corresponding rule id.
                    string expirationResponse = paramValue.ToString().Trim();
                    string expiryDatePattern  = @"(Sun|Mon|Tue|Wed|Thu|Fri|Sat), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} [A-Z]+";
                    Match  expiryMatch        = Regex.Match(expirationResponse, expiryDatePattern);
                    if (expiryMatch.Success)
                    {
                        objInfo.Expires = DateTime.SpecifyKind(
                            DateTime.Parse(expiryMatch.Value),
                            DateTimeKind.Utc);
                    }
                    break;

                case "x-amz-object-lock-mode":
                    Console.WriteLine(paramValue.ToString());
                    if (!string.IsNullOrWhiteSpace(paramValue.ToString()))
                    {
                        objInfo.ObjectLockMode = (paramValue.ToString().ToLower().Equals("governance"))?RetentionMode.GOVERNANCE:RetentionMode.COMPLIANCE;
                    }
                    break;

                case "x-amz-object-lock-retain-until-date":
                    Console.WriteLine(paramValue.ToString());
                    string lockUntilDate = paramValue.ToString();
                    if (!string.IsNullOrWhiteSpace(lockUntilDate))
                    {
                        objInfo.ObjectLockRetainUntilDate = DateTime.SpecifyKind(
                            DateTime.Parse(lockUntilDate),
                            DateTimeKind.Utc);;
                    }
                    break;

                case "x-amz-object-lock-legal-hold":
                    string legalHoldON = paramValue.ToString().Trim();
                    if (!string.IsNullOrWhiteSpace(legalHoldON))
                    {
                        objInfo.LegalHoldEnabled = legalHoldON.ToLower().Equals("on");
                    }
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(paramName))
                    {
                        objInfo.MetaData[paramName] = paramValue;
                    }
                    else if (paramName.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[paramName.Substring("x-amz-meta-".Length)] = paramValue;
                    }
                    else
                    {
                        objInfo.ExtraHeaders[paramName] = paramValue;
                    }
                    break;
                }
            }

            return(objInfo);
        }
Beispiel #3
0
        public static ObjectStat FromResponseHeaders(string objectName, Dictionary <string, string> responseHeaders)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("Name of an object cannot be empty");
            }
            ObjectStat objInfo = new ObjectStat();

            objInfo.ObjectName = objectName;
            foreach (var paramName in responseHeaders.Keys)
            {
                string paramValue = responseHeaders[paramName];
                switch (paramName.ToLower())
                {
                case "content-length":
                    objInfo.Size = long.Parse(paramValue);
                    break;

                case "last-modified":
                    objInfo.LastModified = DateTime.Parse(paramValue, CultureInfo.InvariantCulture);
                    break;

                case "etag":
                    objInfo.ETag = paramValue.Replace("\"", string.Empty);
                    break;

                case "content-type":
                    objInfo.ContentType = paramValue.ToString();
                    objInfo.MetaData["Content-Type"] = objInfo.ContentType;
                    break;

                case "x-amz-version-id":
                    objInfo.VersionId = paramValue;
                    break;

                case "x-amz-delete-marker":
                    objInfo.DeleteMarker = paramValue.Equals("true");
                    break;

                case "x-amz-tagging-count":
                    if (Int32.TryParse(paramValue.ToString(), out int tagCount) && tagCount >= 0)
                    {
                        objInfo.TaggingCount = (uint)tagCount;
                    }
                    break;

                default:
                    if (OperationsUtil.IsSupportedHeader(paramName))
                    {
                        objInfo.MetaData[paramName] = paramValue;
                    }
                    else if (paramName.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                    {
                        objInfo.MetaData[paramName.Substring("x-amz-meta-".Length)] = paramValue;
                    }
                    else
                    {
                        objInfo.ExtraHeaders[paramName] = paramValue;
                    }
                    break;
                }
            }

            return(objInfo);
        }