Beispiel #1
0
 public static bool?FilenameIsInLog(string filename)
 {
     try
     {
         using (var con = new OracleConnection(ConnectionProvider.GetConnectionString()))
         {
             con.Open();
             using (
                 OracleCommand cmd =
                     new OracleCommand(
                         "<stored procedure here>", con)
                 )
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 using (OracleParameter in_filename = new OracleParameter())
                 {
                     in_filename.OracleDbType = OracleDbType.Varchar2;
                     in_filename.Direction    = ParameterDirection.Input;
                     in_filename.Value        = filename;
                     cmd.Parameters.Add(in_filename);
                     OracleParameter filename_exists_c = cmd.Parameters.Add("filename_exists_c", OracleDbType.RefCursor);
                     filename_exists_c.Direction = ParameterDirection.Output;
                     OracleDataReader dr = cmd.ExecuteReader();
                     if (dr.Read())
                     {
                         if (log.IsInfoEnabled)
                         {
                             log.Info(string.Format("{0} has already been imported, according to the log. Skipping import of this file.", filename));
                         }
                         return(true);
                     }
                     else
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(string.Format("Something went wrong while trying to check if {0} has been logged. I'll assume the file is already logged and skip it this time. Please try again later.", filename), ex);
         }
         return(true);
     }
 }
Beispiel #2
0
 public static void WriteFilenameToDb(string filename)
 {
     try
     {
         using (var con = new OracleConnection(ConnectionProvider.GetConnectionString()))
         {
             con.Open();
             using (
                 OracleCommand cmd =
                     new OracleCommand(
                         "<stored procedure here>", con)
                 )
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 using (OracleParameter filename_insert = new OracleParameter())
                 {
                     filename_insert.OracleDbType = OracleDbType.Varchar2;
                     filename_insert.Direction    = ParameterDirection.Input;
                     filename_insert.Value        = filename;
                     cmd.Parameters.Add(filename_insert);
                     cmd.ExecuteNonQuery();
                 }
             }
         }
         if (log.IsInfoEnabled)
         {
             log.Info(filename + " was imported successfully.");
         }
     }
     catch (Exception ex)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(string.Format("Something went wrong while trying to add the filename {0} to the log.", filename), ex);
         }
     }
 }