/// <summary> /// Creates an instance of Products from a base64 encoded BSON string /// </summary> /// <param name="bson">The base64 encoded BSON string</param> /// <returns>A Products object instance</returns> public static Products FromBson(string bson) { List <DataLayer.FooEnterprises.Product.SerializableProduct> zc; byte[] data = Convert.FromBase64String(bson); Products tmp = new Products(); using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data)) { using (Newtonsoft.Json.Bson.BsonReader reader = new Newtonsoft.Json.Bson.BsonReader(ms)) { reader.ReadRootValueAsArray = true; Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); zc = serializer.Deserialize <List <DataLayer.FooEnterprises.Product.SerializableProduct> >(reader); } } foreach (DataLayer.FooEnterprises.Product.SerializableProduct z in zc) { tmp.Add(Product.FromJson(Newtonsoft.Json.JsonConvert.SerializeObject(z))); } if (zc.Count > 0) { Encryption64 decryptor = new Encryption64(); tmp._connectionString = decryptor.Decrypt(zc[0].SerializationConnectionString, DataLayer.FooEnterprises.Universal.LayerGenEncryptionKey); } return(tmp); }
/// <summary> /// Creates an instance of Products from a JSON string /// </summary> /// <param name="json">The JSON string</param> /// <returns>A Products object instance</returns> public static Products FromJson(string json) { List <DataLayer.FooEnterprises.Product.SerializableProduct> zs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DataLayer.FooEnterprises.Product.SerializableProduct> >(json); Products tmp = new Products(); foreach (DataLayer.FooEnterprises.Product.SerializableProduct z in zs) { tmp.Add(Product.FromJson(Newtonsoft.Json.JsonConvert.SerializeObject(z))); } if (zs.Count > 0) { Encryption64 decryptor = new Encryption64(); tmp._connectionString = decryptor.Decrypt(zs[0].SerializationConnectionString, DataLayer.FooEnterprises.Universal.LayerGenEncryptionKey); } return(tmp); }
/// <summary> /// Creates an instance of Products from an XML string /// </summary> /// <param name="xml">The XML string</param> /// <returns>A Products object instance</returns> public static Products FromXml(string xml) { System.Xml.Serialization.XmlSerializer xType = new System.Xml.Serialization.XmlSerializer(typeof(List <DataLayer.FooEnterprises.Product.SerializableProduct>)); List <DataLayer.FooEnterprises.Product.SerializableProduct> zc; Products tmp = new Products(); using (System.IO.StringReader sr = new System.IO.StringReader(xml)) { zc = (List <DataLayer.FooEnterprises.Product.SerializableProduct>)xType.Deserialize(sr); } foreach (DataLayer.FooEnterprises.Product.SerializableProduct z in zc) { tmp.Add(Product.FromJson(Newtonsoft.Json.JsonConvert.SerializeObject(z))); } if (zc.Count > 0) { Encryption64 decryptor = new Encryption64(); tmp._connectionString = decryptor.Decrypt(zc[0].SerializationConnectionString, DataLayer.FooEnterprises.Universal.LayerGenEncryptionKey); } return(tmp); }