private bool TryUpdateMservEntry(ADUser user, FblRequestParameters fblRequestParameters) { bool result; try { if (user == null || fblRequestParameters == null) { result = false; } else { if (this.tenantRecipientSession is IAggregateSession) { ((IAggregateSession)this.tenantRecipientSession).MbxReadMode = MbxReadMode.NoMbxRead; } user[ADUserSchema.FblEnabled] = fblRequestParameters.OptIn; this.tenantRecipientSession.Save(user); FBLPerfCounters.NumberOfSuccessfulMSERVWriteRequests.Increment(); result = true; } } catch (Exception ex) { FBLPerfCounters.NumberOfFailedMSERVWriteRequests.Increment(); LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_TransientFblErrorUpdatingMServ, new object[] { ex.InnerException ?? ex }); result = false; } return(result); }
private EmailMessage CreateFblRequestMessage(FblRequestParameters requestParameters) { if (requestParameters == null) { throw new ArgumentNullException("requestParameters", "Cannot create FBL Request Message from null request parameters."); } EmailMessage emailMessage = EmailMessage.Create(); this.AddHeader(emailMessage, "X-Version", "1"); this.AddHeader(emailMessage, "X-GuidCustomer", requestParameters.CustomerGuid.ToString()); if (requestParameters.IsClassifyRequest()) { this.AddHeader(emailMessage, "X-GuidMail", requestParameters.MailGuid.ToString()); this.AddHeader(emailMessage, "X-Class", requestParameters.MessageClass); } else { RoutingAddress routingAddress = new RoutingAddress(requestParameters.PrimaryEmail); this.AddHeader(emailMessage, "X-UserName", routingAddress.LocalPart); this.AddHeader(emailMessage, "X-Domain", routingAddress.DomainPart); this.AddHeader(emailMessage, "X-OptIn", requestParameters.OptIn ? "1" : "0"); } this.AddEncryptedMessageRoutingHeaderToMessage(emailMessage); return(emailMessage); }
private void ProcessClassificationRequest(FblRequestParameters fblRequestParameters) { if (fblRequestParameters == null) { return; } Task.Factory.StartNew(delegate() { FBLPerfCounters.NumberOfFblClassificationRequestsReceived.Increment(); ADRawEntry adrawEntry = this.GetADRawEntry(fblRequestParameters.Puid, fblRequestParameters.PrimaryEmail); if (!this.IsFblUser(adrawEntry)) { FBLPerfCounters.NumberOfFblClassificationRequestsSuccessfullyProcessed.Increment(); return; } if (this.TryPrepareAndSendXmrMessage(fblRequestParameters, "*****@*****.**")) { FBLPerfCounters.NumberOfFblClassificationRequestsSuccessfullyProcessed.Increment(); return; } FBLPerfCounters.NumberOfFblClassificationRequestsFailed.Increment(); }).ContinueWith(delegate(Task t) { if (t.Exception != null) { FBLPerfCounters.NumberOfFblClassificationRequestsFailed.Increment(); Exception innerException = t.Exception.Flatten().InnerException; LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblUnableToProcessRequest, new object[] { innerException }); } }, TaskContinuationOptions.OnlyOnFaulted); }
internal bool TryProcessFbl(string queryParams, out bool?isClassifyRequest, out bool?isOptIn) { isClassifyRequest = null; isOptIn = null; FblRequestParameters fblRequestParameters = null; bool result; try { FBLPerfCounters.NumberOfFblRequestsReceived.Increment(); if (!this.FblEnabled) { result = true; } else if (string.IsNullOrEmpty(queryParams)) { FBLPerfCounters.NumberOfFblRequestsFailed.Increment(); result = false; } else { fblRequestParameters = this.DecryptAndParseUrlParameters(queryParams); if (fblRequestParameters == null) { result = false; } else { if (fblRequestParameters.IsClassifyRequest()) { isClassifyRequest = new bool?(true); this.ProcessClassificationRequest(fblRequestParameters); } else { isClassifyRequest = new bool?(false); isOptIn = new bool?(fblRequestParameters.OptIn); if (!this.TryProcessSubscriptionRequest(fblRequestParameters)) { FBLPerfCounters.NumberOfFblRequestsFailed.Increment(); return(false); } } FBLPerfCounters.NumberOfFblRequestsSuccessfullyProcessed.Increment(); result = true; } } } catch (Exception ex) { FBLPerfCounters.NumberOfFblRequestsFailed.Increment(); LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblUnableToProcessRequest, new object[] { ex.InnerException ?? ex }); result = (fblRequestParameters != null && fblRequestParameters.IsClassifyRequest()); } return(result); }
private bool TryProcessSubscriptionRequest(FblRequestParameters fblRequestParameters) { if (fblRequestParameters == null) { return(false); } ExPerformanceCounter exPerformanceCounter = fblRequestParameters.OptIn ? FBLPerfCounters.NumberOfFblOptInRequestsReceived : FBLPerfCounters.NumberOfFblOptOutRequestsReceived; ExPerformanceCounter successSubscriptionCounter = fblRequestParameters.OptIn ? FBLPerfCounters.NumberOfFblOptInRequestsSuccessfullyProcessed : FBLPerfCounters.NumberOfFblOptOutRequestsSuccessfullyProcessed; ExPerformanceCounter failedSubscriptionCounter = fblRequestParameters.OptIn ? FBLPerfCounters.NumberOfFblOptInRequestsFailed : FBLPerfCounters.NumberOfFblOptOutRequestsFailed; try { FBLPerfCounters.NumberOfFblSubscriptionRequestsReceived.Increment(); exPerformanceCounter.Increment(); ADUser aduser = this.GetADUser(fblRequestParameters.Puid, fblRequestParameters.PrimaryEmail); if (aduser == null || !this.TryUpdateMservEntry(aduser, fblRequestParameters)) { FBLPerfCounters.NumberOfFblSubscriptionRequestsFailed.Increment(); failedSubscriptionCounter.Increment(); return(false); } Task.Factory.StartNew(delegate() { if (this.TryPrepareAndSendXmrMessage(fblRequestParameters, "*****@*****.**")) { FBLPerfCounters.NumberOfFblSubscriptionRequestsSuccessfullyProcessed.Increment(); successSubscriptionCounter.Increment(); return; } FBLPerfCounters.NumberOfFblSubscriptionRequestsFailed.Increment(); failedSubscriptionCounter.Increment(); }).ContinueWith(delegate(Task t) { if (t.Exception != null) { FBLPerfCounters.NumberOfFblSubscriptionRequestsFailed.Increment(); failedSubscriptionCounter.Increment(); Exception innerException = t.Exception.Flatten().InnerException; LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblUnableToProcessRequest, new object[] { innerException }); } }, TaskContinuationOptions.OnlyOnFaulted); } catch (Exception ex) { FBLPerfCounters.NumberOfFblSubscriptionRequestsFailed.Increment(); failedSubscriptionCounter.Increment(); LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblUnableToProcessRequest, new object[] { ex.InnerException ?? ex }); return(false); } return(true); }
private bool TryPrepareAndSendXmrMessage(FblRequestParameters fblRequestParameters, string recipientAddress) { if (fblRequestParameters == null || string.IsNullOrEmpty(recipientAddress)) { return(false); } try { EmailMessage msg = this.CreateFblRequestMessage(fblRequestParameters); this.SendMessage(msg, recipientAddress); FBLPerfCounters.NumberOfXMRMessagesSuccessfullySent.Increment(); return(true); } catch (FailedToConnectToSMTPServerException ex) { LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblFailedToConnectToSmtpServer, new object[] { ex }); } catch (UnexpectedSmtpServerResponseException ex2) { LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblSmtpServerResponse, new object[] { ex2 }); } catch (Exception ex3) { LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_FblErrorSendingMessage, new object[] { ex3.InnerException ?? ex3 }); } FBLPerfCounters.NumberOfXMRMessagesFailedToSend.Increment(); return(false); }