From 4bce9ce4d92650d6e3fcd11eb054b5a7904bb373 Mon Sep 17 00:00:00 2001 From: zpp <865287328@qq.com> Date: Wed, 3 Jul 2024 11:39:35 +0800 Subject: [PATCH] fix: dara to darabonba --- Dara/.DS_Store | Bin 6148 -> 0 bytes Dara/Exceptions/DaraUnretryableException.cs | 21 ----- Dara/Utils/ListUtil.cs | 40 --------- DaraUnitTests/.DS_Store | Bin 6148 -> 0 bytes DaraUnitTests/DaraCoreTest.cs | 6 +- DaraUnitTests/DaraDateTest.cs | 3 +- DaraUnitTests/DaraFileTest.cs | 2 +- DaraUnitTests/DaraModelTest.cs | 2 +- DaraUnitTests/DaraRequestTest.cs | 2 +- DaraUnitTests/DaraResponseTest.cs | 2 +- DaraUnitTests/DaraURLTest.cs | 2 +- DaraUnitTests/DaraUnitTests.csproj | 2 +- DaraUnitTests/DaraValidatorTest.cs | 3 +- .../Exceptions/DaraRetryableExceptionTest.cs | 4 +- .../DaraUnretryableExceptionTest.cs | 22 ----- .../{ => Exceptions}/TeaExceptionTest.cs | 3 +- .../Exceptions/TeaUnretryableExceptionTest.cs | 22 +++++ .../Models/ListAllMyBucketsResult.cs | 2 +- DaraUnitTests/Models/TestDicStringModel.cs | 2 +- DaraUnitTests/Models/TestRegModel.cs | 3 +- DaraUnitTests/Models/TestRegSubModel.cs | 2 +- DaraUnitTests/Models/ToBodyModel.cs | 2 +- .../RetryPolicy/BackoffPolicyTest.cs | 4 +- DaraUnitTests/Streams/FileFormStreamTest.cs | 2 +- DaraUnitTests/Streams/StreamUtilTest.cs | 4 +- DaraUnitTests/Utils/BytesUitlTest.cs | 2 +- DaraUnitTests/Utils/ConverterUtilTest.cs | 2 +- DaraUnitTests/Utils/DictUtilsTest.cs | 2 +- DaraUnitTests/Utils/ExtensionsTest.cs | 4 +- DaraUnitTests/Utils/FormUtilTest.cs | 14 ++-- DaraUnitTests/Utils/HttpClientUtilsTest.cs | 2 +- DaraUnitTests/Utils/HttpUtilsTest.cs | 2 +- .../{ReadJsonUtilTest.cs => JSONUtilTest.cs} | 25 +++--- DaraUnitTests/Utils/ListUtilTest.cs | 29 ++++++- DaraUnitTests/Utils/MathUtilTest.cs | 76 ++++++++++++++++++ DaraUnitTests/Utils/StringUtilTest.cs | 14 +++- DaraUnitTests/Utils/XmlUtilTest.cs | 4 +- .../Attributes/NameInMapAttribute.cs | 2 +- .../Attributes/ValidationAttribute.cs | 2 +- {Dara => Darabonba}/DaraCore.cs | 8 +- {Dara => Darabonba}/DaraDate.cs | 2 +- {Dara => Darabonba}/DaraFile.cs | 2 +- {Dara => Darabonba}/DaraModel.cs | 3 +- {Dara => Darabonba}/DaraModelExtensions.cs | 22 +++-- {Dara => Darabonba}/DaraRequest.cs | 2 +- {Dara => Darabonba}/DaraResponse.cs | 2 +- {Dara => Darabonba}/DaraURL.cs | 2 +- {Dara => Darabonba}/DaraValidator.cs | 2 +- .../dara.csproj => Darabonba/Darabonba.csproj | 6 +- .../Exceptions/DaraException.cs | 2 +- .../Exceptions/DaraRetryableException.cs | 2 +- .../Exceptions/RespException.cs | 2 +- .../Exceptions}/TeaException.cs | 2 +- .../Exceptions/TeaUnretryableException.cs | 22 +++++ .../Models/ExtendsParameters.cs | 2 +- {Dara => Darabonba}/Models/RuntimeOptions.cs | 6 +- {Dara => Darabonba}/Models/SSEEvent.cs | 4 +- .../Properties/AssemblyInfo.cs | 0 .../RetryPolicy/BackoffPolicy.cs | 4 +- .../RetryPolicy/EqualJitterBackoffPolicy.cs | 2 +- .../RetryPolicy/ExponentialBackoffPolicy.cs | 2 +- .../RetryPolicy/FixedBackoffPolicy.cs | 2 +- .../RetryPolicy/FullJitterBackoffPolicy.cs | 2 +- .../RetryPolicy/RandomBackoffPolicy.cs | 2 +- .../RetryPolicy/RetryCondition.cs | 2 +- .../RetryPolicy/RetryOptions.cs | 4 +- .../RetryPolicy/RetryPolicyContext.cs | 2 +- {Dara => Darabonba}/Streams/FileFormStream.cs | 3 +- {Dara => Darabonba}/Streams/StreamUtil.cs | 10 +-- {Dara => Darabonba}/Utils/BytesUtil.cs | 2 +- {Dara => Darabonba}/Utils/ConverterUtil.cs | 2 +- {Dara => Darabonba}/Utils/DictUtils.cs | 2 +- {Dara => Darabonba}/Utils/Extensions.cs | 2 +- {Dara => Darabonba}/Utils/FormUtil.cs | 6 +- {Dara => Darabonba}/Utils/HttpClientUtils.cs | 2 +- {Dara => Darabonba}/Utils/HttpUtils.cs | 2 +- .../Utils/JSONUtil.cs | 4 +- Darabonba/Utils/ListUtil.cs | 71 ++++++++++++++++ .../Utils/MathUtil.cs | 21 ++++- {Dara => Darabonba}/Utils/StringUtil.cs | 28 ++----- {Dara => Darabonba}/Utils/XmlUtil.cs | 3 +- tea-csharp.sln | 2 +- 82 files changed, 373 insertions(+), 239 deletions(-) delete mode 100644 Dara/.DS_Store delete mode 100644 Dara/Exceptions/DaraUnretryableException.cs delete mode 100644 Dara/Utils/ListUtil.cs delete mode 100644 DaraUnitTests/.DS_Store delete mode 100644 DaraUnitTests/Exceptions/DaraUnretryableExceptionTest.cs rename DaraUnitTests/{ => Exceptions}/TeaExceptionTest.cs (99%) create mode 100644 DaraUnitTests/Exceptions/TeaUnretryableExceptionTest.cs rename DaraUnitTests/Utils/{ReadJsonUtilTest.cs => JSONUtilTest.cs} (74%) create mode 100644 DaraUnitTests/Utils/MathUtilTest.cs rename {Dara => Darabonba}/Attributes/NameInMapAttribute.cs (91%) rename {Dara => Darabonba}/Attributes/ValidationAttribute.cs (94%) rename {Dara => Darabonba}/DaraCore.cs (99%) rename {Dara => Darabonba}/DaraDate.cs (99%) rename {Dara => Darabonba}/DaraFile.cs (99%) rename {Dara => Darabonba}/DaraModel.cs (96%) rename {Dara => Darabonba}/DaraModelExtensions.cs (91%) rename {Dara => Darabonba}/DaraRequest.cs (99%) rename {Dara => Darabonba}/DaraResponse.cs (98%) rename {Dara => Darabonba}/DaraURL.cs (99%) rename {Dara => Darabonba}/DaraValidator.cs (99%) rename Dara/dara.csproj => Darabonba/Darabonba.csproj (95%) rename {Dara => Darabonba}/Exceptions/DaraException.cs (88%) rename {Dara => Darabonba}/Exceptions/DaraRetryableException.cs (77%) rename {Dara => Darabonba}/Exceptions/RespException.cs (84%) rename {Dara/Tea => Darabonba/Exceptions}/TeaException.cs (99%) create mode 100644 Darabonba/Exceptions/TeaUnretryableException.cs rename {Dara => Darabonba}/Models/ExtendsParameters.cs (97%) rename {Dara => Darabonba}/Models/RuntimeOptions.cs (98%) rename {Dara => Darabonba}/Models/SSEEvent.cs (97%) rename {Dara => Darabonba}/Properties/AssemblyInfo.cs (100%) rename {Dara => Darabonba}/RetryPolicy/BackoffPolicy.cs (98%) rename {Dara => Darabonba}/RetryPolicy/EqualJitterBackoffPolicy.cs (95%) rename {Dara => Darabonba}/RetryPolicy/ExponentialBackoffPolicy.cs (94%) rename {Dara => Darabonba}/RetryPolicy/FixedBackoffPolicy.cs (91%) rename {Dara => Darabonba}/RetryPolicy/FullJitterBackoffPolicy.cs (95%) rename {Dara => Darabonba}/RetryPolicy/RandomBackoffPolicy.cs (95%) rename {Dara => Darabonba}/RetryPolicy/RetryCondition.cs (91%) rename {Dara => Darabonba}/RetryPolicy/RetryOptions.cs (84%) rename {Dara => Darabonba}/RetryPolicy/RetryPolicyContext.cs (89%) rename {Dara => Darabonba}/Streams/FileFormStream.cs (99%) rename {Dara => Darabonba}/Streams/StreamUtil.cs (97%) rename {Dara => Darabonba}/Utils/BytesUtil.cs (97%) rename {Dara => Darabonba}/Utils/ConverterUtil.cs (99%) rename {Dara => Darabonba}/Utils/DictUtils.cs (97%) rename {Dara => Darabonba}/Utils/Extensions.cs (94%) rename {Dara => Darabonba}/Utils/FormUtil.cs (96%) rename {Dara => Darabonba}/Utils/HttpClientUtils.cs (97%) rename {Dara => Darabonba}/Utils/HttpUtils.cs (97%) rename Dara/Utils/ReadJsonUtil.cs => Darabonba/Utils/JSONUtil.cs (97%) create mode 100644 Darabonba/Utils/ListUtil.cs rename Dara/Utils/NumberUtil.cs => Darabonba/Utils/MathUtil.cs (67%) rename {Dara => Darabonba}/Utils/StringUtil.cs (58%) rename {Dara => Darabonba}/Utils/XmlUtil.cs (99%) diff --git a/Dara/.DS_Store b/Dara/.DS_Store deleted file mode 100644 index 21b76fc6837d08259b9b2d4cdefd49b58cd14d13..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5FA5_C^RW4{R{koi9(OW51m6G+ z#qBMCvN~@cfF*!A-4LG^db54=&TcYeSp19~HaO#icO1Lw>j~p7@JP-H2Tb_e0s~?fH-5?jn6(y5UVAKEpZHFhE{?~3~I>{qXeD#nsqI43=BGo-^_FJ=8_Xi z@!OfNUXIcN6{Ua_xK!XamP_mZPxN2r|4WiqQa}p)D+S7I{jy&1m9n>XFK4~B(qHM{ p##%3D@K#LpR?LO9;`>QmwP)_P#4*t6%sZW^9|6-vCI$XNfiJya9BBXm diff --git a/Dara/Exceptions/DaraUnretryableException.cs b/Dara/Exceptions/DaraUnretryableException.cs deleted file mode 100644 index d28f345..0000000 --- a/Dara/Exceptions/DaraUnretryableException.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Dara.Exceptions -{ - public class DaraUnretryableException : Exception - { - private readonly DaraRequest _lastRequest; - - public DaraRequest LastRequest { get { return _lastRequest; } } - - public DaraUnretryableException() : base() - { - - } - - public DaraUnretryableException(DaraRequest lastRequest, Exception innerException) : base(" Retry failed : " + (innerException == null ? "" : innerException.Message), innerException) - { - _lastRequest = lastRequest; - } - } -} diff --git a/Dara/Utils/ListUtil.cs b/Dara/Utils/ListUtil.cs deleted file mode 100644 index c105048..0000000 --- a/Dara/Utils/ListUtil.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Dara.Utils -{ - public class ListUtil - { - public static int Unshift(List array, T data) - { - array.Insert(0, data); - return array.Count; - } - - - public static int Push(List array, T data) - { - array.Add(data); - return array.Count; - } - - public static List Sort(List array, string order) where T : IComparable - { - if (order == "asc") - { - array.Sort(); - } - else if (order == "desc") - { - array.Sort((x, y) => y.CompareTo(x)); - } - return array; - } - - public static List Concat(List array1, List array2) - { - array1.AddRange(array2); - return array1; - } - } -} \ No newline at end of file diff --git a/DaraUnitTests/.DS_Store b/DaraUnitTests/.DS_Store deleted file mode 100644 index 1d028c9147b8d19ef0e55637d49799b22ae4fb80..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}N6?5T4j-Q;N`oLXQEj1^Xif@v_wF1Gu6GmD;667uQYcZmm!Xd)627Nqin> zk}O!-gC`L?1Iag;pJeBQ%?|*G?sV7$r~-h*Mkq*GBV=Cd+H%2!!pt#+35*~KX32QX zM1Rpl-!9=CLU@G~zI}fX=>UBn!8i(&w9)t!TZQ8GPDz$zMc(<3dgiBtbeePrlN%ac zY8?f+J_xSD(X3zHJJoSI2;&D>U - + diff --git a/DaraUnitTests/DaraValidatorTest.cs b/DaraUnitTests/DaraValidatorTest.cs index 51fe801..c13a812 100644 --- a/DaraUnitTests/DaraValidatorTest.cs +++ b/DaraUnitTests/DaraValidatorTest.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; -using Dara; - +using Darabonba; using Xunit; namespace DaraUnitTests diff --git a/DaraUnitTests/Exceptions/DaraRetryableExceptionTest.cs b/DaraUnitTests/Exceptions/DaraRetryableExceptionTest.cs index fa5da53..d1d9997 100644 --- a/DaraUnitTests/Exceptions/DaraRetryableExceptionTest.cs +++ b/DaraUnitTests/Exceptions/DaraRetryableExceptionTest.cs @@ -2,8 +2,8 @@ using System.Net; using System.Net.Http; using System.Text; -using Dara; -using Dara.Exceptions; +using Darabonba; +using Darabonba.Exceptions; using Xunit; namespace DaraUnitTests.Exceptions diff --git a/DaraUnitTests/Exceptions/DaraUnretryableExceptionTest.cs b/DaraUnitTests/Exceptions/DaraUnretryableExceptionTest.cs deleted file mode 100644 index b8f51f8..0000000 --- a/DaraUnitTests/Exceptions/DaraUnretryableExceptionTest.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using Dara.Exceptions; -using Dara; -using Xunit; - -namespace DaraUnitTests.Exceptions -{ - public class DaraUnretryableExceptionTest - { - [Fact] - public void TestDaraUnretryableException() - { - DaraUnretryableException daraUnretryableExceptionEmpty = new DaraUnretryableException(); - Assert.NotNull(daraUnretryableExceptionEmpty); - - DaraUnretryableException daraUnretryableException = new DaraUnretryableException(new DaraRequest(), new Exception("Exception")); - Assert.NotNull(daraUnretryableException); - Assert.Equal(" Retry failed : Exception", daraUnretryableException.Message); - Assert.NotNull(daraUnretryableException.LastRequest); - } - } -} diff --git a/DaraUnitTests/TeaExceptionTest.cs b/DaraUnitTests/Exceptions/TeaExceptionTest.cs similarity index 99% rename from DaraUnitTests/TeaExceptionTest.cs rename to DaraUnitTests/Exceptions/TeaExceptionTest.cs index 7d8e57c..d9c27aa 100644 --- a/DaraUnitTests/TeaExceptionTest.cs +++ b/DaraUnitTests/Exceptions/TeaExceptionTest.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Tea; -using Dara.Utils; - +using Darabonba.Utils; using Xunit; namespace DaraUnitTests diff --git a/DaraUnitTests/Exceptions/TeaUnretryableExceptionTest.cs b/DaraUnitTests/Exceptions/TeaUnretryableExceptionTest.cs new file mode 100644 index 0000000..c7e8939 --- /dev/null +++ b/DaraUnitTests/Exceptions/TeaUnretryableExceptionTest.cs @@ -0,0 +1,22 @@ +using System; +using Darabonba; +using Tea; +using Xunit; + +namespace DaraUnitTests.Exceptions +{ + public class TeaUnretryableExceptionTest + { + [Fact] + public void TestDaraUnretryableException() + { + TeaUnretryableException teaUnretryableExceptionEmpty = new TeaUnretryableException(); + Assert.NotNull(teaUnretryableExceptionEmpty); + + TeaUnretryableException teaUnretryableException = new TeaUnretryableException(new DaraRequest(), new Exception("Exception")); + Assert.NotNull(teaUnretryableException); + Assert.Equal(" Retry failed : Exception", teaUnretryableException.Message); + Assert.NotNull(teaUnretryableException.LastRequest); + } + } +} diff --git a/DaraUnitTests/Models/ListAllMyBucketsResult.cs b/DaraUnitTests/Models/ListAllMyBucketsResult.cs index 54db399..e200b6e 100644 --- a/DaraUnitTests/Models/ListAllMyBucketsResult.cs +++ b/DaraUnitTests/Models/ListAllMyBucketsResult.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Dara; +using Darabonba; namespace DaraUnitTests.Models { diff --git a/DaraUnitTests/Models/TestDicStringModel.cs b/DaraUnitTests/Models/TestDicStringModel.cs index 6b6f86d..804f7a1 100644 --- a/DaraUnitTests/Models/TestDicStringModel.cs +++ b/DaraUnitTests/Models/TestDicStringModel.cs @@ -1,4 +1,4 @@ -using Dara; +using Darabonba; namespace DaraUnitTests.Models { diff --git a/DaraUnitTests/Models/TestRegModel.cs b/DaraUnitTests/Models/TestRegModel.cs index 21aeb75..0260831 100644 --- a/DaraUnitTests/Models/TestRegModel.cs +++ b/DaraUnitTests/Models/TestRegModel.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; - -using Dara; +using Darabonba; namespace DaraUnitTests.Models { diff --git a/DaraUnitTests/Models/TestRegSubModel.cs b/DaraUnitTests/Models/TestRegSubModel.cs index 44b7db1..5ca79b4 100644 --- a/DaraUnitTests/Models/TestRegSubModel.cs +++ b/DaraUnitTests/Models/TestRegSubModel.cs @@ -1,4 +1,4 @@ -using Dara; +using Darabonba; namespace DaraUnitTests.Models { diff --git a/DaraUnitTests/Models/ToBodyModel.cs b/DaraUnitTests/Models/ToBodyModel.cs index 31344e5..7ecadb5 100644 --- a/DaraUnitTests/Models/ToBodyModel.cs +++ b/DaraUnitTests/Models/ToBodyModel.cs @@ -1,4 +1,4 @@ -using Dara; +using Darabonba; namespace DaraUnitTests.Models { diff --git a/DaraUnitTests/RetryPolicy/BackoffPolicyTest.cs b/DaraUnitTests/RetryPolicy/BackoffPolicyTest.cs index 61092bd..5ca1f87 100644 --- a/DaraUnitTests/RetryPolicy/BackoffPolicyTest.cs +++ b/DaraUnitTests/RetryPolicy/BackoffPolicyTest.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using Dara.Exceptions; -using Dara.RetryPolicy; +using Darabonba.Exceptions; +using Darabonba.RetryPolicy; using Xunit; namespace DaraUnitTests.RetryPolicy diff --git a/DaraUnitTests/Streams/FileFormStreamTest.cs b/DaraUnitTests/Streams/FileFormStreamTest.cs index fad62dd..73a560c 100644 --- a/DaraUnitTests/Streams/FileFormStreamTest.cs +++ b/DaraUnitTests/Streams/FileFormStreamTest.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -using Dara.Streams; +using Darabonba.Streams; using Xunit; namespace DaraUnitTests.Streams diff --git a/DaraUnitTests/Streams/StreamUtilTest.cs b/DaraUnitTests/Streams/StreamUtilTest.cs index 39e655c..099b47a 100644 --- a/DaraUnitTests/Streams/StreamUtilTest.cs +++ b/DaraUnitTests/Streams/StreamUtilTest.cs @@ -3,8 +3,8 @@ using System.Text; using System.Threading.Tasks; using System.Threading; -using Dara.Streams; -using Dara.Models; +using Darabonba.Streams; +using Darabonba.Models; using Xunit; using System.Net; using System.Net.Http; diff --git a/DaraUnitTests/Utils/BytesUitlTest.cs b/DaraUnitTests/Utils/BytesUitlTest.cs index e8d106f..d840240 100644 --- a/DaraUnitTests/Utils/BytesUitlTest.cs +++ b/DaraUnitTests/Utils/BytesUitlTest.cs @@ -1,6 +1,6 @@ using System.Text; using Xunit; -using Dara.Utils; +using Darabonba.Utils; namespace DaraUnitTests.Utils { diff --git a/DaraUnitTests/Utils/ConverterUtilTest.cs b/DaraUnitTests/Utils/ConverterUtilTest.cs index 2ffc058..fc8ada9 100644 --- a/DaraUnitTests/Utils/ConverterUtilTest.cs +++ b/DaraUnitTests/Utils/ConverterUtilTest.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Dara.Utils; +using Darabonba.Utils; using DaraUnitTests.Models; using Xunit; diff --git a/DaraUnitTests/Utils/DictUtilsTest.cs b/DaraUnitTests/Utils/DictUtilsTest.cs index 43a8b85..ebaa5eb 100644 --- a/DaraUnitTests/Utils/DictUtilsTest.cs +++ b/DaraUnitTests/Utils/DictUtilsTest.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using Dara.Utils; +using Darabonba.Utils; using Xunit; diff --git a/DaraUnitTests/Utils/ExtensionsTest.cs b/DaraUnitTests/Utils/ExtensionsTest.cs index 0104d2c..21666a3 100644 --- a/DaraUnitTests/Utils/ExtensionsTest.cs +++ b/DaraUnitTests/Utils/ExtensionsTest.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Dara.Utils; +using Darabonba.Utils; using Xunit; namespace DaraUnitTests.Utils @@ -10,7 +10,9 @@ public class ExtensionsTest public void TestIsNull() { string str = null; + byte[] bytes = null; Assert.True(str.IsNull()); + Assert.True(bytes.IsNull()); string nonNullStr = "not null"; Assert.False(nonNullStr.IsNull()); diff --git a/DaraUnitTests/Utils/FormUtilTest.cs b/DaraUnitTests/Utils/FormUtilTest.cs index 253b07e..8d95ad5 100644 --- a/DaraUnitTests/Utils/FormUtilTest.cs +++ b/DaraUnitTests/Utils/FormUtilTest.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.IO; using System.Text; -using Dara; +using Darabonba.Utils; using Xunit; -using Dara.Streams; +using Darabonba.Streams; namespace DaraUnitTests.Utils { @@ -15,10 +15,12 @@ public void Test_ToFormString() Assert.Empty(FormUtil.ToFormString(null)); Assert.Empty(FormUtil.ToFormString(new Dictionary())); - Dictionary dict = new Dictionary(); - dict.Add("form", "test"); - dict.Add("param", "test"); - dict.Add("testNull", null); + Dictionary dict = new Dictionary + { + { "form", "test" }, + { "param", "test" }, + { "testNull", null } + }; Assert.Equal("form=test¶m=test", FormUtil.ToFormString(dict)); } diff --git a/DaraUnitTests/Utils/HttpClientUtilsTest.cs b/DaraUnitTests/Utils/HttpClientUtilsTest.cs index ab984da..04dd996 100644 --- a/DaraUnitTests/Utils/HttpClientUtilsTest.cs +++ b/DaraUnitTests/Utils/HttpClientUtilsTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using System.Text; -using Dara.Utils; +using Darabonba.Utils; using Xunit; namespace DaraUnitTests.Utils diff --git a/DaraUnitTests/Utils/HttpUtilsTest.cs b/DaraUnitTests/Utils/HttpUtilsTest.cs index 5a0265f..6c4a720 100644 --- a/DaraUnitTests/Utils/HttpUtilsTest.cs +++ b/DaraUnitTests/Utils/HttpUtilsTest.cs @@ -1,6 +1,6 @@ using System.Net.Http; -using Dara.Utils; +using Darabonba.Utils; using Xunit; diff --git a/DaraUnitTests/Utils/ReadJsonUtilTest.cs b/DaraUnitTests/Utils/JSONUtilTest.cs similarity index 74% rename from DaraUnitTests/Utils/ReadJsonUtilTest.cs rename to DaraUnitTests/Utils/JSONUtilTest.cs index a0b5174..80aa804 100644 --- a/DaraUnitTests/Utils/ReadJsonUtilTest.cs +++ b/DaraUnitTests/Utils/JSONUtilTest.cs @@ -1,14 +1,11 @@ using System.Collections.Generic; - -using Dara.Utils; - +using Darabonba.Utils; using Newtonsoft.Json.Linq; - using Xunit; namespace DaraUnitTests.Utils { - public class ReadJsonUtilTest + public class JSONUtilTest { [Fact] public void Test_SerializeObject() @@ -16,19 +13,19 @@ public void Test_SerializeObject() Dictionary dict = new Dictionary { { "key", "value" } }; - string jsonStr = ReadJsonUtil.SerializeObject(dict); + string jsonStr = JSONUtil.SerializeObject(dict); Assert.NotNull(jsonStr); Assert.NotEmpty(jsonStr); Assert.Equal("{\"key\":\"value\"}", jsonStr); - Assert.Equal("{}", ReadJsonUtil.SerializeObject(new Dictionary())); - Assert.Equal("test str", ReadJsonUtil.SerializeObject("test str")); - Assert.Equal("1", ReadJsonUtil.SerializeObject(1)); - Assert.Equal("true", ReadJsonUtil.SerializeObject(true)); - Assert.Equal("null", ReadJsonUtil.SerializeObject(null)); + Assert.Equal("{}", JSONUtil.SerializeObject(new Dictionary())); + Assert.Equal("test str", JSONUtil.SerializeObject("test str")); + Assert.Equal("1", JSONUtil.SerializeObject(1)); + Assert.Equal("true", JSONUtil.SerializeObject(true)); + Assert.Equal("null", JSONUtil.SerializeObject(null)); Dictionary unicode = new Dictionary { { "str", "test&<>://中文" } }; - Assert.Equal("{\"key\":\"value\",\"map\":{\"str\":\"test&<>://中文\"},\"num\":1}", ReadJsonUtil.SerializeObject( + Assert.Equal("{\"key\":\"value\",\"map\":{\"str\":\"test&<>://中文\"},\"num\":1}", JSONUtil.SerializeObject( new Dictionary { { "key", "value" }, @@ -40,11 +37,11 @@ public void Test_SerializeObject() [Fact] public void TestDeserializeToDic() { - Assert.Null(ReadJsonUtil.Deserialize(null)); + Assert.Null(JSONUtil.Deserialize(null)); string jsonStr = "{\"arrayObj\":[[{\"itemName\":\"item\",\"itemInt\":1},{\"itemName\":\"item2\",\"itemInt\":2}],[{\"itemName\":\"item3\",\"itemInt\":3}]],\"arrayList\":[[[1,2],[3,4]],[[5,6],[7]],[]],\"listStr\":[1,2,3],\"items\":[{\"total_size\":18,\"partNumber\":1,\"tags\":[{\"aa\":\"11\"}]},{\"total_size\":20,\"partNumber\":2,\"tags\":[{\"aa\":\"22\"}]}],\"next_marker\":\"\",\"test\":{\"total_size\":19,\"partNumber\":1,\"tags\":[{\"aa\":\"11\"}]}}"; JObject jObject = JObject.Parse(jsonStr); - Dictionary dic = (Dictionary) ReadJsonUtil.Deserialize(jObject); + Dictionary dic = (Dictionary) JSONUtil.Deserialize(jObject); Assert.NotNull(dic); List listResult = (List) dic["items"]; Dictionary item1 = (Dictionary) listResult[0]; diff --git a/DaraUnitTests/Utils/ListUtilTest.cs b/DaraUnitTests/Utils/ListUtilTest.cs index d04692a..d427872 100644 --- a/DaraUnitTests/Utils/ListUtilTest.cs +++ b/DaraUnitTests/Utils/ListUtilTest.cs @@ -1,4 +1,4 @@ -using Dara.Utils; +using Darabonba.Utils; using Xunit; using System.Collections.Generic; @@ -6,8 +6,19 @@ namespace DaraUnitTests.Utils { public class ListUtilTest { + + [Fact] + public void TestShift() + { + List array = new List { "a", "b", "c" }; + string first = ListUtil.Shift(array); + Assert.Equal(2, array.Count); + Assert.Equal("a", first); + Assert.Equal("b", array[0]); + } + [Fact] - public void Test_Unshift() + public void TestUnshift() { List array = new List { "a", "b", "c" }; ListUtil.Unshift(array, "x"); @@ -16,7 +27,7 @@ public void Test_Unshift() } [Fact] - public void Test_Push() + public void TestPush() { List array = new List { "a", "b", "c" }; ListUtil.Push(array, "x"); @@ -25,7 +36,17 @@ public void Test_Push() } [Fact] - public void Test_Concat() + public void TestPop() + { + List array = new List { "a", "b", "c" }; + string last = ListUtil.Pop(array); + Assert.Equal(2, array.Count); + Assert.Equal("c", last); + Assert.Equal("b", array[1]); + } + + [Fact] + public void TestConcat() { List array1 = new List { "a", "b", "c" }; List array2 = new List { "d", "e", "f" }; diff --git a/DaraUnitTests/Utils/MathUtilTest.cs b/DaraUnitTests/Utils/MathUtilTest.cs new file mode 100644 index 0000000..3cb1cff --- /dev/null +++ b/DaraUnitTests/Utils/MathUtilTest.cs @@ -0,0 +1,76 @@ +using Darabonba.Utils; +using Xunit; + +namespace DaraUnitTests.Utils +{ + public class MathUtilTest + { + [Fact] + public void TestFloor() + { + float funm = 2.13f; + Assert.Equal(2, MathUtil.Floor(funm)); + double dunm = 2.13d; + Assert.Equal(2, MathUtil.Floor(dunm)); + } + + [Fact] + public void TestRound() + { + float funm = 2.49f; + Assert.Equal(2, MathUtil.Round(funm)); + double dunm = 2.51d; + Assert.Equal(3, MathUtil.Round(dunm)); + } + + [Fact] + public void TestParseInt() + { + float funm = 2.13f; + Assert.Equal(2, MathUtil.ParseInt(funm)); + double dunm = 2.13d; + Assert.Equal(2, MathUtil.ParseInt(dunm)); + } + + [Fact] + public void TestParseLong() + { + float funm = 2.13f; + Assert.Equal(2L, MathUtil.ParseLong(funm)); + double dunm = 2.13d; + Assert.Equal(2L, MathUtil.ParseLong(dunm)); + } + + [Fact] + public void TestParseFloat() + { + int iunm = 2; + Assert.Equal(2f, MathUtil.ParseFloat(iunm)); + float funm = 2.13f; + Assert.Equal(2.13f, MathUtil.ParseFloat(funm)); + double dunm = 2.13d; + Assert.Equal(2.13f, MathUtil.ParseFloat(dunm)); + } + + [Fact] + public void TestMin() + { + int inum = 2; + float fnum = 2.01f; + double dnum = 2.001d; + Assert.Equal(2, MathUtil.Min(inum, fnum)); + Assert.Equal(2.001d, MathUtil.Min(dnum, fnum)); + } + + [Fact] + public void TestMax() + { + int inum = 2; + float fnum = 2.01f; + double dnum = 2.02d; + Assert.Equal(2.01f, MathUtil.Max(inum, fnum)); + Assert.Equal(2.02d, MathUtil.Max(dnum, fnum)); + } + } + +} \ No newline at end of file diff --git a/DaraUnitTests/Utils/StringUtilTest.cs b/DaraUnitTests/Utils/StringUtilTest.cs index 603e010..d038d18 100644 --- a/DaraUnitTests/Utils/StringUtilTest.cs +++ b/DaraUnitTests/Utils/StringUtilTest.cs @@ -1,4 +1,5 @@ -using Dara.Utils; +using System; +using Darabonba.Utils; using Xunit; namespace DaraUnitTests.Utils @@ -6,7 +7,16 @@ namespace DaraUnitTests.Utils public class StringUtilTest { [Fact] - public void Test_ToBytes() + public void TestSubString() + { + int? start = null; + int? end = null; + Assert.Throws(() => StringUtil.SubString("test", start, end)); + Assert.Equal("te", StringUtil.SubString("test", 0, 2)); + } + + [Fact] + public void TestToBytes() { string data = "test"; Assert.Equal(new byte[] { 116, 101, 115, 116 }, BytesUtil.From(data, "utf8")); diff --git a/DaraUnitTests/Utils/XmlUtilTest.cs b/DaraUnitTests/Utils/XmlUtilTest.cs index 34e403a..bcecd4f 100644 --- a/DaraUnitTests/Utils/XmlUtilTest.cs +++ b/DaraUnitTests/Utils/XmlUtilTest.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using Dara; -using Dara.Utils; +using Darabonba; +using Darabonba.Utils; using Xunit; using DaraUnitTests.Models; using static DaraUnitTests.Models.ListAllMyBucketsResult; diff --git a/Dara/Attributes/NameInMapAttribute.cs b/Darabonba/Attributes/NameInMapAttribute.cs similarity index 91% rename from Dara/Attributes/NameInMapAttribute.cs rename to Darabonba/Attributes/NameInMapAttribute.cs index f05f0d3..e7fb851 100644 --- a/Dara/Attributes/NameInMapAttribute.cs +++ b/Darabonba/Attributes/NameInMapAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Dara +namespace Darabonba { public class NameInMapAttribute : Attribute { diff --git a/Dara/Attributes/ValidationAttribute.cs b/Darabonba/Attributes/ValidationAttribute.cs similarity index 94% rename from Dara/Attributes/ValidationAttribute.cs rename to Darabonba/Attributes/ValidationAttribute.cs index 070fe3f..3184a43 100644 --- a/Dara/Attributes/ValidationAttribute.cs +++ b/Darabonba/Attributes/ValidationAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Dara +namespace Darabonba { public class ValidationAttribute : Attribute { diff --git a/Dara/DaraCore.cs b/Darabonba/DaraCore.cs similarity index 99% rename from Dara/DaraCore.cs rename to Darabonba/DaraCore.cs index dcc1916..1a73973 100644 --- a/Dara/DaraCore.cs +++ b/Darabonba/DaraCore.cs @@ -10,11 +10,11 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Dara.RetryPolicy; -using Dara.Exceptions; -using Dara.Utils; +using Darabonba.RetryPolicy; +using Darabonba.Exceptions; +using Darabonba.Utils; -namespace Dara +namespace Darabonba { public class DaraCore { diff --git a/Dara/DaraDate.cs b/Darabonba/DaraDate.cs similarity index 99% rename from Dara/DaraDate.cs rename to Darabonba/DaraDate.cs index b26150c..bac23a0 100644 --- a/Dara/DaraDate.cs +++ b/Darabonba/DaraDate.cs @@ -1,6 +1,6 @@ using System; -namespace Dara +namespace Darabonba { public class DaraDate { diff --git a/Dara/DaraFile.cs b/Darabonba/DaraFile.cs similarity index 99% rename from Dara/DaraFile.cs rename to Darabonba/DaraFile.cs index 1ba5141..8020e02 100644 --- a/Dara/DaraFile.cs +++ b/Darabonba/DaraFile.cs @@ -2,7 +2,7 @@ using System.IO; using System.Threading.Tasks; -namespace Dara +namespace Darabonba { public class DaraFile : IDisposable { diff --git a/Dara/DaraModel.cs b/Darabonba/DaraModel.cs similarity index 96% rename from Dara/DaraModel.cs rename to Darabonba/DaraModel.cs index 20d8257..829a52f 100644 --- a/Dara/DaraModel.cs +++ b/Darabonba/DaraModel.cs @@ -3,10 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; - using Newtonsoft.Json; -namespace Dara +namespace Darabonba { public class DaraModel { diff --git a/Dara/DaraModelExtensions.cs b/Darabonba/DaraModelExtensions.cs similarity index 91% rename from Dara/DaraModelExtensions.cs rename to Darabonba/DaraModelExtensions.cs index ca1dcbc..191bbfb 100644 --- a/Dara/DaraModelExtensions.cs +++ b/Darabonba/DaraModelExtensions.cs @@ -4,12 +4,10 @@ using System.IO; using System.Reflection; -namespace Dara +namespace Darabonba { public static class DaraModelExtensions { - // TODO Copy/FromMap. - public static Dictionary ToMap(this DaraModel model) { if (model == null) @@ -24,7 +22,7 @@ public static Dictionary ToMap(this DaraModel model) { PropertyInfo propertyInfo = properties[i]; Type property = propertyInfo.PropertyType; - if(typeof(Stream).IsAssignableFrom(property)) + if (typeof(Stream).IsAssignableFrom(property)) { continue; } @@ -44,8 +42,8 @@ public static object ToMapFactory(Type type, object value) } if (typeof(IList).IsAssignableFrom(type) && !typeof(Array).IsAssignableFrom(type)) { - IList list = (IList) value; - Type listType = type.GetGenericArguments() [0]; + IList list = (IList)value; + Type listType = type.GetGenericArguments()[0]; List resultList = new List(); for (int j = 0; j < list.Count; j++) { @@ -62,7 +60,7 @@ public static object ToMapFactory(Type type, object value) } else if (typeof(IDictionary).IsAssignableFrom(type)) { - IDictionary dic = (IDictionary) value; + IDictionary dic = (IDictionary)value; IDictionary resultDic = new Dictionary(); foreach (DictionaryEntry keypair in dic) { @@ -80,7 +78,7 @@ public static object ToMapFactory(Type type, object value) } else if (typeof(DaraModel).IsAssignableFrom(type)) { - DaraModel daraModel = (DaraModel) value; + DaraModel daraModel = (DaraModel)value; return daraModel.ToMap(); } @@ -109,18 +107,18 @@ public static void Validate(this DaraModel model) } if (typeof(IList).IsAssignableFrom(propertyType) && !typeof(Array).IsAssignableFrom(propertyType)) { - IList list = (IList) obj; + IList list = (IList)obj; //validate list count daraValidator.ValidateMaxLength(list); daraValidator.ValidateMinLength(list); - Type listType = propertyType.GetGenericArguments() [0]; + Type listType = propertyType.GetGenericArguments()[0]; if (typeof(DaraModel).IsAssignableFrom(listType)) { for (int j = 0; j < list.Count; j++) { - ((DaraModel) list[j]).Validate(); + ((DaraModel)list[j]).Validate(); } } else @@ -134,7 +132,7 @@ public static void Validate(this DaraModel model) } else if (typeof(DaraModel).IsAssignableFrom(propertyType)) { - ((DaraModel) obj).Validate(); + ((DaraModel)obj).Validate(); } else { diff --git a/Dara/DaraRequest.cs b/Darabonba/DaraRequest.cs similarity index 99% rename from Dara/DaraRequest.cs rename to Darabonba/DaraRequest.cs index 76b2a05..a381e31 100644 --- a/Dara/DaraRequest.cs +++ b/Darabonba/DaraRequest.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; -namespace Dara +namespace Darabonba { public class DaraRequest { diff --git a/Dara/DaraResponse.cs b/Darabonba/DaraResponse.cs similarity index 98% rename from Dara/DaraResponse.cs rename to Darabonba/DaraResponse.cs index 063fc59..04e2653 100644 --- a/Dara/DaraResponse.cs +++ b/Darabonba/DaraResponse.cs @@ -2,7 +2,7 @@ using System.IO; using System.Net.Http; -namespace Dara +namespace Darabonba { public class DaraResponse { diff --git a/Dara/DaraURL.cs b/Darabonba/DaraURL.cs similarity index 99% rename from Dara/DaraURL.cs rename to Darabonba/DaraURL.cs index 7098441..3acd2a9 100644 --- a/Dara/DaraURL.cs +++ b/Darabonba/DaraURL.cs @@ -3,7 +3,7 @@ using System.Net; using System.Text; -namespace Dara +namespace Darabonba { public class DaraURL { diff --git a/Dara/DaraValidator.cs b/Darabonba/DaraValidator.cs similarity index 99% rename from Dara/DaraValidator.cs rename to Darabonba/DaraValidator.cs index a2ccd22..f5ab71d 100644 --- a/Dara/DaraValidator.cs +++ b/Darabonba/DaraValidator.cs @@ -5,7 +5,7 @@ [assembly : InternalsVisibleTo("DaraUnitTests")] -namespace Dara +namespace Darabonba { internal class DaraValidator { diff --git a/Dara/dara.csproj b/Darabonba/Darabonba.csproj similarity index 95% rename from Dara/dara.csproj rename to Darabonba/Darabonba.csproj index 5c2bc63..74ad329 100644 --- a/Dara/dara.csproj +++ b/Darabonba/Darabonba.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;netstandard2.1;netcoreapp3.1 - Dara + Darabonba Library Alibaba Cloud Alibaba Aliyun Dara Core SDK @@ -13,7 +13,7 @@ false false - Dara + Darabonba 1.1.3 false 5 @@ -63,7 +63,7 @@ - + diff --git a/Dara/Exceptions/DaraException.cs b/Darabonba/Exceptions/DaraException.cs similarity index 88% rename from Dara/Exceptions/DaraException.cs rename to Darabonba/Exceptions/DaraException.cs index d570360..6f0d80c 100644 --- a/Dara/Exceptions/DaraException.cs +++ b/Darabonba/Exceptions/DaraException.cs @@ -1,7 +1,7 @@ using System.Collections; using Tea; -namespace Dara.Exceptions +namespace Darabonba.Exceptions { public class DaraException : TeaException { diff --git a/Dara/Exceptions/DaraRetryableException.cs b/Darabonba/Exceptions/DaraRetryableException.cs similarity index 77% rename from Dara/Exceptions/DaraRetryableException.cs rename to Darabonba/Exceptions/DaraRetryableException.cs index e06aed2..46717fd 100644 --- a/Dara/Exceptions/DaraRetryableException.cs +++ b/Darabonba/Exceptions/DaraRetryableException.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.Exceptions +namespace Darabonba.Exceptions { public class DaraRetryableException : Exception { diff --git a/Dara/Exceptions/RespException.cs b/Darabonba/Exceptions/RespException.cs similarity index 84% rename from Dara/Exceptions/RespException.cs rename to Darabonba/Exceptions/RespException.cs index fda3b03..7d446ec 100644 --- a/Dara/Exceptions/RespException.cs +++ b/Darabonba/Exceptions/RespException.cs @@ -1,4 +1,4 @@ -namespace Dara.Exceptions +namespace Darabonba.Exceptions { public class RespException : DaraException { diff --git a/Dara/Tea/TeaException.cs b/Darabonba/Exceptions/TeaException.cs similarity index 99% rename from Dara/Tea/TeaException.cs rename to Darabonba/Exceptions/TeaException.cs index 7d22ad8..88b5bc2 100644 --- a/Dara/Tea/TeaException.cs +++ b/Darabonba/Exceptions/TeaException.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using Dara.Utils; +using Darabonba.Utils; namespace Tea { diff --git a/Darabonba/Exceptions/TeaUnretryableException.cs b/Darabonba/Exceptions/TeaUnretryableException.cs new file mode 100644 index 0000000..77cd8ac --- /dev/null +++ b/Darabonba/Exceptions/TeaUnretryableException.cs @@ -0,0 +1,22 @@ +using System; +using Darabonba; + +namespace Tea +{ + public class TeaUnretryableException : Exception + { + private readonly DaraRequest _lastRequest; + + public DaraRequest LastRequest { get { return _lastRequest; } } + + public TeaUnretryableException() : base() + { + + } + + public TeaUnretryableException(DaraRequest lastRequest, Exception innerException) : base(" Retry failed : " + (innerException == null ? "" : innerException.Message), innerException) + { + _lastRequest = lastRequest; + } + } +} diff --git a/Dara/Models/ExtendsParameters.cs b/Darabonba/Models/ExtendsParameters.cs similarity index 97% rename from Dara/Models/ExtendsParameters.cs rename to Darabonba/Models/ExtendsParameters.cs index bd32b6e..d95cd8e 100644 --- a/Dara/Models/ExtendsParameters.cs +++ b/Darabonba/Models/ExtendsParameters.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Dara.Models +namespace Darabonba.Models { public class ExtendsParameters : DaraModel { diff --git a/Dara/Models/RuntimeOptions.cs b/Darabonba/Models/RuntimeOptions.cs similarity index 98% rename from Dara/Models/RuntimeOptions.cs rename to Darabonba/Models/RuntimeOptions.cs index 8e23125..572e672 100644 --- a/Dara/Models/RuntimeOptions.cs +++ b/Darabonba/Models/RuntimeOptions.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using Dara; -using Dara.RetryPolicy; +using Darabonba; +using Darabonba.RetryPolicy; -namespace Dara.Models +namespace Darabonba.Models { public class RuntimeOptions : DaraModel { diff --git a/Dara/Models/SSEEvent.cs b/Darabonba/Models/SSEEvent.cs similarity index 97% rename from Dara/Models/SSEEvent.cs rename to Darabonba/Models/SSEEvent.cs index cc25a43..ed2bc3d 100644 --- a/Dara/Models/SSEEvent.cs +++ b/Darabonba/Models/SSEEvent.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using Dara; +using Darabonba; -namespace Dara.Models +namespace Darabonba.Models { public class SSEEvent : DaraModel { diff --git a/Dara/Properties/AssemblyInfo.cs b/Darabonba/Properties/AssemblyInfo.cs similarity index 100% rename from Dara/Properties/AssemblyInfo.cs rename to Darabonba/Properties/AssemblyInfo.cs diff --git a/Dara/RetryPolicy/BackoffPolicy.cs b/Darabonba/RetryPolicy/BackoffPolicy.cs similarity index 98% rename from Dara/RetryPolicy/BackoffPolicy.cs rename to Darabonba/RetryPolicy/BackoffPolicy.cs index e783c6f..1bc76e9 100644 --- a/Dara/RetryPolicy/BackoffPolicy.cs +++ b/Darabonba/RetryPolicy/BackoffPolicy.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using Dara.Exceptions; +using Darabonba.Exceptions; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public interface IBackoffPolicy { diff --git a/Dara/RetryPolicy/EqualJitterBackoffPolicy.cs b/Darabonba/RetryPolicy/EqualJitterBackoffPolicy.cs similarity index 95% rename from Dara/RetryPolicy/EqualJitterBackoffPolicy.cs rename to Darabonba/RetryPolicy/EqualJitterBackoffPolicy.cs index 5e3cd2c..9cb139f 100644 --- a/Dara/RetryPolicy/EqualJitterBackoffPolicy.cs +++ b/Darabonba/RetryPolicy/EqualJitterBackoffPolicy.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class EqualJitterBackoffPolicy : BackoffPolicy { diff --git a/Dara/RetryPolicy/ExponentialBackoffPolicy.cs b/Darabonba/RetryPolicy/ExponentialBackoffPolicy.cs similarity index 94% rename from Dara/RetryPolicy/ExponentialBackoffPolicy.cs rename to Darabonba/RetryPolicy/ExponentialBackoffPolicy.cs index f488367..3a39590 100644 --- a/Dara/RetryPolicy/ExponentialBackoffPolicy.cs +++ b/Darabonba/RetryPolicy/ExponentialBackoffPolicy.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class ExponentialBackoffPolicy : BackoffPolicy { diff --git a/Dara/RetryPolicy/FixedBackoffPolicy.cs b/Darabonba/RetryPolicy/FixedBackoffPolicy.cs similarity index 91% rename from Dara/RetryPolicy/FixedBackoffPolicy.cs rename to Darabonba/RetryPolicy/FixedBackoffPolicy.cs index 64d8da9..f89888d 100644 --- a/Dara/RetryPolicy/FixedBackoffPolicy.cs +++ b/Darabonba/RetryPolicy/FixedBackoffPolicy.cs @@ -1,4 +1,4 @@ -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class FixedBackoffPolicy : BackoffPolicy { diff --git a/Dara/RetryPolicy/FullJitterBackoffPolicy.cs b/Darabonba/RetryPolicy/FullJitterBackoffPolicy.cs similarity index 95% rename from Dara/RetryPolicy/FullJitterBackoffPolicy.cs rename to Darabonba/RetryPolicy/FullJitterBackoffPolicy.cs index 23444d0..40154f7 100644 --- a/Dara/RetryPolicy/FullJitterBackoffPolicy.cs +++ b/Darabonba/RetryPolicy/FullJitterBackoffPolicy.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class FullJitterBackoffPolicy : BackoffPolicy { diff --git a/Dara/RetryPolicy/RandomBackoffPolicy.cs b/Darabonba/RetryPolicy/RandomBackoffPolicy.cs similarity index 95% rename from Dara/RetryPolicy/RandomBackoffPolicy.cs rename to Darabonba/RetryPolicy/RandomBackoffPolicy.cs index f9aea96..f23126c 100644 --- a/Dara/RetryPolicy/RandomBackoffPolicy.cs +++ b/Darabonba/RetryPolicy/RandomBackoffPolicy.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class RandomBackoffPolicy : BackoffPolicy { diff --git a/Dara/RetryPolicy/RetryCondition.cs b/Darabonba/RetryPolicy/RetryCondition.cs similarity index 91% rename from Dara/RetryPolicy/RetryCondition.cs rename to Darabonba/RetryPolicy/RetryCondition.cs index c89626f..6d28102 100644 --- a/Dara/RetryPolicy/RetryCondition.cs +++ b/Darabonba/RetryPolicy/RetryCondition.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class RetryCondition { diff --git a/Dara/RetryPolicy/RetryOptions.cs b/Darabonba/RetryPolicy/RetryOptions.cs similarity index 84% rename from Dara/RetryPolicy/RetryOptions.cs rename to Darabonba/RetryPolicy/RetryOptions.cs index d9f8b82..c8a9b5b 100644 --- a/Dara/RetryPolicy/RetryOptions.cs +++ b/Darabonba/RetryPolicy/RetryOptions.cs @@ -1,8 +1,8 @@ -using Dara; +using Darabonba; using System; using System.Collections.Generic; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class RetryOptions { diff --git a/Dara/RetryPolicy/RetryPolicyContext.cs b/Darabonba/RetryPolicy/RetryPolicyContext.cs similarity index 89% rename from Dara/RetryPolicy/RetryPolicyContext.cs rename to Darabonba/RetryPolicy/RetryPolicyContext.cs index 9632e67..221db19 100644 --- a/Dara/RetryPolicy/RetryPolicyContext.cs +++ b/Darabonba/RetryPolicy/RetryPolicyContext.cs @@ -1,6 +1,6 @@ using System; -namespace Dara.RetryPolicy +namespace Darabonba.RetryPolicy { public class RetryPolicyContext { diff --git a/Dara/Streams/FileFormStream.cs b/Darabonba/Streams/FileFormStream.cs similarity index 99% rename from Dara/Streams/FileFormStream.cs rename to Darabonba/Streams/FileFormStream.cs index 01390f6..1d9245a 100644 --- a/Dara/Streams/FileFormStream.cs +++ b/Darabonba/Streams/FileFormStream.cs @@ -5,8 +5,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Darabonba; -namespace Dara.Streams +namespace Darabonba.Streams { public class FileField { diff --git a/Dara/Streams/StreamUtil.cs b/Darabonba/Streams/StreamUtil.cs similarity index 97% rename from Dara/Streams/StreamUtil.cs rename to Darabonba/Streams/StreamUtil.cs index 7abb53b..e6b71b9 100644 --- a/Dara/Streams/StreamUtil.cs +++ b/Darabonba/Streams/StreamUtil.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; using Newtonsoft.Json; using System.Threading.Tasks; -using Dara.Utils; -using Dara.Models; +using Darabonba.Utils; +using Darabonba.Models; -namespace Dara.Streams +namespace Darabonba.Streams { public class StreamUtil { @@ -138,14 +138,14 @@ public static async Task ReadAsStringAsync(Stream stream) public static object ReadAsJSON(Stream stream) { object jResult = ParseJSON(ReadAsString(stream)); - object result = ReadJsonUtil.Deserialize(jResult); + object result = JSONUtil.Deserialize(jResult); return result; } public async static Task ReadAsJSONAsync(Stream stream) { object jResult = ParseJSON(await ReadAsStringAsync(stream)); - object result = ReadJsonUtil.Deserialize(jResult); + object result = JSONUtil.Deserialize(jResult); return result; } diff --git a/Dara/Utils/BytesUtil.cs b/Darabonba/Utils/BytesUtil.cs similarity index 97% rename from Dara/Utils/BytesUtil.cs rename to Darabonba/Utils/BytesUtil.cs index dabbaca..c71e8f1 100644 --- a/Dara/Utils/BytesUtil.cs +++ b/Darabonba/Utils/BytesUtil.cs @@ -1,6 +1,6 @@ using System.Text; -namespace Dara.Utils +namespace Darabonba.Utils { public class BytesUtil { diff --git a/Dara/Utils/ConverterUtil.cs b/Darabonba/Utils/ConverterUtil.cs similarity index 99% rename from Dara/Utils/ConverterUtil.cs rename to Darabonba/Utils/ConverterUtil.cs index 67bf3b3..3f38405 100644 --- a/Dara/Utils/ConverterUtil.cs +++ b/Darabonba/Utils/ConverterUtil.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Dara.Utils +namespace Darabonba.Utils { public class ConverterUtil { diff --git a/Dara/Utils/DictUtils.cs b/Darabonba/Utils/DictUtils.cs similarity index 97% rename from Dara/Utils/DictUtils.cs rename to Darabonba/Utils/DictUtils.cs index 5af29c0..198f5f0 100644 --- a/Dara/Utils/DictUtils.cs +++ b/Darabonba/Utils/DictUtils.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Dara.Utils +namespace Darabonba.Utils { internal class DictUtils { diff --git a/Dara/Utils/Extensions.cs b/Darabonba/Utils/Extensions.cs similarity index 94% rename from Dara/Utils/Extensions.cs rename to Darabonba/Utils/Extensions.cs index 7f33af4..267f407 100644 --- a/Dara/Utils/Extensions.cs +++ b/Darabonba/Utils/Extensions.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; -namespace Dara.Utils +namespace Darabonba.Utils { public static class Extensions { diff --git a/Dara/Utils/FormUtil.cs b/Darabonba/Utils/FormUtil.cs similarity index 96% rename from Dara/Utils/FormUtil.cs rename to Darabonba/Utils/FormUtil.cs index 462100d..13bf2b7 100644 --- a/Dara/Utils/FormUtil.cs +++ b/Darabonba/Utils/FormUtil.cs @@ -3,11 +3,9 @@ using System.IO; using System.Text; using System.Web; +using Darabonba.Streams; -using Dara.Utils; -using Dara.Streams; - -namespace Dara +namespace Darabonba.Utils { public class FormUtil { diff --git a/Dara/Utils/HttpClientUtils.cs b/Darabonba/Utils/HttpClientUtils.cs similarity index 97% rename from Dara/Utils/HttpClientUtils.cs rename to Darabonba/Utils/HttpClientUtils.cs index f2e157a..cf758cd 100644 --- a/Dara/Utils/HttpClientUtils.cs +++ b/Darabonba/Utils/HttpClientUtils.cs @@ -9,7 +9,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; -namespace Dara.Utils +namespace Darabonba.Utils { public static class HttpClientUtils { diff --git a/Dara/Utils/HttpUtils.cs b/Darabonba/Utils/HttpUtils.cs similarity index 97% rename from Dara/Utils/HttpUtils.cs rename to Darabonba/Utils/HttpUtils.cs index d9abd5b..5f3aa23 100644 --- a/Dara/Utils/HttpUtils.cs +++ b/Darabonba/Utils/HttpUtils.cs @@ -1,6 +1,6 @@ using System.Net.Http; -namespace Dara.Utils +namespace Darabonba.Utils { internal static class HttpUtils { diff --git a/Dara/Utils/ReadJsonUtil.cs b/Darabonba/Utils/JSONUtil.cs similarity index 97% rename from Dara/Utils/ReadJsonUtil.cs rename to Darabonba/Utils/JSONUtil.cs index 4dab64a..4ec3055 100644 --- a/Dara/Utils/ReadJsonUtil.cs +++ b/Darabonba/Utils/JSONUtil.cs @@ -2,9 +2,9 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Dara.Utils +namespace Darabonba.Utils { - internal static class ReadJsonUtil + internal static class JSONUtil { public static string SerializeObject(object data) { diff --git a/Darabonba/Utils/ListUtil.cs b/Darabonba/Utils/ListUtil.cs new file mode 100644 index 0000000..78dfac2 --- /dev/null +++ b/Darabonba/Utils/ListUtil.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using Darabonba.Exceptions; + +namespace Darabonba.Utils +{ + public class ListUtil + { + public static T Shift(List list) + { + if (list == null || list.Count == 0) + { + // TODO return default 还是抛出错误 + throw new DaraException + { + Message = "array is empty" + }; + } + T first = list[0]; + list.RemoveAt(0); + return first; + } + + public static int Unshift(List array, T data) + { + array.Insert(0, data); + return array.Count; + } + + + public static int Push(List array, T data) + { + array.Add(data); + return array.Count; + } + + public static T Pop(List list) + { + if (list == null || list.Count == 0) + { + // TODO return default 还是抛出错误 + throw new DaraException + { + Message = "array is empty" + }; + } + T last = list[list.Count - 1]; + list.RemoveAt(list.Count - 1); + return last; + } + + public static List Sort(List array, string order) where T : IComparable + { + if (order == "asc") + { + array.Sort(); + } + else if (order == "desc") + { + array.Sort((x, y) => y.CompareTo(x)); + } + return array; + } + + public static List Concat(List array1, List array2) + { + array1.AddRange(array2); + return array1; + } + } +} \ No newline at end of file diff --git a/Dara/Utils/NumberUtil.cs b/Darabonba/Utils/MathUtil.cs similarity index 67% rename from Dara/Utils/NumberUtil.cs rename to Darabonba/Utils/MathUtil.cs index db1e9d5..46f4aac 100644 --- a/Dara/Utils/NumberUtil.cs +++ b/Darabonba/Utils/MathUtil.cs @@ -1,15 +1,28 @@ using System; +using Darabonba.Exceptions; -namespace Dara.Utils +namespace Darabonba.Utils { - public class NumberUtil + public class MathUtil { + public static int Floor(double? num) + { + return (int)Math.Floor(num.Value); + } + + public static int Round(double? num) + { + return (int)Math.Round(num.Value, MidpointRounding.AwayFromZero); + } + public static int ParseInt(T data) { if (data == null) { - // TODO - return 0; + throw new DaraException + { + Message = "data is null" + }; } return (int)double.Parse(data.ToString()); } diff --git a/Dara/Utils/StringUtil.cs b/Darabonba/Utils/StringUtil.cs similarity index 58% rename from Dara/Utils/StringUtil.cs rename to Darabonba/Utils/StringUtil.cs index cfa7ae8..7943d6d 100644 --- a/Dara/Utils/StringUtil.cs +++ b/Darabonba/Utils/StringUtil.cs @@ -2,30 +2,18 @@ using System.Text; using System.Globalization; -namespace Dara.Utils +namespace Darabonba.Utils { public class StringUtil { - public static byte[] ToBytes(string data, string enCoding) + public static string SubString(string str, int? start, int? end) { - string lowerEncoding = enCoding.ToLower(); - switch (lowerEncoding.ToLowerInvariant()) - { - case "ascii": - return Encoding.ASCII.GetBytes(data); - case "bigendianunicode": - return Encoding.BigEndianUnicode.GetBytes(data); - case "unicode": - return Encoding.Unicode.GetBytes(data); - case "utf32": - case "utf-32": - return Encoding.UTF32.GetBytes(data); - case "utf8": - case "utf-8": - return Encoding.UTF8.GetBytes(data); - default: - return Encoding.UTF8.GetBytes(data); - } + return str.Substring(start.Value, end.Value - start.Value); + } + + public static byte[] ToBytes(string data, string type) + { + return BytesUtil.From(data, type); } public static string Replace(string data, string newStr, string regexStr) diff --git a/Dara/Utils/XmlUtil.cs b/Darabonba/Utils/XmlUtil.cs similarity index 99% rename from Dara/Utils/XmlUtil.cs rename to Darabonba/Utils/XmlUtil.cs index 54c3811..0a9582f 100644 --- a/Dara/Utils/XmlUtil.cs +++ b/Darabonba/Utils/XmlUtil.cs @@ -5,8 +5,9 @@ using System.Reflection; using System.Xml; using System.Xml.Linq; +using Darabonba; -namespace Dara.Utils +namespace Darabonba.Utils { internal class XmlUtil { diff --git a/tea-csharp.sln b/tea-csharp.sln index 9cfd028..83104d5 100644 --- a/tea-csharp.sln +++ b/tea-csharp.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29306.81 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dara", "Dara\dara.csproj", "{BA7831AD-0335-437E-8F8F-EDB62B874D22}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Darabonba", "Darabonba\Darabonba.csproj", "{BA7831AD-0335-437E-8F8F-EDB62B874D22}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DaraUnitTests", "DaraUnitTests\DaraUnitTests.csproj", "{9BC6DAB8-9222-4856-AE71-05E0AB1B8B61}" EndProject