Advertisement
Guest User

Untitled

a guest
Jan 10th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. namespace H_Auth
  2. {
  3.   internal class AuthSvc
  4.   {
  5.     private static void Main(string[] args)
  6.     {
  7.             var adrs = new Uri[1];
  8.             adrs[0] = new Uri("net.tcp://localhost:5031/");
  9.             using (ServiceHost serviceHost = new ServiceHost(typeof (HBChannel), adrs))
  10.             {
  11.       try
  12.       {
  13.         serviceHost.AddServiceEndpoint(typeof (IA), (System.ServiceModel.Channels.Binding) new NetTcpBinding(SecurityMode.None), "Auth.svc");
  14.         ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
  15.         serviceHost.Description.Behaviors.Add((IServiceBehavior) metadataBehavior);
  16.         ((ServiceHostBase) serviceHost).AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
  17.         serviceHost.Open();
  18.         string str = Regex.Match(((AssemblyFileVersionAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof (AssemblyFileVersionAttribute), false)[0]).Version, "^\\d+\\.\\d+").Value;
  19.         Console.ForegroundColor = ConsoleColor.Green;
  20.         Console.WriteLine("Revision " + str + "\r\n");
  21.         Console.ResetColor();
  22.         Console.WriteLine("press \"S\" for stats print");
  23.         Console.WriteLine();
  24.  
  25.         ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();
  26.         while (consoleKeyInfo.Key != ConsoleKey.Enter)
  27.         {
  28.                     consoleKeyInfo = Console.ReadKey(true);
  29.                     if (consoleKeyInfo.Key == ConsoleKey.S)
  30.                     {
  31.                       AuthImpl.Instance.RemoveExpiredSessions();
  32.                        AuthSvc.PrintStats(AuthImpl.Instance.GetSessions);
  33.                      }
  34.         }
  35.         serviceHost.Close();
  36.       }
  37.       catch (CommunicationException ex)
  38.       {
  39.         Logging.Ex(ex.Message);
  40.         serviceHost.Abort();
  41.       }
  42.             }
  43.       Console.ReadLine();
  44.  
  45.     }
  46.  
  47.     private static void PrintStats(List<SessInfo> Sessions)
  48.     {
  49.       Console.WriteLine("Current active sessions:");
  50.       Dictionary<string, int> dictionary1 = new Dictionary<string, int>();
  51.       foreach (SessInfo sessInfo in Sessions)
  52.       {
  53.         if (!dictionary1.ContainsKey(sessInfo.BotSignature))
  54.         {
  55.           dictionary1.Add(sessInfo.BotSignature, 1);
  56.         }
  57.         else
  58.         {
  59.           Dictionary<string, int> dictionary2;
  60.           string botSignature;
  61.           (dictionary2 = dictionary1)[botSignature = sessInfo.BotSignature] = dictionary2[botSignature] + 1;
  62.         }
  63.       }
  64.       if (dictionary1.Count > 0)
  65.       {
  66.         foreach (KeyValuePair<string, int> keyValuePair in dictionary1)
  67.           Console.WriteLine(string.Format("'{0}': {1} user {2}", (object) keyValuePair.Key, (object) keyValuePair.Value, keyValuePair.Value > 1 ? (object) "S" : (object) ""));
  68.       }
  69.       else
  70.         Console.WriteLine("There is no active sessions");
  71.     }
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement