} // Execute // async public ActionMetaData Execute(ExecuteArguments oArgs) { ActionMetaData amd = null; try { if (oArgs == null) { throw new Alert(Log, "No ExecuteArguments specified."); } SetLogThreadProperties(oArgs); Log.Debug("Executing " + oArgs.StrategyType + " started..."); amd = NewAsync( oArgs.StrategyType.ToString(), comment: oArgs.StrategyArgumentsStr, nCustomerID: oArgs.CustomerID, nUserID: oArgs.UserID ); ConstructorInfo oCreator = oArgs.StrategyType.GetConstructors().FirstOrDefault( ci => ci.GetParameters().Length == oArgs.StrategyArguments.Count ); if (oCreator == null) { string msg = string.Format( "Failed to find a constructor for {0} with {1} arguments.", oArgs.StrategyType, oArgs.StrategyArguments.Count ); throw new Alert(Log, msg); } // if Log.Debug(oArgs.StrategyType + " constructor found, invoking..."); amd.UnderlyingThread = new Thread(() => { try { SetLogThreadProperties(oArgs); AStrategy oInstance = (AStrategy)oCreator.Invoke(oArgs.StrategyArguments.ToArray()); if (oInstance == null) { throw new NullReferenceException("Failed to create an instance of " + oArgs.StrategyType); } amd.Strategy = oInstance; oInstance.Context.UserID = oArgs.UserID; oInstance.Context.CustomerID = oArgs.CustomerID; if (oArgs.OnInit != null) { Log.Debug(oInstance.Name + " instance created, invoking an initialization action..."); oArgs.OnInit(oInstance, amd); Log.Debug(oInstance.Name + " initialization action complete."); } // if Log.Debug(oInstance.Name + " instance is initialized, executing..."); oInstance.Execute(); Log.Debug("Executing " + oArgs.StrategyType + " complete."); SaveActionStatus(amd, ActionStatus.Done); if (oArgs.OnSuccess != null) { Log.Debug(oInstance.Name + " instance running complete, invoking an OnSuccess action..."); oArgs.OnSuccess(oInstance, amd); Log.Debug(oInstance.Name + " OnSuccess action complete."); } // if } catch (Exception e) { Log.Alert(e, "Exception during executing " + oArgs.StrategyType + " strategy."); amd.Comment = e.Message; SaveActionStatus(amd, ActionStatus.Failed); if (oArgs.OnFail != null) { Log.Debug(oArgs.StrategyType + " instance running failed, invoking an OnFail action..."); try { oArgs.OnFail(amd); Log.Debug(oArgs.StrategyType + " OnFail action complete."); } catch (Exception ie) { Log.Alert( ie, "Exception during executing of OnFail handler of " + oArgs.StrategyType + " strategy." ); } // try } // if } // try }); SaveActionStatus(amd, ActionStatus.Launched); if (oArgs.OnLaunch != null) { Log.Debug(oArgs.StrategyType + " instance is to be launched, invoking an OnLaunch action..."); oArgs.OnLaunch(amd); Log.Debug(oArgs.StrategyType + " OnLaunch action complete."); } // if amd.UnderlyingThread.Start(); Log.Debug( "Executing {0} started on another thread [{1}].", oArgs.StrategyType, amd.UnderlyingThread.ManagedThreadId ); return(amd); } catch (Exception e) { if (amd != null) { amd.Comment += " Exception caught: " + e.Message; SaveActionStatus(amd, ActionStatus.Failed); } // if if (!(e is AException)) { string sStrategyType = oArgs == null ? "UNKNOWN" : oArgs.StrategyType.ToString(); Log.Alert(e, "Exception during executing " + sStrategyType + " strategy."); } // if if ((oArgs != null) && (oArgs.OnException != null)) { try { oArgs.OnException(amd); } catch (Exception ie) { Log.Alert( ie, "Exception during executing of OnException handler of " + oArgs.StrategyType + " strategy." ); } // try } // if throw new FaultException(e.Message); } // try } // Execute
} // GetBusinessData public override void Execute() { Log.Info( "Starting company check with parameters: IsLimited={0} ExperianRefNum={1}", this.isLimited ? "yes" : "no", this.experianRefNum ); if (!this.foundCompany || (this.experianRefNum == "NotFound")) { Log.Info("Can't execute Experian company check for customer with no company"); return; } // if string experianError = null; BusinessReturnData oExperianData = null; if (string.IsNullOrEmpty(this.experianRefNum)) { experianError = "RefNumber is empty"; } else { Log.Info("ExperianCompanyCheck strategy will make sure we have experian data"); oExperianData = GetBusinessData( this.isLimited, this.experianRefNum, this.customerId, false, this.forceCheck ); if (oExperianData != null) { Log.Info( "Fetched BureauScore {0} & MaxBureauScore {1} for customer {2}.", oExperianData.BureauScore, oExperianData.MaxBureauScore, this.customerId ); if (!oExperianData.IsError) { MaxScore = oExperianData.MaxBureauScore; Score = oExperianData.BureauScore; Log.Info("Filled Score & MaxScore of the strategy"); } else { experianError = oExperianData.Error; } if (!oExperianData.CacheHit && CurrentValues.Instance.CreditSafeEnabled) { try { AStrategy stra = this.isLimited ? (AStrategy) new ServiceLogCreditSafeLtd(this.experianRefNum, this.customerId) : (AStrategy) new ServiceLogCreditSafeNonLtd(this.customerId); stra.Execute(); } catch (Exception e) { Log.Error(e, "CreditSafeLtd/NonLtd NonCachHit failed for unexpected reason"); } // try } // if } // if } // if if (!string.IsNullOrEmpty(experianError)) { Log.Warn( "Error in experian company check. Customer:{0} RefNumber:{1} Errors: {2}", this.customerId, this.experianRefNum, experianError ); } // if Log.Info("Filling Analytics with Score: {0} & max score: {1}", Score, MaxScore); if (oExperianData == null) { Log.Debug("Premature completion: no data received from Experian."); return; } // if if (oExperianData.IsError) { Log.Debug("Premature completion because of error: {0}.", oExperianData.Error); return; } // if if (oExperianData.IsLimited) { new UpdateLimitedExperianDirectors(this.customerId, oExperianData.ServiceLogID).Execute(); } if (this.doSilentAutomation) { new SilentAutomation(this.customerId).SetTag(SilentAutomation.Callers.Company).Execute(); } } // Execute