/// <summary> /// DenpendencyMiddleware /// </summary> /// <param name="services"></param> public static IServiceCollection AddDenpendencyServices(this IServiceCollection services) { var _Assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList().FindAll(s => s.FullName.StartsWith("HongMouer.")); var _Types = _Assemblies.SelectMany(a => a.DefinedTypes).Select(type => type.AsType()) .Where(x => x != typeof(IDenpendency) && typeof(IDenpendency).IsAssignableFrom(x)).ToArray(); var _Context = services.BuildServiceProvider().GetService <IRepository>(); var _Plugin = _Context.FindList <SystemPlugin>().ToList(); var _ClassTypes = _Types.Where(x => x.IsClass).ToArray(); var _InterfaceTypes = _Types.Where(x => x.IsInterface).ToArray(); foreach (var item in _ClassTypes) { var _Interface = _InterfaceTypes.FirstOrDefault(x => x.IsAssignableFrom(item)); if (_Interface != null) { object[] objParam = new object[item.GetConstructors().Length]; for (int i = 0; i < item.GetConstructors().Length; i++) { objParam[i] = null; } IDenpendency denpendency = (IDenpendency)Activator.CreateInstance(item, objParam); if (!_Plugin.Exists(s => s.Status == EnumStatus.正常.GetHashCode())) { services.AddScoped(_Interface, item); } else if (_Plugin.Exists(s => s.Name == denpendency.Name && s.Status == EnumStatus.正常.GetHashCode())) { services.AddScoped(_Interface, item); } if (_Plugin == null || _Plugin.Count == 0 || !_Plugin.Exists(s => s.Name == denpendency.Name)) { _Context.Insert(new SystemPlugin { Id = SnowflakeHelper.NextId(), GroupName = denpendency.GroupName, Version = denpendency.Version, Name = denpendency.Name, PluginFullName = item.FullName, InterfaceFullName = _Interface.FullName, Status = EnumStatus.停用.GetHashCode(), Remark = denpendency.Remark, CreateTime = DateTime.Now, ModifyTime = DateTime.Now, RowVersion = DateTime.Now.Ticks }); } } } return(services); }
static void Main(string[] args) { byte[] inputByteArray = Encoding.UTF8.GetBytes("1升等于多少斤"); var _Aes = AesHelper.AESEncrypt(inputByteArray, Key, IV); string a = Convert.ToBase64String(_Aes); Console.WriteLine("SnowflakeHelper.NextId:" + SnowflakeHelper.NextId()); Console.WriteLine(a); string _aes = StringHelper.byteToHexStr(_Aes); Console.WriteLine(StringHelper.byteToHexStr(_Aes)); byte[] by = StringHelper.HexToByte(_aes); Console.WriteLine(Encoding.UTF8.GetString(AesHelper.AESDecrypt(by, Key, IV))); Console.WriteLine(AesHelper.AESDecryptHex(_aes, Key, IV)); //for (long i = 0; i < long.MaxValue; i++) //{ //Console.WriteLine("ObjectId.NewId:" + ObjectIdInt.NewId()); //} //for (long i = 0; i < long.MaxValue; i++) //{ // Console.WriteLine("ObjectId.GenerateNewStringId:" + ObjectId.NewId()); //} //for (long i = 0; i < 1000; i++) //{ // Console.WriteLine("TimestampId.GetInstance1:" + TimestampId.Instance.GetId()); // Console.WriteLine("TimestampId.GetInstance2:" + TimestampId.Instance.GetId()); // Console.WriteLine("TimestampId.GetInstance3:" + TimestampId.Instance.GetId()); // Console.WriteLine("TimestampId.GetInstance4:" + TimestampId.Instance.GetId()); //} Console.WriteLine("Hello World!"); }