当前位置: 首页>>代码示例>>C#>>正文


C# IUnitOfWork.DropAndCreateDatabase方法代码示例

本文整理汇总了C#中IUnitOfWork.DropAndCreateDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# IUnitOfWork.DropAndCreateDatabase方法的具体用法?C# IUnitOfWork.DropAndCreateDatabase怎么用?C# IUnitOfWork.DropAndCreateDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUnitOfWork的用法示例。


在下文中一共展示了IUnitOfWork.DropAndCreateDatabase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Seed

        /// <summary>
        /// Creates and seeds the local database with default settings.
        /// (DEBUG) : In debug mode the Db is always re-created.
        /// (RELEASE) : In reelase, the Db is not dropped.
        /// </summary>
        /// <param name="unitOfWork"></param>
        public static bool Seed(IUnitOfWork unitOfWork, bool repopulate = false)
        {
            if (unitOfWork == null)
                throw new ArgumentNullException("unitOfWork");

            bool isCreated = false;
            User user = null;

            //#if DEBUG
            if (repopulate)
            {
                unitOfWork.ClearCachedItems();
                unitOfWork.Save();
            }
            //#else
                isCreated = unitOfWork.CreateDatabase();
            //#endif

            if (!isCreated)
            {
                try
                {
                    CacheSetting database = unitOfWork.CacheSettingRepository.GetByType(ResourceType.Database);

                    if (database == null || database.LastRefreshedDateUtc < lastDatabaseUpdate)
                    {
                        if (database != null)
                        {
                            // Save the user's details to be re-added to the database.
                            user = unitOfWork.UserRepository.GetUser();
                        }

                        isCreated = unitOfWork.DropAndCreateDatabase();

                        unitOfWork.Save();
                    }
                }
                catch (Exception)
                {
                    isCreated = unitOfWork.DropAndCreateDatabase();

                    unitOfWork.Save();
                }
            }

            if (isCreated || repopulate)
            {
                // Prepopulate the cache settings.
                unitOfWork.CacheSettingRepository.Insert(new CacheSetting(null, ResourceType.Operators));
                unitOfWork.CacheSettingRepository.Insert(new CacheSetting(lastDatabaseUpdate, ResourceType.Database));

                // Prepopulate the application settings.
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AllowLocation, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.UseMetric, new RegionInfo(CultureInfo.CurrentCulture.Name).IsMetric));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowWeather, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.StoreLocation, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.UseUber, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateLocation, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateMostFrequent, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.AutoPopulateMostRecent, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.StoreRecent, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.SkipTripSelection, false));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowAnnouncementsApplicationBar, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.ShowTripApplicationBar, true));
                unitOfWork.AppSettingRepository.Insert(new AppSetting(ApplicationSetting.LoginUber, false));

                // Prepopulate the modes.
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Bus, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Rail, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Taxi, true));
                unitOfWork.TransportModeRepository.Insert(new TransportMode(ApplicationTransportMode.Boat, true));

                // Save cache setting to the database.
                unitOfWork.Save();

                if (user != null)
                {
                    // Re-populate the user
                    user = new User(Guid.NewGuid(), user.Token, user.Country, user.DismissedLocationPopup, user.LastKnownGeneralLocation, user.LastLocationUpdate, user.DismissedRateAppPopup, user.DismissedSignUpPopup, user.IsBumbleRegistered, user.Email, user.FirstName, user.LastName, user.IsFacebookRegistered, user.IsTwitterRegistered, user.FacebookInfo, user.TwitterInfo, user.TwitterHandle, user.AppUsageCount, user.DismissedLoginUberPopup, user.UberInfo, user.IsUberAuthenticated);
                    unitOfWork.UserRepository.Insert(user);
                    unitOfWork.Save();
                }
            }

            return isCreated;
        }
开发者ID:CodeObsessed,项目名称:drumbleapp,代码行数:92,代码来源:DatabaseSetup.cs


注:本文中的IUnitOfWork.DropAndCreateDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。