Пример #1
0
        public string Serialize(ParamValues datavalue)
        {
            try
            {
                ParamValuesNodeHierarchical firstnode = ParamValuesTools.GetHierarchicalNodes(datavalue.GetList());
                //Newtonsoft.Json.Linq.JToken jobject = Serialize_Recursif(firstnode,true);

                //Newtonsoft.Json.Formatting outjsonformating = Newtonsoft.Json.Formatting.None;
                //string jsontstr = jobject.ToString(outjsonformating);
                ////jsontstr = jsontstr.Replace("\r\n", "");//.Replace("\"", "");
                ////jsontstr = System.Text.RegularExpressions.Regex.Unescape(jsontstr);
                //return jsontstr;

                var options = new JsonWriterOptions()
                {
                    Indented = ConfigIndented
                };
                using (var stream = new MemoryStream())
                {
                    using (var writer = new Utf8JsonWriter(stream, options))
                    {
                        // on écrit pas le premier noeud param
                        writer.WriteStartObject();
                        foreach (var subnode in firstnode.ChildrenNodes)
                        {
                            Serialize_Recursif(writer, subnode);
                        }
                        writer.WriteEndObject();
                    }
                    string json = Encoding.UTF8.GetString(stream.ToArray());
                    return(json);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("SerializeJson " + ex.Message, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Chargement d'un flux(Json/Ou XML) dans le datavalue
        /// </summary>
        /// <param name="itemdv"></param>
        /// <param name="flux"></param>
        public static void FromFlux(this ParamValues datavalue, string flux, bool?isXml = null)
        {
            //clean
            if (string.IsNullOrWhiteSpace(flux))
            {
                return;
            }
            flux = flux.Trim();

            if (!isXml.HasValue)
            {
                isXml = flux.TrimStart().StartsWith("<");
            }


            IParamValuesSerializer serial = ParamValuesTools.SerializerFactory(isXml.Value);

            serial.DeSerialize(flux, datavalue);

            //parse
            //if (flux.StartsWith("{")) this.FromFluxJson(flux);
            //if (flux.StartsWith("<")) fromFluxXML(datavalue,flux);
        }
Пример #3
0
 /// <summary>
 /// Deserialisation, FromFlux
 /// </summary>
 /// <param name="fluxContent"></param>
 public void DeSerializeField(string fluxContent)
 {
     ParamValuesTools.FromFlux(this, fluxContent);
 }
Пример #4
0
        /// <summary>
        /// Exporter un flux du datavalue
        /// </summary>
        /// <param name="datavalue"></param>
        /// <param name="Xml">true=xml, false=json</param>
        /// <returns></returns>
        public static string ToFlux(this ParamValues datavalue, bool isXml = true)
        {
            IParamValuesSerializer serial = ParamValuesTools.SerializerFactory(isXml);

            return(serial.Serialize(datavalue));
        }
Пример #5
0
 /// <summary>
 /// Serialisation du FLUX ToFlux
 /// </summary>
 /// <returns></returns>
 public string SerializeField()
 {
     return(ParamValuesTools.ToFlux(this, fieldType == FlowTypeEnum.JSON ? false:true));
 }