Changeset 4723
- Timestamp:
- 06/17/08 19:45:03 (5 months ago)
- Files:
-
- trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs (modified) (6 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/WorkerQueue.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj (modified) (2 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SdbAction.cs (modified) (14 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/ITask.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/PutAttributes.cs (modified) (2 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/Query.cs (modified) (2 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Linq/Async.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs
r4722 r4723 28 28 stopwatch.Start(); 29 29 agent.Initialize(); 30 agent.Invoke<XElement>( args[0]);30 agent.Invoke<XElement>("AD.txt"); 31 31 stopwatch.Stop(); 32 32 trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs
r4722 r4723 23 23 24 24 public void Initialize() { 25 26 25 ServicePointManager.DefaultConnectionLimit = int.Parse(ConfigurationManager.AppSettings["DefaultConnectionLimit"]); 27 28 26 int minWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MinimumWorkerThreads"]); 29 27 int minAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MinimumAsyncIOThreds"]); 30 28 int maxWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MaximumWorkerThreads"]); 31 29 int maxAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MaximumAsyncIOThreads"]); 32 33 30 ThreadPool.SetMaxThreads(maxWorkerThreads, maxAsyncIOThreads); 34 31 ThreadPool.SetMinThreads(minWorkerThreads, minAsyncIOThreads); … … 43 40 logger.Message = "Processing SOAP requests"; 44 41 45 scope.Begin = () => { 42 scope.Begin = () => { 46 43 using (WorkerQueue q = new WorkerQueue(m_workers)) { 47 44 List<string> lines = new List<string>(); … … 80 77 } 81 78 82 83 79 private static IEnumerable<IAsync> InvokeOperation<T>(List<string> operation) { 84 Dictionary< XElement, T> responseList = new Dictionary<XElement, T>();80 Dictionary<IRequest, T> responseList = new Dictionary<IRequest, T>(); 85 81 IEnumerable<IAsync>[] processList = new IEnumerable<IAsync>[operation.Count]; 86 82 int i = 0; … … 91 87 } 92 88 yield return Async.Parallel(processList); 93 //int c = 1;94 //IEnumerator responseEnumerator = responseList.GetEnumerator();95 //while (responseEnumerator.MoveNext()) {96 // KeyValuePair<XElement, XElement> responseItem = (KeyValuePair<XElement, XElement>)responseEnumerator.Current;97 // System.Console.WriteLine(".......................... Begin Message {0} ............................", c);98 // System.Console.WriteLine("\n");99 // System.Console.WriteLine("[Message {0} Sent]", c);100 // responseItem.Key.Save(System.Console.Out);101 // System.Console.WriteLine("\n");102 // System.Console.WriteLine("[Message {0} Received]", c);103 // responseItem.Value.Save(System.Console.Out);104 // System.Console.WriteLine("\n");105 // System.Console.WriteLine(".......................... End Message {0} ............................", c);106 // c++;107 //}108 89 } 109 90 110 91 private static PutAttributes CreateTask<T>(string[] inputArray) { 111 System.Console.WriteLine(System.String.Format("Loading Item: {0}, with Place Name: {1}", (string)inputArray.GetValue(0), (string)inputArray.GetValue(1)));112 System.Console.WriteLine(System.String.Format("Array Length: {0}", inputArray.Length));113 92 114 KeyValuePair<string, string>[] geoNames = 93 KeyValuePair<string, string>[] geoNames = 115 94 new KeyValuePair<System.String, System.String>[] { 116 95 new KeyValuePair<string,string>("geonamesid",(string)inputArray.GetValue(0)), … … 136 115 IEnumerator attributeArray = geoNames.GetEnumerator(); 137 116 138 ArrayList attributes = new ArrayList();117 List<Attribute> attributes = new List<Attribute>(); 139 118 140 119 while (attributeArray.MoveNext()) { … … 154 133 } 155 134 } 156 return new PutAttributes { DomainName = "foobar", ItemName = (string)inputArray.GetValue(0), Attribute Array= attributes };135 return new PutAttributes { DomainName = "foobar", ItemName = (string)inputArray.GetValue(0), Attribute = attributes }; 157 136 } 137 138 //private void OutputResultList(Dictionary<XElement, T> responseList) { 139 // int c = 1; 140 // IEnumerator responseEnumerator = responseList.GetEnumerator(); 141 // while (responseEnumerator.MoveNext()) { 142 // KeyValuePair<XElement, XElement> responseItem = (KeyValuePair<XElement, XElement>)responseEnumerator.Current; 143 // System.Console.WriteLine(".......................... Begin Message {0} ............................", c); 144 // System.Console.WriteLine("\n"); 145 // System.Console.WriteLine("[Message {0} Sent]", c); 146 // responseItem.Key.Save(System.Console.Out); 147 // System.Console.WriteLine("\n"); 148 // System.Console.WriteLine("[Message {0} Received]", c); 149 // responseItem.Value.Save(System.Console.Out); 150 // System.Console.WriteLine("\n"); 151 // System.Console.WriteLine(".......................... End Message {0} ............................", c); 152 // c++; 153 // } 154 //} 158 155 } 159 156 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/WorkerQueue.cs
r4717 r4723 37 37 return; 38 38 } 39 Console.WriteLine("Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);39 //Console.WriteLine("Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 40 40 task.ExecuteAndWait(); 41 41 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj
r4715 r4723 71 71 </Compile> 72 72 <Compile Include="Request\IRequest.cs" /> 73 <Compile Include="Request\PutAttributesRequest.cs" /> 73 74 <Compile Include="Response\IResponse.cs" /> 74 75 <Compile Include="Scope\LoggerScope.cs" /> 75 76 <Compile Include="Scope\ProfilerScope.cs" /> 76 77 <Compile Include="SimpleDB\Model\Attribute.cs" /> 78 <Compile Include="SimpleDB\Model\Domain.cs" /> 79 <Compile Include="SimpleDB\Model\Item.cs" /> 77 80 <Compile Include="SimpleDB\Operation\Operation.cs" /> 78 81 <Compile Include="SimpleDB\SdbAction.cs" /> … … 87 90 <Compile Include="SimpleDB\Task\Task.cs" /> 88 91 <Compile Include="Utils\HMACSigner.cs" /> 92 <Compile Include="Utils\PropertyCaller.cs" /> 93 <Compile Include="Utils\Serializer.cs" /> 94 <Compile Include="Utils\Util.cs" /> 89 95 </ItemGroup> 90 96 <ItemGroup> trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs
r4715 r4723 6 6 7 7 namespace Nuxleus.Extension.AWS.SimpleDB { 8 interface IRequest {9 KeyValuePair<string, string>[] Headers { get; set;}10 RequestType RequestType { get; set;}11 //T Request{ get; set; }8 public interface IRequest { 9 KeyValuePair<string, string>[] Headers { get; } 10 RequestType RequestType { get; } 11 String RequestMessage { get; set; } 12 12 } 13 13 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SdbAction.cs
r4715 r4723 1 using System; 2 using System.Collections.Generic; 1 using System.Collections.Generic; 3 2 using System.Linq; 4 3 using System.Text; … … 8 7 using Nuxleus.MetaData; 9 8 using System.Collections; 9 using Nuxleus.Extension.AWS.SimpleDB.Model; 10 10 11 11 namespace Nuxleus.Extension.AWS.SimpleDB { … … 24 24 [Label("DeleteAttributes")] 25 25 DeleteAttributes, 26 [Label("GetAttributes")] 27 GetAttributes 26 [Label("GetAttributes")] 27 GetAttributes 28 28 } 29 29 … … 36 36 37 37 public static XElement Query(string domainName, string maxNumberOfTokens, string nextToken, string queryExpression) { 38 return 38 return 39 39 new XElement(aws + "Query", 40 40 new XElement(aws + "DomainName", domainName), … … 52 52 53 53 public static XElement CreateDomain(string domainName) { 54 return 54 return 55 55 new XElement(aws + "CreateDomain", 56 56 new XElement(aws + "DomainName", domainName), … … 60 60 61 61 public static XElement DeleteDomain(string domainName) { 62 return 62 return 63 63 new XElement(aws + "DeleteDomain", 64 64 new XElement(aws + "DomainName", domainName), … … 68 68 69 69 public static XElement ListDomains(string maxNumberOfDomains, string nextToken) { 70 return 70 return 71 71 new XElement(aws + "ListDomains", 72 72 (maxNumberOfDomains == null) … … 86 86 } 87 87 88 public static XElement PutAttributes(string domainName, string itemName, ArrayListattributes) {88 public static XElement PutAttributes(string domainName, string itemName, List<Attribute> attributes) { 89 89 return 90 90 new XElement(aws + "PutAttributesRequest", … … 96 96 } 97 97 98 public static XElement DeleteAttributes(string domainName, string itemName, ArrayListattributes) {99 return 98 public static XElement DeleteAttributes(string domainName, string itemName, List<Attribute> attributes) { 99 return 100 100 new XElement(aws + "DeleteAttributes", 101 101 new XElement(aws + "DomainName", domainName), … … 106 106 } 107 107 108 public static XElement GetAttributes(string domainName, string itemName, params String[] attributeNames) {109 return 108 public static XElement GetAttributes(string domainName, string itemName, params string[] attributeNames) { 109 return 110 110 new XElement(aws + "GetAttributes", 111 111 new XElement(aws + "DomainName", domainName), … … 116 116 } 117 117 118 p rivatestatic XElement[] GetAuthorizationElements(string action) {119 String timestamp = GetFormattedTimestamp();120 return 118 public static XElement[] GetAuthorizationElements(string action) { 119 string timestamp = GetFormattedTimestamp(); 120 return 121 121 new XElement[] { 122 122 new XElement(aws + "AWSAccessKeyId", AWS_PUBLIC_KEY), … … 127 127 } 128 128 129 private static XElement[] CreateSdbAttributeElements(AttributeActionType attributeActionType, ArrayListattributes) {129 private static XElement[] CreateSdbAttributeElements(AttributeActionType attributeActionType, List<Attribute> attributes) { 130 130 XElement[] xElements = new XElement[attributes.Count]; 131 131 int i = 0; 132 132 foreach (Nuxleus.Extension.AWS.SimpleDB.Model.Attribute attribute in attributes) { 133 switch (attributeActionType){133 switch (attributeActionType) { 134 134 case AttributeActionType.PUT: 135 135 case AttributeActionType.DELETE: … … 154 154 break; 155 155 case AttributeActionType.PUT: 156 case AttributeActionType.DELETE: 156 case AttributeActionType.DELETE: 157 157 default: 158 break; 158 break; 159 159 } 160 160 i++; … … 172 172 173 173 private static XElement GetSignature(string action, string timestamp) { 174 return new XElement(aws + "Signature", Sign(S tring.Format("{0}{1}", action, timestamp), AWS_PRIVATE_KEY));175 } 176 177 private static String Sign(String data, String key) {174 return new XElement(aws + "Signature", Sign(System.String.Format("{0}{1}", action, timestamp), AWS_PRIVATE_KEY)); 175 } 176 177 private static string Sign(string data, string key) { 178 178 Encoding encoding = new UTF8Encoding(); 179 179 HMACSHA1 signature = new HMACSHA1(encoding.GetBytes(key)); 180 return Convert.ToBase64String(signature.ComputeHash(180 return System.Convert.ToBase64String(signature.ComputeHash( 181 181 encoding.GetBytes(data.ToCharArray()))); 182 182 } 183 183 184 private static String GetFormattedTimestamp() {185 DateTime dateTime =DateTime.Now;186 return 187 new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,184 private static string GetFormattedTimestamp() { 185 System.DateTime dateTime = System.DateTime.Now; 186 return 187 new System.DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 188 188 dateTime.Hour, dateTime.Minute, dateTime.Second, 189 dateTime.Millisecond, DateTimeKind.Local)189 dateTime.Millisecond, System.DateTimeKind.Local) 190 190 .ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture); 191 191 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs
r4715 r4723 16 16 using Nuxleus.MetaData; 17 17 using System.Collections; 18 using System.Xml.Serialization; 18 19 19 20 namespace Nuxleus.Extension.AWS.SimpleDB { 20 21 21 public struct SimpleDBService {22 public struct SimpleDBService<TRequestType> { 22 23 23 public XElement GetMessage(RequestType requestType, params string[] paramArray) { 24 25 XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 26 27 XElement awsSOAPMessage = 28 new XElement(s + "Envelope", 29 new XElement(s + "Body" 30 //GetRequestXElement(requestType, paramArray) 31 ) 32 ); 33 34 return awsSOAPMessage; 35 } 24 static XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 25 static XmlSerializer m_xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(TRequestType)); 36 26 37 27 //static XElement GetRequestXElement(RequestType requestType, params string[] paramArray) { … … 128 118 } 129 119 130 public static IEnumerable<IAsync> MakeSoapRequestAsync<T>(RequestType requestType, XElement message, Dictionary<XElement,T> responseList) { 131 132 string rType = LabelAttribute.FromMember(requestType); 120 public static IEnumerable<IAsync> CallWebService<TRequestType, TResponseType>(ITask task, IRequest sdbRequest, Dictionary<IRequest, TResponseType> responseList) { 133 121 134 122 Encoding encoding = new UTF8Encoding(); 135 123 136 124 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sdb.amazonaws.com/"); 125 request.Timeout = 30000 /*TODO: This should be set dynamically*/; 126 request.KeepAlive = true; 127 request.Pipelined = false; 137 128 138 request.Timeout = 10000 /*TODO: This should be set dynamically*/; 139 request.KeepAlive = true; 140 request.Pipelined = true; 129 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 130 using (XmlReader xreader = CreateSoapMessage(task, LabelAttribute.FromMember(sdbRequest.RequestType)).CreateReader()) { 131 while (xreader.Read()) { 132 if (xreader.IsStartElement()) { 133 output.Append(xreader.ReadOuterXml()); 134 } 135 } 136 } 141 137 142 XmlReader xreader = message.CreateReader(); 143 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 138 string soapMessage = output.ToString(); 139 sdbRequest.RequestMessage = soapMessage; 140 Console.WriteLine("XML: {0}", soapMessage); 144 141 145 byte[] buffer = null; 146 147 do { 148 if (xreader.IsStartElement()) { 149 output.Append(xreader.ReadOuterXml()); 150 buffer = encoding.GetBytes(output.ToString()); 151 } 152 } while (xreader.Read()); 142 byte[] buffer = encoding.GetBytes(soapMessage); 153 143 154 144 int contentLength = buffer.Length; … … 156 146 request.Method = "POST"; 157 147 request.ContentType = "application/soap+xml"; 158 request.Headers.Add("SOAPAction", rType);159 148 160 request.Timeout = 10000 /*TODO: This should be set dynamically*/;161 request.KeepAlive = true;162 request.Pipelined = true;149 foreach (KeyValuePair<string, string> header in sdbRequest.Headers) { 150 request.Headers.Add(header.Key, header.Value); 151 } 163 152 164 Console.WriteLine("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);153 System.Console.WriteLine("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 165 154 166 155 using (Stream newStream = request.GetRequestStream()) { 156 newStream.Write(buffer, 0, contentLength); 157 Async<WebResponse> response = request.GetResponseAsync(); 158 yield return response; 159 System.Console.WriteLine("[] got response on thread: {0}", Thread.CurrentThread.ManagedThreadId); 160 Stream stream = response.Result.GetResponseStream(); 161 Async<TResponseType> responseObject = stream.ReadToEndAsync<TResponseType>().ExecuteAsync<TResponseType>(); 162 yield return responseObject; 163 responseList.Add(sdbRequest, responseObject.Result); 164 } 165 } 167 166 168 newStream.Write(buffer, 0, contentLength); 169 Async<WebResponse> response = request.GetResponseAsync(); 170 yield return response; 171 Console.WriteLine("[] got response on thread: {0}", Thread.CurrentThread.ManagedThreadId); 172 Stream stream = response.Result.GetResponseStream(); 173 Async<T> responseObject = stream.ReadToEndAsync<T>().ExecuteAsync<T>(); 174 yield return responseObject; 175 responseList.Add(message, responseObject.Result); 167 private static XElement CreateSoapMessage(ITask task, String action) { 168 169 StringBuilder builder = new StringBuilder(); 170 using (TextWriter writer = new StringWriter(builder)) { 171 m_xSerializer.Serialize(writer, (TRequestType)task); 176 172 } 173 XElement body = XElement.Parse(builder.ToString()); 174 body.Add(SdbAction.GetAuthorizationElements(action)); 177 175 178 Console.WriteLine("End Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 179 176 return new XElement(s + "Envelope", 177 new XElement(s + "Body", 178 body 179 ) 180 ); 180 181 } 181 182 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/ITask.cs
r4715 r4723 7 7 8 8 namespace Nuxleus.Extension.AWS.SimpleDB { 9 interface ITask {10 //Guid TaskID { get; set; }11 //IRequest Request { get; set; }9 public interface ITask { 10 Guid TaskID { get; } 11 IRequest Request { get; } 12 12 //IResponse<T> Response { get; set; } 13 RequestType RequestType { get; } 14 XElement[] GetXMLBody { get; } 15 IEnumerable<IAsync> Invoke<T>(Dictionary<XElement, T> responseList); 13 IEnumerable<IAsync> Invoke<T>(Dictionary<IRequest, T> responseList); 16 14 } 17 15 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/PutAttributes.cs
r4720 r4723 21 21 public struct PutAttributes : ITask { 22 22 23 static string AWS_PUBLIC_KEY = System.Environment.GetEnvironmentVariable("AWS_PUBLIC_KEY"); 24 static string AWS_PRIVATE_KEY = System.Environment.GetEnvironmentVariable("AWS_PRIVATE_KEY"); 23 static XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 25 24 26 25 string m_domainName; 27 26 string m_itemName; 28 ArrayList m_attributeArray; 27 List<Attribute> m_attributeArray; 28 static System.Guid m_taskID = new System.Guid(); 29 static IRequest m_request = new PutAttributesRequest(); 29 30 30 31 static XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; … … 43 44 } 44 45 45 public ArrayList AttributeArray { 46 [XmlElementAttribute(ElementName = "Attribute")] 47 public List<Attribute> Attribute { 46 48 get { return m_attributeArray; } 47 49 set { m_attributeArray = value; } 48 50 } 49 51 52 public System.Guid TaskID { 53 get { return m_taskID; } 54 } 50 55 51 public XElement[] GetXMLBody{56 public IRequest Request { 52 57 get { 53 return CreateAttributeElements();58 return m_request; 54 59 } 55 60 } 56 57 public RequestType RequestType { get { return RequestType.PutAttributes; } } 58 59 private XElement GetRequest() { 60 XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 61 return new XElement(s + "Envelope", 62 new XElement(s + "Body", 63 SdbAction.PutAttributes(DomainName, ItemName, AttributeArray) 64 ) 65 ); 66 } 67 68 public IEnumerable<IAsync> Invoke<T>(Dictionary<XElement, T> responseList) { 69 70 XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 71 72 XElement awsSOAPMessage = GetRequest(); 73 74 return CallWebService<T>(awsSOAPMessage, responseList); 75 } 76 77 private IEnumerable<IAsync> CallWebService<T>(XElement awsSOAPMessage, Dictionary<XElement, T> responseList) { 78 string rType = LabelAttribute.FromMember(RequestType); 79 80 Encoding encoding = new UTF8Encoding(); 81 82 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sdb.amazonaws.com/"); 83 84 request.Timeout = 30000 /*TODO: This should be set dynamically*/; 85 request.KeepAlive = true; 86 request.Pipelined = false; 87 88 XmlReader xreader = awsSOAPMessage.CreateReader(); 89 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 90 91 byte[] buffer = null; 92 93 do { 94 if (xreader.IsStartElement()) { 95 output.Append(xreader.ReadOuterXml()); 96 buffer = encoding.GetBytes(output.ToString()); 97 } 98 } while (xreader.Read()); 99 100 int contentLength = buffer.Length; 101 request.ContentLength = contentLength; 102 request.Method = "POST"; 103 request.ContentType = "application/soap+xml"; 104 request.Headers.Add("SOAPAction", rType); 105 106 System.Console.WriteLine("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 107 108 using (Stream newStream = request.GetRequestStream()) { 109 newStream.Write(buffer, 0, contentLength); 110 Async<WebResponse> response = request.GetResponseAsync(); 111 yield return response; 112 System.Console.WriteLine("[] got response on thread: {0}", Thread.CurrentThread.ManagedThreadId); 113 Stream stream = response.Result.GetResponseStream(); 114 Async<T> responseObject = stream.ReadToEndAsync<T>().ExecuteAsync<T>(); 115 yield return responseObject; 116 responseList.Add(awsSOAPMessage, responseObject.Result); 117 } 118 } 119 private XElement[] CreateAttributeElements() { 120 XElement[] xElements = new XElement[m_attributeArray.Count]; 121 int i = 0; 122 foreach (Attribute attribute in m_attributeArray) { 123 xElements[i] = CreateAttributeElement(attribute); 124 i++; 125 } 126 return xElements; 127 } 128 129 private static XElement CreateAttributeElement(Attribute attribute) { 130 return new XElement(aws + "Attribute", 131 new XElement(aws + "Name", attribute.Name), 132 new XElement(aws + "Value", attribute.Value), 133 new XElement(aws + "Replace", attribute.Replace) 134 ); 135 } 136 137 private static XElement[] GetAuthorizationElements(string action) { 138 string timestamp = GetFormattedTimestamp(); 139 return 140 new XElement[] { 141 new XElement(aws + "AWSAccessKeyId", AWS_PUBLIC_KEY), 142 new XElement(aws + "Timestamp", timestamp), 143 GetSignature(action, timestamp) 144 }; 145 146 } 147 148 private static XElement GetSignature(string action, string timestamp) { 149 return new XElement(aws + "Signature", Sign(string.Format("{0}{1}", action, timestamp), AWS_PRIVATE_KEY)); 150 } 151 152 private static string Sign(string data, string key) { 153 Encoding encoding = new UTF8Encoding(); 154 HMACSHA1 signature = new HMACSHA1(encoding.GetBytes(key)); 155 return System.Convert.ToBase64String(signature.ComputeHash( 156 encoding.GetBytes(data.ToCharArray()))); 157 } 158 159 private static string GetFormattedTimestamp() { 160 System.DateTime dateTime = System.DateTime.Now; 161 return 162 new System.DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 163 dateTime.Hour, dateTime.Minute, dateTime.Second, 164 dateTime.Millisecond, System.DateTimeKind.Local) 165 .ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture); 61 public IEnumerable<IAsync> Invoke<T>(Dictionary<IRequest, T> responseList) { 62 return SimpleDBService<PutAttributes>.CallWebService<PutAttributes,T>(this, Request, responseList); 166 63 } 167 64 } trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/Query.cs
r4715 r4723 17 17 string m_maxNumberOfItems; 18 18 string m_nextToken; 19 static System.Guid m_taskID = new System.Guid(); 19 20 20 21 [XmlElementAttribute(ElementName = "DomainName")] … … 43 44 } 44 45 46 public IRequest Request { 47 get { throw new NotImplementedException(); } 48 set { throw new NotImplementedException(); } 49 } 50 45 51 public System.Xml.Linq.XElement[] GetXMLBody { 46 52 get { throw new NotImplementedException(); } 47 53 } 48 54 49 public IEnumerable<IAsync> Invoke<T>(Dictionary<XElement, T> responseList) { 55 public System.Guid TaskID { 56 get { return m_taskID; } 57 } 58 59 public IEnumerable<IAsync> Invoke<T>(Dictionary<IRequest, T> responseList) { 50 60 throw new NotImplementedException(); 51 61 } trunk/nuxleus/Source/Nuxleus.Extension.Linq/Async.cs
r4698 r4723 8 8 using System.Xml.Linq; 9 9 using System.Xml; 10 using System.Xml.Serialization; 10 11 11 12 namespace EeekSoft.Asynchronous { … … 95 96 Async<int> count = stream.ReadAsync(buffer, 0, 1024); 96 97 yield return count; 97 98 Console.WriteLine("[{0}] got data: {1}", "url", count.Result);99 98 ms.Write(buffer, 0, count.Result); 100 99 read = count.Result; … … 120 119 break; 121 120 case "System.String": 122 default:123 121 string s = new StreamReader(ms).ReadToEnd(); 124 122 yield return new Result<string>(s); 123 break; 124 default: 125 string sr = new StreamReader(ms).ReadToEnd(); 126 XmlSerializer serializer = new XmlSerializer(typeof(T)); 127 yield return new Result<T>((T)serializer.Deserialize(new StringReader(sr))); 125 128 break; 126 129 }
