public void TestShowTree(IResultSink res) { Expression<Func<int, bool>> expEven = x => x % 2 == 0; res.Send("Code :" + expEven.ToString()); res.Send("Exp body: " + expEven.Body.ToString()); res.Send("Exp node type: " + expEven.NodeType.ToString()); Func<int, bool> realExp = expEven.Compile(); res.Send("Calling compiled on (2): " + realExp(2).ToString()); }
public async void GetPrimesAsync(IResultSink res) { Stopwatch sw = new Stopwatch(); sw.Start(); var result = await GetPrimes(1, 10000000); sw.Stop(); res.Send("Elapsed: " + sw.ElapsedMilliseconds.ToString() + " ms"); result.Take(100).ToList().ForEach(x => res.Send(x.ToString())); }
public async void TestAwait(IResultSink sink) { sink.Send("Waiting for the result..."); sink.SetResult(false); //string result = await Task<string>.Factory.StartNew(() => GetSomeStringTakesLongTime()); Task<string> t1 = new Task<string>(() => GetSomeStringTakesLongTime()); t1.Start(); string result = await t1; sink.Send(result); sink.SetResult(true); }
public void TestConnection(IResultSink res) { var cnt = from c in ctx.Contacts select c; res.Send("Connected, there are " + cnt.Count().ToString() + " contacts in database"); }
public void TestListIndividualCustomers(IResultSink res) { using (StringWriter sw = new StringWriter()) { var cust = from c in ctx.Customers from i in ctx.Individuals from co in ctx.Contacts where c.CustomerType == 'I' && co.ContactID == i.ContactID && i.CustomerID == c.CustomerID select co; //select new //{ // co.FirstName, // co.LastName, // co.EmailAddress //}; ctx.Log = sw; foreach (var customer in cust.Take(10)) { res.Send ( customer.FirstName + " " + customer.LastName + " " + customer.EmailAddress + " " ); } //res.Send(sw.ToString()); //ctx.Log = null; } }
public void TestParallelFor(IResultSink res) { int[] tbl = new int[20]; Stopwatch psw = new Stopwatch(); psw.Start(); Parallel.For(1, 21, i => tbl[i-1] = Factorial(i)); psw.Stop(); foreach (int i in tbl) res.Send(i.ToString()); res.Send("Parallelized: " + psw.Elapsed.Milliseconds.ToString()); psw = Stopwatch.StartNew(); for (int i = 1; i <= 20; ++i) tbl[i - 1] = Factorial(i); psw.Stop(); res.Send("Non-parallelized: " + psw.Elapsed.Milliseconds.ToString()); }
public void TestRecursiveAnonymous(IResultSink res) { Func<long, long> Factorial = x => (x > 1 ? x * (long)(new StackTrace().GetFrame(0).GetMethod().Invoke(null, new object[] { x-1 })) : x); res.Send(Factorial(5).ToString()); }
public void TestFib(IResultSink res) { Func<long, long> Fib = x => x < 2 ? x : ((long)(new StackTrace().GetFrame(0).GetMethod().Invoke(null, new object[] { x-1 }))) + ((long)(new StackTrace().GetFrame(0).GetMethod().Invoke(null, new object[] { x-2 }))); for (int i = 0; i < 10; ++i) res.Send(Fib(i).ToString()); }
public void TestTasks(IResultSink res) { Task<int> t1 = new Task<int>(() => Factorial(5)); Task<int> t2 = new Task<int>(() => Factorial(10)); t1.Start(); t2.Start(); Task.WaitAll(t1, t2); res.Send("Factorials: " + t1.Result.ToString() + " " + t2.Result.ToString()); }
public void ListProcesses(IResultSink res) { var processes = from p in Process.GetProcesses() orderby p.ProcessName, p.Id group p by p.ProcessName into g let tot_mem = g.Sum (p => (double)p.PrivateMemorySize64 / (1024 * 1024)) orderby tot_mem descending select new { Name = g.Key, TotalMem = tot_mem }; foreach (var pp in processes) res.Send(string.Format("{0,-20}{1,10:n2}", pp.Name, pp.TotalMem)); }
public void TestCopyStream(IResultSink res) { using (MemoryStream ms = new MemoryStream()) using (FileStream fs = File.Open(@"..\..\test.txt", FileMode.Open)) { fs.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(ms)) { res.Send(sr.ReadToEnd()); } } }
public void GetCards(IResultSink sink) { DataContext db = new DataContext("server=.;database=adventureworks2008;integrated security=true"); Table<CreditCardInfo> cards = db.GetTable<CreditCardInfo>(); var r = from c in cards where c.ExpYear > 2007 && c.ExpYear < 2010 select c; foreach (var card in r.Take(10)) { sink.Send(card.CardType + " " + card.CardNumber + " " + card.ExpYear.ToString() + "\n"); } }
public void TakeWhileTest(IResultSink res) { var t = greets.TakeWhile(x => x.StartsWith("G")); foreach (var x in t) res.Send(x.ToString()); }
public void TestGenerateSequence(IResultSink res) { var f = Enumerable.Range(1, 20); foreach (int x in f) res.Send(x.ToString()); }
public void TestGroupJoin(IResultSink res) { var gj = from a in ages join p in persons on a.Age equals p.Age into g select new { a.Age, Count = g.Count() }; foreach (var g in gj) res.Send("Age: " + g.Age + " has count: " + g.Count); }
public void GetDistictTest(IResultSink res) { var dist = from g in greets.Distinct() select g; foreach (var x in dist) res.Send(x.ToString()); }
public void TestVariations(IResultSink res) { foreach (var p in "abdc".AllPermutations()) res.Send(p); }
public void TestQueryInts(IResultSink res) { var sums = from e in ints group e by (e % 2 == 0) into g select new { Key = g.Key, Total = g.Sum() }; foreach(var sum in sums) res.Send(sum.Key.ToString() + " has sum: " + sum.Total.ToString()); }
public void DisplaySorted(IResultSink res) { string[] sorted = greets.Select(s => s).OrderBy(s => s).ToArray(); foreach (string s in sorted) res.Send(s); }
public void QueryGreaterThanTwo(IResultSink res) { var items = from greet in greets where greet.Length > 2 select greet; foreach (var item in items) res.Send("Greet: " + item); }
public void CallImplPartial(IResultSink res) { PMethodTwo(); res.Send(count.ToString()); }
public void CallAbsentPartial(IResultSink res) { PMethodOne(); res.Send(count.ToString()); }
public void SelectManyTest(IResultSink res) { var t = greets.SelectMany(g => g.ToArray()); foreach (var x in t) res.Send(x.ToString()); }
public void TestParallelArray(IResultSink res) { var q = from p in persons.AsParallel() where p.Age < 18 select p; foreach (var p in q) res.Send("Person: " + p.Name + " " + p.Age); }
public void ListGreets(IResultSink res) { foreach (string s in greets) res.Send(s); }
public void TestVariationBase(IResultSink res) { //res.Send ( char.ConvertFromUtf32('A' + 1).ToString()); foreach(var r in GetVariations(99)) res.Send(r); }