} // CreateErrorResult private void CreateOfferResult(string errorMsg = null) { bool hasError = !string.IsNullOrWhiteSpace(errorMsg); if (hasError) { Log.Warn("{0}", errorMsg); } OfferResult = new OfferResult { CustomerId = this.customerID, CalculationTime = DateTime.UtcNow, Amount = ProposedAmount, MedalClassification = Medal == null ? EZBob.DatabaseLib.Model.Database.Medal.NoClassification : Medal.MedalClassification, FlowType = this.autoRejectionOutput.FlowType, GradeID = this.gradeID, SubGradeID = this.subGradeID, CashRequestID = this.cashRequestID, NLCashRequestID = this.nlCashRequestID, ScenarioName = this.autoRejectionOutput.FlowType.ToString(), Period = this.repaymentPeriod, LoanTypeId = this.loanTypeID, LoanSourceId = LoanSourceID, Message = hasError ? errorMsg.Trim() : null, IsError = hasError, IsMismatch = false, HasDecision = !hasError, }; } // CreateOfferResult
public DispatchNotifications( string outerContextDescription, bool isSilentlyApproved, StrategiesMailer mailer, MedalResult medal, CustomerDetails customerDetails, AutoDecisionResponse autoDecisionResponse, OfferResult offerResult, Guid?approvalTrailUniqueID, string silentEmailRecipient, string silentEmailSenderName, string silentEmailSenderAddress ) : base(outerContextDescription) { this.isSilentlyApproved = isSilentlyApproved; this.mailer = mailer; this.medal = medal; this.customerDetails = customerDetails; this.autoDecisionResponse = autoDecisionResponse; this.offerResult = offerResult; this.approvalTrailUniqueID = approvalTrailUniqueID; this.silentEmailRecipient = silentEmailRecipient; this.silentEmailSenderName = silentEmailSenderName; this.silentEmailSenderAddress = silentEmailSenderAddress; } // constructor
protected override StepResults Run() { if (this.autoRejectionOutput.FlowType == AutoDecisionFlowTypes.Unknown) { Log.Alert("Illegal flow type specified for {0}, auto decision is aborted.", OuterContextDescription); this.outcome = "'failure - illegal flow type'"; return(StepResults.Failed); } // if this.medalAgent.Execute(); switch (this.autoRejectionOutput.FlowType) { case AutoDecisionFlowTypes.LogicalGlue: CreateLogicalOffer(); break; case AutoDecisionFlowTypes.Internal: CreateUnlogicalOffer(); break; default: throw new ArgumentOutOfRangeException(); } // switch if (OfferResult != null) { Log.Msg("Offer proposed for {0}:\n{1}.", OuterContextDescription, OfferResult); OfferResult.SaveToDb(DB); } // if bool failure = (OfferResult == null) || OfferResult.IsError || OfferResult.IsMismatch || !OfferResult.HasDecision || (LoanSourceID <= 0); if (failure) { this.outcome = "'failure'"; return(StepResults.Failed); } // if this.outcome = "'success'"; return(StepResults.Success); } // Run
/// <summary> /// ACCEPT means driver has accepted, no output required. /// PASS and EXPIRE means driver has either rejected the offer, /// or it has expired. Add the shipmentId associated with this offer /// to the expired/rejected offers for the given driver and output /// the name of the next best driver. /// </summary> /// <param name="shipmentId"></param> /// <param name="result"></param> /// <param name="driverName"></param> /// <param name="hasError">If error was encountered, we want to output it even if it was accepted.</param> /// <returns></returns> public string Offer(uint shipmentId, OfferResult result, string driverName, out bool hasError) { hasError = false; Driver driver; if (!_nameToDriver.TryGetValue(driverName, out driver)) { hasError = true; return(string.Format("Error: unrecognized driver \'{0}\'", driverName)); } uint requiredCapacity; if (!_shipmentToCapacity.TryGetValue(shipmentId, out requiredCapacity)) { hasError = true; return(string.Format("Error: unrecognized shipment ID \'{0}\'", shipmentId)); } switch (result) { case OfferResult.accept: return(null); case OfferResult.expire: case OfferResult.pass: // Offer expired or driver rejected, return next best driver driver.AddRejectedExpiredOffer(shipmentId); var bestDriver = GetBestDriver(shipmentId, requiredCapacity); if (bestDriver != null) { driver.IncrementOfferCount(); return(bestDriver.Name); } else { return(null); } default: return(null); } }
public LockApproved( string outerContextDescription, AutoDecisionResponse autoDecisionResponse, bool autoApproveIsSilent, OfferResult offerResult, int loanSourceID, bool isEmailSendingBanned, int offerValidForHours, int minLoanAmount, int maxLoanAmount, int?productSubTypeID ) : base(outerContextDescription) { this.autoDecisionResponse = autoDecisionResponse; this.autoApproveIsSilent = autoApproveIsSilent; this.offerResult = offerResult; this.loanSourceID = loanSourceID; this.isEmailSendingBanned = isEmailSendingBanned; this.offerValidForHours = offerValidForHours; this.minLoanAmount = minLoanAmount; this.maxLoanAmount = maxLoanAmount; this.productSubTypeID = productSubTypeID; IsSilentlyApproved = false; } // constructor
public void SignalingHandler(WebSocket webSocket, byte[] Incbuffer, WebSocketReceiveResult result) { var buffer = Incbuffer.Where(x => x != 0).ToArray(); var strCommand = Encoding.ASCII.GetString(buffer).Replace(@"\0", string.Empty); var objBuffer = new Tuple <byte[], int>(null, 0); try { dynamic objSocket = new ExpandoObject(); objSocket.connection = webSocket; objSocket.name = string.Empty; objSocket.otherName = string.Empty; BaseObject incType = null; CandidateObject CandidateType = null; try { //Todo : You Can Do This Part Better That This //Fix Commands With Leave Handeling v1 strCommand = StringHelper.FixCommand(strCommand); incType = SerializationHelper.Deserialize <BaseObject>(strCommand); } catch (Exception e) { Console.WriteLine(e); throw; } if (incType.type == ClsEnumeration.EnumCommandType.login.ToString()) { var loginObj = new LoginResult() { type = "login", success = "true" }; var incData = SerializationHelper.Deserialize <LoginObject>(strCommand); try { if (ClsStatics.UsersStatic.ContainsKey(incData.name)) { ClsStatics.UsersStatic.Remove(incData.name); objSocket.name = incData.name; ClsStatics.UsersStatic.Add(incData.name, objSocket); objBuffer = ObjectHelper.GetObjectBuffer(loginObj); objSocket.connection.SendAsync( new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); Console.WriteLine($"Send Success Login For User {incData.name}"); } else { loginObj.success = "false"; objSocket.name = incData.name; ClsStatics.UsersStatic.Add(incData.name, objSocket); objBuffer = ObjectHelper.GetObjectBuffer(loginObj); objSocket.connection.SendAsync( new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); Console.WriteLine($"Send Success Login For User {incData.name}"); } } catch (Exception e) { objBuffer = ObjectHelper.GetObjectBuffer(loginObj); objSocket.connection.SendAsync( new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); Console.WriteLine($"Send Failed Login For User {incData.name}"); } } if (incType.type == ClsEnumeration.EnumCommandType.offer.ToString()) { var incData = SerializationHelper.Deserialize <OfferObject>(strCommand); //for ex. UserA wants to call UserB //if UserB exists then send him offer details dynamic Dyncon = ClsStatics.UsersStatic[incData.name]; if (Dyncon != null) { var offResObj = new OfferResult() { type = "offer", offer = incData.offer, name = incData.Owner }; Dyncon.otherName = incData.name; objBuffer = ObjectHelper.GetObjectBuffer(offResObj); Dyncon.connection.SendAsync(new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); Console.WriteLine($"Sending offer from : {incData.Owner} to: {incData.name}"); } } if (incType.type == ClsEnumeration.EnumCommandType.candidate.ToString()) { lock (ClsStatics.MessageLockCandidate) { var incData = SerializationHelper.Deserialize <CandidateObject>(strCommand); dynamic Dyncon = ClsStatics.UsersStatic[incData.name]; if (Dyncon != null) { var candidateResObj = new CandidateResult() { type = "candidate", candidate = incData.candidate }; objBuffer = ObjectHelper.GetObjectBuffer(candidateResObj); Dyncon.connection.SendAsync(new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); Console.WriteLine("Sending candidate to:", incData.name); } } } if (incType.type == ClsEnumeration.EnumCommandType.answer.ToString()) { var incData = SerializationHelper.Deserialize <AnswerObject>(strCommand); dynamic Dyncon = ClsStatics.UsersStatic[incData.name]; Console.WriteLine($"Sending answer to: {incData.name}"); //for ex. UserB answers UserA if (Dyncon != null) { var answerObj = new AnswerObject() { type = "answer", answer = incData.answer }; objBuffer = ObjectHelper.GetObjectBuffer(answerObj); Dyncon.connection.SendAsync( new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); } } else if (incType.type == ClsEnumeration.EnumCommandType.leave.ToString()) { lock (ClsStatics.MessageLockCandidate) { var incData = SerializationHelper.Deserialize <LoginObject>(strCommand); dynamic Dyncon = ClsStatics.UsersStatic[incData.name]; Dyncon.otherName = null; Console.WriteLine(string.Format("Sending answer to: {0}", incData.name)); //for ex. UserB answers UserA if (Dyncon != null) { var leaveObj = new BaseObject() { type = "leave" }; objBuffer = ObjectHelper.GetObjectBuffer(leaveObj); Dyncon.connection.SendAsync( new ArraySegment <byte>(objBuffer.Item1, 0, objBuffer.Item2), result.MessageType, result.EndOfMessage, CancellationToken.None); ClsStatics.UsersStatic.Remove(incData.name); } } } } catch (Exception e) { Console.WriteLine(e); } //await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, result.Count), result.MessageType, result.EndOfMessage, CancellationToken.None); }
} // Outcome protected override StepResults Run() { BackdoorInvestorID = null; ABackdoorSimpleDetails backdoorSimpleDetails = CreateBackdoor(); if (backdoorSimpleDetails == null) { Log.Debug( "Not using back door simple for {0}: back door code from customer email '{1}' " + "ain't no matches any existing back door regex.", OuterContextDescription, this.customerEmail ); return(StepResults.NotApplied); } // if Log.Debug("Using back door simple for {0} as: {1}.", OuterContextDescription, backdoorSimpleDetails); backdoorSimpleDetails.SetAdditionalCustomerData( this.cashRequestID, this.nlCashRequestID, this.smallLoanScenarioLimit, this.aspireToMinSetupFee, this.typeOfBusiness, this.customerOriginID, this.requestedLoan, this.offerValidHours ); if (!backdoorSimpleDetails.SetResult(AutoDecisionResponse)) { return(StepResults.NotApplied); } Medal = backdoorSimpleDetails.Medal; OfferResult = backdoorSimpleDetails.OfferResult; Medal.SaveToDb(this.cashRequestID, this.nlCashRequestID, this.tag, DB); OfferResult.SaveToDb(DB); BackdoorLogicApplied = true; if (backdoorSimpleDetails.Decision != DecisionActions.Approve) { return(StepResults.Applied); } BackdoorSimpleApprove bsa = backdoorSimpleDetails as BackdoorSimpleApprove; if (bsa == null) // Should never happen because of the "if" condition. { BackdoorLogicApplied = false; return(StepResults.NotApplied); } // if BackdoorInvestorID = bsa.InvestorID; Medal.MedalClassification = bsa.MedalClassification; Medal.OfferedLoanAmount = bsa.ApprovedAmount; Medal.TotalScoreNormalized = 1m; Medal.AnnualTurnover = bsa.ApprovedAmount; var glcd = new GetLoanCommissionDefaults(this.cashRequestID, bsa.ApprovedAmount); glcd.Execute(); if (!glcd.IsBrokerCustomer) { return(StepResults.Applied); } AutoDecisionResponse.BrokerSetupFeePercent = glcd.Result.BrokerCommission; AutoDecisionResponse.SetupFee = glcd.Result.ManualSetupFee; return(StepResults.Applied); } // Run