public async Task <JsonResult> Create(SqlLiteModel model) { model.F_Guid = Guid.NewGuid().ToString(); using (var db = new SqlLiteDb(HttpContext.Server.MapPath(@"~\App_Data\data.db"))) { db.SqlLiteModel.Add(model); await db.SaveChangesAsync(); return(Json(new { state = true, value = "操作成功" })); } }
public ActionResult Create() { var model = new SqlLiteModel(); model.F_DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.F_Bool = true; model.F_Float = 0.01f; model.F_Int = SqlLiteModel.GetNewId(); model.F_BoolNull = true; model.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); return(View("Create", model)); }
public async Task <JsonResult> Edit(SqlLiteModel model) { if (!this.TryValidateModel(model)) { return(Json(new { state = false, value = this.ModelState.FirstModelErrorMessage() })); } using (var db = new SqlLiteDb(HttpContext.Server.MapPath(@"~\App_Data\data.db"))) { db.Entry(model).State = EntityState.Modified; await db.SaveChangesAsync(); return(Json(new { state = true, value = "编辑成功" })); } }
public static void Main(string[] args) { Parser.Default.ParseArguments <DamselflyOptions>(args).WithParsed(o => { Logging.Verbose = o.Verbose; Logging.Trace = o.Trace; if (Directory.Exists(o.SourceDirectory)) { if (!Directory.Exists(o.ConfigPath)) { Directory.CreateDirectory(o.ConfigPath); } Logging.LogFolder = Path.Combine(o.ConfigPath, "logs"); Log.Logger = Logging.InitLogs(); if (o.ReadOnly) { o.NoEnableIndexing = true; o.NoGenerateThumbnails = true; } ImageProcessService.UseImageSharp = o.ImageSharp; IndexingService.EnableIndexing = !o.NoEnableIndexing; IndexingService.EnableThumbnailGeneration = !o.NoGenerateThumbnails; IndexingService.RootFolder = o.SourceDirectory; ThumbnailService.PicturesRoot = o.SourceDirectory; ThumbnailService.Synology = o.Synology; ThumbnailService.SetThumbnailRoot(o.ThumbPath); Logging.Log("Startup State:"); Logging.Log($" Damselfly Ver: {Assembly.GetExecutingAssembly().GetName().Version}"); Logging.Log($" CLR Ver: {Environment.Version}"); Logging.Log($" OS: {Environment.OSVersion}"); Logging.Log($" CPU Arch: {RuntimeInformation.ProcessArchitecture}"); Logging.Log($" Processor Count: {Environment.ProcessorCount}"); Logging.Log($" Read-only mode: {o.ReadOnly}"); Logging.Log($" Synology = {o.Synology}"); Logging.Log($" Indexing = {!o.NoEnableIndexing}"); Logging.Log($" ThumbGen = {!o.NoGenerateThumbnails}"); Logging.Log($" Images Root set as {o.SourceDirectory}"); IDataBase dbType = null; //if (true) // SQLite Check { string dbFolder = Path.Combine(o.ConfigPath, "db"); if (!Directory.Exists(dbFolder)) { Logging.Log(" Created DB folder: {0}", dbFolder); Directory.CreateDirectory(dbFolder); } string dbPath = Path.Combine(dbFolder, "damselfly.db"); Logging.Log(" Sqlite Database location: {0}", dbPath); dbType = new SqlLiteModel(dbPath); } //else // MySql //{ // dbType = new MySqlModel(); //} BaseDBModel.InitDB <ImageContext>(dbType, o.ReadOnly); StartWebServer(o.Port, args); Logging.Log("Shutting down."); } else { Logging.Log("Folder {0} did not exist. Exiting.", o.SourceDirectory); } }); }
/// <summary> /// Process the startup args and initialise the logging. /// </summary> /// <param name="o"></param> /// <param name="args"></param> private static void Startup(DamselflyOptions o, string[] args) { Logging.Verbose = o.Verbose; Logging.Trace = o.Trace; if (Directory.Exists(o.SourceDirectory)) { if (!Directory.Exists(o.ConfigPath)) { Directory.CreateDirectory(o.ConfigPath); } Logging.LogFolder = Path.Combine(o.ConfigPath, "logs"); Log.Logger = Logging.InitLogs(); if (o.ReadOnly) { o.NoEnableIndexing = true; o.NoGenerateThumbnails = true; } // TODO: Do away with static members here. We should pass this // through to the config service and pick them up via DI IndexingService.EnableIndexing = !o.NoEnableIndexing; IndexingService.RootFolder = o.SourceDirectory; ThumbnailService.PicturesRoot = o.SourceDirectory; ThumbnailService.Synology = o.Synology; ThumbnailService.SetThumbnailRoot(o.ThumbPath); ThumbnailService.EnableThumbnailGeneration = !o.NoGenerateThumbnails; var tieredPGO = System.Environment.GetEnvironmentVariable("DOTNET_TieredPGO") == "1"; Logging.Log("Startup State:"); Logging.Log($" Damselfly Ver: {Assembly.GetExecutingAssembly().GetName().Version}"); Logging.Log($" CLR Ver: {Environment.Version}"); Logging.Log($" OS: {Environment.OSVersion}"); Logging.Log($" CPU Arch: {RuntimeInformation.ProcessArchitecture}"); Logging.Log($" Processor Count: {Environment.ProcessorCount}"); Logging.Log($" Read-only mode: {o.ReadOnly}"); Logging.Log($" Synology = {o.Synology}"); Logging.Log($" Indexing = {!o.NoEnableIndexing}"); Logging.Log($" ThumbGen = {!o.NoGenerateThumbnails}"); Logging.Log($" Images Root set as {o.SourceDirectory}"); Logging.Log($" TieredPGO Enabled={tieredPGO}"); IDataBase dbType = null; if (!o.UsePostgresDB) { string dbFolder = Path.Combine(o.ConfigPath, "db"); if (!Directory.Exists(dbFolder)) { Logging.Log(" Created DB folder: {0}", dbFolder); Directory.CreateDirectory(dbFolder); } string dbPath = Path.Combine(dbFolder, "damselfly.db"); dbType = new SqlLiteModel(dbPath); Logging.Log(" Sqlite Database location: {0}", dbPath); } else // Postgres { // READ Postgres config json dbType = PostgresModel.ReadSettings("settings.json"); Logging.Log(" Postgres Database location: {0}"); } // TODO: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/providers?tabs=dotnet-core-cli BaseDBModel.InitDB <ImageContext>(dbType, o.ReadOnly); // Make ourselves low-priority. System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle; StartWebServer(o.Port, args); Logging.Log("Shutting down."); } else { Console.WriteLine("Folder {0} did not exist. Exiting.", o.SourceDirectory); } }