Пример #1
0
        static async Task Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(helpMessage);
                return;
            }
            args[0] = args[0].ToLower();
            if (args[0] == "-h" || args[0] == "--help" || args[0] == "h" || args[0] == "help")
            {
                Console.WriteLine(helpMessage);
                return;
            }
            Console.Out.Flush();
            PerformanceMeasurer.dumpnr    = int.Parse(args[1]);
            PerformanceMeasurer.StartTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
            Console.WriteLine($"Starting {PerformanceMeasurer.StartTime}...");

            while (conns.Count < threadCount)
            {
                await CreateClient();
            }

            await Task.Delay(1000); //Delay the start of the logging to prevent outliers

            if (args[0] == "auto" && args.Length >= 2)
            {
                Console.WriteLine(PerformanceMeasurer.dumpnr);
                Console.WriteLine("Starting Measurement");
                currentlyMeasuring = true;
                Thread.Sleep(trackTime);
                currentlyMeasuring = false;
                Console.WriteLine("Dumping Measurement");
                PerformanceMeasurer.DumpLog();
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine(runningHelpMessage);
                string input = "";
                while (input != "exit")
                {
                    input = Console.ReadLine().ToLowerInvariant();
                    switch (input)
                    {
                    case "start": currentlyMeasuring = true; break;

                    case "stop": currentlyMeasuring = false; break;

                    case "dump": PerformanceMeasurer.DumpLog(); break;

                    default: Console.WriteLine(runningHelpMessage); break;
                    }
                }
            }
        }
Пример #2
0
        private static async Task CreateClient()
        {
            Console.WriteLine($"Live clients: {conns.Count + 1}");
            await Task.Run(async() =>
            {
                HubConnection conn = new HubConnectionBuilder()
                                     .WithAutomaticReconnect()
                                     .WithUrl("https://home.hounsvad.dk:44380/SubscribeHub", (opts) =>
                {
                    opts.HttpMessageHandlerFactory = (message) =>
                    {
                        if (message is HttpClientHandler clientHandler)
                        {
                            // bypass SSL certificate
                            clientHandler.ServerCertificateCustomValidationCallback +=
                                (sender, certificate, chain, sslPolicyErrors) => { return(true); }
                        }
                        ;
                        return(message);
                    };
                })
                                     .Build();

                conns.Add(conn);

                Guid clientId = Guid.NewGuid();

                conn.On <string>("NewData", data =>
                {
                    try
                    {
                        if (currentlyMeasuring)
                        {
                            PerformanceMeasurer.Log(JsonConvert.DeserializeObject <ClientMessageDto>(data), DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), clientId);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e.Message + e.StackTrace);
                    }
                });

                try
                {
                    await conn.StartAsync();
                    //Console.WriteLine("Connection started");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    conns.Remove(conn);
                }

                try
                {
                    await conn.InvokeAsync("SubscribeTo", "Hounsvad%2Fpi%2Fcputemp%2FDEG_C", "K");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    conns.Remove(conn);
                }

                if (conn.State == HubConnectionState.Connected)
                {
                    return;
                }
                else
                {
                    conns.Remove(conn);
                }
            });
        }