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