public static DatabaseResourceLibrary Create(IQuiltContextFactory quiltContextFactory, JToken json)
        {
            if (json == null)
            {
                throw new ArgumentNullException(nameof(json));
            }

            var libraryName = json.Value <string>(Json_Name);

            using (var ctx = quiltContextFactory.Create())
            {
                var dbResourceLibrary = ctx.ResourceLibraries.Where(r => r.Name == libraryName).SingleOrDefault();
                if (dbResourceLibrary == null)
                {
                    dbResourceLibrary = new ResourceLibrary()
                    {
                        Name = libraryName
                    };
                    _ = ctx.ResourceLibraries.Add(dbResourceLibrary);
                }

                foreach (var jsonEntry in json[Json_Entries])
                {
                    var entry = new ResourceLibraryEntry(jsonEntry);

                    var dbResourceType = ctx.ResourceTypes.Where(r => r.Name == entry.Type).SingleOrDefault();
                    if (dbResourceType == null)
                    {
                        // Look for resource types created below.  These entries aren't normally found until
                        // ctx.SaveChanges is called.
                        //
                        dbResourceType = ctx.ResourceTypes.Local.Where(r => r.Name == entry.Type).SingleOrDefault();
                    }
                    if (dbResourceType == null)
                    {
                        dbResourceType = new ResourceType()
                        {
                            Name = entry.Type
                        };
                        _ = ctx.ResourceTypes.Add(dbResourceType);
                    }

                    var dbResource = dbResourceLibrary.Resources.Where(r => r.Name == entry.Name).SingleOrDefault();
                    if (dbResource == null)
                    {
                        dbResource = new Resource()
                        {
                            Name = entry.Name
                        };
                        _ = ctx.Resources.Add(dbResource);
                    }
                    dbResource.ResourceType = dbResourceType;
                    dbResource.ResourceData = entry.Data;
                }

                _ = ctx.SaveChanges();
            }

            return(Load(quiltContextFactory, libraryName));
        }
Exemple #2
0
        public static void CreateDatabase(IQuiltContextFactory quiltContextFactory)
        {
            using var ctx = quiltContextFactory.Create();

            _ = ctx.Database.EnsureCreated();
            ExecuteScript(ctx, Resources.ModelCreateViews);
        }
Exemple #3
0
        private static void CreateTestPricingSchedules(IQuiltContextFactory quiltContextFactory)
        {
            using var ctx = quiltContextFactory.Create();

            var dbPricingSchedule = ctx.PricingSchedules.Where(r => r.Name == TestPricingScheduleName).SingleOrDefault();

            if (dbPricingSchedule == null)
            {
                dbPricingSchedule = new PricingSchedule()
                {
                    Name = TestPricingScheduleName
                };
                _ = ctx.PricingSchedules.Add(dbPricingSchedule);
            }

            CreateTestPricingScheduleEntry(ctx, dbPricingSchedule, UnitOfMeasureCodes.FatQuarter, 2.5m);

            CreateTestPricingScheduleEntry(ctx, dbPricingSchedule, UnitOfMeasureCodes.HalfYardage, 5.0m);

            CreateTestPricingScheduleEntry(ctx, dbPricingSchedule, UnitOfMeasureCodes.Yardage, 10.0m);

            CreateTestPricingScheduleEntry(ctx, dbPricingSchedule, UnitOfMeasureCodes.TwoYards, 20.0m);

            CreateTestPricingScheduleEntry(ctx, dbPricingSchedule, UnitOfMeasureCodes.ThreeYards, 30.0m);

            _ = ctx.SaveChanges();
        }
Exemple #4
0
        private static void CreateStandardStates(IConfiguration configuration, IQuiltContextFactory quiltContextFactory)
        {
            var text  = AzureUtility.LoadAzureStringBlob(configuration, "database-load", "states.csv");
            var lines = text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            using var ctx = quiltContextFactory.Create();

            var dbCountry = ctx.Countries.Where(r => r.CountryCode == "US").SingleOrDefault();

            if (dbCountry == null)
            {
                dbCountry = new Country()
                {
                    CountryCode = "US",
                    Name        = "United States"
                };
                _ = ctx.Countries.Add(dbCountry);
            }

            foreach (var line in lines)
            {
                var fields = line.Split(new char[] { ',' });

                var stateCode   = fields[0];
                var name        = fields[1];
                var countryCode = fields[2];

                CreateState(ctx, stateCode, name, countryCode);
            }

            _ = ctx.SaveChanges();
        }
Exemple #5
0
        public void Run(IReportWriter wtr, IQuiltContextFactory quiltContextFactory)
        {
            WriteHeading(wtr);

            using (var conn = quiltContextFactory.CreateConnection())
            {
                conn.Open();

                var records = GetRecords(conn);

                TRecord previousRecord = null;

                foreach (var record in records)
                {
                    var currentBreakLevel = GetBreakLevel(record, previousRecord);

                    for (int breakLevel = BreakLevelMax; breakLevel >= currentBreakLevel; --breakLevel)
                    {
                        WriteTotals(wtr, breakLevel);
                    }

                    WriteRecord(wtr, record, previousRecord, currentBreakLevel);

                    AccumulateTotals(record);

                    previousRecord = record;
                }
            }

            for (int breakLevel = BreakLevelMax; breakLevel >= BreakLevelMin; --breakLevel)
            {
                WriteTotals(wtr, breakLevel);
            }
        }
Exemple #6
0
 public MicroService(
     IApplicationLocale locale,
     ILogger logger,
     IQuiltContextFactory quiltContextFactory)
 {
     Locale = locale ?? throw new ArgumentNullException(nameof(locale));
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
     QuiltContextFactory = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
 }
Exemple #7
0
 public LedgerMicroService(
     IApplicationLocale locale,
     ILogger <LedgerMicroService> logger,
     IQuiltContextFactory quiltContextFactory)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
 }
Exemple #8
0
        //private static void CreateStandardResourcesX(IApplicationConfiguration appConfiguration, QuiltContextFactory quiltContextFactory)
        //{
        //    var json = AbstractResourceLibrary.AzureLoad(appConfiguration, Constants.DefaultComponentCategory);
        //    DatabaseResourceLibrary.Create(quiltContextFactory, json);

        //    var library = DatabaseResourceLibrary.Load(quiltContextFactory, Constants.DefaultComponentCategory);
        //    foreach (var entry in library.GetEntries())
        //    {
        //        var node = ResourceNodeFactory.Create(entry);
        //        library.UpdateEntry(entry.Name, node.JsonSave().ToString());
        //    }
        //}

        private static void CreateStandardShippingVendors(IQuiltContextFactory quiltContextFactory)
        {
            using var ctx = quiltContextFactory.Create();

            CreateShippingVendor(ctx, "USPS");
            CreateShippingVendor(ctx, "FedEx");
            CreateShippingVendor(ctx, "UPS");

            _ = ctx.SaveChanges();
        }
 public DomainMicroService(
     IApplicationLocale locale,
     ILogger <DesignMicroService> logger,
     IQuiltContextFactory quiltContextFactory)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
 }
        public static DatabaseResourceLibrary Load(IQuiltContextFactory quiltContextFactory, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(m_cachedLibraries.TryGetValue(name, out var library)
                ? library :
                   LoadSync(quiltContextFactory, name));
        }
Exemple #11
0
 public BusinessOperation(
     ILogger applicationLogger,
     IApplicationLocale applicationLocale,
     IQuiltContextFactory quiltContextFactory,
     ICommunicationMicroService communicationMicroService)
 {
     Logger = applicationLogger ?? throw new ArgumentNullException(nameof(applicationLogger));
     Locale = applicationLocale ?? throw new ArgumentNullException(nameof(applicationLocale));
     QuiltContextFactory       = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
     CommunicationMicroService = communicationMicroService ?? throw new ArgumentNullException(nameof(communicationMicroService));
 }
        private DatabaseResourceLibrary(IQuiltContextFactory quiltContextFactory, long resourceLibraryId, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            m_quiltContextFactory = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
            m_resourceLibraryId   = resourceLibraryId;
            m_name = name;
        }
 public MockMicroEventMicroService(
     IApplicationLocale locale,
     ILogger logger,
     IQuiltContextFactory quiltContextFactory,
     IServiceProvider serviceProvider)
 {
     Locale = locale ?? throw new ArgumentNullException(nameof(locale));
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
     QuiltContextFactory = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
     ServiceProvider     = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
 }
Exemple #14
0
 public ProjectEventMicroService(
     IApplicationLocale locale,
     ILogger <ProjectEventMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     IServiceProvider serviceProvider)
     : base(
         locale,
         logger,
         quiltContextFactory,
         serviceProvider)
 {
 }
Exemple #15
0
 public InventoryMicroService(
     IApplicationLocale locale,
     ILogger <InventoryMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     ICacheMicroService cache)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
     m_cache = cache ?? throw new ArgumentNullException(nameof(cache));
 }
Exemple #16
0
 public UspsAddressValidateOperation(
     ILogger applicationLogger,
     IApplicationLocale applicationLocale,
     IQuiltContextFactory quiltContextFactory,
     ICommunicationMicroService communicationMicroService)
     : base(
         applicationLogger,
         applicationLocale,
         quiltContextFactory,
         communicationMicroService)
 {
 }
 public UserMicroService(
     IApplicationLocale locale,
     ILogger <UserMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     IUserEventMicroService userEventService)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
     UserEventService = userEventService ?? throw new ArgumentNullException(nameof(userEventService));
 }
Exemple #18
0
 public UserManagementMicroService(
     IApplicationLocale locale,
     ILogger <UserMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     UserManager <IdentityUser> userManager)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
     UserManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
 }
Exemple #19
0
 public SalesTaxLookupOperation(
     ILogger applicationLogger,
     IApplicationLocale applicationLocale,
     IQuiltContextFactory quiltContextFactory,
     ICommunicationMicroService communicationMicroService)
     : base(
         applicationLogger,
         applicationLocale,
         quiltContextFactory,
         communicationMicroService)
 {
 }
Exemple #20
0
 public DebugController(
     IApplicationLocale applicationLocale,
     IDomainMicroService domainMicroService,
     IQuiltContextFactory quiltContextFactory,
     IOptionsMonitor <ApplicationOptions> applicationOptions,
     ISquareMicroService squareMicroService)
     : base(
         applicationLocale,
         domainMicroService)
 {
     QuiltContextFactory = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
     ApplicationOptions  = applicationOptions ?? throw new ArgumentNullException(nameof(applicationOptions));
     SquareMicroService  = squareMicroService ?? throw new ArgumentNullException(nameof(squareMicroService));
 }
 public ProjectMicroService(
     IApplicationLocale locale,
     ILogger <ProjectMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     IProjectEventMicroService projectEventService,
     IInventoryMicroService inventoryMicroService)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
     ProjectEventService   = projectEventService ?? throw new ArgumentNullException(nameof(projectEventService));
     InventoryMicroService = inventoryMicroService ?? throw new ArgumentNullException(nameof(inventoryMicroService));
 }
 public CommunicationMicroService(
     IApplicationLocale locale,
     ILogger <CommunicationMicroService> logger,
     IQuiltContextFactory quiltContextFactory,
     IApplicationEmailSender applicationEmailSender,
     ICommunicationEventMicroService communicationEventService)
     : base(
         locale,
         logger,
         quiltContextFactory)
 {
     ApplicationEmailSender    = applicationEmailSender ?? throw new ArgumentNullException(nameof(applicationEmailSender));
     CommunicationEventService = communicationEventService ?? throw new ArgumentNullException(nameof(communicationEventService));
 }
        public void Run(IReportWriter wtr, IQuiltContextFactory quiltContextFactory)
        {
            using var conn = quiltContextFactory.CreateConnection();

            conn.Open();

            // Get list of tables.
            //
            var tableNames = new List <string>();

            using (var cmd = new SqlCommand("select name from sys.tables order by name", conn))
            {
                using var rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    var tableName = rdr.GetString(0);
                    tableNames.Add(tableName);
                }
            }

            // Get record count for each table.
            //
            var recordCounts = new Dictionary <string, int>();

            foreach (var tableName in tableNames)
            {
#pragma warning disable CA2100 // Review SQL queries for security vulnerabilities
                using var cmd = new SqlCommand("select count(*) from [" + tableName + "]", conn);

                using var rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    var recordCount = rdr.GetInt32(0);
                    recordCounts.Add(tableName, recordCount);
                }
            }

            // Write report.
            //
            wtr.DefineColumn("Table Name");
            wtr.DefineColumn("Record Count");
            foreach (var tableName in tableNames)
            {
                wtr.WriteCell(tableName, 1);
                wtr.WriteCell(recordCounts[tableName].ToString(), 1);
            }
        }
        private static DatabaseResourceLibrary LoadSync(IQuiltContextFactory quiltContextFactory, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (!m_cachedLibraries.TryGetValue(name, out var library))
            {
                library = Create(quiltContextFactory, name);
                m_cachedLibraries[name] = library;
            }

            return(library);
        }
 public UserAdminService(
     IApplicationRequestServices requestServices,
     ILogger <UserAdminService> logger,
     IQuiltContextFactory quiltContextFactory,
     //UserManager<IdentityUser> userManager,
     IOrderMicroService orderMicroService,
     ISquareMicroService squareMicroService,
     IUserMicroService userMicroService,
     IUserManagementMicroService userManagementMicroService)
     : base(requestServices, logger)
 {
     QuiltContextFactory        = quiltContextFactory ?? throw new ArgumentNullException(nameof(quiltContextFactory));
     OrderMicroService          = orderMicroService ?? throw new ArgumentNullException(nameof(orderMicroService));
     SquareMicroService         = squareMicroService ?? throw new ArgumentNullException(nameof(squareMicroService));
     UserMicroService           = userMicroService ?? throw new ArgumentNullException(nameof(userMicroService));
     UserManagementMicroService = userManagementMicroService ?? throw new ArgumentNullException(nameof(userManagementMicroService));
 }
Exemple #26
0
        private static void CreateTestStockTransactions(IQuiltContextFactory quiltContextFactory, DateTime utcNow, DateTime localNow)
        {
            using var ctx = quiltContextFactory.Create();

            var builder = ctx.GetInventoryItemStockTransactionBuilder(utcNow, localNow).Begin();

            foreach (var dbInventoryItem in ctx.InventoryItems.ToList())
            {
                if (dbInventoryItem.Quantity == 0)
                {
                    _ = builder.AddInventoryItemStock(dbInventoryItem.InventoryItemId, UnitOfMeasureCodes.FatQuarter, TestInventoryUnitCost, 4 * 50);
                }
            }

            _ = builder.Create();

            _ = ctx.SaveChanges();
        }
        private static DatabaseResourceLibrary Create(IQuiltContextFactory quiltContextFactory, string name)
        {
            using var ctx = quiltContextFactory.Create();

            var dbResourceLibrary = ctx.ResourceLibraries.Where(r => r.Name == name).SingleOrDefault();

            if (dbResourceLibrary == null)
            {
                dbResourceLibrary = new ResourceLibrary()
                {
                    Name = name
                };
                _ = ctx.ResourceLibraries.Add(dbResourceLibrary);

                _ = ctx.SaveChanges();
            }

            return(new DatabaseResourceLibrary(quiltContextFactory, dbResourceLibrary.ResourceLibraryId, name));
        }
Exemple #28
0
        private static void CreateTestLedgerAccountTransactions(IQuiltContextFactory quiltContextFactory, DateTime utcNow, DateTime localNow)
        {
            using var ctx = quiltContextFactory.Create();

            var unitOfWork = new UnitOfWork("TEMP");

            var dbLedgerTransaction = ctx.LedgerTransactions.Where(r => r.Description == TestLedgerAccountTransactionDescription).SingleOrDefault();

            if (dbLedgerTransaction == null)
            {
                _ = ctx.CreateLedgerAccountTransactionBuilder()
                    .Begin(TestLedgerAccountTransactionDescription, localNow, utcNow)
                    .UnitOfWork(unitOfWork)
                    .Debit(LedgerAccountNumbers.Cash, 50000.00m)
                    .Credit(LedgerAccountNumbers.OwnersEquity, 50000.00m)
                    .Create();

                _ = ctx.SaveChanges();
            }
        }
Exemple #29
0
        private static void CreateTestAccountingYears(IQuiltContextFactory quiltContextFactory)
        {
            using var ctx = quiltContextFactory.Create();

            var year = DateTime.Now.Year;

            var dbAccountingYear = ctx.AccountingYears.Where(r => r.Year == year).SingleOrDefault();

            if (dbAccountingYear == null)
            {
                dbAccountingYear = new AccountingYear()
                {
                    Year = year,
                    AccountingYearStatusCode = AccountingYearStatusTypeCodes.Open
                };
                _ = ctx.AccountingYears.Add(dbAccountingYear);

                _ = ctx.SaveChanges();
            }
        }
Exemple #30
0
        public static void CreateStandardResources(IQuiltContextFactory quiltContextFactory)
        {
            var library = DatabaseResourceLibrary.Load(quiltContextFactory, Constants.DefaultComponentCategory);

            foreach (var nodeGenerator in GetNodeGenerators())
            {
                foreach (var item in nodeGenerator.Generate())
                {
                    var entry = library.GetEntry(item.Name);
                    if (entry == null)
                    {
                        library.CreateEntry(item.Name, DatabaseBlockComponentProvider.ResourceTypePrefix + BlockComponent.TypeName, item.Node.JsonSave().ToString(), item.Tags);
                    }
                    else
                    {
                        library.UpdateEntry(item.Name, item.Node.JsonSave().ToString(), item.Tags);
                    }
                }
            }
        }