public static bool RemoveJob(string jobName, string comment, string samayDB_ConnectionString) { Engine engine = GetSamayConfig(samayDB_ConnectionString); Job jobToRemove = null; foreach (var j in engine.Jobs) { if (j.JobName.ToLower() == jobName.ToLower()) { jobToRemove = j; break; } } if (jobToRemove != null) { engine.Jobs.Remove(jobToRemove); SaveSamayConfig(engine, comment, samayDB_ConnectionString); SamayLogger.Log("Successfully removed new Job '" + jobName + "'", SamayLogger.SamayEngineLogJobName, "Config", "Engine", LogLevel.Info); return(true); } SamayLogger.Log("Failed to removed new Job '" + jobName + "'. Job does not exist", SamayLogger.SamayEngineLogJobName, "Config", "Engine", LogLevel.Error); throw new Exception("Job '" + jobName + "' does not exist"); }
public static bool SaveSamayConfig(Engine config, string comment, string samayDB_ConnectionString) { using (SQLiteConnection cn = new SQLiteConnection(samayDB_ConnectionString)) { try { cn.Open(); SQLiteCommand sCommand1 = new SQLiteCommand(@"create table if not exists ConfigHistory (ID integer primary key autoincrement, TimeStamp datetime default current_timestamp, UserID integer,Title varchar,Config varchar);", cn); sCommand1.ExecuteScalar(); SQLiteCommand sCommand2 = new SQLiteCommand(@"INSERT INTO ConfigHistory ([TimeStamp], UserID, Title, Config) VALUES (@TimeStamp, @UserID, @Title, @Config); SELECT last_insert_rowid();", cn); sCommand2.Parameters.AddRange(new[] { new SQLiteParameter { DbType = DbType.DateTime, ParameterName = "TimeStamp", Value = DateTime.UtcNow }, new SQLiteParameter { DbType = DbType.Int16, ParameterName = "UserID", Value = 1 }, new SQLiteParameter { DbType = DbType.String, ParameterName = "Title", Value = comment }, new SQLiteParameter { DbType = DbType.String, ParameterName = "Config", Value = JsonConvert.SerializeObject(config) }, }); sCommand2.ExecuteScalar(); SQLiteCommand sCommand3 = new SQLiteCommand(@"create table if not exists LOGS (ID integer primary key autoincrement, TimeStamp datetime default current_timestamp, Level varchar, Message varchar, JobName varchar, TaskName varchar);", cn); sCommand3.ExecuteScalar(); return(true); } catch (Exception ex) { SamayLogger.Log("Error while saving config. " + ex.ToString(), SamayLogger.SamayEngineLogJobName, "Config", "Startup", LogLevel.Error, DateTime.Now); return(false); } finally { cn.Close(); } } }
public static bool AddJob(string jobString, string comment, string samayDB_ConnectionString) { Engine engine = GetSamayConfig(samayDB_ConnectionString); Job job = JsonConvert.DeserializeObject <Job>(jobString); foreach (var j in engine.Jobs) { if (j.JobName.ToLower() == job.JobName.ToLower()) { SamayLogger.Log("Failed to add new Job '" + job.JobName + "'. Job already exists", SamayLogger.SamayEngineLogJobName, "Config", "Engine", LogLevel.Error); throw new Exception("Job with the name '" + job.JobName + "' already exists"); } } engine.Jobs.Add(job); SaveSamayConfig(engine, comment, samayDB_ConnectionString); SamayLogger.Log("Successfully added new Job '" + job.JobName + "'", SamayLogger.SamayEngineLogJobName, "Config", "Engine", LogLevel.Info); return(true); }
public static Engine GetSamayConfig(string samayDB_ConnectionString) { // XmlSerializer serializer = new XmlSerializer(typeof(Engine)); Engine output; using (SQLiteConnection cn = new SQLiteConnection(samayDB_ConnectionString)) { try { cn.Open(); SQLiteCommand sCommand = new SQLiteCommand( @"SELECT Config FROM ConfigHistory ORDER BY TimeStamp DESC LIMIT 1", cn); string engineString = (string)sCommand.ExecuteScalar(); output = JsonConvert.DeserializeObject <Engine>(engineString); if (output == null) { throw new Exception(); } } catch (Exception ex) { SamayLogger.Log("Failed to Read Samay Engine Configuration. " + ex.ToString(), "Config", "Config Reader", "Startup", LogLevel.Info, DateTime.Now); throw ex; } finally { cn.Close(); } } //using (StringReader reader = new StringReader(File.ReadAllText("EngineConfig.xml"))) //{ // output = (Engine)serializer.Deserialize(reader); //} SamayLogger.Log("Samay Engine Configuration sucessfully read into memory", SamayLogger.SamayEngineLogJobName, "Config", "Startup", LogLevel.Info, DateTime.Now); return(output); }
internal static void LogWarning(string logMsg) { SamayLogger.Log(logMsg, SamayLogger.SamayEngineLogJobName, "Engine", SamayLogger.SamayEngineLoggingGUID, LogLevel.Warn, DateTime.Now); }
public void Log(string logMsg, string job, string task, string id, LogLevel logLevel) { SamayLogger.Log(logMsg, job, task, id, logLevel, DateTime.Now); }