Пример #1
0
        public void AddTablesHistoryTables(DatabaseSchemaUpdater updater)
        {
            //DML update
            updater.AddTable <StopHistoryEntry>();
            updater.AddTable <PlanningHistoryEntry>();
            updater.AddTable <RecentEntry>();
            updater.DatabaseSchemaVersion = 2;
            updater.Execute();

            //DDL update
            var ctx = (DyanamicDBContext)updater.Context;

            foreach (var entry in ctx.HistoryEntries)
            {
                if (entry.TypeLegacy == HistoryEntry.HistoryEntryTypeLegacy.Stop)
                {
                    entry.TypeIDLegacy = 0;
                    var stopEntry = new StopHistoryEntry {
                        StopID = entry.StopID, Count = entry.Count
                    };
                    ctx.StopHistoryEntries.InsertOnSubmit(stopEntry);
                    ctx.HistoryEntries.DeleteOnSubmit(entry);
                }
                else if (entry.TypeLegacy == HistoryEntry.HistoryEntryTypeLegacy.SourceTarget)
                {
                    entry.TypeIDLegacy = 0;
                    var planningEntry = new PlanningHistoryEntry {
                        StopID = entry.StopID, Count = entry.Count, IsSource = false
                    };
                    var planningEntry2 = new PlanningHistoryEntry {
                        StopID = entry.StopID, Count = entry.Count, IsSource = true
                    };
                    ctx.PlanningHistoryEntries.InsertOnSubmit(planningEntry);
                    ctx.PlanningHistoryEntries.InsertOnSubmit(planningEntry2);
                    ctx.HistoryEntries.DeleteOnSubmit(entry);
                }
                else
                {
                    entry.TypeIDLegacy = 0;
                }
            }
            ctx.SubmitChanges();
        }
Пример #2
0
 public void AddStopHistory(StopGroup stop)
 {
     lock (ctx)
     {
         DateTime now = DateTime.Now;
         var      q   = from e in ctx.StopHistoryEntries
                        where e.StopID == stop.ID
                        select e;
         StopHistoryEntry entry = q.ToList().SingleOrDefault(e => e.IsActive(now));
         if (entry != null)
         {
             entry.RawCount = entry.RawCount + (1 << FloatingBits);
         }
         else
         {
             entry = new StopHistoryEntry(now)
             {
                 Stop = stop, RawCount = 1 << FloatingBits
             };
             ctx.StopHistoryEntries.InsertOnSubmit(entry);
         }
         ctx.SubmitChanges();
     }
 }
Пример #3
0
        public DyanamicDBContext(string connectionString, int currentDDBVersion, bool forbidMigration = false) //currentDDBVersion = Config.DDBVersion
            : base(connectionString)
        {
            if (!DatabaseExists())
            {
                CreateDatabase();
                DatabaseSchemaUpdater versionSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                versionSchemaUpdater.DatabaseSchemaVersion = currentDDBVersion;
                versionSchemaUpdater.Execute();
            }
            else
            {
                DatabaseSchemaUpdater versionSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                int version = versionSchemaUpdater.DatabaseSchemaVersion;
                if (version != currentDDBVersion)
                {
                    if (forbidMigration)
                    {
                        throw new InvalidOperationException("Database migration is forbidden!");
                    }
                    Migrates.Execute(versionSchemaUpdater, version, currentDDBVersion);
                }
            }

            try
            {
                FavoriteEntry entry = FavoriteEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <FavoriteEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                TileEntry entry = TileEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <TileEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                HistoryEntry entry = HistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <HistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                StopHistoryEntry entry = StopHistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <StopHistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                PlanningHistoryEntry entry = PlanningHistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <PlanningHistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                RecentEntry entry = RecentEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <RecentEntry>();
                databaseSchemaUpdater.Execute();
            }
        }