protected virtual IServiceConfiguration <IDiscoveryService> GetServiceConfiguration(CrmConnection connection) { var mode = connection.ServiceConfigurationInstanceMode; if (mode == ServiceConfigurationInstanceMode.Static) { return(_config ?? (_config = CreateServiceConfiguration(connection))); } if (mode == ServiceConfigurationInstanceMode.PerName) { var key = connection.GetConnectionId(); if (!_configLookup.ContainsKey(key)) { _configLookup[key] = CreateServiceConfiguration(connection); } return(_configLookup[key]); } if (mode == ServiceConfigurationInstanceMode.PerRequest && HttpSingleton <IServiceConfiguration <IDiscoveryService> > .Enabled) { var key = connection.GetConnectionId(); return(HttpSingleton <IServiceConfiguration <IDiscoveryService> > .GetInstance(key, () => CreateServiceConfiguration(connection))); } var config = CreateServiceConfiguration(connection); return(config); }
private static void LoadOutputCache(object sender, EventArgs e) { var name = AdxstudioCrmConfigurationManager.GetCrmSection().OutputObjectCacheName; var keys = HttpSingleton <OutputCacheKeyCollection> .GetInstance(name, () => new OutputCacheKeyCollection()); HttpContext.Current.Response.AddCacheItemDependencies(keys.ToArray()); }
public async Task <string> PutAsyncCheckOut(List <HistorialActivity> data) { try { var json = JsonConvert.SerializeObject(data); HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = await HttpSingleton.GetInstance().PutAsync(String.Format("{0}api/ActivityHistory", APISettings.API_URL), httpContent).ConfigureAwait(false); result.EnsureSuccessStatusCode(); var respuesta = await result.Content.ReadAsStringAsync(); ErrorResponse response = JsonConvert.DeserializeObject <ErrorResponse>(respuesta); return(response.message); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw new Exception("Ha ocurrido un error al consultar los datos", ex); } }
public async Task <Token> PostUserAsync(Login data) { try { var json = JsonConvert.SerializeObject(data); HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = await HttpSingleton.GetInstance().PostAsync(String.Format("{0}api/Account/token", APISettings.API_URL), httpContent).ConfigureAwait(false); if (result.StatusCode == HttpStatusCode.BadRequest) { throw new WebException("Usuario o contraseƱa incorrectos"); } string jsonResult = await result.Content.ReadAsStringAsync(); Token token = JsonConvert.DeserializeObject <Token>(jsonResult); return(token); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw new Exception("Ha ocurrido un error al consultar los datos", ex); } }
public async Task ValidateProject(string projectID) { try { //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token"); var response = await HttpSingleton.GetInstance().GetAsync(String.Format("{0}/api/Project/{1}", APISettings.API_URL, projectID)).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { var jsonResult = await response.Content.ReadAsStringAsync(); ErrorResponse errorFromAPI = JsonConvert.DeserializeObject <ErrorResponse>(jsonResult); throw new Exception(errorFromAPI.message); } } catch (HttpRequestException ex) { if (ex.Message == "404 (Not Found)") { throw new Exception(ex.Message); } else { throw new Exception("Ha ocurrido un error al consultar los datos", ex); } } }
public async Task <List <SelectedData <TareasModel> > > GetActivityAsync(string idProyecto) { try { var json = await HttpSingleton.GetInstance().GetStringAsync(String.Format("{0}/api/Project/{1}/Activities", APISettings.API_URL, idProyecto)).ConfigureAwait(false); var taskModels = JsonConvert.DeserializeObject <List <TareasModel> > (json); List <SelectedData <TareasModel> > result = new List <SelectedData <TareasModel> >(); foreach (TareasModel obj in taskModels) { result.Add(new SelectedData <TareasModel>(obj, false)); } return(result); } catch (HttpRequestException ex) { if (ex.Message == "404 (Not Found)") { throw new Exception("No fueron encontradas actividades asignadas a este proyecto", ex); } else { throw new Exception("Ha ocurrido un error al consultar los datos", ex); } } }
private bool AddKey(string key) { if (_excludeKeys.Any(key.StartsWith)) { return(false); } return(HttpSingleton <OutputCacheKeyCollection> .Enabled ? HttpSingleton <OutputCacheKeyCollection> .GetInstance(OutputObjectCacheName, () => new OutputCacheKeyCollection()).Add(key) : false); }
/// <summary> /// Retrieves the configured <see cref="IPortalContext"/>. /// </summary> /// <param name="portalName"></param> /// <param name="request"></param> /// <param name="allowDefaultFallback"></param> /// <returns></returns> public virtual IPortalContext CreatePortalContext(string portalName = null, RequestContext request = null, bool allowDefaultFallback = false) { var portalContextElement = GetPortalContextElement(portalName, allowDefaultFallback); var mode = portalContextElement.InstanceMode; if (mode == PortalContextInstanceMode.PerRequest && HttpSingleton <IPortalContext> .Enabled) { return(HttpSingleton <IPortalContext> .GetInstance(portalName, () => portalContextElement.CreatePortalContext(request))); } // PortalContextInstanceMode.PerInstance var portal = portalContextElement.CreatePortalContext(request); return(portal); }
private CacheItemPolicy GetPolicy(ObjectCache cache, DateTime utcExpiry, string regionName) { // Add an output cache specific dependency item and key cache.AddOrGetExisting(_outputCacheDependency, _outputCacheDependency, ObjectCache.InfiniteAbsoluteExpiration, CacheRegionName); // Get the keys from HttpContext var name = AdxstudioCrmConfigurationManager.GetCrmSection().OutputObjectCacheName; var keys = HttpSingleton <OutputCacheKeyCollection> .GetInstance(name, () => new OutputCacheKeyCollection()); // Create Monitor and Policy objects var monitorKeys = keys.Select(d => d.ToLower()).ToArray(); var monitor = GetChangeMonitor(cache, monitorKeys, regionName); var policy = monitor.GetCacheItemPolicy(cache.Name); policy.AbsoluteExpiration = ToDateTimeOffset(utcExpiry); policy.RemovedCallback += CacheEventSource.Log.OnRemovedCallback; return(policy); }
/// <summary> /// Retrieves the configured <see cref="IOrganizationService"/>. /// </summary> /// <param name="connection"></param> /// <param name="serviceName"></param> /// <param name="allowDefaultFallback"></param> /// <returns></returns> public virtual IOrganizationService CreateService(CrmConnection connection, string serviceName = null, bool allowDefaultFallback = false) { var section = GetCrmSection(); var serviceElement = section.Services.GetElementOrDefault(serviceName, allowDefaultFallback); var mode = serviceElement.InstanceMode; var name = serviceElement.Name; if (mode == OrganizationServiceInstanceMode.Static) { // return a single instance return(_service ?? (_service = CreateService(serviceElement, connection))); } if (mode == OrganizationServiceInstanceMode.PerName) { var key = name ?? GetDefaultContextName(); if (!_serviceLookup.ContainsKey(key)) { _serviceLookup[key] = CreateService(serviceElement, connection); } return(_serviceLookup[key]); } if (mode == OrganizationServiceInstanceMode.PerRequest && HttpSingleton <IOrganizationService> .Enabled) { var key = name ?? GetDefaultContextName(); return(HttpSingleton <IOrganizationService> .GetInstance(key, () => CreateService(serviceElement, connection))); } var service = CreateService(serviceElement, connection); return(service); }
public virtual IEnumerable <IOrganizationServiceEventProvider> CreateEventProviders(string eventName = null, bool allowDefaultFallback = false) { var section = GetCrmSection(); var eventElement = section.Events.GetElementOrDefault(eventName, allowDefaultFallback); var mode = eventElement.InstanceMode; var name = !string.IsNullOrWhiteSpace(eventName) ? eventName : eventElement.Name; if (mode == ServiceEventInstanceMode.Static) { // return a single instance return(_eventProviders ?? (_eventProviders = eventElement.CreateEventProviders())); } if (mode == ServiceEventInstanceMode.PerName) { var key = name ?? GetDefaultContextName(); if (!_eventProvidersLookup.ContainsKey(key)) { _eventProvidersLookup[key] = eventElement.CreateEventProviders(); } return(_eventProvidersLookup[key]); } if (mode == ServiceEventInstanceMode.PerRequest && HttpSingleton <IEnumerable <IOrganizationServiceEventProvider> > .Enabled) { var key = name ?? GetDefaultContextName(); return(HttpSingleton <IEnumerable <IOrganizationServiceEventProvider> > .GetInstance(key, eventElement.CreateEventProviders)); } var providers = eventElement.CreateEventProviders(); return(providers); }
protected override void OnStart() { HttpSingleton.Get(AzureBackendUrl); ((App)Application.Current).SwichView <MainPage>(); }