public void SR_HAPAG_CONDITION() { var context = new ContextHolder { UserProfiles = new SortedSet <int?> { 3 }, ApplicationLookupContext = new ApplicationLookupContext { Schema = "list" } }; var result = ConfigurationService.BuildResultValues <string>(_values, context); Assert.AreEqual("5", result.First().Value.Value); context = new ContextHolder { UserProfiles = new SortedSet <int?> { 3 }, ApplicationLookupContext = new ApplicationLookupContext { Schema = "detail" } }; result = ConfigurationService.BuildResultValues <string>(_values, context); Assert.AreEqual("7", result.First().Value.Value); context = new ContextHolder { UserProfiles = new SortedSet <int?> { 3 }, }; result = ConfigurationService.BuildResultValues <string>(_values, context); Assert.AreEqual("5", result.First().Value.Value); }
public static ContextHolder AddContext(ContextHolder context, bool isHttp) { context.Environment = ApplicationConfiguration.Profile; if (isHttp) { System.Web.HttpContext.Current.Items["context"] = context; } else { LogicalThreadContext.SetData("context", context); } try { var user = SecurityFacade.CurrentUser(); context.UserProfiles = new SortedSet <int?>(user.Profiles.Select(s => s.Id)); context.Environment = ApplicationConfiguration.Profile; context.OrgId = user.OrgId; context.SiteId = user.SiteId; if (isHttp) { System.Web.HttpContext.Current.Items["context"] = context; } else { LogicalThreadContext.SetData("context", context); } Log.DebugFormat("adding context {0}", context); return(context); } catch (Exception e) { //not logged users return(context); } }
public override void OnCreate() { base.OnCreate(); // Clean up the cache before the process starts. CredentialManager.Instance.Exit(this.ApplicationContext); ContextHolder.Init(this.ApplicationContext); }
public void AskAndDoNotFind() { var context = new ContextHolder(); var result = ConfigurationService.BuildResultValues <string>(_list2NoDefault, context); Assert.IsFalse(result.Any()); }
public static bool ValidateRegionSelectionIsAllowed(ContextHolder ctx, InMemoryUser user, bool forceXITCContext = false) { if (forceXITCContext || ctx.IsInModule(FunctionalRole.XItc)) { return(user.IsWWUser()); } return(ctx.IsInAnyModule(FunctionalRole.Tom, FunctionalRole.Itom, FunctionalRole.Purchase, FunctionalRole.AssetControl)); }
public ContextHolder(ContextHolder other) { this.prior = other; this.tracing = other.tracing; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.currentDirectory = other.currentDirectory; }
public ContextHolder() { this.prior = null; this.tracing = false; this.outWriter = Console.Out; this.errorWriter = Console.Error; this.traceWriter = null; this.currentDirectory = Environment.CurrentDirectory; }
public void ModuleAskTest() { var context = new ContextHolder { Module = "xitc", }; var result = ConfigurationService.BuildResultValues <string>(_values, context); Assert.AreEqual("2", result.First().Value.Value); }
public void ModuleAskTest2() { var context = new ContextHolder { Module = "xitc", UserProfiles = new SortedSet <int?> { 2 }, }; var result = ConfigurationService.BuildResultValues <string>(_list1ProfileNoModule, context); Assert.IsFalse(result.Any()); }
public ContextHolder() { this.prior = null; this.tracing = false; this.logging = false; this.outWriter = Console.Out; this.errorWriter = Console.Error; this.traceWriter = null; this.logCapture = new Log4NetCapture(); this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; }
public virtual ConditionMatchResult MatchesConditions(ContextHolder context) { if (Definition != null && false.Equals(Definition.Contextualized)) { return(ConditionMatchResult.Match()); } var result = new ConditionMatchResult(Module, UserProfile); result.AppendModule(Module, context.Module); result.AppendProfile(UserProfile, context.UserProfiles); context.MatchesCondition(Condition, result); return(result); }
public ContextHolder(ContextHolder other) { this.prior = other; this.tracing = other.tracing; this.logging = other.logging; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.logCapture = other.logCapture; this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; }
public void TestCurrentThread() { var internalContainerMock = GetMock <IInternalContainer>(); internalContainerMock.Setup(c => c.CreateNewLog()).Returns((IGroboContainerLog)null); var context = new InjectionContext(internalContainerMock.Object); IContextHolder holder = new ContextHolder(context, Thread.CurrentThread.ManagedThreadId); var internalContainerMock2 = GetMock <IInternalContainer>(); Assert.AreSame(context, holder.GetContext(internalContainerMock2.Object)); holder.KillContext(); CheckGet(holder); }
public void AskForSchemaWithProfile2() { var context = new ContextHolder { UserProfiles = new SortedSet <int?> { 4 }, ApplicationLookupContext = new ApplicationLookupContext { Schema = "detail" } }; var result = ConfigurationService.BuildResultValues <string>(_values3, context); Assert.AreEqual("8", result.First().Value.Value); }
public void TestCurrentThread() { var ic = GetMock <IInternalContainer>(); ic.Expect(c => c.CreateNewLog()).Return(null); var context = new InjectionContext(ic); IContextHolder holder = new ContextHolder(context, Thread.CurrentThread.ManagedThreadId); var ic2 = GetMock <IInternalContainer>(); Assert.AreSame(context, holder.GetContext(ic2)); holder.KillContext(); CheckGet(holder); }
public CoreMethods(CoreTypes types) { Contract.ThrowIfNull(types); PhpValue = new PhpValueHolder(types); PhpAlias = new PhpAliasHolder(types); PhpArray = new PhpArrayHolder(types); PhpNumber = new PhpNumberHolder(types); PhpString = new PhpStringHolder(types); Operators = new OperatorsHolder(types); Ctors = new ConstructorsHolder(types); Context = new ContextHolder(types); Dynamic = new DynamicHolder(types); Reflection = new ReflectionHolder(types); }
public void MetadataAskTest2() { var context = new ContextHolder { UserProfiles = new SortedSet <int?> { 2 }, ApplicationLookupContext = new ApplicationLookupContext { MetadataId = "zzz" }, SiteId = "site" }; var result = ConfigurationService.BuildResultValues <string>(_values, context); Assert.AreEqual("9", result.First().Value.Value); }
public ContextHolder() { this.prior = null; this.tracing = false; this.logging = false; this.outWriter = Console.Out; this.errorWriter = Console.Error; this.traceWriter = null; this.logCapture = new Log4NetCapture(); this.testCaseTimeout = 0; this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; this.currentUICulture = CultureInfo.CurrentUICulture; this.currentPrincipal = System.Threading.Thread.CurrentPrincipal; }
public ContextHolder(ContextHolder other) { this.prior = other; this.tracing = other.tracing; this.logging = other.logging; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.logCapture = other.logCapture; this.testCaseTimeout = other.testCaseTimeout; this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; this.currentUICulture = CultureInfo.CurrentUICulture; this.currentPrincipal = System.Threading.Thread.CurrentPrincipal; }
public void _2ConditionsOneWithModuleAnotherWithout_returnDefault() { var context = new ContextHolder(); IEnumerable <PropertyValue> values = new List <PropertyValue> { new PropertyValue { Value = "1" }, new PropertyValue { Value = "2", Module = "xxx" } }; var result = ConfigurationService.BuildResultValues <string>(values, context); Assert.AreEqual("1", result.First().Value.Value); }
public void TestAnotherThread() { var threadId = Thread.CurrentThread.ManagedThreadId; var internalContainerMock = GetMock <IInternalContainer>(); internalContainerMock.Setup(c => c.CreateNewLog()).Returns((IGroboContainerLog)null); IContextHolder holder = new ContextHolder(new InjectionContext(internalContainerMock.Object), threadId); var task = Task.Run(() => { Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId); CheckGet(holder); }); task.Wait(TimeSpan.FromSeconds(1)); holder.KillContext(); CheckGet(holder); }
public void TestAnotherThread() { var threadId = Thread.CurrentThread.ManagedThreadId; var ic = GetMock <IInternalContainer>(); ic.Expect(c => c.CreateNewLog()).Return(null); IContextHolder holder = new ContextHolder(new InjectionContext(ic), threadId); Action check = () => { Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId); CheckGet(holder); }; var result = check.BeginInvoke(null, null); Assert.That(result.AsyncWaitHandle.WaitOne(1000), "ŠæŠ¾ŃŠ¾Šŗ Š·Š°Š²ŠøŃ"); holder.KillContext(); CheckGet(holder); }
public void AskForModule_DoNotConsiderDefault() { var context = new ContextHolder { Module = "yyy" }; IEnumerable <PropertyValue> values = new List <PropertyValue> { new PropertyValue { Value = "1" }, new PropertyValue { Value = "2", Module = "xxx" } }; var result = ConfigurationService.BuildResultValues <string>(values, context); Assert.IsFalse(result.Any()); }
private HlagGroupedLocation[] HandleSelectedRegion(ContextHolder ctx) { HlagGroupedLocation[] hlagGroupedLocations; //HAP-994 var parentRegion = ctx.MetadataParameters["region"]; Log.DebugFormat("Region {0} was previously selected", parentRegion); try { hlagGroupedLocations = FindLocationsOfParentLocation(new PersonGroup { Name = parentRegion }) .ToArray(); } catch (Exception) { Log.WarnFormat("region {0} not found, applying default", parentRegion); hlagGroupedLocations = FindAllLocations().ToArray(); } return(hlagGroupedLocations); }
private T HandleConditions <T>(IEnumerable <PropertyValue> values, ContextHolder lookupContext, PropertyDefinition definition, ConcurrentDictionary <ContextHolder, object> fromContext, ContextHolder configCacheKey) { var resultingValues = BuildResultValues <T>(values, lookupContext); if (!resultingValues.Any()) { if (lookupContext.Module != null) { //if a module was asked and nothing was found do not return(default(T)); } Log.Debug(String.Format(NoPropertiesForContext, lookupContext)); return(DefaultValueCase <T>(definition, fromContext, configCacheKey)); } return(ValueMatched <T>(definition, resultingValues.First().Value, fromContext, configCacheKey)); }
public T Lookup <T>(string configKey, ContextHolder lookupContext) { ConcurrentDictionary <ContextHolder, object> fromContext; if (ConfigCache.TryGetValue(configKey, out fromContext)) { if (fromContext.ContainsKey(lookupContext)) { Log.DebugFormat("Retrieving key {0} from cache. Retrieved content: {1}", lookupContext, (T)fromContext[lookupContext]); return((T)fromContext[lookupContext]); } } else { fromContext = new ConcurrentDictionary <ContextHolder, object>(); ConfigCache.TryAdd(configKey, fromContext); } var definition = _dao.FindSingleByQuery <PropertyDefinition>(PropertyDefinition.ByKey, configKey); if (definition == null) { Log.Warn(String.Format("property {0} not found", configKey)); return(default(T)); } var values = definition.Values; if (!values.Any()) { return(DefaultValueCase <T>(definition, fromContext, lookupContext)); } if (values.Count == 1) { var propertyValue = values.First(); if (!ConditionMatch.No.Equals(propertyValue.MatchesConditions(lookupContext).MatchType)) { return(ValueMatched <T>(definition, propertyValue, fromContext, lookupContext)); } return(DefaultValueCase <T>(definition, fromContext, lookupContext)); } //TODO: finish Conditions return(HandleConditions <T>(values, lookupContext, definition, fromContext, lookupContext)); }
public void ModuleAskTestCombination() { IEnumerable <PropertyValue> allModulesTest = new List <PropertyValue> { new PropertyValue { Value = "2", Module = Conditions.AnyCondition }, new PropertyValue { Value = "3", Module = "purchase" }, new PropertyValue { Value = "4", Module = "sso,tui" }, }; var context = new ContextHolder { Module = "xitc", }; var result = ConfigurationService.BuildResultValues <string>(allModulesTest, context); Assert.AreEqual("2", result.First().Value.Value); context = new ContextHolder { Module = "purchase", }; result = ConfigurationService.BuildResultValues <string>(allModulesTest, context); Assert.AreEqual("3", result.First().Value.Value); context = new ContextHolder { Module = "sso", }; result = ConfigurationService.BuildResultValues <string>(allModulesTest, context); Assert.AreEqual("4", result.First().Value.Value); context = new ContextHolder { Module = null, }; result = ConfigurationService.BuildResultValues <string>(allModulesTest, context); Assert.AreEqual("2", result.First().Value.Value); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; IJobManager jobManager = new JobManager(); IExchangeRateProvider exchangeRateProvider = new BitfinexExchangeRateProvider(); IContextHolder contextHolder = new ContextHolder(Configuration, jsonSerializerSettings); DaemonClientFactory daemonClientFactory = new DaemonClientFactory(contextHolder, jsonSerializerSettings); IConnectionFactory dbFactory = new PgConnectionFactory(contextHolder); ITransferRequestRepository transferRequestRepository = new TransferRequestRepository(); ITransferRepository transferRepository = new TransferRepository(); NotificationService notificationService = new NotificationService(contextHolder, jsonSerializerSettings); services.AddSingleton <IContextHolder>(contextHolder); services.AddSingleton <IExchangeRateProvider>(exchangeRateProvider); services.AddSingleton <IJobManager>(jobManager); services.AddSingleton <JsonSerializerSettings>(jsonSerializerSettings); services.AddSingleton <DaemonClientFactory>(daemonClientFactory); services.AddSingleton <IConnectionFactory>(dbFactory); services.AddSingleton <ITransferRequestRepository>(transferRequestRepository); services.AddSingleton <ITransferRepository>(transferRepository); services.AddSingleton <NotificationService>(notificationService); jobManager.Start(); //Lazy load, requires explicit instantiation ExchangeRateUpdater exchangeRateUpdater = new ExchangeRateUpdater(jobManager, exchangeRateProvider, contextHolder); PayoutManager payoutManager = new PayoutManager(jobManager, contextHolder, transferRequestRepository, transferRepository, dbFactory, jsonSerializerSettings, daemonClientFactory, notificationService); services.Configure <IISOptions>(options => { options.ForwardClientCertificate = false; }); services.AddSingleton <PayoutManager>(payoutManager); services.RegisterServices(); // Add framework services. services.AddMvc(); }
public ContextHolder( ContextHolder other ) { this.prior = other; this.tracing = other.tracing; this.logging = other.logging; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.logCapture = other.logCapture; this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; }
public ConfigCacheKey(string configKey, ContextHolder conditions) { ConfigKey = configKey; Conditions = conditions; }
/// <summary> /// Restores the last saved context and puts /// any saved settings back into effect. /// </summary> public static void Restore() { current.ReverseChanges(); current = current.prior; }
private void FetchAsync(SlicedEntityMetadata entityMetadata, EntityAssociation collectionAssociation, IDictionary <string, ApplicationCompositionSchema> compositionSchemas, IEnumerable <AttributeHolder> entitiesList, ContextHolder ctx, Dictionary <string, EntityRepository.SearchEntityResult> results, PaginatedSearchRequestDto paginatedSearch) { Quartz.Util.LogicalThreadContext.SetData("context", ctx); var lookupAttributes = collectionAssociation.Attributes; var collectionEntityMetadata = MetadataProvider.Entity(collectionAssociation.To); var targetCollectionAttribute = EntityUtil.GetRelationshipName(collectionAssociation.Qualifier); var applicationCompositionSchema = compositionSchemas[collectionAssociation.Qualifier] as ApplicationCompositionCollectionSchema; if (applicationCompositionSchema == null) { throw ExceptionUtil.InvalidOperation("collection schema {0} not found", collectionAssociation.Qualifier); } var lookupattributes = lookupAttributes as EntityAssociationAttribute[] ?? lookupAttributes.ToArray(); var attributeHolders = entitiesList as AttributeHolder[] ?? entitiesList.ToArray(); var matchingResultWrapper = new CollectionMatchingResultWrapper(); var searchRequestDto = BuildSearchRequestDto(applicationCompositionSchema, lookupattributes, matchingResultWrapper, attributeHolders, collectionEntityMetadata, paginatedSearch); searchRequestDto.QueryAlias = collectionAssociation.To; var firstAttributeHolder = attributeHolders.First(); if (applicationCompositionSchema.PrefilterFunction != null) { var dataSet = DataSetProvider.GetInstance().LookupDataSet(entityMetadata.ApplicationName); //we will call the function passing the first entry, altough this method could have been invoked for a list of items (printing) //TODO: think about it var preFilterParam = new CompositionPreFilterFunctionParameters(entityMetadata.AppSchema, searchRequestDto, firstAttributeHolder, applicationCompositionSchema); searchRequestDto = PrefilterInvoker.ApplyPreFilterFunction(dataSet, preFilterParam, applicationCompositionSchema.PrefilterFunction); } EntityRepository.SearchEntityResult queryResult = null; if (paginatedSearch == null) { //if thereĀ“s no pagination needed we can just do one thread-query queryResult = EntityRepository.GetAsRawDictionary(collectionEntityMetadata, searchRequestDto); } else { var tasks = new Task[2]; tasks[0] = Task.Factory.NewThread(() => { queryResult = EntityRepository.GetAsRawDictionary(collectionEntityMetadata, searchRequestDto); }); // one thread to count results for paginations tasks[1] = Task.Factory.NewThread(() => { paginatedSearch.TotalCount = EntityRepository.Count(collectionEntityMetadata, searchRequestDto); }); Task.WaitAll(tasks); // add paginationData to result // creating a new pagination data in order to have everything calculated correctly queryResult.PaginationData = new PaginatedSearchRequestDto( paginatedSearch.TotalCount, paginatedSearch.PageNumber, paginatedSearch.PageSize, paginatedSearch.SearchValues, paginatedSearch.PaginationOptions ); } // one thread to fetch results results.Add(collectionAssociation.Qualifier, queryResult); if (attributeHolders.Length == 1) { //default scenario, we have just one entity here firstAttributeHolder.Attributes.Add(targetCollectionAttribute, queryResult.ResultList); return; } MatchResults(queryResult, matchingResultWrapper, targetCollectionAttribute); }
/// <summary> /// Saves the old context and makes a fresh one /// current without changing any settings. /// </summary> public static void Save() { TestContext.current = new ContextHolder( current ); }
public ContextHolder( ContextHolder other ) { this.prior = other; this.tracing = other.tracing; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.currentDirectory = other.currentDirectory; }
public ContextHolder( ContextHolder other ) { this.prior = other; this.tracing = other.tracing; this.logging = other.logging; this.outWriter = other.outWriter; this.errorWriter = other.errorWriter; this.traceWriter = other.traceWriter; this.logCapture = other.logCapture; this.testCaseTimeout = other.testCaseTimeout; this.currentDirectory = Environment.CurrentDirectory; this.currentCulture = CultureInfo.CurrentCulture; this.currentUICulture = CultureInfo.CurrentUICulture; this.currentPrincipal = System.Threading.Thread.CurrentPrincipal; }
public CoreMethods(CoreTypes types) { Contract.ThrowIfNull(types); PhpValue = new PhpValueHolder(types); PhpAlias = new PhpAliasHolder(types); PhpArray = new PhpArrayHolder(types); IPhpArray = new IPhpArrayHolder(types); PhpNumber = new PhpNumberHolder(types); PhpString = new PhpStringHolder(types); Operators = new OperatorsHolder(types); Ctors = new ConstructorsHolder(types); Context = new ContextHolder(types); Dynamic = new DynamicHolder(types); Reflection = new ReflectionHolder(types); }