コード例 #1
0
        public async Task GetGistListForUserTest()
        {
            var gistList = await GistClient.ListGistsForUserAsync("rickstrahl");

            Assert.IsNotNull(gistList);
            Assert.IsTrue(gistList.Count > 0);

            Console.WriteLine("Count: " + gistList.Count);
            Console.WriteLine(JsonSerializationUtils.Serialize(gistList, formatJsonOutput: true));
        }
        public void GetGistTest()
        {
            var gistId = "ef851ce1597b97ee0c2dba06a858db07";

            var gist = GistClient.GetGistFromServer(gistId);

            Assert.IsFalse(gist.hasError);

            Console.WriteLine(JsonSerializationUtils.Serialize(gist, formatJsonOutput: true));
        }
コード例 #3
0
        public void ColumnInfoTest()
        {
            var data = GetTableData();

            var parser  = new TableParserHtml();
            var colInfo = parser.GetColumnInfo(data);

            Assert.IsNotNull(colInfo);
            Console.WriteLine(JsonSerializationUtils.Serialize(colInfo));
        }
コード例 #4
0
        public void GetMissingGistTest()
        {
            var gistId = "bogus";

            var gist = GistClient.GetGistFromServer(gistId);

            Assert.IsTrue(gist.hasError);

            Console.WriteLine(JsonSerializationUtils.Serialize(gist, formatJsonOutput: true));
        }
コード例 #5
0
        /// <summary>
        /// Calls a method on the TextEditor in JavaScript a single JSON encoded
        /// value or object. The receiving function should expect a JSON object and parse it.
        ///
        /// This version returns no result value.
        /// </summary>
        public async Task CallMethodWithJson(string method, object parameter = null)
        {
            string cmd = method;

            if (parameter != null)
            {
                var jsonParm = JsonSerializationUtils.Serialize(parameter);
                cmd += "(" + jsonParm + ")";
            }

            await WebBrowser.CoreWebView2.ExecuteScriptAsync(cmd);
        }
コード例 #6
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (IsPreCaptureMode)
            {
                DialogResult = true;
            }

            if (!ScreenCaptureConfiguration.Current.Write())
            {
                mmApp.Log("Failed to save Screen Capture " + ScreenCaptureConfiguration.Current.ErrorMessage + "\r\n" +
                          JsonSerializationUtils.Serialize(ScreenCaptureConfiguration.Current));
            }
            Close();
        }
コード例 #7
0
        /// <summary>
        /// Calls a method on the TextEditor in JavaScript a single JSON encoded
        /// value or object. The receiving function should expect a JSON object and parse it.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public async Task <object> CallMethodWithJson <TResult>(string method, object parameter = null)
        {
            string cmd = method;

            if (parameter != null)
            {
                var jsonParm = JsonSerializationUtils.Serialize(parameter);
                cmd += "(" + jsonParm + ")";
            }

            string result = await WebBrowser.CoreWebView2.ExecuteScriptAsync(cmd);

            return(JsonSerializationUtils.Deserialize(result, typeof(TResult), true));
        }
コード例 #8
0
        public void JsonDeserializeStringTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;
            string json = JsonSerializationUtils.Serialize(config, true, true);

            config = null;

            config = JsonSerializationUtils.Deserialize(json, typeof(AutoConfigFileConfiguration), true) as AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
コード例 #9
0
        public async Task ProcessRequest()
        {
            var context = new ServiceHandlerRequestContext()
            {
                HttpContext   = HttpContext,
                ServiceConfig = ServiceConfiguration,

                Url = new ServiceHandlerRequestContextUrl()
                {
                    Url         = UriHelper.GetDisplayUrl(HttpContext.Request),
                    UrlPath     = HttpContext.Request.Path.Value.ToString(),
                    QueryString = HttpContext.Request.QueryString,
                    HttpMethod  = HttpContext.Request.Method.ToUpper()
                }
            };

            try
            {
                if (context.ServiceConfig.HttpsMode == ControllerHttpsMode.RequireHttps && HttpContext.Request.Scheme != "https")
                {
                    throw new UnauthorizedAccessException(Resources.ServiceMustBeAccessedOverHttps);
                }

                if (ServiceConfiguration.OnAfterMethodInvoke != null)
                {
                    await ServiceConfiguration.OnBeforeMethodInvoke(context);
                }

                await ExecuteMethod(context);

                ServiceConfiguration.OnAfterMethodInvoke?.Invoke(context);

                if (string.IsNullOrEmpty(context.ResultJson))
                {
                    context.ResultJson = JsonSerializationUtils.Serialize(context.ResultValue);
                }

                SendJsonResponse(context, context.ResultValue);
            }
            catch (Exception ex)
            {
                var error = new ErrorResponse(ex);
                SendJsonResponse(context, error);
            }
        }
コード例 #10
0
        /// <summary>
        /// Writes out the request data to disk
        /// </summary>
        /// <param name="requests"></param>
        /// <param name="filename"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public bool Save(List <HttpRequestData> requests, string filename,
                         StressTesterConfiguration options = null)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var request in requests)
            {
                sb.Append(request.ToRequestHttpHeader());

                if (!string.IsNullOrEmpty(request.ResponseHeaders))
                {
                    sb.Append(request.ToResponseHttpHeader());
                }

                sb.AppendLine(STR_Separator);
            }

            if (options != null)
            {
                sb.AppendLine("\r\n" + STR_StartWebSurgeOptions + "\r\n");

                // Encrypt and write
                string password = options.Password;
                if (!string.IsNullOrEmpty(password))
                {
                    options.Password = Encryption.EncryptString(options.Password, App.EncryptionMachineKey);
                }
                sb.AppendLine(JsonSerializationUtils.Serialize(options, false, true));
                options.Password = password;

                sb.AppendLine("\r\n// This file was generated by West Wind WebSurge");
                sb.AppendLine($"// Get your free copy at {App.WebHomeUrl}");
                sb.AppendLine("// to easily test or load test the requests in this file.");

                sb.AppendLine("\r\n" + STR_EndWebSurgeOptions + "\r\n");
            }

            File.WriteAllText(filename, sb.ToString());

            return(true);
        }
コード例 #11
0
        public void Native2PerfTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;

            string result = JsonSerializationUtils.Serialize(config, true, true);

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 10000; i++)
            {
                result = JsonSerializationUtils.Serialize(config, true, true);
            }

            sw.Stop();
            Console.WriteLine("Utils Serialize: " + sw.ElapsedMilliseconds + "ms");
            Console.WriteLine(result);
        }
コード例 #12
0
        /// <summary>
        /// Calls a method with simple parameters: String, number, boolean
        /// This version returns no results.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public async Task CallMethod(string method, params object[] parameters)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(method + "(");

            if (parameters != null)
            {
                for (var index = 0; index < parameters.Length; index++)
                {
                    object parm     = parameters[index];
                    var    jsonParm = JsonSerializationUtils.Serialize(parm);
                    sb.Append(jsonParm);
                    if (index < parameters.Length - 1)
                    {
                        sb.Append(",");
                    }
                }
            }
            sb.Append(")");

            await WebBrowser.CoreWebView2.ExecuteScriptAsync(sb.ToString());
        }
コード例 #13
0
        /// <summary>
        /// Writes a response with a full WebServerResult structure
        /// that allows maximum control over the response output.
        /// </summary>
        /// <param name="result"></param>

        public void WriteResponse(WebServerResult result)
        {
            var status = "OK";

            if (result.HttpStatusCode == 500)
            {
                status = "Server Error";
            }
            else if (result.HttpStatusCode == 404)
            {
                status = "Not Found";
            }
            else if (result.HttpStatusCode == 401)
            {
                status = "Unauthorized";
            }
            else if (result.HttpStatusCode == 204)
            {
                status = "No Content";
            }

            string headers =
                $"HTTP/1.1 {result.HttpStatusCode} {status}\r\n" +
                "Access-Control-Allow-Origin: *\r\n" +
                "Access-Control-Allow-Methods: GET,POST,PUT,OPTIONS\r\n" +
                "Access-Control-Allow-Headers: *\r\n";

            if (result.hasNoData)
            {
                WriteResponseInternal(null, headers);
            }
            else
            {
                var json = JsonSerializationUtils.Serialize(result, formatJsonOutput: true);
                WriteResponseInternal(json, headers + "Content-Type: application/json\r\n");
            }
        }
コード例 #14
0
        public void RequestSummaryTest()
        {
            var time = DateTime.UtcNow;

            var requests = new List <HttpRequestData>()
            {
                new HttpRequestData()
                {
                    Url          = "http://localhost/",
                    Timestamp    = time,
                    IsError      = false,
                    TimeTakenMs  = 10,
                    ErrorMessage = "Invalid Server Response",
                    StatusCode   = "500"
                },
                new HttpRequestData()
                {
                    Url         = "http://localhost/wconnect",
                    Timestamp   = time.AddMilliseconds(20),
                    IsError     = false,
                    TimeTakenMs = 95
                },
                new HttpRequestData
                {
                    Url          = "http://localhost/",
                    Timestamp    = time.AddMilliseconds(220),
                    IsError      = false,
                    TimeTakenMs  = 15,
                    ErrorMessage = "Bogus Invalid Server Response",
                    StatusCode   = "500"
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/",
                    Timestamp   = time.AddMilliseconds(1020),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect",
                    Timestamp   = time.AddMilliseconds(1050),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/",
                    Timestamp   = time.AddMilliseconds(1200),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/",
                    Timestamp   = time.AddMilliseconds(3020),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/",
                    Timestamp   = time.AddMilliseconds(3050),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect",
                    Timestamp   = time.AddMilliseconds(3200),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect",
                    Timestamp   = time.AddMilliseconds(3500),
                    TimeTakenMs = 50
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect/testpage",
                    Timestamp   = time.AddMilliseconds(3100),
                    IsError     = false,
                    TimeTakenMs = 50
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect/testpage",
                    IsError     = false,
                    Timestamp   = time.AddMilliseconds(3200),
                    TimeTakenMs = 57
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect/testpage2",
                    Timestamp   = time.AddMilliseconds(3100),
                    TimeTakenMs = 50
                },
                new HttpRequestData
                {
                    Url         = "http://localhost/wconnect/testpage2",
                    Timestamp   = time.AddMilliseconds(3200),
                    TimeTakenMs = 57
                }
            };

            var writer = new RequestWriter(null, requests);


            var parser = new ResultsParser();
            var res    = parser.UrlSummary(writer, 200);

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Count() > 0);

            foreach (var r in res)
            {
                Console.WriteLine(r.Url + ": " + JsonSerializationUtils.Serialize(r.Results, false, true));
            }


            var html = parser.GetResultReportHtml(writer, 10, 2);

            Console.WriteLine(html);

            var file = App.UserDataPath + "html\\_preview.html";

            File.WriteAllText(file, html);
            ShellUtils.GoUrl(file);
        }
コード例 #15
0
        public void ResultsReportTimeTakenTest()
        {
            var time = DateTime.UtcNow;

            var requests = new List <HttpRequestData>()
            {
                new HttpRequestData()
                {
                    Timestamp   = time,
                    TimeTakenMs = 10
                },
                new HttpRequestData()
                {
                    Timestamp   = time.AddMilliseconds(20),
                    TimeTakenMs = 15
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(220),
                    TimeTakenMs = 15
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(1020),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(1050),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(1200),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(3020),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(3050),
                    TimeTakenMs = 20
                },
                new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(3200),
                    TimeTakenMs = 20
                }, new HttpRequestData
                {
                    Timestamp   = time.AddMilliseconds(3500),
                    TimeTakenMs = 50
                }
            };
            var timeTakenMs = 30000;

            var stressTester = new StressTester();
            var writer       = new RequestWriter(stressTester);

            writer.SetResults(requests);

            var parser  = new ResultsParser();
            var results = parser.GetResultReport(writer, timeTakenMs, 10);

            Assert.AreEqual(timeTakenMs / 1000, results.TestResult.TimeTakenSecs);

            Console.WriteLine(JsonSerializationUtils.Serialize(results, false, true));
        }
コード例 #16
0
ファイル: UserManager.cs プロジェクト: fzfy6/ktv
 public static string SaveUsersToJsonString(List <UserEntry> users)
 {
     return(JsonSerializationUtils.Serialize(users, throwExceptions: true, formatJsonOutput: true));
 }
コード例 #17
0
        public string Export(string name, List <HttpRequestData> requests, StressTesterConfiguration config, string filename = null)
        {
            var pm = new PostmanCollection();

            foreach (var request in requests)
            {
                pm.info._postman_id = Guid.NewGuid().ToString();
                if (!string.IsNullOrEmpty(name))
                {
                    pm.info.name = name;
                }
                else
                {
                    pm.info.name = "Collection-" + DataUtils.GenerateUniqueId(8);
                }
                pm.info.schema = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json";

                var item = new Item();
                pm.item.Add(item);

                item.name = request.Url;

                var req = new Request();
                item.request = req;

                req.url    = new Url();
                req.method = request.HttpVerb;

                var body = new Body();
                req.body  = body;
                body.mode = "raw";
                body.raw  = request.RequestContent;

                // don't copy over credentials explicitly
                //if (!string.IsNullOrEmpty(config.Username))
                //{
                //    req.auth = new Auth();
                //    req.auth.type = "ntlm";
                //    var ntlm = new List<Ntlm>();
                //    req.auth.ntlm = ntlm;
                //    ntlm.Add(new Ntlm {key = "username", value = config.Username});
                //    ntlm.Add(new Ntlm {key = "password", value = ""});
                //}

                foreach (var header in request.Headers)
                {
                    req.header.Add(new Header
                    {
                        key = header.Name, name = header.Name, value = header.Value, type = "text"
                    });
                }

                req.url.raw      = request.Url;
                req.url.protocol = "http";
                req.url.host.Add(request.Host);
            }

            if (!string.IsNullOrEmpty(filename))
            {
                if (JsonSerializationUtils.SerializeToFile(pm, filename, false, true))
                {
                    return("OK");
                }

                return(null);
            }

            return(JsonSerializationUtils.Serialize(pm, false, formatJsonOutput: true));
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: fzfy6/ktv
        static void Main(string[] args)
        {
            var origColor = Console.ForegroundColor;


            var options = new CommandLineOptions();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return;
            }


            Console.ForegroundColor = ConsoleColor.White;

            // If SessionFile is a Url assign to Url so we run on a single URL
            if (!string.IsNullOrEmpty(options.SessionFile) &&
                (options.SessionFile.StartsWith("http://") || options.SessionFile.StartsWith("https://")))
            {
                options.Url         = options.SessionFile;
                options.SessionFile = null;
            }


            var stressTester = new StressTester();

            List <HttpRequestData> requests;

            if (!string.IsNullOrEmpty(options.SessionFile))
            {
                requests = stressTester.ParseSessionFile(options.SessionFile);
            }
            else
            {
                if (string.IsNullOrEmpty(options.Url))
                {
                    Console.WriteLine(options.GetUsage());
                    Console.ForegroundColor = origColor;
                    return;
                }

                requests = new List <HttpRequestData>();
                requests.Add(new HttpRequestData
                {
                    Url = options.Url
                });
            }

            if (options.Silent != 0 && options.Silent != 1)
            {
                Console.WriteLine("West Wind WebSurge v" + GetVersion());
                Console.WriteLine("------------------------");
            }

            int time    = options.Time;
            int threads = options.Threads;

            stressTester.Options.DelayTimeMs       = options.DelayTimeMs;
            stressTester.Options.RandomizeRequests = options.RandomizeRequests;
            stressTester.Options.WarmupSeconds     = options.WarmupSeconds;

            if (options.Silent != 0 && options.Silent != 1)
            {
                stressTester.RequestProcessed += stressTester_RequestProcessed;
            }

            if (options.Silent != 0 && options.Silent != 2)
            {
                stressTester.Progress += stressTester_Progress;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            var results = stressTester.CheckAllSites(requests, threads, time);

            if (results == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: " + stressTester.ErrorMessage);
                Console.ForegroundColor = origColor;
                return;
            }
            Console.ForegroundColor = ConsoleColor.White;

            if (options.Json)
            {
                var result = stressTester.ResultsParser.GetResultReport(stressTester.Results,
                                                                        stressTester.TimeTakenForLastRunMs,
                                                                        stressTester.ThreadsUsed);
                string json = JsonSerializationUtils.Serialize(result, formatJsonOutput: true);

                Console.WriteLine(json);
                Console.ForegroundColor = origColor;
                if (options.OutputFile != null)
                {
                    File.WriteAllText(options.OutputFile, json);
                }
                return;
            }

            string resultText = stressTester.ParseResults(results);

            if (options.Silent != 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine();
                Console.WriteLine("Summary:");
                Console.WriteLine("--------");
                Console.ForegroundColor = ConsoleColor.White;
            }

            if (options.SessionFile != null)
            {
                Console.WriteLine("Session: " + options.SessionFile);
            }
            else
            {
                Console.WriteLine("Url: " + options.Url);
            }


            Console.WriteLine();
            Console.WriteLine(resultText);

            if (options.OutputFile != null)
            {
                File.WriteAllText(options.OutputFile, resultText);
            }

            Console.ForegroundColor = origColor;
        }