コード例 #1
0
        public IEnumerator UpdateSlotMetadata(string @namespace, string userId, string accessToken, string slotId,
                                              string[] tags, string label, string customMetadata, ResultCallback <Slot> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update a slot! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a slot! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            Assert.IsNotNull(slotId, "Can't update a slot! slotId parameter is null!");

            FormDataContent customAttribute = new FormDataContent();

            customAttribute.Add("customAttribute", customMetadata);

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/slots/{slotId}/metadata")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("slotId", slotId)
                          .WithQueryParam("tags", tags)
                          .WithQueryParam("label", label)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBearerAuth(accessToken)
                          .WithContentType(customAttribute.GetMediaType())
                          .WithBody(customAttribute)
                          .GetResult();

            IHttpResponse response = null;

            yield return(this.httpWorker.SendRequest(request, rsp => response = rsp));

            var result = response.TryParseJson <Slot>();

            callback.Try(result);
        }
コード例 #2
0
        public IEnumerator UpdateSlot(string @namespace, string userId, string accessToken, string slotId, byte[] data,
                                      string filename, ResultCallback <Slot> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update a slot! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a slot! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            Assert.IsNotNull(data, "Can't update a slot! data parameter is null!");
            Assert.IsNotNull(filename, "Can't update a slot! filename parameter is null!");
            Assert.IsNotNull(slotId, "Can't update a slot! slotId parameter is null!");

            string checkSum;

            using (MD5 md5 = MD5.Create())
            {
                byte[] computeHash = md5.ComputeHash(data);
                checkSum = BitConverter.ToString(computeHash).Replace("-", "");
            }

            FormDataContent formDataContent = new FormDataContent();

            formDataContent.Add(filename, data);

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/slots/{slotId}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("slotId", slotId)
                          .WithQueryParam("checksum", checkSum)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBearerAuth(accessToken)
                          .WithContentType(formDataContent.GetMediaType())
                          .WithBody(formDataContent)
                          .GetResult();

            IHttpResponse response = null;

            yield return(this.httpWorker.SendRequest(request, rsp => response = rsp));

            var result = response.TryParseJson <Slot>();

            callback.Try(result);
        }
コード例 #3
0
        public IEnumerator <ITask> CreateSlot(string @namespace, string userId, string accessToken,
                                              byte[] data, string filename, ResultCallback <Slot> callback)
        {
            Assert.IsNotNull(@namespace, "Can't create a slot! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't create a slot! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't create a slot! accessToken parameter is null!");
            Assert.IsNotNull(data, "Can't create a slot! data parameter is null!");
            Assert.IsNotNull(filename, "Can't create a slot! filename parameter is null!");

            string checkSum;

            using (MD5 md5 = MD5.Create())
            {
                byte[] computeHash = md5.ComputeHash(data);
                checkSum = BitConverter.ToString(computeHash).Replace("-", "");
            }

            FormDataContent formDataContent = new FormDataContent();

            formDataContent.Add(data, filename);

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/binary-store/namespaces/{namespace}/users/{userId}/slots")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithQueryParam("checksum", checkSum)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBearerAuth(accessToken)
                          .WithContentType(formDataContent.GetMediaType())
                          .WithBody(formDataContent)
                          .ToRequest();

            HttpWebResponse response = null;

            yield return(Task.Await(request, rsp => response = rsp));

            var result = response.TryParseJsonBody <Slot>();

            callback.Try(result);
        }