partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Field <PayrollLevelSchemaType>( "level", resolve: context => cache.Components[context.Source.LevelId] ); }
public PayrollScopeSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "PayrollScope"; Field(x => x.ProposalId, nullable: true); Field(x => x.Countries, nullable: true, type: typeof(ListGraphType <PayrollCountryScopeSchemaType>)); this.Extend(client, cache, accessor); }
partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Field <ProductModelSchemaType>( "productModel", resolve: context => cache.ProductModels[context.Source.ProductModelId] ); Field <ListGraphType <ProductDefinitionSchemaType> >( "products", resolve: context => { var model = cache.ProductModels[context.Source.ProductModelId]; return(context.Source.ProductIds .GetBits() .Select(id => model.Products.First(p => p.Id == id))); } ); Field <PayrollScopeSchemaType>( "payrollScope", resolve: context => client.PayrollScope_GetGlobalScopeAsync(context.Source.Id) ); Field <HrScopeSchemaType>( "hrScope", resolve: context => client.HrScope_GetGlobalScopeAsync(context.Source.Id) ); }
public ProposalCountryInputSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "ProposalCountryInput"; Field(x => x.CountryId, nullable: true); Field(x => x.Headcount, nullable: true); this.Extend(client, cache, accessor); }
public UpdateHrScopeSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "UpdateHrScope"; Field(x => x.LevelId, nullable: true); Field(x => x.CountryIds, nullable: true, type: typeof(ListGraphType <IntGraphType>)); this.Extend(client, cache, accessor); }
public ProposalListPageSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "ProposalListPage"; Field(x => x.TotalCount, nullable: true); Field(x => x.Page, nullable: true); Field(x => x.Rows, nullable: true, type: typeof(ListGraphType <ProposalSchemaType>)); this.Extend(client, cache, accessor); }
public HrCountryScopeSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "HrCountryScope"; Field(x => x.ProposalId, nullable: true); Field(x => x.CountryId, nullable: true); Field(x => x.Level, nullable: true, type: typeof(ComponentSchemaType)); this.Extend(client, cache, accessor); }
public ProductModelSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "ProductModel"; Field(x => x.Id, nullable: false); Field(x => x.Name, nullable: true); Field(x => x.Products, nullable: true, type: typeof(ListGraphType <ProductDefinitionSchemaType>)); this.Extend(client, cache, accessor); }
public void cleanupTest() { //cache.Dispose(); cache = null; dbRef.Dispose(); dbRef = null; System.GC.WaitForPendingFinalizers(); }
public UpdateProposalSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "UpdateProposal"; Field(x => x.ProposalId, nullable: true); Field(x => x.Name, nullable: true); Field(x => x.ClientName, nullable: true); Field(x => x.Comments, nullable: true); this.Extend(client, cache, accessor); }
public CreateProposalSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "CreateProposal"; Field(x => x.Name, nullable: false); Field(x => x.ClientName, nullable: false); Field(x => x.Comments, nullable: true); Field(x => x.Countries, nullable: false, type: typeof(ListGraphType <ProposalCountryInputSchemaType>)); this.Extend(client, cache, accessor); }
public CountrySchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "Country"; Field(x => x.Id, nullable: false); Field(x => x.Name, nullable: true); Field(x => x.IsoCode, nullable: true); Field(x => x.RegionId, nullable: true); Field(x => x.RegionName, nullable: true); this.Extend(client, cache, accessor); }
public void setupTest() { // set current directory to expected value, i.e. directory of binaries, so relative paths for databases work as expected // Note: otherwise likely to fail as default current directory may be within protected dir, e.g. Visual Studio install directory Directory.SetCurrentDirectory(Path.GetDirectoryName((Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly())?.Location)); // WARNING! test.db must be setup already with proper schema dbRef = new Database(@"C:\DB\test.db"); cache = new ReferenceDataCache(dbRef); }
partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Field <ProductDefinitionSchemaType>( "payroll", resolve: context => cache.ProductModels[context.Source.Id].Products.Find(p => p.Id == (long)ProductType.Payroll) ); Field <ProductDefinitionSchemaType>( "hr", resolve: context => cache.ProductModels[context.Source.Id].Products.Find(p => p.Id == (long)ProductType.Hr) ); }
public void Exercise() { UnitTest.Caching.Policy.CachePolicyManagerTest.TestSetUp(); var coll = new TestRdCollection { new TestRd { Id = 1, Code = "A" }, new TestRd { Id = 2, Code = "B" } }; int i = 0; var rdc = new ReferenceDataCache <TestRdCollection, TestRd>(() => { i++; return(Task.FromResult(coll)); }); // Nothing loaded. Assert.AreEqual(0, i); Assert.AreEqual(0, rdc.Count); Assert.IsTrue(rdc.IsExpired); // Now loaded. var c = rdc.GetCollection(); Assert.AreEqual(1, i); Assert.IsNotNull(c); Assert.AreEqual(2, c.ActiveList.Count); Assert.AreEqual(2, rdc.Count); Assert.IsFalse(rdc.IsExpired); // Same cached version. c = rdc.GetCollection(); Assert.AreEqual(1, i); Assert.IsNotNull(c); Assert.AreEqual(2, c.ActiveList.Count); Assert.AreEqual(2, rdc.Count); Assert.IsFalse(rdc.IsExpired); // Expire the cache; entries remain. rdc.GetPolicy().Refresh(); Assert.AreEqual(1, i); Assert.IsTrue(rdc.IsExpired); Assert.AreEqual(2, rdc.Count); // New collection cached. c = rdc.GetCollection(); Assert.AreEqual(2, i); Assert.IsNotNull(c); Assert.AreEqual(2, c.ActiveList.Count); Assert.AreEqual(2, rdc.Count); Assert.IsFalse(rdc.IsExpired); }
public ComponentSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "Component"; Field(x => x.Id, nullable: false); Field(x => x.Name, nullable: true); Field(x => x.FullName, nullable: true); Field(x => x.IsActive, nullable: true); Field(x => x.SortOrder, nullable: true); Field(x => x.ProductId, nullable: true); Field(x => x.ComponentTypeID, nullable: true); this.Extend(client, cache, accessor); }
public ProposalCountrySchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "ProposalCountry"; Field(x => x.Id, nullable: false); Field(x => x.ProposalId, nullable: true); Field(x => x.CountryId, nullable: true); Field(x => x.Name, nullable: true); Field(x => x.ProductModelId, nullable: true); Field(x => x.ProductIds, nullable: true); Field(x => x.Headcount, nullable: true); this.Extend(client, cache, accessor); }
public UpdatePayrollCountryScopeSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "UpdatePayrollCountryScope"; Field(x => x.CountryId, nullable: true); Field(x => x.LevelId, nullable: true); Field(x => x.WeeklyPayees, nullable: true); Field(x => x.BiWeeklyPayees, nullable: true); Field(x => x.SemiMonthlyPayees, nullable: true); Field(x => x.MonthlyPayees, nullable: true); Field(x => x.Reporting, nullable: true); Field(x => x.PayslipStorage, nullable: true); this.Extend(client, cache, accessor); }
partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Field <ListGraphType <ProductDefinitionSchemaType> >( "products", resolve: context => { var model = cache.ProductModels[context.Source.ProductModelId]; return(context.Source.ProductIds .GetBits() .Select(id => model.Products.First(p => p.Id == id))); } ); Field <PayrollCountryScopeSchemaType, PayrollCountryScopeViewModel>() .Name("payrollScope") .ResolveAsync(context => { var loader = accessor.Context.GetOrAddBatchLoader <Tuple <int, int>, PayrollCountryScopeViewModel>( "GetPayrollCountryScopes", async keys => { var countriesByProposal = await Task.WhenAll(keys .GroupBy(key => key.Item1) .Select(group => client.PayrollScope_GetCountryScopeAsync(group.Key, null))); return(countriesByProposal .SelectMany(batch => batch) .ToDictionary(c => Tuple.Create(c.ProposalId, c.CountryId))); } ); return(loader.LoadAsync(Tuple.Create(context.Source.ProposalId, context.Source.CountryId))); } ); Field <HrCountryScopeSchemaType, HrCountryScopeViewModel>() .Name("hrScope") .ResolveAsync(context => { var loader = accessor.Context.GetOrAddBatchLoader <Tuple <int, int>, HrCountryScopeViewModel>( "GetHrCountryScopes", async keys => { var countriesByProposal = await Task.WhenAll(keys .GroupBy(key => key.Item1) .Select(group => client.HrScope_GetCountryScopeAsync(group.Key, null))); return(countriesByProposal .SelectMany(batch => batch) .ToDictionary(c => Tuple.Create(c.ProposalId, c.CountryId))); } ); return(loader.LoadAsync(Tuple.Create(context.Source.ProposalId, context.Source.CountryId))); } ); }
public SalesSchemaQueryRoot(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Field <ProposalSchemaType>( "Proposal", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "id" }), resolve: context => client.Proposals_GetProposalAsync(context.GetArgument <int>("id")) ); Field <ProposalListPageSchemaType>( "ProposalListPage", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "page", DefaultValue = 1 }, new QueryArgument <IntGraphType> { Name = "rowsPerPage", DefaultValue = 25 }, new QueryArgument <StringGraphType> { Name = "orderBy", DefaultValue = "name" }, new QueryArgument <StringGraphType> { Name = "order", DefaultValue = "asc" }, new QueryArgument <IntGraphType> { Name = "hasProduct" }, new QueryArgument <IntGraphType> { Name = "hasAnyProduct" } ), resolve: context => client.Proposals_GetProposalsAsync( context.GetArgument <int>("page"), context.GetArgument <int>("rowsPerPage")) ); Field <ListGraphType <CountrySchemaType> >( "Countries", resolve: context => client.Countries_GetCountriesAsync() ); Field <ListGraphType <ProductModelSchemaType> >( "ProductModels", resolve: context => cache.ProductModels.Values ); }
private void referenceDataType_SelectionChanged(object sender, SelectionChangedEventArgs eventArgs) { try { if (eventArgs.AddedItems.Count >= 1) { // selection is one of referenceDataType items added to combobox in // constructor, should match name of DB table and corresponding DataModel class dynamic selection = eventArgs.AddedItems[0]; logger.Debug(selection); // get reference to data repository from main Application var db = DataRepository.GetDataRepository; try { // convert class name to Type object, note since not in same DLL, need to use full specifier var objType = ReferenceDataCache.GetReferenceType(selection.TypeName); // initialize our UserControl with reference to how to create new objects and list of existing ones #pragma warning disable IDE0039 // Use local function Func <ItemBase> newItemFn = delegate() { return((ItemBase)Activator.CreateInstance(objType)); }; #pragma warning restore IDE0039 // Use local function ItemList.Initialize(newItemFn, db.ReferenceData[selection.TypeName]); } catch (Exception e) { // verify able to obtain type, in case typo or other error ... logger.Warn(e, $"ReferenceData.SelectionChanged({selection}) - failed to obtain Type, list not updated."); ItemList.Initialize(null, null); } } else { // if nothing selected, just reset ItemList.Initialize(null, null); } } catch (Exception e) { logger.Error(e); throw; } }
partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { }
public void Exercise_SlidingCache() { UnitTest.Caching.Policy.CachePolicyManagerTest.TestSetUp(); var coll = new TestRdCollection { new TestRd { Id = 1, Code = "A" }, new TestRd { Id = 2, Code = "B" } }; var policy = new SlidingCachePolicy { Duration = new TimeSpan(0, 0, 3), MaxDuration = new TimeSpan(0, 0, 4) }; int dataRequests = 0; var rdc = new ReferenceDataCache <TestRdCollection, TestRd>(() => { dataRequests++; return(Task.FromResult(coll)); }); CachePolicyManager.Current.Set(rdc.PolicyKey, policy); // Nothing loaded. Assert.AreEqual(0, dataRequests); Assert.AreEqual(0, rdc.Count); Assert.IsTrue(rdc.IsExpired); // Now loaded. var c = rdc.GetCollection(); Assert.AreEqual(1, dataRequests); Assert.IsNotNull(c); Assert.AreEqual(2, c.ActiveList.Count); Assert.AreEqual(2, rdc.Count); Assert.IsFalse(rdc.IsExpired); // Multiple cycles to test Max cache for (int cycle = 0; cycle < 3; cycle++) { coll.Add(new TestRd { Id = 3 + cycle, Code = $"X{3 + cycle}" }); // Running till max cache expires. while (!rdc.IsExpired) { c = rdc.GetCollection(); Assert.AreEqual(1 + cycle, dataRequests); Assert.IsNotNull(c); Assert.AreEqual(3 + cycle, c.ActiveList.Count); Assert.AreEqual(3 + cycle, rdc.Count); Assert.IsFalse(rdc.IsExpired); System.Threading.Thread.Sleep((int)Math.Floor(policy.Duration.TotalMilliseconds / 2)); } // reload collection cached. c = rdc.GetCollection(); Assert.AreEqual(2 + cycle, dataRequests); Assert.IsNotNull(c); Assert.AreEqual(3 + cycle, c.ActiveList.Count); Assert.AreEqual(3 + cycle, rdc.Count); Assert.IsFalse(rdc.IsExpired); // New collection cached. c = rdc.GetCollection(); Assert.AreEqual(2 + cycle, dataRequests); Assert.IsNotNull(c); Assert.AreEqual(3 + cycle, c.ActiveList.Count); Assert.AreEqual(3 + cycle, rdc.Count); Assert.IsFalse(rdc.IsExpired); } }
public UpdateProposalCountriesSchemaType(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor) { Name = "UpdateProposalCountries"; Field(x => x.Countries, nullable: true, type: typeof(ListGraphType <ProposalCountryInputSchemaType>)); this.Extend(client, cache, accessor); }