public string DoWork()
        {
            WPConfigurationSourceDTO configurationSource = new WPConfigurationSourceDTO()
            {
                DB_HOST      = this._wpToJsonDTO.WPSourceDBHost,
                DB_NAME      = this._wpToJsonDTO.WPSourceDBName,
                DB_PASSWORD  = this._wpToJsonDTO.WPSourceDBPassword,
                DB_USER      = this._wpToJsonDTO.WPSourceDBUser,
                TABLE_PREFIX = this._wpToJsonDTO.WPSourceDBTablePrefix,
            };

            WPConfigurationPluginExportDTO configurationPluginExport = new WPConfigurationPluginExportDTO()
            {
                WooCommerce = (Array.IndexOf(this._wpToJsonDTO.PluginExport, ListOfPlugin.WooCommerce) != -1),
                Yoast       = (Array.IndexOf(this._wpToJsonDTO.PluginExport, ListOfPlugin.Yoast) != -1)
            };


            WPExportDTO exportDTO = WPExportEngine.RunAllQueries(configurationSource, configurationPluginExport);

            Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.None;
            if (this._wpToJsonDTO.JSONIndented)
            {
                formatting = Newtonsoft.Json.Formatting.Indented;
            }

            WPToJson wPToJson = new WPToJson(exportDTO)
            {
                ExportSeoWithYoast = configurationPluginExport.Yoast
            };

            return(wPToJson.CreateJSON(formatting));
        }
    static int ToString(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(Newtonsoft.Json.Linq.JToken)))
            {
                Newtonsoft.Json.Linq.JToken obj = (Newtonsoft.Json.Linq.JToken)ToLua.ToObject(L, 1);
                string o = obj.ToString();
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (TypeChecker.CheckTypes(L, 1, typeof(Newtonsoft.Json.Linq.JToken), typeof(Newtonsoft.Json.Formatting)) && TypeChecker.CheckParamsType(L, typeof(Newtonsoft.Json.JsonConverter), 3, count - 2))
            {
                Newtonsoft.Json.Linq.JToken     obj  = (Newtonsoft.Json.Linq.JToken)ToLua.ToObject(L, 1);
                Newtonsoft.Json.Formatting      arg0 = (Newtonsoft.Json.Formatting)ToLua.ToObject(L, 2);
                Newtonsoft.Json.JsonConverter[] arg1 = ToLua.ToParamsObject <Newtonsoft.Json.JsonConverter>(L, 3, count - 2);
                string o = obj.ToString(arg0, arg1);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Newtonsoft.Json.Linq.JToken.ToString"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 3
0
        public static string SerializeXmlNode(System.Xml.XmlNode node, Newtonsoft.Json.Formatting formatting)
        {
            XmlNodeConverter converter = new XmlNodeConverter();

            JsonConverter[] converters = new JsonConverter[] { converter };
            return(SerializeObject(node, formatting, converters));
        }
        public static string SerializeObject(object value, Type type, Newtonsoft.Json.Formatting formatting, JsonSerializerSettings settings)
        {
            JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);

            jsonSerializer.Formatting = formatting;
            return(JsonConvert.SerializeObjectInternal(value, type, jsonSerializer));
        }
Esempio n. 5
0
        public string ToJson(Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.Indented)
        {
            Config config = ToConfig();

            try { return(Newtonsoft.Json.JsonConvert.SerializeObject(config, formatting)); }
            catch { return(null); }
        }
Esempio n. 6
0
 /// <summary>
 /// Serializes a CFX object into JSON format, including type information
 /// </summary>
 /// <param name="o">The object to be serialized</param>
 /// <param name="formatted">If true, the resultant JSON will be formatted for easy human interpretation (whitespace and carriage returns added)</param>
 /// <returns>A string representing the CFX object in JSON format</returns>
 public static string SerializeObjectWithTypes(object o, bool formatted = false)
 {
     Newtonsoft.Json.Formatting format = formatted ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None;
     JsonSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto;
     JsonSettings.TypeNameAssemblyFormatHandling = Newtonsoft.Json.TypeNameAssemblyFormatHandling.Simple;
     return(Newtonsoft.Json.JsonConvert.SerializeObject(o, format, JsonSettings));
 }
Esempio n. 7
0
 public static string ToJson(this object obj, Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.None)
 {
     if (obj == null)
     {
         return("");
     }
     return(Newtonsoft.Json.JsonConvert.SerializeObject(obj, formatting));
 }
Esempio n. 8
0
        public static string SerializeXNode(XObject node, Newtonsoft.Json.Formatting formatting, bool omitRootObject)
        {
            XmlNodeConverter converter = new XmlNodeConverter {
                OmitRootObject = omitRootObject
            };

            return(SerializeObject(node, formatting, new JsonConverter[] { converter }));
        }
    static int ToString(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                Newtonsoft.Json.Linq.JValue obj = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1);
                string o = obj.ToString();
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <System.IFormatProvider>(L, 2))
            {
                Newtonsoft.Json.Linq.JValue obj  = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1);
                System.IFormatProvider      arg0 = (System.IFormatProvider)ToLua.ToObject(L, 2);
                string o = obj.ToString(arg0);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <string>(L, 2))
            {
                Newtonsoft.Json.Linq.JValue obj = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                string o    = obj.ToString(arg0);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, System.IFormatProvider>(L, 2))
            {
                Newtonsoft.Json.Linq.JValue obj = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                System.IFormatProvider arg1 = (System.IFormatProvider)ToLua.ToObject(L, 3);
                string o = obj.ToString(arg0, arg1);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (TypeChecker.CheckTypes <Newtonsoft.Json.Linq.JValue, Newtonsoft.Json.Formatting>(L, 1) && TypeChecker.CheckParamsType <Newtonsoft.Json.JsonConverter>(L, 3, count - 2))
            {
                Newtonsoft.Json.Linq.JValue     obj  = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1);
                Newtonsoft.Json.Formatting      arg0 = (Newtonsoft.Json.Formatting)ToLua.ToObject(L, 2);
                Newtonsoft.Json.JsonConverter[] arg1 = ToLua.ToParamsObject <Newtonsoft.Json.JsonConverter>(L, 3, count - 2);
                string o = obj.ToString(arg0, arg1);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Newtonsoft.Json.Linq.JValue.ToString"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 10
0
 public void SavePackets(string filename = "packets.json", Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.Indented, bool informative = true)
 {
     if (!RememberPackets)
     {
         Console.WriteLine("There are no packets to save. Set 'RememberPackets' before you start or pass in packets to this function");
         return;
     }
     SavePackets(remeberedPackets.ToArray(), filename, formatting, informative);
 }
Esempio n. 11
0
        public static Task <string> SerializeObjectAsync(object value, Newtonsoft.Json.Formatting formatting, JsonSerializerSettings settings)
        {
            Class108 class2 = new Class108 {
                object_0                 = value,
                formatting_0             = formatting,
                jsonSerializerSettings_0 = settings
            };

            return(Task.Factory.StartNew <string>(new Func <string>(class2.method_0)));
        }
Esempio n. 12
0
            public string FromObject(object obj, Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.None)
            {
                var Preferences = new Newtonsoft.Json.JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                    Formatting            = formatting
                };

                return(Newtonsoft.Json.JsonConvert.SerializeObject(obj, Preferences));
            }
Esempio n. 13
0
        public static Byte[] ToUTF8Bytes(this JObject JSONObject,
                                         Newtonsoft.Json.Formatting Format = Newtonsoft.Json.Formatting.None)
        {
            if (JSONObject == null)
            {
                return(new Byte[0]);
            }

            return(Encoding.UTF8.GetBytes(JSONObject.ToString(Format)));
        }
Esempio n. 14
0
        public void SavePackets(Packet[] packet, string filename = "packets.json", Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.Indented, bool informative = true)
        {
            var outs = File.Create(filename);

            Serializer.informativeDump = informative;
            string json = Serializer.Serialize(packet, informative);

            outs.Write(Encoding.ASCII.GetBytes(json), 0, json.Length);
            outs.Flush();
            outs.Close();
        }
 /// <summary>
 /// Convert To Json
 /// </summary>
 /// <param name="data"></param>
 /// <param name="formatting"></param>
 /// <returns></returns>
 public static string ToJson(this object obj, Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.None)
 {
     try
     {
         return(Newtonsoft.Json.JsonConvert.SerializeObject(obj, formatting).ToString() ?? null);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
        public static string SerializeObject(object value, Newtonsoft.Json.Formatting formatting, JsonSerializerSettings settings)
        {
            JsonSerializer jsonSerializer = JsonSerializer.Create(settings);
            StringWriter   stringWriter   = new StringWriter(new StringBuilder(128), CultureInfo.InvariantCulture);

            using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
            {
                jsonTextWriter.Formatting = formatting;
                jsonSerializer.Serialize(jsonTextWriter, value);
            }
            return(stringWriter.ToString());
        }
Esempio n. 17
0
        /// <summary>
        /// Json形式で返す。
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public string ToJson(Newtonsoft.Json.Formatting format)
        {
            var list = this.GetDataRows().Select(n => n.GetDataDicForJson()).ToList();

            if (list.Count == 1)
            {
                return(Newtonsoft.Json.JsonConvert.SerializeObject(list.First(), format));
            }
            else
            {
                return(Newtonsoft.Json.JsonConvert.SerializeObject(list, format));
            }
        }
Esempio n. 18
0
        public static string SerializeObject(object value, Type type, Newtonsoft.Json.Formatting formatting, JsonSerializerSettings settings)
        {
            JsonSerializer serializer = JsonSerializer.CreateDefault(settings);
            StringBuilder  sb         = new StringBuilder(0x100);
            StringWriter   textWriter = new StringWriter(sb, CultureInfo.InvariantCulture);

            using (JsonTextWriter writer2 = new JsonTextWriter(textWriter))
            {
                writer2.Formatting = formatting;
                serializer.Serialize(writer2, value, type);
            }
            return(textWriter.ToString());
        }
Esempio n. 19
0
 public static Task <string> UploadJsonAsync <T>(this S3Helper s3,
                                                 string bucketName,
                                                 string key,
                                                 T content,
                                                 Newtonsoft.Json.Formatting formatting = Newtonsoft.Json.Formatting.Indented,
                                                 string keyId      = null,
                                                 Encoding encoding = null,
                                                 CancellationToken cancellationToken = default(CancellationToken))
 => s3.UploadStreamAsync(bucketName: bucketName,
                         key: key,
                         inputStream: content.JsonSerialize(formatting).ToMemoryStream(encoding),
                         contentType: "text/plain",
                         cancellationToken: cancellationToken);
Esempio n. 20
0
        public static void SaveObjToFile(object obj, string path, bool prettyFormat = false)
        {
            Newtonsoft.Json.Formatting format = prettyFormat ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None;
            string str = Newtonsoft.Json.JsonConvert.SerializeObject(obj, format);
            string dir = Path.GetDirectoryName(path);

            if (string.IsNullOrEmpty(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8);

            sw.WriteLine(str);
            sw.Close();
        }
        public static string SerializeObject(object value, Newtonsoft.Json.Formatting formatting, params JsonConverter[] converters)
        {
            object jsonSerializerSetting;

            if (converters == null || converters.Length == 0)
            {
                jsonSerializerSetting = null;
            }
            else
            {
                jsonSerializerSetting = new JsonSerializerSettings();
                ((JsonSerializerSettings)jsonSerializerSetting).Converters = converters;
            }
            return(JsonConvert.SerializeObject(value, null, formatting, (JsonSerializerSettings)jsonSerializerSetting));
        }
Esempio n. 22
0
        public int Run(ResultMatchingOptions matchingOptions)
        {
            try
            {
                SarifLog baselineFile = null;
                if (!string.IsNullOrEmpty(matchingOptions.PreviousFilePath))
                {
                    baselineFile = ReadSarifFile <SarifLog>(_fileSystem, matchingOptions.PreviousFilePath);
                }

                string outputFilePath = matchingOptions.OutputFilePath;
                if (string.IsNullOrEmpty(outputFilePath))
                {
                    outputFilePath = Path.GetFileNameWithoutExtension(matchingOptions.PreviousFilePath) + "-annotated.sarif";
                }

                if (!DriverUtilities.ReportWhetherOutputFileCanBeCreated(outputFilePath, matchingOptions.Force, _fileSystem))
                {
                    return(FAILURE);
                }

                var currentSarifLogs = new List <SarifLog>();

                foreach (string currentFilePath in matchingOptions.CurrentFilePaths)
                {
                    currentSarifLogs.Add(ReadSarifFile <SarifLog>(_fileSystem, currentFilePath));
                }

                ISarifLogMatcher matcher = ResultMatchingBaselinerFactory.GetDefaultResultMatchingBaseliner();

                SarifLog output = matcher.Match(new SarifLog[] { baselineFile }, currentSarifLogs).First();

                Newtonsoft.Json.Formatting formatting = matchingOptions.PrettyPrint
                        ? Newtonsoft.Json.Formatting.Indented
                        : Newtonsoft.Json.Formatting.None;

                WriteSarifFile(_fileSystem, output, outputFilePath, formatting);
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(FAILURE);
            }

            return(SUCCESS);
        }
        public static string SerializeObject(object value, Newtonsoft.Json.Formatting formatting, params JsonConverter[] converters)
        {
            JsonSerializerSettings jsonSerializerSetting;

            if (converters == null || (int)converters.Length <= 0)
            {
                jsonSerializerSetting = null;
            }
            else
            {
                jsonSerializerSetting = new JsonSerializerSettings()
                {
                    Converters = converters
                };
            }
            return(JsonConvert.SerializeObject(value, formatting, jsonSerializerSetting));
        }
        public string CreateJSON(Newtonsoft.Json.Formatting formatting)
        {
            WPDirtyExportResult dirtyExport = new WPDirtyExportResult()
            {
                Categories      = this._export.WPCategories,
                PostChildren    = this._export.WPPostChildren,
                PostMeta        = this._export.WPPostsMeta,
                Posts           = this._export.WPPosts,
                ProductChildren = this._export.WPProductChildren,
                Products        = this._export.WPProducts,
                Tags            = this._export.WPTags,
                Users           = this._export.WPUsers,
            };

            string result = Newtonsoft.Json.JsonConvert.SerializeObject(dirtyExport, formatting);

            return(result);
        }
        public BrowserCommandResult <bool> SaveAs(string outputPath, Newtonsoft.Json.Formatting jsonFormatting)
        {
            return(this.Execute("Save Performance Markers", driver =>
            {
                var jsonResults = driver.ExecuteScript(GetAllMarkersJavascriptCommand).ToString();
                var jsonFormattedString = JValue.Parse(jsonResults).ToString(jsonFormatting);

                using (FileStream fs = File.Open(outputPath, FileMode.CreateNew))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write(jsonFormattedString);
                    }
                }

                return true;
            }));
        }
 /// <summary>
 /// Writes collection as json
 /// </summary>
 /// <param name="collection"></param>
 /// <param name="context"></param>
 /// <param name="formatting"></param>
 /// <param name="ostrm"></param>
 public static void SaveAsJson(this NodeStateCollection collection, Stream ostrm,
                               Newtonsoft.Json.Formatting formatting, ISystemContext context)
 {
     using (var encoder = new JsonEncoderEx(ostrm, context.ToMessageContext(),
                                            JsonEncoderEx.JsonEncoding.Array, formatting)
     {
         UseAdvancedEncoding = true,
         IgnoreDefaultValues = true
     }) {
         foreach (var node in collection.ToNodeModels(context))
         {
             if (node != null)
             {
                 encoder.WriteEncodeable(null, new EncodeableNodeModel(node));
             }
         }
     }
 }
Esempio n. 27
0
        /// <summary>
        /// 将对象序列化为JSON字符串,循环引用的对象将被忽略
        /// </summary>
        /// <param name="value"></param>
        /// <param name="formatting"></param>
        /// <param name="settings"></param>
        /// <param name="nullValue"></param>
        /// <param name="referenceLoop"></param>
        /// <returns></returns>
        public static string ToJson(this object value,
                                    Newtonsoft.Json.Formatting formatting               = Newtonsoft.Json.Formatting.None,
                                    Newtonsoft.Json.NullValueHandling nullValue         = Newtonsoft.Json.NullValueHandling.Ignore,
                                    Newtonsoft.Json.ReferenceLoopHandling referenceLoop = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                                    Newtonsoft.Json.JsonSerializerSettings settings     = null)
        {
            if (settings == null)
            {
                settings = new Newtonsoft.Json.JsonSerializerSettings()
                {
                    ReferenceLoopHandling = referenceLoop, // 忽略循环引用
                    NullValueHandling     = nullValue,
                };
            }
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(value, formatting, settings);

            return(json);
        }
Esempio n. 28
0
        public static string DebuggerJSON(object ToSerialize, Newtonsoft.Json.Formatting PreferredFormat = Newtonsoft.Json.Formatting.Indented)
        {
            if (DebugIsEnabled())
            {
                Type objectType = ToSerialize.GetType();
                IList <PropertyInfo> objectprops = new List <PropertyInfo>(objectType.GetProperties());
                var serializedSelect             = string.Empty;
                var serializedData = string.Empty;
                foreach (var prop in objectprops)
                {
                    var visible = (prop.Name.ToString() == objectprops[0].Name.ToString()) ? "" : "hidden";
                    serializedSelect += "<option value='" + prop.Name.ToString() + "'>" + prop.Name.ToString() + "</option>";
                    serializedData   += "<pre class='" + visible + "' id='" + prop.Name.ToString() + "'>" + Newtonsoft.Json.JsonConvert.SerializeObject(prop.GetValue(ToSerialize, null), Newtonsoft.Json.Formatting.Indented) + "</pre>";
                }
                return(" <div class='debug-serial-cp well block'><span class='debug-serial-cp-open' data-role='open-debug-serial-cpanel'><i class='fa fa-chevron-left fa-2x debug-low-opacity hidden'></i><i class='fa fa-chevron-right fa-2x debug-low-opacity'></i></span><div class='space-15'></div><h3>Debug Serializations</h3><hr/><select class='form-control'>" + serializedSelect + "</select><div class='space-10'></div><button class='btn btn-default' data-role='add-serialized'><i class='fa fa-plus'></i></button><button class='btn btn-default' data-role='go-to-serialized'><i class='fa fa-arrow-right'></i></button><hr /><div class='scroll-container'>" + serializedData + "</div></div>");
            }

            return(string.Empty);
        }
Esempio n. 29
0
        public static string GetRelationshipsJson(this Table table, Newtonsoft.Json.Formatting format, bool hasRelationshipVariations)
        {
            JArray rels = new JArray();

            foreach (var rel in table.Model.Relationships.Where(r => r.FromTable == table)
                     .OrderBy(r => r.FromColumn.Name).ThenBy(r => r.ToColumn.DaxObjectFullName))
            {
                var json = TOM.JsonSerializer.SerializeObject(rel.MetadataObject, new TOM.SerializeOptions()
                {
                    IgnoreInferredObjects = true, IgnoreInferredProperties = true, IgnoreTimestamps = true
                });
                var jObj = JObject.Parse(json);
                // Only remove relationship name if model does not use variations:
                if (!hasRelationshipVariations)
                {
                    jObj.Remove("name");
                }
                rels.Add(jObj);
            }
            return(rels.ToString(format));
        }
        public String ToJSON(Boolean iFinish,
                             HttpStatusCode iStatusCode,
                             IJSONSerialisable iReturnValue,
                             Newtonsoft.Json.Formatting iFormatting)
        {
            if (iFinish)
            {
                Finish();
            }
            JObject pJOtJSON       = new JObject();
            JObject pJOtStatistics = new JObject();

            pJOtStatistics.Add("StartedAt", new JValue(StartedAt.ToString(EnvironmentHelpers.GetEnvironmentVariable("DateTimeFormat"))));
            pJOtStatistics.Add("FinishedAt", new JValue(StartedAt.ToString(EnvironmentHelpers.GetEnvironmentVariable("DateTimeFormat"))));
            pJOtStatistics.Add("Ellapsed", new JValue(Ellapsed.ToString()));
            pJOtJSON.Add("Statistics", pJOtStatistics);
            JObject pJOtResponse = new JObject();

            pJOtResponse.Add("StatusCode", new JValue((Int32)iStatusCode));
            pJOtResponse.Add("ReturnValue", iReturnValue.ToJObject());
            pJOtJSON.Add("Response", pJOtResponse);
            return(pJOtJSON.ToString(iFormatting));
        }