Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        void DeleteAllData(string databasename)
        {
            // データベースにテーブルなどの構造を初期化する
            string sqltext = "";

            System.Reflection.Assembly assm = System.Reflection.Assembly.GetExecutingAssembly();

            using (var stream = assm.GetManifestResourceStream(
                       string.Format("Mogami.CT.xUnit.Assets.Sql.{0}.DeleteAllData.txt", databasename)
                       ))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    sqltext = reader.ReadToEnd();
                }
            }

            if (!string.IsNullOrEmpty(sqltext))
            {
                using (var @dbc = new AppDbContext())
                {
                    @dbc.Database.ExecuteSqlCommand(sqltext);
                    @dbc.SaveChanges();
                }

                using (var @dbc = new ThumbDbContext())
                {
                    @dbc.Database.ExecuteSqlCommand(sqltext);
                    @dbc.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// データベースに関する初期化処理
        /// </summary>
        private void InitializeDatabaseThumbnail()
        {
            ApMetadata apMetadata = null;
            bool       isMigrate  = false;

            // 構造の初期化
            using (var @dbc = new ThumbDbContext())
            {
                bool isInitializeDatabase = false;
                var  @repo = new ApMetadataRepository(@dbc);
                try
                {
                    apMetadata = @repo.FindBy(p => p.Key == "APVER").FirstOrDefault();
                    if (apMetadata == null)
                    {
                        isInitializeDatabase = true;
                    }
                }
                catch (Exception)
                {
                    isInitializeDatabase = true;
                }

                if (isInitializeDatabase)
                {
                    // データベースにテーブルなどの構造を初期化する
                    string sqltext = "";
                    System.Reflection.Assembly assm = System.Reflection.Assembly.GetExecutingAssembly();

                    using (var stream = assm.GetManifestResourceStream("Mogami.Assets.Sql.Thumbnail_Initialize_sql.txt"))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            sqltext = reader.ReadToEnd();
                        }
                    }
                    @dbc.Database.ExecuteSqlCommand(sqltext);
                    @dbc.SaveChanges();

                    apMetadata = @repo.FindBy(p => p.Key == "APVER").FirstOrDefault();
                }

                if (apMetadata == null)
                {
                    apMetadata = new ApMetadata {
                        Key = "APVER", Value = "1.0.0"
                    };
                    @repo.Add(apMetadata);

                    @repo.Save();
                }

                string currentVersion = apMetadata.Value;
                string nextVersion    = currentVersion;
                do
                {
                    currentVersion = nextVersion;
                    nextVersion    = UpgradeFromResource(currentVersion, @dbc);
                    if (nextVersion != currentVersion)
                    {
                        isMigrate = true;
                    }
                } while (nextVersion != currentVersion);

                if (isMigrate)
                {
                    apMetadata.Value = nextVersion;

                    @repo.Save();
                }

                @dbc.SaveChanges();
            }
        }