public static IServiceCollection AddWxChatOfficialSyncService(this IServiceCollection collection) { var appfilters = new AppTypes[] { AppTypes.Official }; var apps = "https://www.yourc.club/api/sharing/QueryMerchantDetails" .GetUriJsonContent <JObject>().TryGetValues <MerchantDetails>("$.data") .SelectMany((merchant) => { return(merchant.Apps.Where(app => appfilters.Any(x => x == app.AppType)) .Select(x => new { App = x, MerchantId = merchant.Id, MerchantName = merchant.BrandName })); }); foreach (var app in apps) { var state = new WeChatUserSyncState(new WeChatUserSyncSettings() { AppId = app.App.AppId, AppType = app.App.AppType, Secret = app.App.Secret, MerchantId = app.MerchantId, BrandName = app.MerchantName }); collection.Add(new ServiceDescriptor(typeof(IASfPWorkItem), new WorkItemWithDataflow <WeChatUserSyncState, WeChatUserInfo>(state))); } return(collection); }
public static IASfPWorkItem[] GenernateWorkItems(this IEnumerable <MerchantDetails> details, AppTypes[] filter) { return(details.SelectMany((x) => { return x.Apps.Where(app => filter.Contains(app.AppType)).Select((app) => { var settings = new WeChatUserSyncSettings() { AppId = app.AppId, AppType = app.AppType, MerchantId = x.Id, Secret = app.Secret }; var state = new WeChatUserSyncState(settings); return new WorkItemWithDataflow <WeChatUserSyncState, WeChatUserInfo>(state); }); }) .Where(x => x != null) .ToArray()); }