/// <summary> /// アイテム情報更新 /// </summary> /// <param name="itemID"></param> /// <param name="data"></param> /// <returns></returns> public async Task <CreateItemResults> UpdateItem(long itemID, DataType data) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start UpdateItem "); // 対象データを変換する var r = MakeCreateItemResponse(data.rawData); var content = MakeStringContentSendNotNUll(r); //HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/items/{itemID}/update", r); HttpResponseMessage response = await client.PostAsync($"pleasanter/api/items/{itemID}/update", content); // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <CreateItemResults>(); // 実行成功判定 if (true == response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK ) { return targetData; } // 実行エラー発生 throw new CreateItemException(targetData); }, this.serviceConfig.RetryCount)); }
/// <summary> /// アイテムを1個だけ取得する /// </summary> /// <param name="itemID"></param> /// <returns></returns> public async Task <DataType> GetItem(long itemID) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start GetItem id : {itemID}"); var r = GenerateRequestBase <RequestBase>(); HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/items/{itemID}/get", r); var targetData = await response.Content.ReadAsAsync <ItemApiResults <SingleItemResponse> >(); // 実行成功判定 if (true == response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK) { var ps = targetData.Response.Data.Select(e => { var t = new DataType(); t.rawData = e; return t; }); // 取れてくるのは1個だけなので return ps.FirstOrDefault(); } // 実行エラー発生 throw new GetItemException <ItemApiResults <SingleItemResponse> >(targetData); }, this.serviceConfig.RetryCount)); }
/// <summary> /// 指定条件で削除する /// </summary> /// <param name="itemID"></param> /// <returns></returns> public async Task <DeleteAllItemsResults> DeleteByConditions(DeleteAllItemsRequest <DataType> req) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start DeleteALL "); var r = req.ToDeleteAllItemsRequestSend(); r.ApiKey = serviceConfig.ApiKey; r.ApiVersion = serviceConfig.ApiVersion; r.PhysicalDelete = req.PhysicalDelete; // 検索条件を設定する r.View = MakeSendViewData(req?.View); HttpResponseMessage response = await client.PostAsJsonAsync($"/api/items/{SiteId}/bulkdelete", r); // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <DeleteAllItemsResults>(); // 実行成功判定 if (true == response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK ) { return targetData; } // 実行エラー発生 throw new ChangeItemResultsException(targetData); }, this.serviceConfig.RetryCount)); }
/// <summary> /// アイテムを作成する /// </summary> /// <param name="data"></param> /// <returns></returns> public async Task <CreateItemResults> CreateItem(DataType data) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start CreateItem "); // 対象データを変換する var r = MakeCreateItemResponse(data.rawData); // Attachments列にNULL列をそのまま設定してもエラーとなってしまう。 // HttpClientのデフォルト設定だとNullは送信する事となっているので、 // ここでは、NULLを送信しないように調整する //var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; //var json = JsonConvert.SerializeObject(r, settings); //var content = new StringContent(json, Encoding.UTF8, "application/json"); var content = MakeStringContentSendNotNUll(r); //HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/items/{SiteId}/create", r); HttpResponseMessage response = await client.PostAsync($"pleasanter/api/items/{SiteId}/create", content); // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <CreateItemResults>(); // 実行成功判定 if (true == response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK ) { return targetData; } // 実行エラー発生 throw new CreateItemException(targetData); }, this.serviceConfig.RetryCount)); }
public async Task 正常系_関数の値が帰ってくることを確認() { var r = await ServiceHelperFunctions.DoReyry(async() => { await Task.CompletedTask; return(1); }); Assert.AreEqual(1, r); }
/// <summary> /// 添付ファイルを取得する /// </summary> /// <param name="itemID"></param> /// <returns></returns> public async Task <AttachmentsResults> GetAttachments(Attachments attachments) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start GetAttachments id "); var r = GenerateRequestBase <RequestBase>(); HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/binaries/{attachments.Guid}/get", r); if (response.IsSuccessStatusCode) { // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <AttachmentsResults>(); return targetData; } return null; }, this.serviceConfig.RetryCount)); }
/// <summary> /// アイテムを消去する /// </summary> /// <param name="itemID"></param> /// <returns></returns> public async Task <DeleteApiResults> DeleteItem(long itemID) { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start DeleteItem id : {itemID}"); var r = GenerateRequestBase <RequestBase>(); HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/items/{itemID}/delete", r); // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <DeleteApiResults>(); if (response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK) { return targetData; } // 実行エラー発生 throw new ChangeItemResultsException(targetData); }, this.serviceConfig.RetryCount)); }
public async Task 異常系_指定回数リトライカウントされることを確認() { // 対象例外を発生させる HackPleasanterApiExceptions targrteExp = null; try { var r = await ServiceHelperFunctions.DoReyry <int>(async() => { await Task.CompletedTask; throw new ApplicationException("Error"); }); } catch (HackPleasanterApiExceptions exp) { targrteExp = exp; } Assert.IsNotNull(targrteExp); Assert.AreEqual(DefaultConfiguration.RetryCount, targrteExp.InnerExceptions.Count); var tex = targrteExp.InnerExceptions[0] as ApplicationException; Assert.AreEqual("Error", tex.Message); }
/// <summary> /// アイテムを複数個取得する(検索を含む) /// </summary> /// <param name="itemID"></param> /// <returns></returns> public async Task <IEnumerable <DataType> > FindItems <T>(T request) where T : Request.View.View <DataType>, new() { return(await ServiceHelperFunctions.DoReyry(async() => { L.Info(() => $"Start FindItems id : {request.ToString()}"); // 検索条件を設定 var r = GenerateRequestBase <FindItemsRequest>(); r.Offset = 0; r.ApiKey = serviceConfig.ApiKey; r.ApiVersion = serviceConfig.ApiVersion; // 検索条件を設定する r.View = MakeSendViewData(request); HttpResponseMessage response = await client.PostAsJsonAsync($"pleasanter/api/items/{SiteId}/get", r); // API呼び出しを実行 var targetData = await response.Content.ReadAsAsync <ItemApiResults <MultipleItemResponse> >(); if (response.IsSuccessStatusCode && targetData?.StatusCode == (int)StatusCode.OK) { var ps = targetData.Response.Data.Select(e => { var t = new DataType(); t.rawData = e; return t; }); // 存在するデータは全部とれる return ps; } // 実行エラー発生 throw new GetItemException <ItemApiResults <MultipleItemResponse> >(targetData); }, this.serviceConfig.RetryCount)); }