Beispiel #1
0
        public async Task <object> OnResponse(object response, ResultExecutingContext context, Dictionary <string, string> settings)
        {
            var str = response as string;

            if (string.IsNullOrEmpty(str) || settings == null)
            {
                throw new ResponseErrorException(ResponseErrorCode.InternalException, "Failed to reset password. ");
            }
            if (!settings.ContainsKey("SQSQueueUrl") || string.IsNullOrEmpty(settings["SQSQueueUrl"]) ||
                !settings.ContainsKey("AccessKey") || string.IsNullOrEmpty(settings["AccessKey"]) ||
                !settings.ContainsKey("SecretKey") || string.IsNullOrEmpty(settings["SecretKey"]) ||
                !settings.ContainsKey("Region") || string.IsNullOrEmpty(settings["Region"]))
            {
                throw new ResponseErrorException(ResponseErrorCode.InternalException, "Missing SQS settings. ");
            }
            try
            {
                var client = FDAmazonSQSClient.Instance;
                if (client == null)
                {
                    var region = RegionEndpoint.GetBySystemName(settings["Region"].Trim().ToLower());
                    client = FDAmazonSQSClient.Initialize(settings["AccessKey"].Trim(), settings["SecretKey"].Trim(), region);
                }
                await client.SendMessageAsync(settings["SQSQueueUrl"].Trim(), str);
            }
            catch (Exception e)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Error(e, e.Message);
                throw new ResponseErrorException(ResponseErrorCode.InternalException, e.Message);
            }
            return(await Task.FromResult(response));
        }
Beispiel #2
0
 public static FDAmazonSQSClient Initialize(string accessKey, string secretKey, RegionEndpoint regionEndpoint)
 {
     if (instance == null)
     {
         lock (syncRoot)
         {
             var config = new AmazonSQSConfig
             {
                 Timeout        = new TimeSpan(0, 0, 5),
                 RegionEndpoint = regionEndpoint
             };
             instance    = new FDAmazonSQSClient(config, accessKey, secretKey);
             initialized = true;
         }
     }
     return(instance);
 }
Beispiel #3
0
        public async Task <object> OnResponse(object response, ResultExecutingContext context, Dictionary <string, string> settings)
        {
            var requestData = response as CommitAgentResponse;

            if (requestData == null || requestData.CommitAgentResData == null || requestData.CommitAgentResData.Agent == null)
            {
                return(await Task.FromResult(response));
            }
            var agentRoles = requestData.CommitAgentResData.Agent.AgentRoles;

            if (agentRoles != null && agentRoles.Length > 0 && agentRoles[0].RoleCode == Constants.MemberRoleCode)
            {
                // assume new member was created if current session is an anonymous session
                var sessionBag = context.HttpContext.RequestServices.GetService(typeof(ISessionBagService)) as SessionBagService;
                if (await sessionBag.RoleCode() != Constants.AnonymousAgentRoleCode)
                {
                    return(await Task.FromResult(response));
                }

                var parameters = new List <Parameter>
                {
                    new Parameter {
                        name = "CultureCode", value = requestData.CommitAgentResData.Person.CultureCode
                    },
                    new Parameter {
                        name = "Destination", value = requestData.CommitAgentResData.Person.EmailAddress
                    }
                };
                var message = new Message
                {
                    Organization = new Organization
                    {
                        ContactTitle     = requestData.CommitAgentResData.Person.Name.Title,
                        ContactFirstName = requestData.CommitAgentResData.Person.Name.FirstName,
                        ContactLastName  = requestData.CommitAgentResData.Person.Name.LastName,
                        EmailAddress     = requestData.CommitAgentResData.Person.EmailAddress
                    }
                };
                var obj = new MemberActivation
                {
                    parameters = parameters,
                    message    = message
                };
                var jsonStr = JsonConvert.SerializeObject(obj);
                try
                {
                    var client = FDAmazonSQSClient.Instance;
                    if (client == null)
                    {
                        var region = RegionEndpoint.GetBySystemName(settings["Region"].Trim().ToLower());
                        client = FDAmazonSQSClient.Initialize(settings["AccessKey"].Trim(), settings["SecretKey"].Trim(), region);
                    }
                    await client.SendMessageAsync(settings["SQSQueueUrl"].Trim(), jsonStr);
                }
                catch (Exception e)
                {
                    Logger logger = LogManager.GetCurrentClassLogger();
                    logger.Error(e, e.Message);
                    throw new ResponseErrorException(ResponseErrorCode.InternalException, e.Message);
                }
            }
            return(await Task.FromResult(response));
        }