Exemple #1
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));
        }
Exemple #2
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);
        }
Exemple #3
0
        StressTesterConfiguration ParseConfiguration(ref string sessionString)
        {
            StressTesterConfiguration options = null;

            string json = StringUtils.ExtractString(sessionString, STR_StartWebSurgeOptions, STR_EndWebSurgeOptions);

            if (!string.IsNullOrEmpty(json))
            {
                options = JsonSerializationUtils.Deserialize(json, typeof(StressTesterConfiguration))
                          as StressTesterConfiguration;

                if (options == null)
                {
                    options = new StressTesterConfiguration();
                }

                options.Password = Encryption.DecryptString(options.Password, App.EncryptionMachineKey);
            }

            return(options);
        }
Exemple #4
0
        /// <summary>
        /// Parses out the decoded text from the URL formatted text
        /// </summary>
        /// <returns></returns>
        public static string ParseUntitledString(string untitledText)
        {
            string text = null;

            try
            {
                if (untitledText.StartsWith("untitled.base64,", StringComparison.OrdinalIgnoreCase))
                {
                    text = untitledText.Substring("untitled.base64,".Length);
                    text = FromBase64(text);
                }
                else if (untitledText.StartsWith("untitled.urlencoded,", StringComparison.OrdinalIgnoreCase))
                {
                    text = untitledText.Substring("untitled.urlencoded,".Length);
                    text = FromBase64(WebUtility.UrlDecode(text));
                }
                else if (untitledText.StartsWith("untitled.text,", StringComparison.OrdinalIgnoreCase))
                {
                    text = untitledText.Substring("untitled.text,".Length);
                }
                else if (untitledText.StartsWith("untitled.json,", StringComparison.OrdinalIgnoreCase))
                {
                    text = untitledText.Substring("untitled.json,".Length);
                    if (!text.StartsWith("\'") && !text.StartsWith("\""))
                    {
                        text = "\"" + text + "\"";
                    }
                    text = JsonSerializationUtils.Deserialize(text, typeof(string)) as string;
                }
            }
            catch
            {
                text = "Invalid text formatting for imported text.";
            }

            return(text);
        }
Exemple #5
0
        /// <summary>
        /// Shows the WPF Preview menu
        /// </summary>
        /// <param name="positionAndElementType"></param>
        public void PreviewContextMenu(string positionAndElementType)
        {
            var pos = JsonSerializationUtils.Deserialize(positionAndElementType, typeof(PositionAndDocumentType));

            mmApp.Model.Window.PreviewBrowser.ExecuteCommand("PreviewContextMenu", pos);
        }
Exemple #6
0
        public static List <UserEntry> LoadUsersFromJson(string json)
        {
            object result = JsonSerializationUtils.Deserialize(json, typeof(List <UserEntry>), throwExceptions: true);

            return(result as List <UserEntry>);
        }