Advertisement
kpfp_linux

Program.cs wersja 2013-06-05 03:28

Jun 4th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5.  
  6. namespace Tester {
  7.     internal abstract class StatsPerPackageServer {
  8.         private const int DefaultPort = 80;
  9.                                         // ReSharper disable MemberCanBeProtected.Global
  10.         public abstract Dictionary<String, List<Tuple<String, Object>>> Stats { get; }
  11.  
  12.         public Dictionary<Tuple<String, int>, List<Tuple<String, Object>>> StatsByHost {
  13.                                         // ReSharper restore MemberCanBeProtected.Global
  14.             get {
  15.                 var res = new Dictionary<Tuple<string, int>, List<Tuple<String, Object>>>();
  16.                 foreach (var property in Stats) {
  17.                     foreach (var hostRes in property.Value) {
  18.                         var hostNameSplit = hostRes.Item1.Split(':'); // not a best way to do it...
  19.                         var port = DefaultPort;
  20.                         if (hostNameSplit.Length > 1) port = Convert.ToInt32(hostNameSplit[1]);
  21.                         var id = new Tuple<string, int>(hostNameSplit[0], port);
  22.                         List<Tuple<String, Object>> host;
  23.                         if (res.ContainsKey(id))
  24.                             host = res[id];
  25.                         else {
  26.                             host = new List<Tuple<String, Object>>();
  27.                             res.Add(id, host);
  28.                         }
  29.                         host.Add(new Tuple<String, Object>(property.Key, hostRes.Item2));
  30.                         res[id] = host;
  31.                     }
  32.                 }
  33.                 return res;
  34.             }
  35.         }
  36.     };
  37.  
  38.     internal class Mock : StatsPerPackageServer {
  39.         public override Dictionary<string, List<Tuple<String, Object>>> Stats {
  40.             get {
  41.                 return new Dictionary<string, List<Tuple<String, Object>>> {
  42.                     {
  43.                         "benchmark", new List<Tuple<String, Object>> {
  44.                             new Tuple<string, object>("192.168.100.1", 1250),
  45.                             new Tuple<String, Object>("127.0.0.1", 1234),
  46.                             new Tuple<String, Object>("192.168.100.0", 1250),
  47.                             new Tuple<String, Object>("127.0.0.1:8080", 1235)
  48.                         }
  49.                     }, {
  50.                         "load", new List<Tuple<String, Object>> {
  51.                             new Tuple<String, Object>("127.0.0.1:8080", 22.5),
  52.                             new Tuple<String, Object>("192.168.100.0:80", 22.55)
  53.                         }
  54.                     }
  55.                 };
  56.             }
  57.         }
  58.     }
  59.  
  60.  
  61.     internal static class Program {
  62.         private static void Main(string[] args) {
  63.             var stats = new Mock();
  64.             foreach (var property in stats.Stats) {
  65.                 Console.WriteLine("Key {0}", property.Key);
  66.                 Console.WriteLine("=====================================");
  67.                 foreach (var propElem in property.Value)
  68.                     Console.WriteLine("    {0} = {1}", propElem.Item1, propElem.Item2);
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement