public void CheckCompatibilityWithDefaultSerializator(object obj) { var standardXml = SerializeObject(obj); var obj2 = Serializer.Deserialize(standardXml, obj.GetType()); XmlAssert.AreEqual(standardXml, SerializeObject(obj2)); }
public ImportResults <T> Import <T>(string[] Parameters) { string ImportFile = ""; var Source = Parameters[0]; if (File.Exists(Source)) { ImportFile = Source; } // else if (Directory.Exists(Source)) // { // var DirectoryInfo = new DirectoryInfo(Source); // foreach (var FileInfo in DirectoryInfo.EnumerateFiles()) // { // if (FileInfo.Extension == ".xml") // { // ImportFiles.Add(FileInfo.FullName); // } // } // } var ExtendedXmlSerializer = new ExtendedXmlSerializer(); string ImportXml = File.ReadAllText(ImportFile); var ImportResults = new ImportResults <T>(); ImportResults.Result = ExtendedXmlSerializer.Deserialize <T>(ImportXml); return(ImportResults); }
public void Should_Serialize_ObservableCollection() { ObservableCollection <IUiObject> obs = new ObservableCollection <IUiObject>(); for (int i = 0; i < 10; i++) { var payementPlaces = new UiMultipleDfObject(); UiDfObject dataDfObject = new UiDfObject { LabelText = "Plazo de Pago", DataField = "PLAZO", TableName = "PROVEE2", LabelTextWidth = "100", LabelVisible = true, Height = "100", TextContentWidth = "50", PrimaryKey = "NUM_PROVEE", AllowedEmpty = true }; payementPlaces.AddDataField(dataDfObject); // plazo de pago 2. var dataDfObject2 = new UiDfObject { DataField = "PLAZO2", TableName = "PROVEE2", LabelVisible = false, Height = "100", TextContentWidth = "50", PrimaryKey = "NUM_PROVEE", AllowedEmpty = true }; payementPlaces.AddDataField(dataDfObject2); // plazo de pago 3. UiDfObject dataDfObject3 = new UiDfObject(); dataDfObject3.DataField = "PLAZO3"; dataDfObject3.TableName = "PROVEE2"; dataDfObject2.LabelVisible = false; dataDfObject3.Height = "100"; dataDfObject3.TextContentWidth = "50"; dataDfObject3.PrimaryKey = "NUM_PROVEE"; dataDfObject3.AllowedEmpty = true; payementPlaces.AddDataField(dataDfObject3); obs.Add(payementPlaces); } ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); var xml = serializer.Serialize(obs); TextWriter writer = new StreamWriter(@"C:\Users\Usuario\Documents\KarveSnapshots\Observe.xml"); writer.Write(xml); writer.Close(); TextReader reader = new StreamReader(@"C:\Users\Usuario\Documents\KarveSnapshots\Observe.xml"); string xmlValue = reader.ReadToEnd(); var collection = serializer.Deserialize <ObservableCollection <IUiObject> >(xmlValue); }
/// <summary> /// This method loads a collection of UI objects from a file /// An UIObject is an object that it is useful for rendering and it has been already /// binded to a database field. /// </summary> /// <param name="path">Path of the file to be loaded</param> /// <returns></returns> public ObservableCollection <IUiObject> LoadCollection(string path) { TextReader reader = new StreamReader(path); string xml = reader.ReadToEnd(); ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); var collection = serializer.Deserialize <ObservableCollection <IUiObject> >(xml); return(collection); }
/// <summary> /// This loads the xml data list for creating the query. /// </summary> /// <param name="pathName">Path.</param> public DataCollection LoadXmlData(string pathName) { Uri uri = new Uri(pathName); TextReader reader = new StreamReader(uri.LocalPath); ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); string xmlValue = reader.ReadToEnd(); DataCollection coll = null; var collection = serializer.Deserialize <DataCollection>(xmlValue); coll = (DataCollection)collection; return(coll); }
private GameState LoadData() { string data = null; try { data = DeserializedData(); } catch (Exception ex) { MessageBox.Show($"An error has ocurred during game loading {ex.Message}"); } return(xml.Deserialize <GameState>(data)); }
public static void Run() { ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); Program.PrintHeader("Serialization"); var obj = new TestClass(); var xml = serializer.Serialize(obj); Console.WriteLine(xml); Program.PrintHeader("Deserialization"); var obj2 = serializer.Deserialize <TestClass>(xml); Console.WriteLine("Obiect id = " + obj2.Id); }
public static Scene LoadSceneFromName(string name) { // parse xml scene file var xml = ResourceManager.GetString($"Scenes/{ name }.xml"); var serializer = new ExtendedXmlSerializer(); // we use ExtendedXml.. because we do not want to register every possible child of Material var scene = serializer.Deserialize <Scene>(xml); // load referenced resources foreach (var instance in scene.Materials) { instance.Material.Initialize(instance.Shader); } // init stuff return(scene); }
public T DeserializeFromXMLFile <T>(String path) where T : class { T deserializedObject = null; try { using (StreamReader reader = new StreamReader(path)) { var xml = reader.ReadToEnd(); var deserializer = new ExtendedXmlSerializer(); deserializedObject = deserializer.Deserialize <T>(xml); } } catch (IOException e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } return(deserializedObject); }
public static void Test() { var model = StructureGenerator.Generate3DFrameElementGrid(2, 2, 2); model.ReIndexNodes(); var toolsFactory = new SimpleSerializationToolsFactory(); toolsFactory.Configurations.Add(new NodeConfig()); toolsFactory.Configurations.Add(new FrameElementSerializationConfig()); ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(toolsFactory); var modelSt = serializer.Serialize(model); toolsFactory.Configurations.RemoveAt(1); var t = serializer.Deserialize <Model>(modelSt); t.Nodes.ToList().ForEach(o => o.Label = Guid.NewGuid().ToString()); }
static void Main(string[] args) { var toolsFactory = new SimpleSerializationToolsFactory(); toolsFactory.Configurations.Add(new TestClassConfig()); ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(toolsFactory); Console.WriteLine("Serialization"); var obj = new TestClass("Natraj Bontha"); var xml = serializer.Serialize(obj); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); doc.Save(obj.GetType().Name.AddFileExtension("xml")); Console.WriteLine(xml); Console.WriteLine("Deserialization"); var obj2 = serializer.Deserialize <TestClass>(xml); Console.WriteLine("Obiect id = " + obj2.PropStr); Console.ReadKey(); }
private void ExecuteInputTemplate() { try { OpenFileDialog ofDialog = new OpenFileDialog() { Title = "导入参数模板", Filter = Resources.XMLFilter }; if (ofDialog.ShowDialog() == DialogResult.OK) { ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); string xmlstring = File.ReadAllText(ofDialog.FileName); CZ_LockHeadParameters = serializer.Deserialize <LockHeadParameters>(xmlstring); Prompt = ofDialog.FileName + "导入成功"; Status = Resources.Status_Success; } } catch (Exception e) { Prompt = "发生错误" + e.Message; Status = Resources.Status_Fail; } }
public TestClassOtherClass DeserializationClassWithPrimitive() { return(_serializer.Deserialize <TestClassOtherClass>(_xml)); }
public IActionResult HiPaySuccess(string code) { try { HttpResponseMessage resultHttp; using (var http = new HttpClient()) { var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("site_id", "338486"), new KeyValuePair <string, string>("product_id", "1486845"), new KeyValuePair <string, string>("code[]", code) }); resultHttp = http.PostAsync(@"https://payment.allopass.com/api/onetime/validate-codes.apu", formContent).Result; } // Read XML ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); HIPAYRETURN dataAPI = serializer.Deserialize <HIPAYRETURN>(resultHttp.Content.ReadAsStringAsync().Result); if (dataAPI.status == "0" && dataAPI.status_description == "success") { using (var context = new SiteDbContext()) { double doublePrice = -1.0; double.TryParse(dataAPI.price, out doublePrice); if (doublePrice == -1.0) { doublePrice = 0.0; } // Add Deal Deals_statistics stats = new Deals_statistics() { UserId = User.FindFirstValue(ClaimTypes.NameIdentifier), Code = code + "(" + dataAPI.transaction_id + ")", Date = DateTime.Now, Price = doublePrice, Nb_Artifacts = 16, PaymentType = "HiPay Mobile" }; context.Deals_statistics.Add(stats); //Add Artifact Artifacts artifact = context.Artifacts .Where(r => r.UserId == User.FindFirstValue(ClaimTypes.NameIdentifier)) .Select(r => r).FirstOrDefault(); artifact.Number += (int)16; context.Update(artifact); context.SaveChanges(); } TempData["success"] = "Your payment has been successfully completed! You have received your artefacts."; } else { TempData["error"] = "Code can already be used or invalid. If the problem contact the support."; } return(RedirectToAction(nameof(ShopController.Finished), "Shop")); } catch { TempData["error"] = "Error during payment, code can already be used. If the problem contact the support."; return(RedirectToAction(nameof(ShopController.Finished), "Shop")); } }
public BaseSettings Deserialize(string data) { ExtendedXmlSerializer serializer = new ExtendedXmlSerializer(); return(serializer.Deserialize <BaseSettings>(data)); }
protected override void Configure() { base.Configure(); CreateMap <UserDTO, User>(); CreateMap <User, UserDTO>() .ForMember(x => x.RoleName, y => y.MapFrom(t => t.Role.Name)); CreateMap <NetworkUserDTO, User>(); CreateMap <User, NetworkUserDTO>() .ForMember(x => x.RoleName, y => y.MapFrom(t => t.Role.Name)); CreateMap <Category, CategoryDTO>() .ForMember(p => p.ChildrenCategory, m => m.MapFrom(t => new List <CategoryDTO>())); CreateMap <Role, RoleDTO>() .ForMember(p => p.Id, m => m.MapFrom(t => t.Id)) .ForMember(p => p.Name, m => m.MapFrom(t => t.Name)) .ForMember(p => p.Description, m => m.MapFrom(t => t.Description)); CreateMap <Property, PropertyDTO>(); CreateMap <PriceFollower, PriceFollowerDTO>(); CreateMap <PriceFollowerDTO, PriceFollower>(); CreateMap <WebShop, WebShopDTO>(); CreateMap <WebShopDTO, WebShop>(); CreateMap <ParserTask, ParserTaskDTO>() .ForMember( p => p.IteratorSettings, m => m.MapFrom(x => (IteratorSettingsDTO)serializer.Deserialize(x.IteratorSettings, typeof(IteratorSettingsDTO)))) .ForMember( p => p.GrabberSettings, m => m.MapFrom(x => (GrabberSettingsDTO)grabberSerializer.Deserialize(x.GrabberSettings, typeof(GrabberSettingsDTO)))); CreateMap <ParserTaskDTO, ParserTask>() .ForMember( p => p.IteratorSettings, m => m.MapFrom(x => (x.IteratorSettings != null ? serializer.Serialize(x.IteratorSettings) : null))) .ForMember( p => p.Category, m => m.Ignore() ) .ForMember( p => p.WebShop, m => m.Ignore() ) .ForMember( p => p.GrabberSettings, m => m.MapFrom(x => (x.GrabberSettings != null ? serializer.Serialize(x.GrabberSettings) : null))); CreateMap <PropertyDTO, GrabberPropertyItemDTO>(); CreateMap <Good, GoodDTO>() .ForMember( p => p.Category, m => m.Ignore() ) .ForMember( p => p.WebShop, m => m.Ignore() ) .ForMember( x => x.PropertyValues, m => m.MapFrom( t => (serializer.Deserialize(t.XmlData, typeof(PropertyValuesDTO)) as PropertyValuesDTO) ) ); CreateMap <GoodDTO, Good>() .ForMember( p => p.Category, m => m.Ignore() ) .ForMember( p => p.WebShop, m => m.Ignore() ) .ForMember( x => x.XmlData, y => y.MapFrom( t => serializer.Serialize(t.PropertyValues) ) ); CreateMap <PriceHistoryDTO, PriceHistory>(); CreateMap <PriceHistory, PriceHistoryDTO>(); CreateMap <ExecutingInfoDTO, ExecutingInfo>() .ForMember( p => p.ParserTask, m => m.Ignore() ); CreateMap <ExecutingInfo, ExecutingInfoDTO>() .ForMember( p => p.ParserTask, m => m.Ignore() ); CreateMap <CommentDTO, Comment>() .ForMember( p => p.User, m => m.Ignore() ) .ForMember( p => p.Good, m => m.Ignore() ); CreateMap <Comment, CommentDTO>() .ForMember( p => p.User, m => m.Ignore() ) .ForMember( p => p.Good, m => m.Ignore() ); CreateMap <AppSettingsDTO, AppSetting>(); }