コード例 #1
0
        private Action <HttpListenerContext> CreateSyncCallback(int methodDuration)
        {
            return(context =>
            {
                var currentRequestId = Interlocked.Increment(ref RequestsCount);
                var query = context.Request.QueryString["query"];
                log.InfoFormat($"Thread #{Thread.CurrentThread.ManagedThreadId} received request '{query}' #{currentRequestId} at {DateTime.Now.TimeOfDay}");

                Thread.Sleep(methodDuration);

                var encryptedBytes = ClusterHelpers.GetBase64HashBytes(query);
                context.Response.OutputStream.Write(encryptedBytes, 0, encryptedBytes.Length);

                log.InfoFormat($"Thread #{query} sent response for '{Thread.CurrentThread.ManagedThreadId}' for #{currentRequestId} at {DateTime.Now.TimeOfDay}");
            });
        }
コード例 #2
0
        private Func <HttpListenerContext, Task> CreateAsyncCallback(int methodDuration)
        {
            return(async context =>
            {
                var currentRequestNum = Interlocked.Increment(ref RequestsCount);
                var query = context.Request.QueryString["query"];
                Console.WriteLine($"Thread #{Thread.CurrentThread.ManagedThreadId} received request '{query}' #{currentRequestNum} at {DateTime.Now.TimeOfDay}");

                await Task.Delay(methodDuration);

                // Thread.Sleep(methodDuration);

                var encryptedBytes = ClusterHelpers.GetBase64HashBytes(query);
                await context.Response.OutputStream.WriteAsync(encryptedBytes, 0, encryptedBytes.Length);

                Console.WriteLine($"Thread #{Thread.CurrentThread.ManagedThreadId} sent response for '{query}' #{currentRequestNum} at {DateTime.Now.TimeOfDay}");
            });
        }
コード例 #3
0
        private Action <HttpListenerContext> CreateSyncCallback(ServerOptions parsedOptions)
        {
            return(context =>
            {
                var currentRequestId = Interlocked.Increment(ref RequestsCount);
                log.InfoFormat("Thread #{0} received request #{1} at {2}",
                               Thread.CurrentThread.ManagedThreadId, currentRequestId, DateTime.Now.TimeOfDay);

                Thread.Sleep(parsedOptions.MethodDuration);

                var encryptedBytes = ClusterHelpers.GetBase64HashBytes(context.Request.QueryString["query"]);
                context.Response.OutputStream.Write(encryptedBytes, 0, encryptedBytes.Length);

                log.InfoFormat("Thread #{0} sent response #{1} at {2}",
                               Thread.CurrentThread.ManagedThreadId, currentRequestId,
                               DateTime.Now.TimeOfDay);
            });
        }
コード例 #4
0
        private Func <HttpListenerContext, Task> CreateAsyncCallback(ServerOptions parsedOptions)
        {
            return(async context =>
            {
                var currentRequestNum = Interlocked.Increment(ref RequestsCount);
                Console.WriteLine("Thread #{0} received request #{1} at {2}",
                                  Thread.CurrentThread.ManagedThreadId, currentRequestNum, DateTime.Now.TimeOfDay);

                await Task.Delay(parsedOptions.MethodDuration);

                //				Thread.Sleep(parsedArguments.MethodDuration);

                var encryptedBytes = ClusterHelpers.GetBase64HashBytes(context.Request.QueryString["query"]);
                await context.Response.OutputStream.WriteAsync(encryptedBytes, 0, encryptedBytes.Length);

                Console.WriteLine("Thread #{0} sent response #{1} at {2}",
                                  Thread.CurrentThread.ManagedThreadId, currentRequestNum,
                                  DateTime.Now.TimeOfDay);
            });
        }