Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace H_Auth
- {
- internal class AuthSvc
- {
- private static void Main(string[] args)
- {
- var adrs = new Uri[1];
- adrs[0] = new Uri("net.tcp://localhost:5031/");
- using (ServiceHost serviceHost = new ServiceHost(typeof (HBChannel), adrs))
- {
- try
- {
- serviceHost.AddServiceEndpoint(typeof (IA), (System.ServiceModel.Channels.Binding) new NetTcpBinding(SecurityMode.None), "Auth.svc");
- ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
- serviceHost.Description.Behaviors.Add((IServiceBehavior) metadataBehavior);
- ((ServiceHostBase) serviceHost).AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
- serviceHost.Open();
- string str = Regex.Match(((AssemblyFileVersionAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof (AssemblyFileVersionAttribute), false)[0]).Version, "^\\d+\\.\\d+").Value;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Revision " + str + "\r\n");
- Console.ResetColor();
- Console.WriteLine("press \"S\" for stats print");
- Console.WriteLine();
- ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();
- while (consoleKeyInfo.Key != ConsoleKey.Enter)
- {
- consoleKeyInfo = Console.ReadKey(true);
- if (consoleKeyInfo.Key == ConsoleKey.S)
- {
- AuthImpl.Instance.RemoveExpiredSessions();
- AuthSvc.PrintStats(AuthImpl.Instance.GetSessions);
- }
- }
- serviceHost.Close();
- }
- catch (CommunicationException ex)
- {
- Logging.Ex(ex.Message);
- serviceHost.Abort();
- }
- }
- Console.ReadLine();
- }
- private static void PrintStats(List<SessInfo> Sessions)
- {
- Console.WriteLine("Current active sessions:");
- Dictionary<string, int> dictionary1 = new Dictionary<string, int>();
- foreach (SessInfo sessInfo in Sessions)
- {
- if (!dictionary1.ContainsKey(sessInfo.BotSignature))
- {
- dictionary1.Add(sessInfo.BotSignature, 1);
- }
- else
- {
- Dictionary<string, int> dictionary2;
- string botSignature;
- (dictionary2 = dictionary1)[botSignature = sessInfo.BotSignature] = dictionary2[botSignature] + 1;
- }
- }
- if (dictionary1.Count > 0)
- {
- foreach (KeyValuePair<string, int> keyValuePair in dictionary1)
- Console.WriteLine(string.Format("'{0}': {1} user {2}", (object) keyValuePair.Key, (object) keyValuePair.Value, keyValuePair.Value > 1 ? (object) "S" : (object) ""));
- }
- else
- Console.WriteLine("There is no active sessions");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement