public void Incluir(LogSync entidade) { const string Metodo = "Incluir"; try { var sql = new StringBuilder(); sql.Append("INSERT INTO rec_log_sync (dt_evento,tipo,descricao,cliente,id_api,valor) VALUES "); sql.Append("(@dt_evento,@tipo,@descricao,@cliente,@id_api,@valor);"); using (var conn = ConexaoBd.GetConnection()) { using (var cmd = new SqlCommand(sql.ToString(), conn)) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@dt_evento", entidade.DtEvento); cmd.Parameters.AddWithValue("@tipo", Enum.GetName(typeof(TipoLogEnum), entidade.Tipo)); cmd.Parameters.AddWithValue("@descricao", entidade.Descricao); cmd.Parameters.AddWithValue("@cliente", entidade.NomeCliente); cmd.Parameters.AddWithValue("@id_api", entidade.IdApi); cmd.Parameters.AddWithValue("@valor", entidade.Valor); cmd.ExecuteNonQuery(); } } } catch (SqlException sqlException) { string strMensagem = ""; strMensagem = LogDatabaseErrorUtil.CreateErrorDatabaseMessage(sqlException); LogDatabaseErrorUtil.LogFileWrite(strMensagem, Metodo); sqlException.Data["MensagemCustomizada"] = LogDatabaseErrorUtil.ValidateDataBaseErrorNumber(sqlException.Number); sqlException.Data["Metodo"] = Metodo; sqlException.Data["Classe"] = Camada; sqlException.Data["Hora"] = DateTime.Now; throw; } catch (Exception ex) { string strMensagem = ""; strMensagem = LogDatabaseErrorUtil.CreateErrorMessage(ex); LogDatabaseErrorUtil.LogFileWrite(strMensagem, Metodo); ex.Data["MensagemCustomizada"] = "Ocorreu um erro ao tentar executar a operação."; ex.Data["Metodo"] = Metodo; ex.Data["Classe"] = Camada; ex.Data["Hora"] = DateTime.Now; throw; } }
public static void Main(string [] args) { /* * bool timeLogPassedOk = Log.Start(args); * Log.WriteLine(string.Format("Time log passed: {0}", timeLogPassedOk.ToString())); * Log.WriteLine(string.Format("Client database option 1 in ... " + Util.GetDatabaseDir())); * Log.WriteLine(string.Format("Client database option 2 in ... " + Util.GetDatabaseTempDir())); */ LogSync.Initialize(); //1.4.10 Log.Start(); LogB.Debugging = true; //now LogB.Debug will be shown. Also there will be thread info on Warning, Error, Information if (args.Length > 0 && args[0] == "printAll") { LogB.PrintAllThreads = true; } var envPath = Environment.GetEnvironmentVariable("PATH"); var rBinPath = ""; baseDirectory = Util.GetPrefixDir(); /* * location of gtkrc file * DISABLED tight now because on windows there are inestabilities on jumps results * and on Mode menu */ //Rc.AddDefaultFile (Util.GetThemeFile()); //LogB.Information("gtk theme:" + Util.GetThemeFile()); if (UtilAll.IsWindows()) { //Environment.SetEnvironmentVariable ("R_HOME", RelativeToPrefix ("library")); //rBinPath = RelativeToPrefix ("lib"); //rBinPath = RelativeToPrefix ("library"); //var rPath = System.Environment.Is64BitProcess ? @"C:\Program Files\R\R-3.0.2\bin\x64" : @"C:\Program Files\R\R-3.0.2\bin\i386"; string x64 = "bin" + System.IO.Path.DirectorySeparatorChar + "x64"; string i386 = "bin" + System.IO.Path.DirectorySeparatorChar + "i386"; var rPath = System.Environment.Is64BitProcess ? System.IO.Path.Combine(baseDirectory, x64) : System.IO.Path.Combine(baseDirectory, i386); if (Directory.Exists(rPath) == false) { LogB.Error("Could not found the specified path to the directory containing R.dll: ", rPath); throw new DirectoryNotFoundException(string.Format("Could not found the specified path to the directory containing R.dll: {0}", rPath)); } var newPath = string.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, envPath); LogB.Information("newPath:", newPath); System.Environment.SetEnvironmentVariable("PATH", newPath); LogB.Information("path:", System.Environment.GetEnvironmentVariable("PATH")); //use this because we don't want to look at the registry //we don't want to force user to install R Environment.SetEnvironmentVariable("R_HOME", baseDirectory); LogB.Information("R_HOME:", baseDirectory); } else { switch (UtilAll.GetOSEnum()) { case UtilAll.OperatingSystems.MACOSX: LogB.Information(Environment.GetEnvironmentVariable("R_HOME")); rBinPath = "/Library/Frameworks/R.Framework/Libraries"; Environment.SetEnvironmentVariable("R_HOME", "/Library/Frameworks/R.Framework/Resources"); Environment.SetEnvironmentVariable("PATH", rBinPath + Path.PathSeparator + envPath); LogB.Information("environments"); LogB.Information(Environment.GetEnvironmentVariable("R_HOME")); LogB.Information(Environment.GetEnvironmentVariable("PATH")); //Gstreamer stuff string prefix = "/Applications/Chronojump.app/Contents/Home/"; Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", prefix + "lib/gstreamer-0.10"); Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", prefix + "lib/gstreamer-0.10"); Environment.SetEnvironmentVariable("GST_PLUGIN_SCANNER_PATH", prefix + "lib/gstreamer-0.10/gst-plugin-scanner"); break; case UtilAll.OperatingSystems.LINUX: rBinPath = @"/usr/lib/R/lib"; Environment.SetEnvironmentVariable("R_HOME", @"/usr/lib/R"); Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath); break; } } LogB.Information("Platform:" + Environment.OSVersion.Platform); LogB.Information("baseDir0:", System.AppDomain.CurrentDomain.BaseDirectory); LogB.Information("baseDir1:", baseDirectory); LogB.Information("envPath+rBinPath:", envPath + Path.PathSeparator + rBinPath); //UtilCSV.ReadValues("/tmp/chronojump-encoder-graph-input-multi.csv"); if (UtilAll.IsWindows()) { Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", RelativeToPrefix("lib\\gstreamer-0.10")); } //this call has to be done to chronojump.prg //chronojump.prg createBlankDB //this creates a blank database and exists. //Then new user will have an updated database without the need of creating in if (args.Length > 0 && args[0] == "createBlankDB") { createBlankDB(); Environment.Exit(1); } if (args.Length > 0 && args[0] == "createBlankDBServer") { createBlankDBServer(); Environment.Exit(1); } string language = ""; if (File.Exists(System.IO.Path.Combine(Util.GetDatabaseDir(), "chronojump.db"))) { try { Sqlite.Connect(); /* * chronojump 1.5.2 converts DB 1.24 to 1.25 changing language to "" * but this operation is done later (on sqliteThings) * We need here! to define the language from the beginning * so we use language = "" if version is prior to 1.25 */ string currentDBVersion = SqlitePreferences.Select("databaseVersion", false); double currentDBVersionDouble = Convert.ToDouble(Util.ChangeDecimalSeparator(currentDBVersion)); if (currentDBVersionDouble < Convert.ToDouble(Util.ChangeDecimalSeparator("1.25"))) { language = ""; } else { language = SqlitePreferences.Select("language", false); } Sqlite.DisConnect(); if (language != "") { //convert pt-BR to pt_BR if (language.Contains("-")) { language = language.Replace("-", "_"); } Environment.SetEnvironmentVariable("LANGUAGE", language); //works #if OSTYPE_WINDOWS g_setenv("LANGUAGE", language, true); #endif } } catch { LogB.Warning("Problem reading language on start"); } } Catalog.Init("chronojump", System.IO.Path.Combine(Util.GetPrefixDir(), "share/locale")); new ChronoJump(args); }
public IEnumerable <LogSync> ObterTodos(params object[] parametros) { const string Metodo = "ObterTodos"; var listaLogApi = new List <LogSync>(); var nomeCliente = Convert.ToString(parametros[0]); var strDtInicial = $"{Convert.ToDateTime(parametros[1]):yyyy-MM-dd}"; var strDtFinal = $"{Convert.ToDateTime(parametros[2]):yyyy-MM-dd}"; var tipo = (TipoLogEnum)parametros[3] == TipoLogEnum.To ? (object)"%" : Enum.GetName(typeof(TipoLogEnum), (TipoLogEnum)parametros[3]); try { var sql = new StringBuilder(); sql.Append("SELECT dt_evento,tipo,descricao,cliente,id_api,valor FROM rec_log_sync "); sql.Append("WHERE CAST(dt_evento as date) BETWEEN @strDtInicial AND @strDtFinal AND cliente LIKE @cliente AND tipo LIKE @tipo;"); using (var conn = ConexaoBd.GetConnection()) { using (var cmd = new SqlCommand(sql.ToString(), conn)) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@strDtInicial", strDtInicial); cmd.Parameters.AddWithValue("@strDtFinal", strDtFinal); cmd.Parameters.AddWithValue("@cliente", "%" + nomeCliente + "%"); cmd.Parameters.AddWithValue("@tipo", tipo); using (var dr = cmd.ExecuteReader()) { if (dr.HasRows) { while (dr.Read()) { var logApiMundipagg = new LogSync { DtEvento = Convert.ToDateTime(dr["dt_evento"]), Tipo = (TipoLogEnum)Enum.Parse(typeof(TipoLogEnum), Convert.ToString(dr["tipo"])), Descricao = Convert.ToString(dr["descricao"]), NomeCliente = Convert.ToString(dr["cliente"]), IdApi = Convert.ToString(dr["id_api"]), Valor = Convert.ToDecimal(dr["valor"]) }; listaLogApi.Add(logApiMundipagg); } } } } } return(listaLogApi); } catch (SqlException sqlException) { string strMensagem = ""; strMensagem = LogDatabaseErrorUtil.CreateErrorDatabaseMessage(sqlException); LogDatabaseErrorUtil.LogFileWrite(strMensagem, Metodo); sqlException.Data["MensagemCustomizada"] = LogDatabaseErrorUtil.ValidateDataBaseErrorNumber(sqlException.Number); sqlException.Data["Metodo"] = Metodo; sqlException.Data["Classe"] = Camada; sqlException.Data["Hora"] = DateTime.Now; throw; } catch (Exception ex) { string strMensagem = ""; strMensagem = LogDatabaseErrorUtil.CreateErrorMessage(ex); LogDatabaseErrorUtil.LogFileWrite(strMensagem, Metodo); ex.Data["MensagemCustomizada"] = "Ocorreu um erro ao tentar executar a operação."; ex.Data["Metodo"] = Metodo; ex.Data["Classe"] = Camada; ex.Data["Hora"] = DateTime.Now; throw; } }
public void Incluir(LogSync logApiMundipagg) { _logSyncDal.Incluir(logApiMundipagg); }
public static void Commit(LogEntryType type, string message, string details, bool showUser) { if (Mute) { return; } if (message == null) { message = ""; } if (type == LogEntryType.Debug && !Debugging) { return; } if (type != LogEntryType.Information || (type == LogEntryType.Information && !showUser)) { var thread_name = String.Empty; bool printNow = false; if (Debugging) { var thread = Thread.CurrentThread; thread_name = thread.ManagedThreadId.ToString(); if (thread_name == "1") { printNow = true; thread_name = "1-GTK "; } else { thread_name += " "; } } string lineStart = string.Format("[{5}{0} {1:00}:{2:00}:{3:00}.{4:000}]", TypeString(type), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, thread_name); if (PrintAllThreads || printNow) { /* * only doing this in main thread now. * Less buggy and seems to have finished with ^@ and 92M messages */ switch (type) { case LogEntryType.Error: ConsoleCrayon.ForegroundColor = ConsoleColor.Red; break; case LogEntryType.Warning: ConsoleCrayon.ForegroundColor = ConsoleColor.DarkYellow; break; case LogEntryType.Information: ConsoleCrayon.ForegroundColor = ConsoleColor.Green; break; case LogEntryType.Debug: ConsoleCrayon.ForegroundColor = ConsoleColor.Blue; break; case LogEntryType.SQL: ConsoleCrayon.ForegroundColor = ConsoleColor.Cyan; break; case LogEntryType.SQLon: ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan; ConsoleCrayon.ForegroundColor = ConsoleColor.White; break; case LogEntryType.SQLoff: ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; case LogEntryType.SQLonAlready: ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan; ConsoleCrayon.ForegroundColor = ConsoleColor.Gray; break; case LogEntryType.ThreadStart: ConsoleCrayon.BackgroundColor = ConsoleColor.Green; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; case LogEntryType.ThreadEnding: ConsoleCrayon.BackgroundColor = ConsoleColor.Yellow; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; case LogEntryType.ThreadEnded: ConsoleCrayon.BackgroundColor = ConsoleColor.Red; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; case LogEntryType.TestStart: ConsoleCrayon.BackgroundColor = ConsoleColor.Blue; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; case LogEntryType.TestEnd: ConsoleCrayon.BackgroundColor = ConsoleColor.Blue; ConsoleCrayon.ForegroundColor = ConsoleColor.Black; break; } Console.Write(lineStart); ConsoleCrayon.ResetColor(); //print messagesOtherThreads //do not add to "message" because like this is better to find why crashes string messagesOtherThreads = LogSync.ReadAndEmpty(); if (messagesOtherThreads != null) { try { Console.Write(messagesOtherThreads); } catch (System.IndexOutOfRangeException) { Console.Write("CATCHED printing messagesOtherThreads"); } } //print messages this thread if (details != null) { message += " - " + details; } try { if (type == LogEntryType.Debug) { Console.Write(" {0}", message); } else { Console.WriteLine(" {0}", message); } } catch (System.IndexOutOfRangeException) { Console.Write("CATCHED printing main thread"); } } else { LogSync.Add(lineStart + "\n" + message); } } if (showUser) { OnNotify(new LogEntry(type, message, details)); } }