This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Lazy Singleton (abstract base class) | |
| /// </summary> | |
| /// <typeparam name="T">Generic instance type</typeparam> | |
| public abstract class LazySingleton<T> where T : LazySingleton<T>, new() | |
| { | |
| /// <summary> | |
| /// Interlocked maximum initialized number | |
| /// </summary> | |
| const int MaxInitializedCount = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Idea from Node.js https://www.npmjs.com/package/nconf package | |
| public static class JObjectExtension | |
| { | |
| public const string GoNextHierarchyDivider = ":"; // COLON | |
| public const string ArrayElementAppender = ","; // COMMA | |
| public static Dictionary<string, string> ToDictionary(this JObject src) | |
| { | |
| var result = new Dictionary<string, string>(); | |
| DeepParse(src, result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static readonly string[] TrueStrings = { "1", "t", "y", "yes", "true", "on" }; | |
| public static readonly string[] FalseStrings = { "0", "f", "n", "no", "false", "off" }; | |
| public static bool ConvertToBool(this string src, bool defaultVal = false) | |
| { | |
| if (string.IsNullOrWhiteSpace(src)) | |
| { | |
| return defaultVal; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Idea from https://github.com/shshshdy/TopSdk.NetCore-Master/tree/master/TopSdk.NetCore | |
| /// <summary> | |
| /// Usage: The generic type could be primitive type or object type, to store actual return data | |
| /// Wraper a ReturnBase model so we could give extra information, such as IsSuccess, Code, etc | |
| /// Example: | |
| /// ServiceReturn<bool> | |
| /// ServiceReturn<Account> | |
| /// ServiceReturn<Dictionary<string,string>> | |
| /// </summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Http POST method with contet-type = application/json | |
| /// Get Raw response | |
| /// </summary> | |
| /// <param name="url"></param> | |
| /// <param name="jsonData"></param> | |
| /// <param name="headers"></param> | |
| /// <returns></returns> | |
| public static async Task<ServiceResult<string>> HttpPostAsync(string url, string jsonData, IDictionary<string, string> headers = null) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static ServiceReturn<List<string>> Validate(object o, bool throwIfInvalid = false) | |
| { | |
| var context = new ValidationContext(o, null, null); | |
| var validationResults = new List<ValidationResult>(); | |
| var isValid = Validator.TryValidateObject(o, context, validationResults, true); | |
| if (false == isValid && throwIfInvalid) | |
| { | |
| throw new Exception(string.Join(" ", validationResults)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [TestClass] | |
| public class AsyncHttpPhotoDownload_Test | |
| { | |
| [TestMethod] | |
| public async Task Download_ToFile_Test() | |
| { | |
| var randomPhotoUrl = "https://dummyimage.com/600x400/000/fff"; | |
| var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.png"); | |
| using (WebClient webClient = new WebClient()) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AutoMapping_Test : TestBase | |
| { | |
| [Fact] | |
| public async Task CityDeserialize_MappingDTO_Test() | |
| { | |
| var rawUrl = "https://raw.githubusercontent.com/donma/TaiwanAddressCityAreaRoadChineseEnglishJSON/master/AllData.json"; | |
| var getResult = await NetworkUtility.HttpGet(url: rawUrl, headers: null, timeoutSecs: 30); | |
| Assert.True(getResult.IsSuccess); | |
| Assert.NotNull(getResult.Data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| APP_NAME=${APP_NAME:-"____________"} | |
| ECR_HOST=${ECR_HOST:-"${APP_NAME}.dkr.ecr.us-west-2.amazonaws.com"} | |
| REPO=${ECR_HOST}/${APP_NAME} | |
| CONFIGURATION=${CONFIGURATION:-Release} | |
| VERSION=${VERSION:-1.0.0.0} | |
| NUGET_USERNAME=${NUGET_USERNAME:-""} | |
| NUGET_ENDPOINT=${NUGET_ENDPOINT:-"https://pkgs.dev.azure.com/${APP_NAME}/_packaging/xxxxxxxxxxxx.Nuget/nuget/v3/index.json"} | |
| NUGET_PAT=${NUGET_PAT:-""} | |
| TAG=${REPO}:${VERSION} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ASP.NET Core | |
| # Build and test ASP.NET Core projects targeting .NET Core. | |
| # Add steps that run tests, create a NuGet package, deploy, and more: | |
| # https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops | |
| name: "Build API & UnitTest" | |
| trigger: | |
| branches: | |
| include: | |
| - feat/* |
OlderNewer