Changeset 4749
- Timestamp:
- 07/23/08 18:05:36 (4 months ago)
- Files:
-
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs (modified) (5 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Extensions (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Extensions/ExtensionMethods.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Handler/ExceptionHandler.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/IEnumerableIAsyncWorkerQueue.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/SimpleDBProcessQueue.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/TaskWorkerQueue.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/NoLoadBalanceAgent.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj (modified) (5 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Process (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Process/SimpleDBProcess.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/AssemblyInfo.cs (modified) (2 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/Settings.Designer.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Response/IResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Scope/LoggerScope.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Service References (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Operation/Operation.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/CreateDomainRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/DeleteDomainRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/GetAttributesRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/ListDomainsRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/PutAttributesRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/QueryRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/CreateDomainResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/DeleteDomainResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/GetAttributesResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/ListDomainsResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/PutAttributesResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/QueryResponse.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs (modified) (6 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/CreateDomain.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/DeleteDomain.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/GetAttributes.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/ITask.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/ListDomains.cs (modified) (2 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/PutAttributes.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/Query.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SyncAgent.cs (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/app.config (added)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/log4net.config (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs
r4729 r4749 15 15 using log4net; 16 16 using log4net.Config; 17 using System.Web; 18 using Nuxleus.Extension; 19 using System.Web.Configuration; 17 20 18 21 namespace Nuxleus.Extension.Aws { 19 22 20 public struct Agent<T> { 21 22 static readonly ILog m_loggerInstance = LogManager.GetLogger(typeof(T)); 23 public struct Agent { 23 24 24 25 static LoggerScope logger = new LoggerScope(); … … 27 28 static int m_workers = (int.Parse(ConfigurationManager.AppSettings["WorkerQueueMultiplier"]) * System.Environment.ProcessorCount); 28 29 29 public static ILog GetBasicLogger() {30 XmlConfigurator.Configure(new System.IO.FileInfo(("log4net.config")));31 return m_loggerInstance;32 }33 34 30 public void Initialize() { 35 31 ServicePointManager.DefaultConnectionLimit = int.Parse(ConfigurationManager.AppSettings["DefaultConnectionLimit"]); 32 33 //EnableDnsRoundRobin is not implemented on Mono 34 ServicePointManager.EnableDnsRoundRobin = true; 35 36 //ServicePointManager.Expect100Continue = true; 37 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 38 HttpRuntimeSection configSection = (HttpRuntimeSection)config.GetSection("system.web/httpRuntime"); 39 this.LogInfo("ServicePointManager Default Connection Limit: {0}", ServicePointManager.DefaultConnectionLimit); 40 this.LogInfo("system.web/httpRuntime/minFreeThreads: {0}", configSection.MinFreeThreads); 41 this.LogInfo("system.web/httpRuntime/minLocalRequestFreeThreads: {0}", configSection.MinLocalRequestFreeThreads); 42 36 43 int minWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MinimumWorkerThreads"]); 37 44 int minAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MinimumAsyncIOThreds"]); … … 51 58 52 59 scope.Begin = () => { 53 using ( WorkerQueue q = new WorkerQueue(m_workers)) {60 using (IEnumerableTWorkerQueue<IAsync> q = new IEnumerableTWorkerQueue<IAsync>(m_workers)) { 54 61 List<string> lines = new List<string>(); 55 62 using (StreamReader csvReader = new StreamReader(fileName, Encoding.UTF8, true)) { … … 88 95 89 96 private static IEnumerable<IAsync> InvokeOperation<T>(List<string> operation) { 90 Dictionary<IRequest, T> responseList = new Dictionary<IRequest, T>();91 97 IEnumerable<IAsync>[] processList = new IEnumerable<IAsync>[operation.Count]; 92 98 int i = 0; 93 99 foreach (string inputLine in operation) { 94 100 string[] inputArray = inputLine.Split(new char[] { '\u0009' }); 95 processList[i] = CreateTask <T>(inputArray).Invoke(responseList);101 processList[i] = CreateTask(inputArray).InvokeAsync(); 96 102 i++; 97 103 } … … 99 105 } 100 106 101 private static PutAttributes CreateTask <T>(string[] inputArray) {107 private static PutAttributes CreateTask(string[] inputArray) { 102 108 103 109 KeyValuePair<string, string>[] geoNames = trunk/nuxleus/Source/Nuxleus.Extension.Aws/Handler/ExceptionHandler.cs
r4729 r4749 11 11 namespace Nuxleus.Extension.Aws.SimpleDb { 12 12 public class ExceptionHandlerScope : HandlerBase { 13 14 WebException we;15 13 16 14 protected override void Call() { trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj
r4730 r4749 9 9 <OutputType>Library</OutputType> 10 10 <AppDesignerFolder>Properties</AppDesignerFolder> 11 <RootNamespace>Nuxleus.Extension.A WS</RootNamespace>12 <AssemblyName>Nuxleus.Extension.A WS</AssemblyName>11 <RootNamespace>Nuxleus.Extension.Aws</RootNamespace> 12 <AssemblyName>Nuxleus.Extension.Aws</AssemblyName> 13 13 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> … … 49 49 <RequiredTargetFramework>3.0</RequiredTargetFramework> 50 50 </Reference> 51 <Reference Include="System.Management" /> 51 52 <Reference Include="System.Runtime.Serialization"> 52 53 <RequiredTargetFramework>3.0</RequiredTargetFramework> … … 56 57 </Reference> 57 58 <Reference Include="System.Web" /> 59 <Reference Include="System.Web.Extensions"> 60 <RequiredTargetFramework>3.5</RequiredTargetFramework> 61 </Reference> 58 62 <Reference Include="System.Web.Services" /> 59 63 <Reference Include="System.Xml" /> … … 64 68 <ItemGroup> 65 69 <Compile Include="Agent.cs" /> 70 <Compile Include="AwsBaseConnection\HttpQueryConnection.cs" /> 71 <Compile Include="AwsBaseConnection\IAwsConnection.cs" /> 72 <Compile Include="Extensions\ExtensionMethods.cs" /> 73 <Compile Include="LoadBalancer\SimpleDBProcessQueue.cs" /> 74 <Compile Include="NoLoadBalanceAgent.cs" /> 75 <Compile Include="LoadBalancer\TaskWorkerQueue.cs" /> 76 <Compile Include="Process\SimpleDBProcess.cs"> 77 <SubType>Component</SubType> 78 </Compile> 79 <Compile Include="SyncAgent.cs" /> 66 80 <Compile Include="Handler\ExceptionHandler.cs" /> 67 <Compile Include="HttpQueryConnection.cs" /> 68 <Compile Include="IAwsConnection.cs" /> 81 <Compile Include="LoadBalancer\IEnumerableIAsyncWorkerQueue.cs" /> 69 82 <Compile Include="LoadBalancer\WorkerQueue.cs" /> 70 83 <Compile Include="Properties\AssemblyInfo.cs" /> … … 104 117 </ItemGroup> 105 118 <ItemGroup> 119 <None Include="app.config"> 120 <CopyToOutputDirectory>Always</CopyToOutputDirectory> 121 </None> 106 122 <None Include="Extf.Net.snk" /> 107 123 <None Include="log4net.config"> trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/AssemblyInfo.cs
r4148 r4749 2 2 using System.Runtime.CompilerServices; 3 3 using System.Runtime.InteropServices; 4 using System.Security; 4 5 5 6 // General Information about an assembly is controlled through the following 6 7 // set of attributes. Change these attribute values to modify the information 7 8 // associated with an assembly. 8 [assembly: AssemblyTitle("Nuxleus.Extension.A WS")]9 [assembly: AssemblyTitle("Nuxleus.Extension.Aws")] 9 10 [assembly: AssemblyDescription("")] 10 11 [assembly: AssemblyConfiguration("")] 11 12 [assembly: AssemblyCompany("third&urban")] 12 [assembly: AssemblyProduct("Nuxleus.Extension.A WS")]13 [assembly: AssemblyProduct("Nuxleus.Extension.Aws")] 13 14 [assembly: AssemblyCopyright("Copyright © third&urban 2007")] 14 15 [assembly: AssemblyTrademark("")] … … 35 36 [assembly: AssemblyVersion("1.0.0.0")] 36 37 [assembly: AssemblyFileVersion("1.0.0.0")] 38 [assembly: AllowPartiallyTrustedCallers] trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/Settings.Designer.cs
r4715 r4749 9 9 //------------------------------------------------------------------------------ 10 10 11 namespace Nuxleus.Extension.A WS.Properties {11 namespace Nuxleus.Extension.Aws.Properties { 12 12 13 13 trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs
r4729 r4749 8 8 public interface IRequest { 9 9 KeyValuePair<string, string>[] Headers { get; } 10 RequestType RequestType { get; }10 SdbRequestType RequestType { get; } 11 11 String RequestMessage { get; set; } 12 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/Response/IResponse.cs
r4729 r4749 8 8 public interface IResponse { 9 9 KeyValuePair<string,string>[] Headers { get; set;} 10 String Response { get; }10 String Response { get; set; } 11 11 } 12 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/Scope/LoggerScope.cs
r4729 r4749 4 4 using System.Text; 5 5 using VVMF.SOA.Common; 6 using System.Security.Permissions; 6 7 7 8 namespace Nuxleus.Extension.Aws.SimpleDb 8 9 { 10 11 //[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] 9 12 public class LoggerScope : HandlerBase 10 13 { trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Operation/Operation.cs
r4729 r4749 7 7 8 8 namespace Nuxleus.Extension.Aws.SimpleDb { 9 public struct Operation<T> { 10 9 public static class Operation { 10 //public static Async<String> GetResultAsync<T>(this Agent<T> req) { 11 // return new AsyncPrimitive<String>(req.BeginInvoke, req.EndInvoke); 12 //} 11 13 } 12 14 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/CreateDomainRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.CreateDomain;25 return SdbRequestType.CreateDomain; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/DeleteDomainRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.DeleteDomain;25 return SdbRequestType.DeleteDomain; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/GetAttributesRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.GetAttributes;25 return SdbRequestType.GetAttributes; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/ListDomainsRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.ListDomains;25 return SdbRequestType.ListDomains; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/PutAttributesRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.PutAttributes;25 return SdbRequestType.PutAttributes; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/QueryRequest.cs
r4729 r4749 21 21 } 22 22 23 public RequestType RequestType {23 public SdbRequestType RequestType { 24 24 get { 25 return RequestType.Query;25 return SdbRequestType.Query; 26 26 } 27 27 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/CreateDomainResponse.cs
r4729 r4749 7 7 8 8 public struct CreateDomainResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 9 public KeyValuePair<string, string>[] Headers { get; set; } 10 public string Response { get; set; } 27 11 } 28 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/DeleteDomainResponse.cs
r4729 r4749 7 7 8 8 public struct DeleteDomainResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 9 public KeyValuePair<string, string>[] Headers { get; set; } 10 public string Response { get; set; } 27 11 } 28 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/GetAttributesResponse.cs
r4729 r4749 7 7 8 8 public struct GetAttributesResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 9 public KeyValuePair<string, string>[] Headers { get; set; } 10 public string Response { get; set; } 27 11 } 28 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/ListDomainsResponse.cs
r4729 r4749 7 7 8 8 public struct ListDomainsResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 9 public KeyValuePair<string, string>[] Headers { get; set; } 10 public string Response { get; set; } 27 11 } 28 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/PutAttributesResponse.cs
r4729 r4749 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq;4 using System.Text;5 3 6 4 namespace Nuxleus.Extension.Aws.SimpleDb { 7 5 8 6 public struct PutAttributesResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 7 public KeyValuePair<string, string>[] Headers { get; set; } 8 public string Response { get; set; } 27 9 } 28 10 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/QueryResponse.cs
r4729 r4749 7 7 8 8 public struct QueryResponse : IResponse { 9 #region IResponse Members 10 11 public KeyValuePair<string, string>[] Headers { 12 get { 13 throw new NotImplementedException(); 14 } 15 set { 16 throw new NotImplementedException(); 17 } 18 } 19 20 public string Response { 21 get { 22 throw new NotImplementedException(); 23 } 24 } 25 26 #endregion 9 public KeyValuePair<string, string>[] Headers { get; set; } 10 public string Response { get; set; } 27 11 } 28 12 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs
r4729 r4749 20 20 namespace Nuxleus.Extension.Aws.SimpleDb { 21 21 22 public enum RequestType {22 public enum SdbRequestType { 23 23 [Label("Query")] 24 24 Query, … … 37 37 } 38 38 39 public struct SimpleDBService<TRequestType> { 40 41 static string AWS_PUBLIC_KEY = System.Environment.GetEnvironmentVariable("AWS_PUBLIC_KEY"); 42 static string AWS_PRIVATE_KEY = System.Environment.GetEnvironmentVariable("AWS_PRIVATE_KEY"); 43 static XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 44 static XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; 45 static XNamespace i = "http://www.w3.org/2001/XMLSchema-instance"; 39 public enum WebServiceType { 40 SOAP, 41 REST, 42 QUERY 43 } 44 45 public struct HttpRequestSettings { 46 public WebServiceType WebServiceType { get; set; } 47 public int Timeout { get; set; } 48 public bool KeepAlive { get; set; } 49 public bool Pipelined { get; set; } 50 public string Method { get; set; } 51 public string ContentType { get; set; } 52 } 53 54 public struct HttpWebService<TRequestType> { 55 56 static readonly string AWS_PUBLIC_KEY = System.Environment.GetEnvironmentVariable("AWS_PUBLIC_KEY"); 57 static readonly string AWS_PRIVATE_KEY = System.Environment.GetEnvironmentVariable("AWS_PRIVATE_KEY"); 58 static readonly string AWS_URI_ENDPOINT = System.Environment.GetEnvironmentVariable("AWS_URI_ENDPOINT"); 59 static readonly XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 60 static readonly XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; 61 static readonly XNamespace i = "http://www.w3.org/2001/XMLSchema-instance"; 46 62 static XmlSerializer m_xSerializer = new XmlSerializer(typeof(TRequestType)); 47 static ILog m_logger = Agent<SimpleDBService<TRequestType>>.GetBasicLogger(); 48 49 public static IEnumerable<IAsync> CallWebService<TResultType>(ITask task, IRequest sdbRequest, Dictionary<IRequest, TResultType> responseList) { 50 51 Encoding encoding = new UTF8Encoding(); 52 53 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sdb.amazonaws.com/"); 54 request.Timeout = 30000 /*TODO: This should be set dynamically*/; 63 static Encoding m_encoding = new UTF8Encoding(); 64 65 public static IResponse CallWebServiceSync(ITask task) { 66 67 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 68 request.Timeout = 5000 /*TODO: This should be set dynamically*/; 55 69 request.KeepAlive = true; 56 request.Pipelined = false; 70 request.Pipelined = true; 71 72 IRequest sdbRequest = task.Request; 57 73 58 74 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); … … 69 85 string soapMessage = output.ToString(); 70 86 sdbRequest.RequestMessage = soapMessage; 71 m_logger.DebugFormat("SOAP message for task {0}: {1}", task.TaskID, soapMessage);72 73 byte[] buffer = encoding.GetBytes(soapMessage);87 Log.LogDebug<HttpWebService<TRequestType>>("SOAP message for task {0}: {1}", task.TaskID, soapMessage); 88 89 byte[] buffer = m_encoding.GetBytes(soapMessage); 74 90 75 91 int contentLength = buffer.Length; … … 82 98 } 83 99 84 m_logger.DebugFormat("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);100 Log.LogDebug<HttpWebService<TRequestType>>("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 85 101 86 102 using (Stream newStream = request.GetRequestStream()) { 87 103 newStream.Write(buffer, 0, contentLength); 88 m_logger.DebugFormat("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 89 Async<WebResponse> response = request.GetResponseAsync(); 90 yield return response; 91 m_logger.DebugFormat("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 92 Stream stream = response.Result.GetResponseStream(); 93 Async<TResultType> responseObject = stream.ReadToEndAsync<TResultType>().ExecuteAsync<TResultType>(); 94 yield return responseObject; 95 responseList.Add(sdbRequest, responseObject.Result); 104 Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 105 WebResponse response = request.GetResponse(); 106 Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 107 using (StreamReader stream = new StreamReader(response.GetResponseStream())) { 108 task.Response.Response = stream.ReadToEnd(); 109 } 110 return task.Response; 111 } 112 } 113 114 public static IEnumerable<IAsync> CallWebService(ITask task) { 115 116 IRequest sdbRequest = task.Request; 117 118 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 119 using (XmlReader xreader = CreateSoapMessage(task, LabelAttribute.FromMember(sdbRequest.RequestType)).CreateReader()) { 120 while (xreader.Read()) { 121 if (xreader.IsStartElement()) { 122 output.Append(xreader.ReadOuterXml()); 123 } 124 } 125 } 126 127 string soapMessage = output.ToString(); 128 sdbRequest.RequestMessage = soapMessage; 129 byte[] buffer = m_encoding.GetBytes(soapMessage); 130 131 int contentLength = buffer.Length; 132 133 HttpWebRequest request = null; 134 135 try { 136 request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 137 request.Timeout = 10000 /*TODO: This should be set dynamically*/; 138 request.KeepAlive = true; 139 request.Pipelined = true; 140 request.ContentLength = contentLength; 141 request.Method = "POST"; 142 request.ContentType = "application/soap+xml"; 143 } catch (UriFormatException ufe) { 144 Log.LogInfo<HttpWebService<TRequestType>>("Caught UriFormatException on WebRequest.Create: {0}", ufe.Message); 145 } 146 147 foreach (KeyValuePair<string, string> header in sdbRequest.Headers) { 148 request.Headers.Add(header.Key, header.Value); 149 } 150 151 Stream webStream = null; 152 153 try { 154 webStream = request.GetRequestStream(); 155 } catch (WebException we) { 156 Log.LogInfo<HttpWebService<TRequestType>>("Caught WebException on GetResponseAsync: {0}", we.Message); 157 } 158 if (webStream != null) { 159 using (webStream) { 160 webStream.Write(buffer, 0, contentLength); 161 Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 162 163 Async<WebResponse> response = null; 164 try { 165 response = request.GetResponseAsync(); 166 Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 167 } catch (WebException we) { 168 Log.LogDebug<HttpWebService<TRequestType>>("The call to GetResponseAsync for {0} failed with the error: {1}.", task.TaskID, we.Message); 169 //TODO: Add the failed task to a retry queue. 170 } 171 if (response != null) { 172 yield return response; 173 Stream stream = null; 174 try { 175 stream = response.Result.GetResponseStream(); 176 } catch (NotSupportedException nse) { 177 Log.LogDebug<HttpWebService<TRequestType>>("Caught NotSupportedException on Result.GetResponseStream(): {0}", nse.Message); 178 } catch (WebException we) { 179 Log.LogDebug<HttpWebService<TRequestType>>("Caught WebException on Result.GetResponseStream(): {0}", we.Message); 180 } catch (Exception e) { 181 Log.LogDebug<HttpWebService<TRequestType>>("Caught Exception on Result.GetResponseStream(): {0}", e.Message); 182 } 183 if (stream != null) { 184 Async<String> responseObject = null; 185 try { 186 responseObject = stream.ReadToEndAsync<String>().ExecuteAsync<String>(); 187 } catch (Exception e) { 188 //TODO: Add the failed task to a retry queue. 189 Log.LogDebug<HttpWebService<TRequestType>>("The call to stream.ReadToEndAsync<String>().ExecuteAsync<String>() for {0} failed with the error: {1}.", task.TaskID, e.Message); 190 } 191 192 string result = String.Empty; 193 194 if (responseObject != null) { 195 yield return responseObject; 196 result = responseObject.Result; 197 } 198 199 task.Response.Response = result; 200 } 201 } else { 202 Log.LogDebug<HttpWebService<TRequestType>>("Task {0} has failed. Need to add to to new queue to be reprocessed.", task.TaskID); 203 //TODO: Add the failed task to a retry queue. 204 } 205 } 206 } else { 207 Log.LogDebug<HttpWebService<TRequestType>>("Task {0} has failed. Need to add to to new queue to be reprocessed.", task.TaskID); 208 //TODO: Add the failed task to a retry queue. 209 } 210 } 211 212 public static IEnumerable<IAsync> CallWebService(ITask task, HttpRequestSettings settings) { 213 214 WebServiceType type = settings.WebServiceType; 215 216 HttpWebRequest request = null; 217 try { 218 request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 219 request.Timeout = settings.Timeout; 220 request.KeepAlive = settings.KeepAlive; 221 request.Pipelined = settings.Pipelined; 222 request.Method = settings.Method; 223 request.ContentType = settings.ContentType; 224 } catch (UriFormatException ufe) { 225 Log.LogInfo<HttpWebService<TRequestType>>("Caught UriFormatException on WebRequest.Create: {0}", ufe.Message); 226 } 227 IRequest webServiceRequest = task.Request; 228 byte[] buffer = null; 229 230 switch (type) { 231 case WebServiceType.REST: 232 break; 233 case WebServiceType.SOAP: 234 StringBuilder output = new StringBuilder(); 235 //output.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 236 using (XmlReader xreader = CreateSoapMessage(task, LabelAttribute.FromMember(webServiceRequest.RequestType)).CreateReader()) { 237 while (xreader.Read()) { 238 if (xreader.IsStartElement()) { 239 output.Append(xreader.ReadOuterXml()); 240 } 241 } 242 } 243 string soapMessage = output.ToString(); 244 webServiceRequest.RequestMessage = soapMessage; 245 buffer = m_encoding.GetBytes(soapMessage); 246 247 break; 248 } 249 250 int contentLength = buffer.Length; 251 request.ContentLength = contentLength; 252 253 foreach (KeyValuePair<string, string> header in webServiceRequest.Headers) { 254 request.Headers.Add(header.Key, header.Value); 255 } 256 257 Stream webStream = null; 258 259 try { 260 webStream = request.GetRequestStream(); 261 } catch (WebException we) { 262 Log.LogInfo<HttpWebService<TRequestType>>("Caught WebException on GetResponseAsync: {0}", we.Message); 263 } 264 if (webStream != null) { 265 using (webStream) { 266 webStream.Write(buffer, 0, contentLength); 267 Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 268 269 Async<WebResponse> response = null; 270 try { 271 response = request.GetResponseAsync(); 272 Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 273 } catch (WebException we) { 274 Log.LogDebug<HttpWebService<TRequestType>>("The call to GetResponseAsync for {0} failed with the error: {1}.", task.TaskID, we.Message); 275 //TODO: Add the failed task to a retry queue. 276 } 277 if (response != null) { 278 yield return response; 279 Stream stream = null; 280 try { 281 stream = response.Result.GetResponseStream(); 282 } catch (NotSupportedException nse) { 283 Log.LogDebug<HttpWebService<TRequestType>>("Caught NotSupportedException on Result.GetResponseStream(): {0}", nse.Message); 284 } catch (WebException we) { 285 Log.LogDebug<HttpWebService<TRequestType>>("Caught WebException on Result.GetResponseStream(): {0}", we.Message); 286 } catc
