public bool GetBSBReport() { _uow = new UnitOfWork(bsbtacContext); Random rnd = new Random(); SearchDefinition searchDefinition = new SearchDefinition(); ApplSummary applSummary = new ApplSummary(); Cameo2006 cameo2006 = new Cameo2006(); try { lock (this) { var lastUpdatedDatetime = new SqlParameter("@LastUpdatedDatetime", DateTime.Now); searchDefinition = _uow.Repository<SearchDefinition>().SqlQuery("spGetNextBSBSearch @LastUpdatedDatetime", lastUpdatedDatetime).First(); } Thread.Sleep(rnd.Next(3000, 10000)); applSummary.SearchDefinitionId = searchDefinition.SearchDefinitionId; applSummary.AccountInformation = "AccountInformation" + searchDefinition.DebtCode; applSummary.NumberOfDisputes = searchDefinition.DebtCode; cameo2006.SearchDefinitionId = searchDefinition.SearchDefinitionId; cameo2006.LocalityInformation = "LocalityInformation" + searchDefinition.DebtCode; cameo2006.CouncilTaxBand = searchDefinition.DebtCode; lock (this) { applSummary.ObjectState = ObjectState.Added; cameo2006.ObjectState = ObjectState.Added; _uow.Repository<ApplSummary>().Insert(applSummary); _uow.Repository<Cameo2006>().Insert(cameo2006); _uow.Save(); searchDefinition.Status = 3; searchDefinition.LastUpdatedDatetime = DateTime.Now; _uow.Repository<SearchDefinition>().Update(searchDefinition); _uow.Save(); } return true; } catch (EntityCommandExecutionException) { _log.Info("No new search found"); return false; } catch (Exception ex) { lock(this) { searchDefinition.Status = 4; searchDefinition.LastUpdatedDatetime = DateTime.Now; _uow.Repository<SearchDefinition>().Update(searchDefinition); _uow.Save(); } _log.Error(ex.Message); return false; } }
private void LoadNewUploads() { _uow = new UnitOfWork(bsbtacContext); try { UploadDetail upload; lock (this) { upload = _uow.Repository<UploadDetail>().SqlQuery("spGetNextUploadedFile").First(); /* upload = _uow.Repository<UploadDetail>().Query() .Get() .Where(u => u.Status == 1) .First(); upload.Status = 2; upload.ObjectState = ObjectState.Modified; _uow.Repository<UploadDetail>().Update(upload); _uow.Save(); */ } var filename = upload.Filename; var path = @"C:\_Workspace\Projects\2012\BSBTAC\_Uploads\BSB\" + filename; var file = new StreamReader(path); string line = ""; while((line = file.ReadLine()) != null) { try { SearchDefinition searchDefinition = new SearchDefinition(); string[] data = line.Split(','); if(data[0].Equals("DebtCode")) { continue; } else { searchDefinition.UploadDetailId = upload.UploadDetailId; searchDefinition.DebtCode = Convert.ToInt32(data[0]); searchDefinition.Title = data[1]; searchDefinition.Forename = data[2]; searchDefinition.Surname = data[3]; searchDefinition.Othername = data[4]; searchDefinition.DOB = Convert.ToDateTime(data[5]); searchDefinition.BuildingNo = data[6]; searchDefinition.BuildingName = data[7]; searchDefinition.Locality = data[8]; searchDefinition.Sublocality = data[9]; searchDefinition.Posttown = data[10]; searchDefinition.Postcode = data[11]; searchDefinition.Type = Convert.ToByte(upload.Type); searchDefinition.Status = Convert.ToByte(1); searchDefinition.LastUpdatedDatetime = DateTime.Now; searchDefinition.ObjectState = ObjectState.Added; _uow.Repository<SearchDefinition>().Insert(searchDefinition); _uow.Save(); } } catch (Exception ex) { _log.Error(line + "-" + ex.Message); continue; } } file.Close(); } catch (EntityCommandExecutionException) { _log.Info("No new uploads found"); } catch(Exception ex) { _log.Error(ex.Message); } }
private void LoadNewUploadsUsingBulk() { _uow = new UnitOfWork(bsbtacContext); try { UploadDetail upload; lock (this) { upload = _uow.Repository<UploadDetail>().SqlQuery("spGetNextUploadedFile").First(); } var filename = upload.Filename; var path = @"C:\_Workspace\Projects\2012\BSBTAC\_Uploads\BSB"; //IFileParserService fileParser = FileParserFactory.CreateFileParser(filename); //fileParser.ParseFile(); ISqlBulkCopyService bulkcopyService = new SqlBulkCopyService(); bulkcopyService.BulkCopyFile(path, filename); } catch (EntityCommandExecutionException) { _log.Info("No new uploads found"); } catch (Exception ex) { _log.Error(ex.Message); } }