示例#1
0
        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);
        }
示例#2
0
        public bool DoDeletePersonTasks(DeletePersonInfo info)
        {
            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"]);

            string LogInfo = string.Format("EmployeeID={0}, PersonDivisionCheckID={1}, UserID={2}, PersonGUID={3}",
                                           info.EmployeeID, info.PersonDivisionCheckID, info.UserID, info.PersonGUID);

            log("DoDeletePersonTasks():" + LogInfo);

            try
            {
                string EmployeeID            = info.EmployeeID.ToString();
                int    PersonDivisionCheckID = info.PersonDivisionCheckID;
                int    UserID     = info.UserID;
                string PersonGuid = info.PersonGUID;

                var IWSRepo = new IwsRepository();

                int LastTransactionID = IWSRepo.GetLastTSCTransactionID(info.PersonDivisionCheckID);

                IDMSPerson person = IWS_Service.GetPerson(info.PersonGUID);

                if (person == null)
                {
                    log("DoDeletePersonTasks():\tPerson does not exist in IDMS!");
                    return(false);
                }

                IWS_Service.RevokePendingBadge(info.PersonGUID, false);

                foreach (DeletePersonBadgeInfo dr in info.BadgeInfo)
                {
                    LogInfo = string.Format("DoDeletePersonTasks():\tBadgeNumber={0}, CorporationName={1}, BadgeID={2}, BadgeID_IWS={3}, AccessLevel={4}",
                                            dr.BadgeNumber, dr.CorporationName, dr.BadgeID, dr.BadgeID_IWS, dr.AccessLevel);
                    log(LogInfo);
                    List <string> BadgeData = new List <string>();
                    bool          SendToTSC = (dr == info.BadgeInfo.Last());

                    BadgeData.Add(dr.BadgeNumber);
                    BadgeData.Add("Revoked");
                    BadgeData.Add("Delete Person From TSC");
                    BadgeData.Add(string.Empty);
                    BadgeData.Add(string.Empty);
                    BadgeData.Add(dr.CorporationName);

                    IWSRepo.CancelBadge(dr.BadgeID, info.UserID);
                    IWS_Service.CMSRevokeCard(dr.BadgeID_IWS, "Delete/Inactivate, UserID=" + UserID);
                    IWS_Service.UpdatePerson(PersonGuid, new List <string>(), BadgeData, dr.AccessLevel, SendToTSC);
                }

                var DeletePersonTask = Task.Factory.StartNew(() =>
                {
                    log("DoDeletePersonTasks():\tContinue Tasks for " + info.PersonGUID);

                    foreach (DeletePersonCompanyInfo dr in info.CompanyInfo)
                    {
                        IWSRepo.ArchiveFingerprints(info.SSN, dr.CompanyCode, dr.DivisionCode);
                    }

                    if (info.BadgeInfo.Count > 0)
                    {
                        IWSRepo.SaveBadgeCancellationTransaction(PersonDivisionCheckID, UserID);
                    }

                    string TransactionGUID = IWS_Service.DeletePersonFromTSC(PersonGuid, EmployeeID);

                    IWSRepo.SaveDeletePersonSubmission(PersonDivisionCheckID, TransactionGUID, UserID);

                    try
                    {
                        List <DMDocumentInfo> Documents = IWS_Service.GetPersonDocuments(PersonGuid);

                        foreach (DMDocumentInfo doc in Documents)
                        {
                            IWS_Service.RemoveDocument(doc.GUID);
                        }

                        IWS_Service.DeletePersonFromIDMS(PersonGuid);
                    }
                    catch (ISBException ex)
                    {
                        //person alredy deleted, no sense popping up an error if -120
                        if (ex.ErrorCode != -120)
                        {
                            throw;
                        }
                    }
                    log("DoDeletePersonTasks Complete:" + LogInfo);
                });
            }
            catch (Exception ex)
            {
                log("Exception caught in DoDeletePersonTasks: " + ex.ToString());
                return(false);
            }
            return(true);
        }