public static void Example() { SomeWork s1 = new SomeWork(Work1); SomeWork s2 = new SomeWork(Work2); s1 += s2; Work3(s1); }
public void Configure(IApplicationBuilder app) { // MAP app.Map("/now", now => { now.Run(async context => { var time = DateTime.UtcNow.ToString("HH:mm:ss (UTC)"); await context .Response .WriteAsync("<h1 style='color:red;'>" + time + "</h1>"); }); }); // MAPWHEN app.MapWhen( context => context.Request.Query.ContainsKey("utc"), utc => { utc.Run(async context => { var time = DateTime.UtcNow.ToString("HH:mm:ss (UTC)"); await context .Response .WriteAsync("<h1 style='color:blue;'>" + time + "</h1>"); }); }); // BEFORE/AFTER app.Use(async(context, nextMiddleware) => { await context.Response.WriteAsync("BEFORE"); await nextMiddleware(); await context.Response.WriteAsync("AFTER"); }); // BODY SIZE app.Use(async(context, nextMiddleware) => { context.Features .Get <IHttpMaxRequestBodySizeFeature>() .MaxRequestBodySize = 10 * 1024; await nextMiddleware.Invoke(); }); // MOBILE // app.UseMiddleware<MobileDetectionMiddleware>(); app.UseMobileDetection(); app.Run(async(context) => { var obj = new SomeWork(); await context .Response .WriteAsync("<h1 style='color:red;'>" + obj.Now() + "</h1>"); }); }
static void Main(string[] args) { SomeWork rai = new SomeWork(); rai.a = 1; rai.b = -53; rai.ChangeNumbers(33, 66); rai.MaxNumber(); rai.Sum(); rai.ShowNumbers(); }
public static void TestInterfaceOptionalParams() { ISomeWork work = new SomeWork(); var result = work.Exec <bool>(); Assert.AreEqual("empty", result); Action <float> af = (f) => { }; var result1 = work.Exec <bool>(af); Assert.AreEqual("not empty", result1); }
public void Configure(IApplicationBuilder app) { // Add a sample response header app.Use(async(context, nextMiddleware) => { context.Response.OnStarting(() => { context.Response.Headers.Add("Book", "Programming ASP.NET Core"); return(Task.FromResult(0)); }); await nextMiddleware(); }); app.Use(async(context, nextMiddleware) => { using (var memory = new MemoryStream()) { var originalStream = context.Response.Body; context.Response.Body = memory; await nextMiddleware(); memory.Seek(0, SeekOrigin.Begin); var content = new StreamReader(memory).ReadToEnd(); memory.Seek(0, SeekOrigin.Begin); // Apply logic here for deciding which headers to add context.Response.Headers.Add("Body", content); await memory.CopyToAsync(originalStream); context.Response.Body = originalStream; } }); app.Run(async(context) => { var obj = new SomeWork(); await context .Response .WriteAsync("<h1 style='color:red;'>" + obj.Now() + "</h1>"); }); }
public void InvokeOnWorkCompleted(string s) { SomeWork completed = DoWork; if (completed != null) completed(s); }
public bool IsAttached(string methodName) { SomeWork completed = DoWork; return completed.GetInvocationList().Any(m => m.Method.Name == methodName); }
static void Work3(SomeWork v) { v(4, WorkType.Meeting); }
public ValuesController(SomeWork someWork) { _someWork = someWork; }
// button calls the same code as the scheduled task protected void btnRunSomeWork_OnClick(object sender, EventArgs e) { SomeWork.TruncateEventLog(); }