public void RunImportJob(string jobId, string csvFileName) { ImportJob job = ImportJobs.First(x => x.ImportJobId == jobId); if (job != null) { ImportResult result = new ImportResult(); _importResults[jobId] = result; using (var data = GetCsvContent(csvFileName)) { result.Length = data.BaseStream.Length; CsvReader csvReader = new CsvReader(data, job.ColumnDelimiter); try { result.IsRunning = true; result.Started = DateTime.Now; Import(job, csvReader, result); } finally { result.Stopped = DateTime.Now; result.IsRunning = false; } } } }
/// <summary> /// This method will get row(s) from the database using the value of the field specified /// along with the details of the child table. /// </summary> /// /// <param name="pk" type="ListMasterPrimaryKey">Primary Key information based on which data is to be fetched.</param> /// /// <returns>object of class ImportJobs</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 1/27/2010 1:09:45 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// public static ImportJobs SelectAllByForeignKeyFromListMaster(ListMasterPrimaryKey pk, string ConnectionString) { DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString); bool ExecutionState = false; ImportJobs obj = null; // Pass the values of all key parameters to the stored procedure. System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues(); foreach (string key in nvc.Keys) { oDatabaseHelper.AddParameter("@" + key,nvc[key] ); } // The parameter '@ErrorCode' will contain the status after execution of the stored procedure. oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output); IDataReader dr=oDatabaseHelper.ExecuteReader("sp_ImportJob_SelectAllByForeignKeyListMaster", ref ExecutionState); obj = new ImportJobs(); obj = ImportJob.PopulateObjectsFromReaderWithCheckingReader(dr, oDatabaseHelper,ConnectionString); dr.Close(); oDatabaseHelper.Dispose(); return obj; }
/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of ImportJobs</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 1/27/2010 1:09:45 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static ImportJobs PopulateObjectsFromReader(IDataReader rdr, string ConnectionString) { ImportJobs list = new ImportJobs(); while (rdr.Read()) { ImportJob obj = new ImportJob(ConnectionString); PopulateObjectFromReader(obj,rdr); list.Add(obj); } return list; }
/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of ImportJobs</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 1/27/2010 1:09:45 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static ImportJobs PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper, string ConnectionString) { ImportJobs list = new ImportJobs(); if (rdr.Read()) { ImportJob obj = new ImportJob(ConnectionString); PopulateObjectFromReader(obj, rdr); list.Add(obj); while (rdr.Read()) { obj = new ImportJob(ConnectionString); PopulateObjectFromReader(obj, rdr); list.Add(obj); } oDatabaseHelper.Dispose(); return list; } else { oDatabaseHelper.Dispose(); return null; } }