コード例 #1
0
 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());
 }
コード例 #2
0
		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()));
		}
コード例 #3
0
		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);
		}
コード例 #4
0
        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");
        }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
ファイル: Net4Features.cs プロジェクト: ebutusov/GeneralTests
 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());
 }
コード例 #7
0
        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());
        }
コード例 #8
0
 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());
 }
コード例 #9
0
ファイル: Net4Features.cs プロジェクト: ebutusov/GeneralTests
        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());
        }
コード例 #10
0
		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));
		}
コード例 #11
0
ファイル: Net4Features.cs プロジェクト: ebutusov/GeneralTests
 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());
         }
     }
 }
コード例 #12
0
        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");
            }
        }
コード例 #13
0
 public void TakeWhileTest(IResultSink res)
 {
     var t = greets.TakeWhile(x => x.StartsWith("G"));
     foreach (var x in t)
         res.Send(x.ToString());
 }
コード例 #14
0
 public void TestGenerateSequence(IResultSink res)
 {
     var f = Enumerable.Range(1, 20);
     foreach (int x in f)
         res.Send(x.ToString());
 }
コード例 #15
0
        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);
        }
コード例 #16
0
 public void GetDistictTest(IResultSink res)
 {
     var dist = from g in greets.Distinct()
                          select g;
     foreach (var x in dist)
         res.Send(x.ToString());
 }
コード例 #17
0
 public void TestVariations(IResultSink res)
 {
     foreach (var p in "abdc".AllPermutations())
         res.Send(p);
 }
コード例 #18
0
        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());
        }
コード例 #19
0
 public void DisplaySorted(IResultSink res)
 {
     string[] sorted = greets.Select(s => s).OrderBy(s => s).ToArray();
     foreach (string s in sorted)
         res.Send(s);
 }
コード例 #20
0
        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);
        }
コード例 #21
0
 public void CallImplPartial(IResultSink res)
 {
     PMethodTwo();
     res.Send(count.ToString());
 }
コード例 #22
0
 public void CallAbsentPartial(IResultSink res)
 {
     PMethodOne();
     res.Send(count.ToString());
 }
コード例 #23
0
 public void SelectManyTest(IResultSink res)
 {
     var t = greets.SelectMany(g => g.ToArray());
     foreach (var x in t)
         res.Send(x.ToString());
 }
コード例 #24
0
 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);
 }
コード例 #25
0
 public void ListGreets(IResultSink res)
 {
     foreach (string s in greets)
         res.Send(s);
 }
コード例 #26
0
 public void TestVariationBase(IResultSink res)
 {
     //res.Send ( char.ConvertFromUtf32('A' + 1).ToString());
     foreach(var r in GetVariations(99))
         res.Send(r);
 }