/// <summary> /// Agrega la cabecera con los datos de la carga útil necesarios para autenticar a un usuario en el servicio Aspen. /// </summary> /// <param name="request">Solicitud a donde se agrega la cabecera.</param> /// <param name="jwtEncoder">Instancia del codificador del contenido de la carga útil.</param> /// <param name="apiSecret">Secreto de la aplicación que se utiliza para codificar el contenido del carga útil.</param> /// <param name="userIdentity">La información que se utiliza para autenticar la solicitud en función de un usuario.</param> public void AddSigninPayloadHeader( IRestRequest request, IJwtEncoder jwtEncoder, string apiSecret, IUserIdentity userIdentity) { Throw.IfNull(request, nameof(request)); Throw.IfNull(jwtEncoder, nameof(jwtEncoder)); Throw.IfNullOrEmpty(apiSecret, nameof(apiSecret)); Throw.IfNull(userIdentity, nameof(userIdentity)); IDeviceInfo deviceInfo = userIdentity.Device ?? CacheStore.Get <DeviceInfo>(CacheKeys.CurrentDevice) ?? DeviceInfo.Current; request.AddHeader(ServiceLocator.Instance.RequestHeaderNames.DeviceInfoHeaderName, deviceInfo.ToJson()); CacheStore.Add(CacheKeys.CurrentDevice, deviceInfo); Dictionary <string, object> payload = new Dictionary <string, object>(); ServiceLocator.Instance.PayloadClaimsManager.AddNonceClaim(payload, ServiceLocator.Instance.NonceGenerator.GetNonce()); ServiceLocator.Instance.PayloadClaimsManager.AddEpochClaim(payload, ServiceLocator.Instance.EpochGenerator.GetSeconds()); ServiceLocator.Instance.PayloadClaimsManager.AddDocTypeClaim(payload, userIdentity.DocType); ServiceLocator.Instance.PayloadClaimsManager.AddDocNumberClaim(payload, userIdentity.DocNumber); ServiceLocator.Instance.PayloadClaimsManager.AddPasswordClaim(payload, userIdentity.Password); ServiceLocator.Instance.PayloadClaimsManager.AddDeviceIdClaim(payload, deviceInfo.DeviceId); string jwt = jwtEncoder.Encode(payload, apiSecret); request.AddHeader(ServiceLocator.Instance.RequestHeaderNames.PayloadHeaderName, jwt); }
private void AddInjectionAssembly(string assemblyName) { ReflectionAssemblyResolver assemblyInjectionCode = null; if (CacheStore.Exists <ReflectionAssemblyResolver>("injection|" + assemblyName)) { assemblyInjectionCode = CacheStore.Get <ReflectionAssemblyResolver>("injection|" + assemblyName); } else { assemblyInjectionCode = new ReflectionAssemblyResolver(assemblyName); CacheStore.Add <ReflectionAssemblyResolver>("injection|" + assemblyName, assemblyInjectionCode); } var nodeAssembly = new TreeNode { Text = Path.GetFileName(assemblyName), Tag = assemblyInjectionCode }; List <Type> types = assemblyInjectionCode.FindTypes <ICInject>(); for (int i = 0; i < types.Count; i++) { OnBindInjectors(assemblyInjectionCode, types[i], nodeAssembly, true); } // don't show the assembly if it does not have any injectors if (types.Count > 0) { _rootInjection.Nodes.Add(nodeAssembly); treeInjectionCode.ExpandAll(); } _injectorAssemblyLoaded = true; SendMessageToPlugins(EventType.InjectionAssemblyLoaded, null, null, assemblyName); }
public void CacheStoreCanAddAnEntryWithExpirationTime() { // Arrange var keyName = "MyKeyName"; var keyValue = "MyKeyValue"; var secondsToWait = 2; // Expire Configuration Dictionary <string, TimeSpan> expirationConfiguration = new Dictionary <string, TimeSpan>() { { "MyKeyName", TimeSpan.Parse($"00:00:0{secondsToWait}") } }; // Act ICacheStore _cache = new CacheStore(_memoryCache, expirationConfiguration); _cache.Add <string>(keyName, keyValue); var cacheValue = _memoryCache.Get(keyName); Thread.Sleep(secondsToWait * 1000); var cacheValueAfterExpireTime = _memoryCache.Get <string>(keyName); // Assert Assert.NotNull(cacheValue); Assert.Equal(keyValue, cacheValue); Assert.Null(cacheValueAfterExpireTime); }
static HomeController() { Id = 1; //Adding Intial Record CacheStore.Add(Id.ToString(), new Tutor { Id = 1, Name = "Rahul Malviya", Email = "*****@*****.**", Topics = "AngularJS Assignment", Price = 1000 }); }
private void AddTargetAssembly(string assemblyName) { MonoAssemblyResolver assemblyTarget = null; if (CacheStore.Exists <MonoAssemblyResolver>("mono|" + assemblyName)) { assemblyTarget = CacheStore.Get <MonoAssemblyResolver>("mono|" + assemblyName); } else { assemblyTarget = new MonoAssemblyResolver(assemblyName); CacheStore.Add <MonoAssemblyResolver>("mono|" + assemblyName, assemblyTarget); } // add in the dictionary if (_targetAssemblies.ContainsKey(assemblyName) == false) { _targetAssemblies.Add(assemblyName, assemblyTarget); } // attach message received event assemblyTarget.OnMessageReceived += resolver_OnMessageReceived; // add node var nodeAssembly = new TreeNode { Text = Path.GetFileName(assemblyName), Tag = new BindItem { Assembly = assemblyTarget, Method = null } }; _rootTarget.Nodes.Add(nodeAssembly); List <TypeDefinition> types = assemblyTarget.FindClasses(); for (int i = 0; i < types.Count; i++) { if (types[i].HasMethods) { var nodeClass = new TreeNode { Text = types[i].Name, Tag = types[i] }; nodeAssembly.Nodes.Add(nodeClass); OnBindMethodsDefinitions(assemblyTarget, types[i], nodeClass); } } treeTarget.CollapseAll(); _targetAssemblyLoaded = true; SendMessageToPlugins(EventType.TargetAssemblyLoaded, null, null, assemblyName); }
public T Create(T obj) { Type type = typeof(T); int primID = (int)type.GetProperty(type.Name + "ID").GetValue(obj, null); if (primID == 0) { type.GetProperty(type.Name + "ID").SetValue(obj, CreateRandomID(), null); } CacheStore.Add(obj); return(obj); }
internal static InjectionMapping FromProjectInjectionMapping(ProjectInjectionMapping projMapping) { MonoAssemblyResolver targetAssembly = null; TypeDefinition type = null; MethodDefinition method = null; Type injector = null; if (CacheStore.Exists <MonoAssemblyResolver>(projMapping.TargetAssemblyPath)) { targetAssembly = CacheStore.Get <MonoAssemblyResolver>(projMapping.TargetAssemblyPath); } else { targetAssembly = new MonoAssemblyResolver(projMapping.TargetAssemblyPath); CacheStore.Add <MonoAssemblyResolver>(projMapping.TargetAssemblyPath, targetAssembly); } string classNameKey = targetAssembly.Assembly.Name.Name + "." + projMapping.ClassName; if (CacheStore.Exists <TypeDefinition>(classNameKey)) { type = CacheStore.Get <TypeDefinition>(classNameKey); } else { type = targetAssembly.Assembly.MainModule.GetType(classNameKey); CacheStore.Add <TypeDefinition>(classNameKey, type); } if (CacheStore.Exists <MethodDefinition>(classNameKey + projMapping.MethodName)) { method = CacheStore.Get <MethodDefinition>(classNameKey + projMapping.MethodName); } else { method = type.GetMethodDefinition(projMapping.MethodName, projMapping.MethodParameters); CacheStore.Add <MethodDefinition>(classNameKey + projMapping.MethodName, method); } if (CacheStore.Exists <Type>(projMapping.InjectorType)) { injector = CacheStore.Get <Type>(projMapping.InjectorType); } else { injector = Type.GetType(projMapping.InjectorType); CacheStore.Add <Type>(projMapping.InjectorType, injector); } return(new InjectionMapping(targetAssembly, method, injector)); }
/// <summary> /// Obtiene la configuración de valores misceláneos soportados para la aplicación. /// </summary> /// <returns> /// Colección de valores admitidos. /// </returns> public MiscellaneousSettings GetMiscellaneousSettings() { MiscellaneousSettings miscellaneousSettings = CacheStore.Get <MiscellaneousSettings>(CacheKeys.MiscellaneousSettings); if (miscellaneousSettings != null) { return(miscellaneousSettings); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.MiscellaneousSettings); miscellaneousSettings = this.Execute <MiscellaneousSettings>(request); CacheStore.Add(CacheKeys.MiscellaneousSettings, miscellaneousSettings); return(miscellaneousSettings); }
/// <summary> /// Obtiene la lista de canales para los que se pueden generar tokens o claves transaccionales. /// </summary> /// <returns> /// Lista de <see cref="TokenChannelInfo" /> con los canales soportados para generar tokens transaccionales. /// </returns> public IList <TokenChannelInfo> GetChannels() { List <TokenChannelInfo> tokenChannels = CacheStore.Get <List <TokenChannelInfo> >(CacheKeys.TokenChannels); if (tokenChannels != null) { return(tokenChannels); } IRestRequest request = new AspenRequest(Scope.Autonomous, EndpointMapping.TokenChannels); tokenChannels = this.Execute <List <TokenChannelInfo> >(request); CacheStore.Add(CacheKeys.TokenChannels, tokenChannels); return(tokenChannels); }
/// <summary> /// Obtiene la lista de los tipos de transacción para una aplicación. /// </summary> /// <returns> /// Lista de tipos de transacción soportados. /// </returns> public IList <TranTypeInfo> GetTranTypes() { List <TranTypeInfo> tranTypes = CacheStore.Get <List <TranTypeInfo> >(CacheKeys.TranTypes); if (tranTypes != null) { return(tranTypes); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.TranTypes); tranTypes = this.Execute <List <TranTypeInfo> >(request); CacheStore.Add(CacheKeys.TranTypes, tranTypes); return(tranTypes); }
/// <summary> /// Obtiene los tipos de pagos que se pueden realizar a una cuenta. /// </summary> /// <returns> /// Lista de <see cref="PaymentTypeInfo" /> con los tipos de pago para la aplicación solicitante. /// </returns> public IList <PaymentTypeInfo> GetPaymentTypes() { List <PaymentTypeInfo> paymentTypes = CacheStore.Get <List <PaymentTypeInfo> >(CacheKeys.PaymentTypes); if (paymentTypes != null) { return(paymentTypes); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.PaymentTypes); paymentTypes = this.Execute <List <PaymentTypeInfo> >(request); CacheStore.Add(CacheKeys.PaymentTypes, paymentTypes); return(paymentTypes); }
/// <summary> /// Obtiene la lista de operadores de telefonía móvil soportados por el servicio Aspen. /// </summary> /// <returns> /// Lista de operadores de telefonía soportados. /// </returns> public IList <CarrierInfo> GetCarriers() { List <CarrierInfo> carriers = CacheStore.Get <List <CarrierInfo> >(CacheKeys.Carriers); if (carriers != null) { return(carriers); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.Carriers); carriers = this.Execute <List <CarrierInfo> >(request); CacheStore.Add(CacheKeys.Carriers, carriers); return(carriers); }
/// <summary> /// Obtiene la lista de opciones que representan el menú de una aplicación móvil. /// </summary> /// <returns>Lista de opciones de menú.</returns> public IList <MenuItemInfo> GetMenu() { List <MenuItemInfo> menuItems = CacheStore.Get <List <MenuItemInfo> >(CacheKeys.MenuItems); if (menuItems != null) { return(menuItems); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.MenuItems); menuItems = this.Execute <List <MenuItemInfo> >(request); CacheStore.Add(CacheKeys.MenuItems, menuItems); return(menuItems); }
/// <summary> /// Obtiene la lista de tipos de documento soportados por el servicio Aspen. /// </summary> /// <returns> /// Lista de tipos de documento soportados. /// </returns> public IList <DocTypeInfo> GetDocTypes() { List <DocTypeInfo> docTypes = CacheStore.Get <List <DocTypeInfo> >(CacheKeys.DocTypes); if (docTypes != null) { return(docTypes); } IRestRequest request = new AspenRequest(Scope.Delegated, EndpointMapping.DocTypes); docTypes = this.Execute <List <DocTypeInfo> >(request); CacheStore.Add(CacheKeys.DocTypes, docTypes); return(docTypes); }
/// <summary> /// Obtiene la configuración de valores de configuración soportados para la aplicación. /// </summary> /// <param name="apiKey">El identificador de la aplicación.</param> /// <returns> /// Colección de clavesy valores soportados para la aplicación. /// </returns> public AppMovSettings GetAppSettings(string apiKey) { AppMovSettings appMovSettings = CacheStore.Get <AppMovSettings>(CacheKeys.AppMovSettings); if (appMovSettings != null) { return(appMovSettings); } IRestRequest request = new AspenRequest(Scope.Anonymous, EndpointMapping.AppMovSettings); ServiceLocator.Instance.HeadersManager.AddApiKeyHeader(request, apiKey); appMovSettings = this.Execute <AppMovSettings>(request); CacheStore.Add(CacheKeys.AppMovSettings, appMovSettings); return(appMovSettings); }
public void CacheStoreCanAddAnEntry() { // Arrange var keyName = "MyKeyName"; var keyValue = "MyKeyValue"; // Act ICacheStore _cache = new CacheStore(_memoryCache); _cache.Add <string>(keyName, keyValue); // Assert var cacheValue = _memoryCache.Get(keyName); Assert.NotNull(cacheValue); Assert.Equal(keyValue, cacheValue); }
public JsonResult AddEditDetails(Tutor model) { string status = string.Empty; if (ModelState.IsValid) { if (model.Id > 0) { CacheStore.Remove <Tutor>(model.Id.ToString()); CacheStore.Add <Tutor>(model.Id.ToString(), model); status = "updated"; } else { model.Id = ++Id; CacheStore.Add(Id.ToString(), model); status = "saved"; } } string message = $"Tutor has been { status } successfully!"; return(Json(message, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 添加缓存 /// </summary> /// <param name="key">缓存Key</param> /// <param name="objectToCache">缓存对象</param> /// <param name="policy">缓存策略</param> public static void Add(string key, object objectToCache, CacheItemPolicy policy) { CacheStore.Add(key, objectToCache, policy); }