Beispiel #1
0
        public static void SeedHostDb(FrameworkDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            //Host seed
            new InitialHostDbBuilder(context).Create();

            //Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
Beispiel #2
0
        public void Log(LogRecord record)
        {
            using (var db = new FrameworkDbContext())
            {
                // Add the record
                db.Logs.Add(record);

                // Save
                db.SaveChanges();
            }
        }
Beispiel #3
0
        static EntityScriptUtil()
        {
            EntityScriptLazyLoader = new Lazy <ConcurrentDictionary <Type, List <EntityRuleScript> > >(
                () =>
            {
                using (var db = new FrameworkDbContext())
                {
                    var esGroups =
                        from es in db.Set <EntityRuleScript>().ToList()
                        where es.TargetType != null
                        group es by es.TargetType
                        into esGroup
                        select esGroup;

                    var dictionary = esGroups.ToDictionary(esg => esg.Key, esg => esg.ToList());
                    var cach       = new ConcurrentDictionary <Type, List <EntityRuleScript> >(dictionary);
                    return(cach);
                }
            }
                );

            EntityNumberingLazyLoader = new Lazy <ConcurrentDictionary <Type, List <EntityNumbering> > >(
                () =>
            {
                using (var db = new FrameworkDbContext())
                {
                    var enGroups =
                        from en in db.Set <EntityNumbering>().ToList()
                        where en.TargetType != null
                        group en by en.TargetType
                        into enGroup
                        select enGroup;

                    var dictionary = enGroups.ToDictionary(eng => eng.Key, eng => eng.ToList());
                    var cach       = new ConcurrentDictionary <Type, List <EntityNumbering> >(dictionary);
                    return(cach);
                }
            }
                );
        }
        private long RunTest(string testName, List <DummyObject> pack, FrameworkDbContext db)
        {
            LogLine("");
            LogTime(string.Format("{0} test started for {1} items.", testName, pack.Count));

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < pack.Count; i++)
            {
                var p = pack[i];
                db.Set <DummyObject>().Add(p);
                db.SaveChanges();
            }

            var total = stopwatch.ElapsedMilliseconds;

            long average = total / pack.Count;

            LogLine(string.Format("\tAverage: {0} ms.", average));

            return(average);
        }
Beispiel #5
0
 public FrameworkDbContext Init()
 {
     return(dbContext ?? (dbContext = new FrameworkDbContext()));
 }
Beispiel #6
0
 public DefaultSettingsCreator(FrameworkDbContext context)
 {
     _context = context;
 }
 public TestDataBuilder(FrameworkDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Beispiel #8
0
 public HostRoleAndUserCreator(FrameworkDbContext context)
 {
     _context = context;
 }
 private void CreatePaidPayment(FrameworkDbContext context, SubscriptionPayment subscriptionPayment)
 {
     subscriptionPayment.SetAsPaid();
     context.SubscriptionPayments.Add(subscriptionPayment);
 }
 public TestOrganizationUnitsBuilder(FrameworkDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Beispiel #11
0
 public TestSubscriptionPaymentBuilder(FrameworkDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Beispiel #12
0
 public DefaultLanguagesCreator(FrameworkDbContext context)
 {
     _context = context;
 }
        protected override void ExecuteImpl()
        {
            base.ExecuteImpl();

            var testPack = SelectedObject.Id;
            var test     = SelectedObject;


            stopwatch = Stopwatch.StartNew();


            int packSize = 100;

            test.PackSize = packSize;

            Log(string.Format("Creating test objects. Size: {0}", packSize));


            var pack1B =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1B(testPack))
                .ToList();

            var pack1K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1K(testPack))
                .ToList();
            var pack10K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create10K(testPack))
                .ToList();

            var pack100K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create100K(testPack))
                .ToList();

            var pack1000K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1000K(testPack))
                .ToList();

            LogTime("Objects ready.");

            using (var db = new FrameworkDbContext())
            {
                test.AverageTime1B    = RunTest("1B", pack1B, db);
                test.AverageTime1K    = RunTest("1K", pack1K, db);
                test.AverageTime10K   = RunTest("10K", pack10K, db);
                test.AverageTime100K  = RunTest("100K", pack100K, db);
                test.AverageTime1000K = RunTest("1000K", pack1000K, db);

                var queryAll =
                    db.Set <DummyObject>()
                    .Where(d => d.TestPack == testPack);

                LogLine("");
                LogTime("Loading All started.");
                var  list     = queryAll.ToList();
                long loadTime = stopwatch.ElapsedMilliseconds;

                LogLine(string.Format("\tLoad Time:\t{0} ms", loadTime));
                test.LoadAllTime = loadTime;

                LogLine(string.Format("\tCount:\t{0}", list.Count));
                test.LoadAllCount = list.Count;
            }
        }
 public DefaultPersonCreateor(FrameworkDbContext context)
 {
     this._context = context;
 }
Beispiel #15
0
        public static long GetNext(
            string sequenceName,
            string param1  = null,
            string param2  = null,
            string param3  = null,
            string param4  = null,
            string param5  = null,
            string usedFor = null
            )
        {
            using (var db = new FrameworkDbContext())
            {
                var seq = Cache.GetOrAdd(sequenceName, (seqName) =>
                {
                    var s = db.Set <EntitySequence>().FirstOrDefault(es => es.Name == seqName);

                    //if (s == null)
                    //{
                    //    var temp = db.Set<EntitySequence>().Create();
                    //    temp.Name = seqName;
                    //    temp.Description = $"Automatically created for: {usedFor}";
                    //    db.SaveChanges();
                    //}
                    return(s);
                });

                if (seq == null)
                {
                    throw new Exception($"Sequence is not defined: {sequenceName}");
                }

                var sameSequenceItems = db.Set <EntitySequenceItem>()
                                        .Where(si =>
                                               si.Param1 == param1 &&
                                               si.Param2 == param2 &&
                                               si.Param3 == param3 &&
                                               si.Param4 == param4 &&
                                               si.Param5 == param5);

                var maxValue =
                    sameSequenceItems.Any() ?
                    sameSequenceItems.Max(si => si.SeqValue) :
                    0;

                var esi = new EntitySequenceItem(true)
                {
                    SeqValue         = maxValue + 1,
                    EntitySequenceId = seq.Id,
                    CreationDateTime = DateTime.Now,
                    Param1           = param1,
                    Param2           = param2,
                    Param3           = param3,
                    Param4           = param4,
                    Param5           = param5,
                    UsedFor          = usedFor
                };


                db.Set <EntitySequenceItem>().Add(esi);
                db.SaveChanges();

                return(esi.SeqValue);
            }
        }
Beispiel #16
0
 public DefaultEditionCreator(FrameworkDbContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public DefaultTenantBuilder(FrameworkDbContext context)
 {
     _context = context;
 }
Beispiel #18
0
 public InitialHostDbBuilder(FrameworkDbContext context)
 {
     _context = context;
 }
Beispiel #19
0
 public TenantRoleAndUserBuilder(FrameworkDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Beispiel #20
0
 public InitialPeopleCreator(FrameworkDbContext context)
 {
     _context = context;
 }
Beispiel #21
0
 public TestEditionsBuilder(FrameworkDbContext context)
 {
     _context = context;
 }