protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public void Add(CommerceSetting setting) { string commerceFolder = this.GetCommercePhysicalFolder(setting.Name); if (!Directory.Exists(commerceFolder)) { //Create folder Directory.CreateDirectory(commerceFolder); string imagesFolder = this.GetImageFilePhysicalFolder(setting.Name); string databaseFolder = this.GetDatabaseFilePhysicalFolder(setting.Name); string[] folders = new string[] { imagesFolder, databaseFolder }; foreach (string path in folders) { Directory.CreateDirectory(path); } //Create database if (setting.EnableConnectionString) { CommerceDbContext ctx = new CommerceDbContext(setting.ConnectionString); ctx.Database.Create(); ctx.Dispose(); } else { //SqlCE setting.DatabaseFilePath = this.GetDatabaseFilePhysicalPath(setting.Name); CommerceDbContext ctx = new CommerceDbContext(setting.DatabaseFilePath); ctx.Database.Create(); ctx.Dispose(); } //Create file:setting.config string settingFilePath = this.GetSettingFilePhysicalPath(setting.Name); Serialization.Serialize <CommerceSetting>(setting, settingFilePath); } else { string message = string.Format("{0} is already exist.".Localize()); throw new ArgumentException(message); } }