Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Tester {
- internal abstract class StatsPerPackageServer {
- private const int DefaultPort = 80;
- // ReSharper disable MemberCanBeProtected.Global
- public abstract Dictionary<String, List<Tuple<String, Object>>> Stats { get; }
- public Dictionary<Tuple<String, int>, List<Tuple<String, Object>>> StatsByHost {
- // ReSharper restore MemberCanBeProtected.Global
- get {
- var res = new Dictionary<Tuple<string, int>, List<Tuple<String, Object>>>();
- foreach (var property in Stats) {
- foreach (var hostRes in property.Value) {
- var hostNameSplit = hostRes.Item1.Split(':'); // not a best way to do it...
- var port = DefaultPort;
- if (hostNameSplit.Length > 1) port = Convert.ToInt32(hostNameSplit[1]);
- var id = new Tuple<string, int>(hostNameSplit[0], port);
- List<Tuple<String, Object>> host;
- if (res.ContainsKey(id))
- host = res[id];
- else {
- host = new List<Tuple<String, Object>>();
- res.Add(id, host);
- }
- host.Add(new Tuple<String, Object>(property.Key, hostRes.Item2));
- res[id] = host;
- }
- }
- return res;
- }
- }
- };
- internal class Mock : StatsPerPackageServer {
- public override Dictionary<string, List<Tuple<String, Object>>> Stats {
- get {
- return new Dictionary<string, List<Tuple<String, Object>>> {
- {
- "benchmark", new List<Tuple<String, Object>> {
- new Tuple<string, object>("192.168.100.1", 1250),
- new Tuple<String, Object>("127.0.0.1", 1234),
- new Tuple<String, Object>("192.168.100.0", 1250),
- new Tuple<String, Object>("127.0.0.1:8080", 1235)
- }
- }, {
- "load", new List<Tuple<String, Object>> {
- new Tuple<String, Object>("127.0.0.1:8080", 22.5),
- new Tuple<String, Object>("192.168.100.0:80", 22.55)
- }
- }
- };
- }
- }
- }
- internal static class Program {
- private static void Main(string[] args) {
- var stats = new Mock();
- foreach (var property in stats.Stats) {
- Console.WriteLine("Key {0}", property.Key);
- Console.WriteLine("=====================================");
- foreach (var propElem in property.Value)
- Console.WriteLine(" {0} = {1}", propElem.Item1, propElem.Item2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement