コード例 #1
0
        public int GetMinutesRemaining(bool untilStart)
        {
            TimeSpan ts = untilStart ? StartTime.Subtract(DateTime.Now) : ExpireTime.Subtract(DateTime.Now);
            int      days = ts.Days, hours = ts.Hours, mins = ts.Minutes;

            return((days * 1440) + (hours * 60) + ts.Minutes);
        }
コード例 #2
0
        public Uri Create(RequestContext requestContext)
        {
            Ensure.ToBeTrue(ExpireTime > DateTime.UtcNow);
            Ensure.ToBeTrue(HttpMethod == HttpMethod.Get || HttpMethod == HttpMethod.Put, "不支持的http method"); //只支持这两种

            var method = HttpMethod.ToString().ToUpperInvariant();

            var expire = ((long)ExpireTime.Subtract(EpicTime).TotalSeconds).ToString(); //UNIX 时间戳

            // 要额外签名的数据
            var headers = new Dictionary <string, string>();

            if (UserMetadata != null)
            {
                foreach (var pair in UserMetadata)
                {
                    headers.Add(OssHeaders.OssUserMetaPrefix + pair.Key, pair.Value);
                }
            }
            var canonicalHeaders = SignatureHelper.ComputeCanonicalizedOSSHeaders(headers); //? 以STS获得的AccessKeyId和AccessKeySecret发送时,是否考虑SecurityToken的处理?



            //
            var parameters = new Dictionary <string, string>();

            if (requestContext.OssCredential.UseToken)
            {
                parameters.Add(RequestParameters.SECURITY_TOKEN, requestContext.OssCredential.SecurityToken);
            }

            ResponseHeaderOverrides?.Populate(parameters);

            var canonicalResource = SignatureHelper.BuildCanonicalizedResource(Bucket, ObjectKey, parameters);

            //var canonicalResource = "/" + (Bucket ?? "") + ((ObjectKey != null ? "/" + ObjectKey : ""));

            //签名
            var sign = SignatureHelper.HmacSha1Sign(requestContext.OssCredential.AccessKeySecret, method, ContentMd5, ContentType, expire, canonicalHeaders,
                                                    canonicalResource);

            // URL 参数
            var urlParams = new Dictionary <string, string>();

            urlParams.Add(RequestParameters.EXPIRES, expire);
            urlParams.Add(RequestParameters.OSS_ACCESS_KEY_ID, requestContext.OssCredential.AccessKeyId);
            urlParams.Add(RequestParameters.SIGNATURE, sign);
            foreach (var pair in parameters)
            {
                urlParams.Add(pair.Key, pair.Value);
            }
            var queryString = HttpUtils.CombineQueryString(urlParams);

            // 生成最终的URI
            var uriString = Bucket.GetObjectUrl(ObjectKey) + "?" + queryString;

            return(new Uri(uriString));
        }
コード例 #3
0
 public TimeSpan GetTimeRemaining(bool untilStart)
 {
     return(untilStart ? StartTime.Subtract(DateTime.Now) : ExpireTime.Subtract(DateTime.Now));
 }