Exemplo n.º 1
0
 partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor)
 {
     Field <PayrollLevelSchemaType>(
         "level",
         resolve: context => cache.Components[context.Source.LevelId]
         );
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 public void cleanupTest()
 {
     //cache.Dispose();
     cache = null;
     dbRef.Dispose();
     dbRef = null;
     System.GC.WaitForPendingFinalizers();
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
 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)
         );
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 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);
 }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
 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)));
     }
                   );
 }
Exemplo n.º 20
0
        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
                );
        }
Exemplo n.º 21
0
        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;
            }
        }
Exemplo n.º 22
0
 partial void Extend(ProposingClient client, ReferenceDataCache cache, IDataLoaderContextAccessor accessor)
 {
 }
Exemplo n.º 23
0
        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);
            }
        }
Exemplo n.º 24
0
 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);
 }