Changeset 4723

Show
Ignore:
Timestamp:
06/17/08 19:45:03 (5 months ago)
Author:
xmlhacker
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/nuxleus/Source/CodeSamples/AwsSdbSOAP_Test/Program.cs

    r4722 r4723  
    2828            stopwatch.Start(); 
    2929            agent.Initialize(); 
    30             agent.Invoke<XElement>(args[0]); 
     30            agent.Invoke<XElement>("AD.txt"); 
    3131            stopwatch.Stop(); 
    3232 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs

    r4722 r4723  
    2323 
    2424        public void Initialize() { 
    25  
    2625            ServicePointManager.DefaultConnectionLimit = int.Parse(ConfigurationManager.AppSettings["DefaultConnectionLimit"]); 
    27  
    2826            int minWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MinimumWorkerThreads"]); 
    2927            int minAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MinimumAsyncIOThreds"]); 
    3028            int maxWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MaximumWorkerThreads"]); 
    3129            int maxAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MaximumAsyncIOThreads"]); 
    32  
    3330            ThreadPool.SetMaxThreads(maxWorkerThreads, maxAsyncIOThreads); 
    3431            ThreadPool.SetMinThreads(minWorkerThreads, minAsyncIOThreads); 
     
    4340            logger.Message = "Processing SOAP requests"; 
    4441 
    45             scope.Begin = () => {   
     42            scope.Begin = () => { 
    4643                using (WorkerQueue q = new WorkerQueue(m_workers)) { 
    4744                    List<string> lines = new List<string>(); 
     
    8077        } 
    8178 
    82  
    8379        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>(); 
    8581            IEnumerable<IAsync>[] processList = new IEnumerable<IAsync>[operation.Count]; 
    8682            int i = 0; 
     
    9187            } 
    9288            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             //} 
    10889        } 
    10990 
    11091        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)); 
    11392 
    114             KeyValuePair<string, string>[] geoNames =  
     93            KeyValuePair<string, string>[] geoNames = 
    11594                new KeyValuePair<System.String, System.String>[] {  
    11695                    new KeyValuePair<string,string>("geonamesid",(string)inputArray.GetValue(0)), 
     
    136115            IEnumerator attributeArray = geoNames.GetEnumerator(); 
    137116 
    138             ArrayList attributes = new ArrayList(); 
     117            List<Attribute> attributes = new List<Attribute>(); 
    139118 
    140119            while (attributeArray.MoveNext()) { 
     
    154133                } 
    155134            } 
    156             return new PutAttributes { DomainName = "foobar", ItemName = (string)inputArray.GetValue(0), AttributeArray = attributes }; 
     135            return new PutAttributes { DomainName = "foobar", ItemName = (string)inputArray.GetValue(0), Attribute = attributes }; 
    157136        } 
     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        //} 
    158155    } 
    159156} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/LoadBalancer/WorkerQueue.cs

    r4717 r4723  
    3737                    return; 
    3838                } 
    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); 
    4040                task.ExecuteAndWait(); 
    4141            } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj

    r4715 r4723  
    7171    </Compile> 
    7272    <Compile Include="Request\IRequest.cs" /> 
     73    <Compile Include="Request\PutAttributesRequest.cs" /> 
    7374    <Compile Include="Response\IResponse.cs" /> 
    7475    <Compile Include="Scope\LoggerScope.cs" /> 
    7576    <Compile Include="Scope\ProfilerScope.cs" /> 
    7677    <Compile Include="SimpleDB\Model\Attribute.cs" /> 
     78    <Compile Include="SimpleDB\Model\Domain.cs" /> 
     79    <Compile Include="SimpleDB\Model\Item.cs" /> 
    7780    <Compile Include="SimpleDB\Operation\Operation.cs" /> 
    7881    <Compile Include="SimpleDB\SdbAction.cs" /> 
     
    8790    <Compile Include="SimpleDB\Task\Task.cs" /> 
    8891    <Compile Include="Utils\HMACSigner.cs" /> 
     92    <Compile Include="Utils\PropertyCaller.cs" /> 
     93    <Compile Include="Utils\Serializer.cs" /> 
     94    <Compile Include="Utils\Util.cs" /> 
    8995  </ItemGroup> 
    9096  <ItemGroup> 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs

    r4715 r4723  
    66 
    77namespace 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; } 
    1212    } 
    1313} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SdbAction.cs

    r4715 r4723  
    1 using System; 
    2 using System.Collections.Generic; 
     1using System.Collections.Generic; 
    32using System.Linq; 
    43using System.Text; 
     
    87using Nuxleus.MetaData; 
    98using System.Collections; 
     9using Nuxleus.Extension.AWS.SimpleDB.Model; 
    1010 
    1111namespace Nuxleus.Extension.AWS.SimpleDB { 
     
    2424        [Label("DeleteAttributes")] 
    2525        DeleteAttributes, 
    26         [Label("GetAttributes")]  
    27         GetAttributes  
     26        [Label("GetAttributes")] 
     27        GetAttributes 
    2828    } 
    2929 
     
    3636 
    3737        public static XElement Query(string domainName, string maxNumberOfTokens, string nextToken, string queryExpression) { 
    38             return  
     38            return 
    3939                new XElement(aws + "Query", 
    4040                    new XElement(aws + "DomainName", domainName), 
     
    5252 
    5353        public static XElement CreateDomain(string domainName) { 
    54             return  
     54            return 
    5555                new XElement(aws + "CreateDomain", 
    5656                    new XElement(aws + "DomainName", domainName), 
     
    6060 
    6161        public static XElement DeleteDomain(string domainName) { 
    62             return  
     62            return 
    6363                new XElement(aws + "DeleteDomain", 
    6464                    new XElement(aws + "DomainName", domainName), 
     
    6868 
    6969        public static XElement ListDomains(string maxNumberOfDomains, string nextToken) { 
    70             return  
     70            return 
    7171                new XElement(aws + "ListDomains", 
    7272                    (maxNumberOfDomains == null) 
     
    8686        } 
    8787 
    88         public static XElement PutAttributes(string domainName, string itemName, ArrayList attributes) { 
     88        public static XElement PutAttributes(string domainName, string itemName, List<Attribute> attributes) { 
    8989            return 
    9090                new XElement(aws + "PutAttributesRequest", 
     
    9696        } 
    9797 
    98         public static XElement DeleteAttributes(string domainName, string itemName, ArrayList attributes) { 
    99             return  
     98        public static XElement DeleteAttributes(string domainName, string itemName, List<Attribute> attributes) { 
     99            return 
    100100                new XElement(aws + "DeleteAttributes", 
    101101                    new XElement(aws + "DomainName", domainName), 
     
    106106        } 
    107107 
    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 
    110110                new XElement(aws + "GetAttributes", 
    111111                    new XElement(aws + "DomainName", domainName), 
     
    116116        } 
    117117 
    118         private static XElement[] GetAuthorizationElements(string action) { 
    119             String timestamp = GetFormattedTimestamp(); 
    120             return  
     118        public static XElement[] GetAuthorizationElements(string action) { 
     119            string timestamp = GetFormattedTimestamp(); 
     120            return 
    121121                new XElement[] {  
    122122                    new XElement(aws + "AWSAccessKeyId", AWS_PUBLIC_KEY), 
     
    127127        } 
    128128 
    129         private static XElement[] CreateSdbAttributeElements(AttributeActionType attributeActionType, ArrayList attributes) { 
     129        private static XElement[] CreateSdbAttributeElements(AttributeActionType attributeActionType, List<Attribute> attributes) { 
    130130            XElement[] xElements = new XElement[attributes.Count]; 
    131131            int i = 0; 
    132132            foreach (Nuxleus.Extension.AWS.SimpleDB.Model.Attribute attribute in attributes) { 
    133                 switch(attributeActionType)
     133                switch (attributeActionType)
    134134                    case AttributeActionType.PUT: 
    135135                    case AttributeActionType.DELETE: 
     
    154154                        break; 
    155155                    case AttributeActionType.PUT: 
    156                     case AttributeActionType.DELETE:             
     156                    case AttributeActionType.DELETE: 
    157157                    default: 
    158                         break;                    
     158                        break; 
    159159                } 
    160160                i++; 
     
    172172 
    173173        private static XElement GetSignature(string action, string timestamp) { 
    174             return new XElement(aws + "Signature", Sign(String.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) { 
    178178            Encoding encoding = new UTF8Encoding(); 
    179179            HMACSHA1 signature = new HMACSHA1(encoding.GetBytes(key)); 
    180             return Convert.ToBase64String(signature.ComputeHash( 
     180            return System.Convert.ToBase64String(signature.ComputeHash( 
    181181                encoding.GetBytes(data.ToCharArray()))); 
    182182        } 
    183183 
    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, 
    188188                             dateTime.Hour, dateTime.Minute, dateTime.Second, 
    189                              dateTime.Millisecond, DateTimeKind.Local) 
     189                             dateTime.Millisecond, System.DateTimeKind.Local) 
    190190                            .ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture); 
    191191        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs

    r4715 r4723  
    1616using Nuxleus.MetaData; 
    1717using System.Collections; 
     18using System.Xml.Serialization; 
    1819 
    1920namespace Nuxleus.Extension.AWS.SimpleDB { 
    2021 
    21     public struct SimpleDBService
     22    public struct SimpleDBService<TRequestType>
    2223 
    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)); 
    3626 
    3727        //static XElement GetRequestXElement(RequestType requestType, params string[] paramArray) { 
     
    128118        } 
    129119 
    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) { 
    133121 
    134122            Encoding encoding = new UTF8Encoding(); 
    135123 
    136124            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; 
    137128 
    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            } 
    141137 
    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); 
    144141 
    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); 
    153143 
    154144            int contentLength = buffer.Length; 
     
    156146            request.Method = "POST"; 
    157147            request.ContentType = "application/soap+xml"; 
    158             request.Headers.Add("SOAPAction", rType); 
    159148 
    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            } 
    163152 
    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); 
    165154 
    166155            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        } 
    167166 
    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); 
    176172            } 
     173            XElement body = XElement.Parse(builder.ToString()); 
     174            body.Add(SdbAction.GetAuthorizationElements(action)); 
    177175 
    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                ); 
    180181        } 
    181182    } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/ITask.cs

    r4715 r4723  
    77 
    88namespace 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; } 
    1212        //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); 
    1614    } 
    1715} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/PutAttributes.cs

    r4720 r4723  
    2121    public struct PutAttributes : ITask { 
    2222 
    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/"; 
    2524 
    2625        string m_domainName; 
    2726        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(); 
    2930 
    3031        static XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; 
     
    4344        } 
    4445 
    45         public ArrayList AttributeArray { 
     46        [XmlElementAttribute(ElementName = "Attribute")] 
     47        public List<Attribute> Attribute { 
    4648            get { return m_attributeArray; } 
    4749            set { m_attributeArray = value; } 
    4850        } 
    4951 
     52        public System.Guid TaskID { 
     53            get { return m_taskID; } 
     54        } 
    5055 
    51         public XElement[] GetXMLBody
     56        public IRequest Request
    5257            get { 
    53                 return CreateAttributeElements()
     58                return m_request
    5459            } 
    5560        } 
    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); 
    16663        } 
    16764    } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Task/Query.cs

    r4715 r4723  
    1717        string m_maxNumberOfItems; 
    1818        string m_nextToken; 
     19        static System.Guid m_taskID = new System.Guid(); 
    1920 
    2021        [XmlElementAttribute(ElementName = "DomainName")] 
     
    4344        } 
    4445 
     46        public IRequest Request { 
     47            get { throw new NotImplementedException(); } 
     48            set { throw new NotImplementedException(); } 
     49        } 
     50 
    4551        public System.Xml.Linq.XElement[] GetXMLBody { 
    4652            get { throw new NotImplementedException(); } 
    4753        } 
    4854 
    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) { 
    5060            throw new NotImplementedException(); 
    5161        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Linq/Async.cs

    r4698 r4723  
    88using System.Xml.Linq; 
    99using System.Xml; 
     10using System.Xml.Serialization; 
    1011 
    1112namespace EeekSoft.Asynchronous { 
     
    9596                Async<int> count = stream.ReadAsync(buffer, 0, 1024); 
    9697                yield return count; 
    97  
    98                 Console.WriteLine("[{0}] got data: {1}", "url", count.Result); 
    9998                ms.Write(buffer, 0, count.Result); 
    10099                read = count.Result; 
     
    120119                    break; 
    121120                case "System.String": 
    122                 default: 
    123121                    string s = new StreamReader(ms).ReadToEnd(); 
    124122                    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))); 
    125128                    break; 
    126129            }