Changeset 4695
- Timestamp:
- 06/11/08 21:33:41 (6 months ago)
- Files:
-
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SdbAction.cs (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus.Extension.Linq/Async.cs (modified) (21 diffs)
- trunk/nuxleus/Source/Nuxleus.MetaData/Attributes/Label.cs (added)
- trunk/nuxleus/Source/Nuxleus.MetaData/Nuxleus.MetaData.csproj (modified) (2 diffs)
- trunk/nuxleus/Source/nux.build (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj
r4693 r4695 459 459 </ItemGroup> 460 460 <ItemGroup> 461 <ProjectReference Include="..\Nuxleus.Extension.Linq\Nuxleus.Extension.Linq.csproj"> 462 <Project>{D937BA9E-1E6C-4757-98CC-7D932F4697B0}</Project> 463 <Name>Nuxleus.Extension.Linq</Name> 464 </ProjectReference> 461 465 <ProjectReference Include="..\Nuxleus.Extension\Nuxleus.Extension.csproj"> 462 466 <Project>{3EC9EEB0-71CA-4F71-BF8E-AAF0365D4234}</Project> 463 467 <Name>Nuxleus.Extension</Name> 468 </ProjectReference> 469 <ProjectReference Include="..\Nuxleus.MetaData\Nuxleus.MetaData.csproj"> 470 <Project>{82ACAECC-C5E3-470D-91C4-9F6C43CCC1CC}</Project> 471 <Name>Nuxleus.MetaData</Name> 464 472 </ProjectReference> 465 473 </ItemGroup> trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SdbAction.cs
r4693 r4695 6 6 using System.Security.Cryptography; 7 7 using System.Globalization; 8 using Nuxleus.MetaData; 8 9 9 10 namespace Nuxleus.Extension.AWS.SimpleDB { 10 11 11 public enum RequestType { Query, CreateDomain, DeleteDomain, ListDomains, PutAttributes, DeleteAttributes, GetAttributes } 12 public enum RequestType { 13 [Label("Query")] 14 Query, 15 [Label("CreateDomain")] 16 CreateDomain, 17 [Label("DeleteDomain")] 18 DeleteDomain, 19 [Label("ListDomains")] 20 ListDomains, 21 [Label("PutAttributes")] 22 PutAttributes, 23 [Label("DeleteAttributes")] 24 DeleteAttributes, 25 [Label("GetAttributes")] 26 GetAttributes 27 } 12 28 13 29 public struct SdbAction { trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs
r4693 r4695 11 11 using System.Globalization; 12 12 using Nuxleus.Extension; 13 using EeekSoft.Asynchronous; 14 using System.Collections.Generic; 15 using System.Threading; 16 using Nuxleus.MetaData; 17 using System.Collections; 13 18 14 19 namespace Nuxleus.Extension.AWS.SimpleDB { 15 20 16 public class SimpleDBService { 17 18 public SimpleDBService() { } 21 public struct SimpleDBService { 19 22 20 23 public XContainer GetMessage(RequestType requestType, params string[] paramArray) { … … 85 88 public StreamReader MakeRequest(RequestType requestType, XContainer message) { 86 89 87 88 string rType = String.Empty; 89 switch (requestType) { 90 case RequestType.PutAttributes: 91 rType = "PutAttributes"; 92 break; 93 case RequestType.ListDomains: 94 rType = "ListDomains"; 95 break; 96 case RequestType.GetAttributes: 97 rType = "GetAttributes"; 98 break; 99 case RequestType.DeleteDomain: 100 rType = "DeleteDomain"; 101 break; 102 case RequestType.DeleteAttributes: 103 rType = "DeleteAttributes"; 104 break; 105 case RequestType.CreateDomain: 106 rType = "CreateDomain"; 107 break; 108 case RequestType.Query: 109 default: 110 rType = "Query"; 111 break; 112 } 90 string rType = LabelAttribute.FromMember(requestType); 113 91 114 92 Encoding encoding = new UTF8Encoding(); … … 149 127 } 150 128 } 129 130 public static IEnumerable<IAsync> MakeSoapRequestAsync<T>(RequestType requestType, XContainer message, List<T> responseList) { 131 132 string rType = LabelAttribute.FromMember(requestType); 133 134 Encoding encoding = new UTF8Encoding(); 135 136 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sdb.amazonaws.com/"); 137 138 request.Timeout = 10000 /*TODO: This should be set dynamically*/; 139 request.KeepAlive = true; 140 request.Pipelined = true; 141 142 XmlReader xreader = message.CreateReader(); 143 StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 144 145 byte[] buffer = null; 146 147 do { 148 if (xreader.IsStartElement()) { 149 output.Append(xreader.ReadOuterXml()); 150 Console.WriteLine("Output: {0} :/Output", output.ToString()); 151 buffer = encoding.GetBytes(output.ToString()); 152 } 153 } while (xreader.Read()); 154 155 int contentLength = buffer.Length; 156 request.ContentLength = contentLength; 157 request.Method = "POST"; 158 request.ContentType = "application/soap+xml"; 159 request.Headers.Add("SOAPAction", rType); 160 161 request.Timeout = 10000 /*TODO: This should be set dynamically*/; 162 request.KeepAlive = true; 163 request.Pipelined = true; 164 165 Console.WriteLine("[] starting on thread: {0}", Thread.CurrentThread.ManagedThreadId); 166 167 using (Stream newStream = request.GetRequestStream()) { 168 try { 169 newStream.Write(buffer, 0, contentLength); 170 Async<WebResponse> response = request.GetResponseAsync(); 171 yield return response; 172 Console.WriteLine("[] got response on thread: {0}", Thread.CurrentThread.ManagedThreadId); 173 Stream stream = response.Result.GetResponseStream(); 174 Async<T> responseObject = stream.ReadToEndAsync(typeof(T)).ExecuteAsync<T>(); 175 yield return responseObject; 176 responseList.Add(responseObject.Result); 177 //} finally (System.Net.WebException e) { 178 // Console.WriteLine("Failed! Reason: {0}, Message: {1}", e.Response, e.Message); 179 // return new StreamReader(e.Response.GetResponseStream()); 180 //} 181 } finally { 182 183 } 184 } 185 186 Console.WriteLine("Current thread id: {0}", Thread.CurrentThread.ManagedThreadId); 187 188 } 151 189 } 152 190 } trunk/nuxleus/Source/Nuxleus.Extension.Linq/Async.cs
r4592 r4695 17 17 /// </summary> 18 18 public class Unit { 19 private Unit () { }20 static Unit () {19 private Unit() { } 20 static Unit() { 21 21 Value = new Unit(); 22 22 } … … 36 36 public class Result<T> : IAsync { 37 37 public T ReturnValue { get; private set; } 38 public Result ( T value) {38 public Result(T value) { 39 39 ReturnValue = value; 40 40 } 41 41 42 public void ExecuteStep ( Action cont) {42 public void ExecuteStep(Action cont) { 43 43 throw new InvalidOperationException 44 44 ("Cannot call ExecuteStep on IAsync created as a 'Result'."); … … 56 56 /// Asynchronously gets response from the internet using BeginGetResponse method. 57 57 /// </summary> 58 public static Async<WebResponse> GetResponseAsync ( this WebRequest req) {58 public static Async<WebResponse> GetResponseAsync(this WebRequest req) { 59 59 return new AsyncPrimitive<WebResponse>(req.BeginGetResponse, req.EndGetResponse); 60 60 } … … 68 68 /// <param name="count">Maximum number of bytes to read</param> 69 69 /// <returns>Returns non-zero if there are still some data to read</returns> 70 public static Async<int> ReadAsync ( this Stream stream, byte[] buffer, int offset, int count) {70 public static Async<int> ReadAsync(this Stream stream, byte[] buffer, int offset, int count) { 71 71 return new AsyncPrimitive<int>( 72 ( callback, st) => stream.BeginRead(buffer, offset, count, callback, st),72 (callback, st) => stream.BeginRead(buffer, offset, count, callback, st), 73 73 stream.EndRead); 74 74 } … … 79 79 /// </summary> 80 80 /// <returns>Returns string using the 'Result' class.</returns> 81 public static IEnumerable<IAsync> ReadToEndAsync ( this Stream stream) {82 return stream.ReadToEndAsync( ReturnType.String);81 public static IEnumerable<IAsync> ReadToEndAsync(this Stream stream) { 82 return stream.ReadToEndAsync(typeof(String)); 83 83 } 84 84 … … 88 88 /// </summary> 89 89 /// <param name="returnType">Specifies the desired return type. The default is System.String.</param> 90 public static IEnumerable<IAsync> ReadToEndAsync ( this Stream stream, ReturnType returnType) {90 public static IEnumerable<IAsync> ReadToEndAsync(this Stream stream, Type returnType) { 91 91 MemoryStream ms = new MemoryStream(); 92 92 int read = -1; … … 103 103 ms.Seek(0, SeekOrigin.Begin); 104 104 105 switch (returnType ) {106 case ReturnType.XmlReader:105 switch (returnType.FullName) { 106 case "System.Xml.XmlReader": 107 107 yield return new Result<XmlReader>(XmlReader.Create(ms)); 108 108 break; 109 case ReturnType.XDocument:109 case "System.Xml.Linq.XDocument": 110 110 yield return new Result<XDocument>(XDocument.Parse(new StreamReader(ms).ReadToEnd())); 111 111 break; 112 case ReturnType.XElement:112 case "System.Xml.Linq.XElement": 113 113 yield return new Result<XElement>(XElement.Parse(new StreamReader(ms).ReadToEnd())); 114 114 break; 115 case ReturnType.XStreamingElement:115 case "System.Xml.Linq.XStreamingElement": 116 116 yield return new Result<XStreamingElement>(new XStreamingElement("Result", XElement.Parse(new StreamReader(ms).ReadToEnd()))); 117 117 break; 118 case ReturnType.XNode:118 case "System.Xml.Linq.XNode": 119 119 yield return new Result<XNode>(XNode.ReadFrom(XmlReader.Create(ms))); 120 120 break; 121 case ReturnType.String:121 case "System.String": 122 122 default: 123 123 string s = new StreamReader(ms).ReadToEnd(); … … 135 135 /// </summary> 136 136 /// <param name="async"></param> 137 public static void ExecuteAndWait ( this IEnumerable<IAsync> async) {137 public static void ExecuteAndWait(this IEnumerable<IAsync> async) { 138 138 ManualResetEvent wh = new ManualResetEvent(false); 139 139 AsyncExtensions.Run(async.GetEnumerator(), … … 147 147 /// </summary> 148 148 /// <param name="async"></param> 149 public static void Execute ( this IEnumerable<IAsync> async) {149 public static void Execute(this IEnumerable<IAsync> async) { 150 150 AsyncExtensions.Run(async.GetEnumerator()); 151 151 } … … 155 155 /// and assumes that the method returns result of type T. 156 156 /// </summary> 157 public static Async<T> ExecuteAsync<T> ( this IEnumerable<IAsync> async) {157 public static Async<T> ExecuteAsync<T>(this IEnumerable<IAsync> async) { 158 158 return new AsyncWithResult<T>(async); 159 159 } … … 163 163 /// and assumes that the method doesn't return any result. 164 164 /// </summary> 165 public static Async<Unit> ExecuteAsync ( this IEnumerable<IAsync> async) {165 public static Async<Unit> ExecuteAsync(this IEnumerable<IAsync> async) { 166 166 return new AsyncWithUnitResult(async); 167 167 } … … 171 171 #region Implementation 172 172 173 internal static void Run<T> ( IEnumerator<IAsync> en, Action<T> cont) {173 internal static void Run<T>(IEnumerator<IAsync> en, Action<T> cont) { 174 174 if (!en.MoveNext()) 175 175 throw new InvalidOperationException("Asynchronous workflow executed using" 176 + "'AsyncWithResult' didn't return result using 'Result'!");176 + "'AsyncWithResult' didn't return result using 'Result'!"); 177 177 178 178 var res = (en.Current as Result<T>); … … 183 183 } 184 184 185 internal static void Run ( IEnumerator<IAsync> en, Action cont) {185 internal static void Run(IEnumerator<IAsync> en, Action cont) { 186 186 if (!en.MoveNext()) { cont(); return; } 187 187 en.Current.ExecuteStep … … 189 189 } 190 190 191 internal static void Run ( IEnumerator<IAsync> en) {191 internal static void Run(IEnumerator<IAsync> en) { 192 192 if (!en.MoveNext()) 193 193 return; … … 208 208 /// when executed - executes the methods in parallel. 209 209 /// </summary> 210 public static Async<Unit> Parallel ( params IEnumerable<IAsync>[] operations) {211 return new AsyncPrimitive<Unit>(( cont) => {210 public static Async<Unit> Parallel(params IEnumerable<IAsync>[] operations) { 211 return new AsyncPrimitive<Unit>((cont) => { 212 212 bool[] completed = new bool[operations.Length]; 213 213 for (int i = 0; i < operations.Length; i++) … … 218 218 #region Implementation 219 219 220 private static IEnumerable<IAsync> ExecuteAndSet ( IEnumerable<IAsync> op, bool[] flags, int index, Action<Unit> cont) {220 private static IEnumerable<IAsync> ExecuteAndSet(IEnumerable<IAsync> op, bool[] flags, int index, Action<Unit> cont) { 221 221 foreach (IAsync async in op) 222 222 yield return async; … … 239 239 /// </summary> 240 240 public interface IAsync { 241 void ExecuteStep ( Action cont);241 void ExecuteStep(Action cont); 242 242 } 243 243 … … 257 257 } 258 258 259 abstract public void ExecuteStep ( Action cont);259 abstract public void ExecuteStep(Action cont); 260 260 } 261 261 … … 263 263 Action<Action<T>> func; 264 264 265 public AsyncPrimitive ( Action<Action<T>> function) {265 public AsyncPrimitive(Action<Action<T>> function) { 266 266 this.func = function; 267 267 } 268 268 269 public AsyncPrimitive ( Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, T> end) {270 this.func = ( cont ) => begin(delegate( IAsyncResult res) { cont(end(res)); }, null);271 } 272 273 public override void ExecuteStep ( Action cont) {274 func(( res) => {269 public AsyncPrimitive(Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, T> end) { 270 this.func = (cont) => begin(delegate(IAsyncResult res) { cont(end(res)); }, null); 271 } 272 273 public override void ExecuteStep(Action cont) { 274 func((res) => { 275 275 result = res; 276 276 completed = true; … … 283 283 IEnumerable<IAsync> en; 284 284 285 public AsyncWithResult ( IEnumerable<IAsync> async) {285 public AsyncWithResult(IEnumerable<IAsync> async) { 286 286 en = async; 287 287 } 288 288 289 public override void ExecuteStep ( Action cont) {290 AsyncExtensions.Run<T>(en.GetEnumerator(), ( res) => {289 public override void ExecuteStep(Action cont) { 290 AsyncExtensions.Run<T>(en.GetEnumerator(), (res) => { 291 291 completed = true; 292 292 result = res; … … 299 299 IEnumerable<IAsync> en; 300 300 301 public AsyncWithUnitResult ( IEnumerable<IAsync> async) {301 public AsyncWithUnitResult(IEnumerable<IAsync> async) { 302 302 en = async; 303 303 result = Unit.Value; 304 304 } 305 305 306 public override void ExecuteStep ( Action cont) {306 public override void ExecuteStep(Action cont) { 307 307 AsyncExtensions.Run(en.GetEnumerator(), () => { 308 308 completed = true; trunk/nuxleus/Source/Nuxleus.MetaData/Nuxleus.MetaData.csproj
r4649 r4695 3 3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 4 4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 5 <ProductVersion>9.0. 20706</ProductVersion>5 <ProductVersion>9.0.30428</ProductVersion> 6 6 <SchemaVersion>2.0</SchemaVersion> 7 7 <ProjectGuid>{82ACAECC-C5E3-470D-91C4-9F6C43CCC1CC}</ProjectGuid> … … 46 46 <ItemGroup> 47 47 <Compile Include="Agent.cs" /> 48 <Compile Include="Attributes\Label.cs" /> 48 49 <Compile Include="Attributes\Message.cs" /> 49 50 <Compile Include="Properties\AssemblyInfo.cs" /> trunk/nuxleus/Source/nux.build
r4693 r4695 308 308 </csc> 309 309 </target> 310 <target name="Nuxleus.Extension.Aws" depends="init Nuxleus.Extension ">310 <target name="Nuxleus.Extension.Aws" depends="init Nuxleus.Extension Nuxleus.Extension.Linq Nuxleus.MetaData"> 311 311 <csc target="library" output="${build.dir}/Nuxleus.Extension.Aws.dll" keyfile="./Dependencies/Extf.Net.snk"> 312 312 <arg if="${platform::is-unix()}" value="-langversion:linq"/> … … 316 316 <references> 317 317 <include name="${build.dir}/Nuxleus.Extension.dll"/> 318 <include name="${build.dir}/Nuxleus.Extension.Linq.dll"/> 319 <include name="${build.dir}/Nuxleus.MetaData.dll"/> 318 320 <include name="System.dll"/> 319 321 <include name="System.Collections.dll"/> … … 893 895 <references> 894 896 <include name="${build.dir}/Nuxleus.Extension.Aws.dll"/> 895 <include name="System.dll"/> 896 <include name="/usr/lib/mono/3.0/System.ServiceModel.dll"/> 897 <include name="${build.dir}/Nuxleus.Extension.Linq.dll"/> 898 <include name="System.dll"/> 899 <include name="System.Xml.Linq.dll"/> 897 900 <include name="System.Xml.dll"/> 898 901 <include name="System.Web.dll"/>
