public PersonUpdate PopulatePersonUpdate(List <int> BadgeIDs) { var IwsRepo = new IwsRepository(); var returnValue = new PersonUpdate(); DataSet ds = IwsRepo.PopulatePersonUpdate(BadgeIDs); returnValue = MapPersonUpdateDataSet(ds).FirstOrDefault(); return(returnValue); }
public PersonUpdate BeginPersonUpdate(int PersonUpdateID) { var IwsRepo = new IwsRepository(); if (CurrentUpdate != null && CurrentUpdate.Persons.Count > 0) { return(CurrentUpdate); } int UpdatePersonCallsPerHour = 75; Int32.TryParse(System.Configuration.ConfigurationManager.AppSettings["UpdatePersonCallsPerHour"], out UpdatePersonCallsPerHour); TimeSpan timeBetweenCalls = new TimeSpan(0, 0, 3600 / (UpdatePersonCallsPerHour <= 0 ? 75 : UpdatePersonCallsPerHour)); var ds = IwsRepo.GetPersonUpdate(PersonUpdateID); CurrentUpdate = MapPersonUpdateDataSet(ds).FirstOrDefault(); if (CurrentUpdate != null) { Task.Factory.StartNew(() => { try { DateTime lastCallTime = DateTime.UtcNow; var pendingPersons = CurrentUpdate.Persons.Where(x => x.IsPending).OrderBy(x => x.OrderBy).ToList(); log("Person Update ID " + CurrentUpdate.PersonUpdateID + " beginning."); foreach (PersonUpdateDetail detail in pendingPersons) { ISBLibTest.ISBLibExtGCR IWS_Service = new ISBLibExtGCR(System.Configuration.ConfigurationManager.AppSettings["DOCM_IP"], System.Configuration.ConfigurationManager.AppSettings["IDMS_IP"], System.Configuration.ConfigurationManager.AppSettings["CMS_IP"], System.Configuration.ConfigurationManager.AppSettings["EBTS_IP"]); List <string> PersonData = new List <string>(); // empty; Person Update only. log("Update Person: EmployeeID = " + detail.EmployeeID + ", PersonGUID :" + detail.PersonGUID); foreach (BadgeRecord badge in detail.Badges) { List <string> BadgeStatusData = new List <string>(); BadgeStatusData.Add(badge.BadgeNumber); BadgeStatusData.Add(badge.BadgeStatusCode == "ACTV" ? "Active" : "Revoked"); BadgeStatusData.Add(badge.ReasonForDeactivation); BadgeStatusData.Add(""); //Access Level (SIDA, Sterile): this can not be changed, so pass back their existing value if exists BadgeStatusData.Add(""); //LocalBadgeType: BadgeStatusData.Add(badge.CorporationName); //EmployerName: log("\tUpdate Badge Number: + " + badge.BadgeNumber + "," + badge.CorporationName + "," + badge.BadgeStatusCode + "," + badge.ReasonForDeactivation); IWS_Service.UpdatePerson(detail.PersonGUID.ToString(), PersonData, BadgeStatusData, detail.TypeCode, badge == detail.Badges.Last()); if (badge == detail.Badges.Last()) { log("Sent to TSC"); } if (PersonUpdate_CancelToken.IsCancellationRequested) { // Cancel Web service was called. log("BeginPersonUpdate cancelled"); PersonUpdate_CancelTokenSource = new CancellationTokenSource(); PersonUpdate_CancelToken = PersonUpdate_CancelTokenSource.Token; CurrentUpdate = null; break; } } IwsRepo.MarkPersonUpdateDetailAsSent(detail.PersonUpdateID, detail.PersonID); log("Update Person on PersonID " + detail.PersonID + " Complete"); DateTime finishTime = DateTime.UtcNow; DateTime nextCallTime = lastCallTime.Add(timeBetweenCalls); if (finishTime < nextCallTime) { log("Sleeping for " + nextCallTime.Subtract(finishTime).TotalMilliseconds.ToString() + " milliseconds"); System.Threading.Thread.Sleep(Convert.ToInt32(nextCallTime.Subtract(finishTime).TotalMilliseconds)); } lastCallTime = DateTime.UtcNow; } if (CurrentUpdate != null) { log("Person Update ID " + CurrentUpdate.PersonUpdateID + " complete."); } CurrentUpdate = null; } catch (Exception ex) { log(ex.ToString()); } }); } return(CurrentUpdate); }
private List <PersonUpdate> MapPersonUpdateDataSet(DataSet ds) { var returnValue = new List <PersonUpdate>(); ds.Relations.Clear(); ds.Relations.Add("PersonUpdate", ds.Tables[0].Columns["PersonUpdateID"], ds.Tables[1].Columns["PersonUpdateID"], false); ds.Relations.Add("Person", ds.Tables[1].Columns["PersonID"], ds.Tables[2].Columns["PersonID"], false); var PersonUpdates = GetDataFromDataTable <PersonUpdate>(ds.Tables[0]).ToList(); var PersonUpdateDetails = GetDataFromDataTable <PersonUpdateDetail>(ds.Tables[1]).ToList(); var PersonUpdateBadges = GetDataFromDataTable <BadgeRecord>(ds.Tables[2]).ToList(); foreach (DataRow drPU in ds.Tables[0].Rows) { var newPU = new PersonUpdate() { PersonUpdateID = drPU.Field <int>("PersonUpdateID"), CreationDate = drPU.Field <DateTime>("CreationDate") }; var pudChildRows = drPU.GetChildRows(ds.Relations[0]); //var dv = new DataView(ds.Tables[1], "PersonUpdateID=" + newPU.PersonUpdateID, "", DataViewRowState.OriginalRows); foreach (DataRow drDetail in pudChildRows) { var newPerson = new PersonUpdateDetail() { PersonUpdateID = (int)drDetail["PersonUpdateID"], PersonID = (int)drDetail["PersonID"], FirstName = (string)drDetail["FirstName"], LastName = (string)drDetail["LastName"], EmployeeID = (int)drDetail["EmployeeID"], //DivisionTypeID = (short)drv["DivisionTypeID"], //TypeCode = (string)drv["TypeCode"], SocialSecurityNumber = (string)drDetail["SocialSecurityNumber"], PersonGUID = new System.Guid(drDetail["PersonGUID"] == DBNull.Value ? "" : drDetail["PersonGUID"].ToString()), OrderBy = (int)drDetail["OrderBy"], IsPending = (bool)drDetail["IsPending"], IsSuccessful = (bool)drDetail["IsSuccessful"], TransmitStart = (DateTime?)(drDetail["TransmitStart"] == DBNull.Value ? null : drDetail["TransmitStart"]), TransmitEnd = (DateTime?)(drDetail["TransmitEnd"] == DBNull.Value ? null : drDetail["TransmitEnd"]) }; //var dvPerson = new DataView(ds.Tables[2], "PersonUpdateID = " + newPU.PersonUpdateID + " AND PersonID=" + newPerson.PersonID, "", DataViewRowState.OriginalRows); var badgeChildRows = drDetail.GetChildRows(ds.Relations[1]); foreach (DataRow drBadge in badgeChildRows) { var newBadge = new BadgeRecord() { PersonGUID = new System.Guid(drBadge["PersonGUID"] == DBNull.Value ? "" : drBadge["PersonGUID"].ToString()), PersonID = drBadge.Field <int>("PersonID"), BadgeID = drBadge.Field <int>("BadgeID"), DivisionTypeID = drBadge.Field <short>("DivisionTypeID"), TypeCode = drBadge.Field <string>("TypeCode"), BadgeNumber = drBadge.Field <string>("BadgeNumber"), CorporationName = drBadge.Field <string>("CorporationName"), BadgeStatusCode = drBadge.Field <string>("BadgeStatusCode"), BadgeID_IWS = drBadge["BadgeID_IWS"] == DBNull.Value ? 0 : drBadge.Field <long>("BadgeID_IWS"), ReasonForDeactivation = drBadge.Field <string>("ReasonForDeactivation") }; newPerson.Badges.Add(newBadge); } newPU.Persons.Add(newPerson); } returnValue.Add(newPU); } return(returnValue); //foreach (var update in PersonUpdates) //{ // update.Persons = PersonUpdateDetails.Where(x => x.PersonUpdateID == update.PersonUpdateID).ToList(); // foreach (var person in update.Persons) // { // person.Badges = PersonUpdateBadges.Where(y => y.PersonID == person.PersonID).ToList(); // } //} //return PersonUpdates; }