Returns information about the GetSendQuota response and response metadata.
상속: GetSendQuotaResult
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetSendQuotaResponse response = new GetSendQuotaResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {                    
                    if(context.TestExpression("GetSendQuotaResult", 2))
                    {
                        UnmarshallResult(context, response);                        
                        continue;
                    }
                    
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return response;
        }
		public static void Write(GetSendQuotaResponse responseStats, bool verbose) {
			if (verbose) {
				var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(GetSendQuotaResponse));
				xmlSerializer.Serialize(Console.Out, responseStats);
			} else {
				Console.WriteLine("Max24HourSend: " + responseStats.GetSendQuotaResult.Max24HourSend);
				Console.WriteLine("MaxSendRate: " + responseStats.GetSendQuotaResult.MaxSendRate);
				Console.WriteLine("SentLast24Hours: " + responseStats.GetSendQuotaResult.SentLast24Hours);
			}
		}
        private static void UnmarshallResult(XmlUnmarshallerContext context,GetSendQuotaResponse response)
        {
            
            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            
            if (context.IsStartOfDocument) 
               targetDepth += 2;
            
            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Max24HourSend", targetDepth))
                    {
                        response.Max24HourSend = DoubleUnmarshaller.GetInstance().Unmarshall(context);
                            
                        continue;
                    }
                    if (context.TestExpression("MaxSendRate", targetDepth))
                    {
                        response.MaxSendRate = DoubleUnmarshaller.GetInstance().Unmarshall(context);
                            
                        continue;
                    }
                    if (context.TestExpression("SentLast24Hours", targetDepth))
                    {
                        response.SentLast24Hours = DoubleUnmarshaller.GetInstance().Unmarshall(context);
                            
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }
                            


            return;
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetSendQuotaResponse response = new GetSendQuotaResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if(context.TestExpression("GetSendQuotaResult", 2))
                    {
                        response.GetSendQuotaResult = GetSendQuotaResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }

            return response;
        }
예제 #5
0
        private void StartMta()
        {
            // Check if there is already a thread running, if not start one to start proccessing the queue
            if (_mta != null && _mta.IsAlive)
                return;

            _mta = new Thread(() =>
            {
                // Create an amazon ses client
                // Retreive send rate
                if (_ses == null)
                {
                    _ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AwsAccessKey, AwsSecretKey);

                    // Try and get the sending quota from amazon
                    // This will fail if invalid credentials are provided
                    try
                    {
                        _quota = _ses.GetSendQuota(new GetSendQuotaRequest());
                    }
                    catch (Exception ex)
                    {
                        InternalLogger.Fatal("Error retreiving send quota from amazone: {0}", ex.Message);
                        return;
                    }

                    InternalLogger.Info("Amazon SES quota loaded, max send rate: {0} per second, 24 hour quota: {1}, sent in the last 24 hours: {2}", _quota.GetSendQuotaResult.MaxSendRate, _quota.GetSendQuotaResult.Max24HourSend, _quota.GetSendQuotaResult.SentLast24Hours);
                }

                while (true)
                {
                    // Try and get a message from the queue
                    // will fail if there are no messages to send
                    Message message = null;
                    try
                    {
                        message = (Message)_queue.Dequeue();
                    }
                    catch (Exception ex)
                    {
                        InternalLogger.Error("Error dequeuing message: {0}", ex.Message);
                        return;
                    }

                    var request = new SendEmailRequest();
                    request.WithDestination(new Destination(To.Split(',').ToList()));
                    request.WithMessage(message);
                    request.WithSource(From);

                    try
                    {
                        var response = _ses.SendEmail(request);

                        var result = response.SendEmailResult;

                        InternalLogger.Debug("Amazon SES message sent, id: {0}", result.MessageId);
                    }
                    catch (Exception ex)
                    {
                        InternalLogger.Error("Error sending message: {0}", ex.Message);
                    }

                    // sleep for the required send rate quota
                    Thread.Sleep((int)(1000 / _quota.GetSendQuotaResult.MaxSendRate));
                }
            });
            _mta.Start();
        }