public void Nullable_Null_Serialize() { var entity = new MyEntity { StringValue = "就诊编号", Int32Value = 101, Int64Value = 1111119999L, DateTimeValue = new DateTime(1956, 9, 10, 4, 45, 55), DecimalValue = 56652333.5633M, NullableInt32Value = null, NullableInt64Value = null, NullableDateTimeValue = null, NullableDecimalValue = null }; ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var output = xmlSerializer.Serialize(entity); var expected = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <input> <stringvalue>就诊编号</stringvalue> <int32value>101</int32value> <int64value>1111119999</int64value> <datetimevalue>1956-09-10 04:45:55</datetimevalue> <decimalvalue>56652333.56</decimalvalue> <nullableint32value></nullableint32value> <nullableint64value></nullableint64value> <nullabledatetimevalue></nullabledatetimevalue> <nullabledecimalvalue></nullabledecimalvalue> </input>"; Assert.Equal(expected, output); }
public string SaveConfiguration <T>(string configStoreInfor, T configInfor) where T : class { if (string.IsNullOrEmpty(configStoreInfor) || configInfor == null) { return("100001"); } string storeFileName = GetCacheInfor(configStoreInfor); if (!File.Exists(storeFileName)) { return("100003"); } bool saveFlag = ObjectXmlSerializer.SaveXmlToFlie <T>(storeFileName, configInfor); if (saveFlag) { return(string.Empty); } else { return("100004"); } }
public T LoadConfiguration <T>(string configStoreInfor) where T : class { if (string.IsNullOrEmpty(configStoreInfor)) { return(null); } string storeFileName = GetCacheInfor(configStoreInfor); if (!File.Exists(storeFileName)) { return(null); } try { T resultLoad = ObjectXmlSerializer.LoadFromXml <T>(storeFileName); return(resultLoad); } catch { return(null); } }
public void Error_Format_Deserialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <input>就诊编号</input>"; Assert.Throws <XmlSerializeException>(() => xmlSerializer.Deserialize <string>(input)); input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <dataset> <row> <stringvalue>就诊编号</stringvalue> </row> </dataset> </output>"; Assert.Throws <XmlSerializeException>(() => xmlSerializer.Deserialize <List <MyEntity> >(input)); input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <sqldata> <row> <stringvalue>就诊编号</stringvalue> </row> <row1> <stringvalue>就诊编号</stringvalue> </row1> </sqldata> </output>"; Assert.Throws <XmlSerializeException>(() => xmlSerializer.Deserialize <List <MyEntity> >(input)); }
public void Complex_Deserialize() { var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <stringvalue>就诊编号</stringvalue> <int32value>101</int32value> <int64value>1111119999</int64value> <other>1111119999</other> <datetimevalue>1956-09-10 04:45:55</datetimevalue> <decimalvalue>56652333.56</decimalvalue> <nullableint32value>102</nullableint32value> <nullableint64value>1111129999</nullableint64value> <nullabledatetimevalue>1956-09-20 04:45:55</nullabledatetimevalue> <nullabledecimalvalue>256652333.56</nullabledecimalvalue> </output>"; ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var result = xmlSerializer.Deserialize <MyEntity>(input); Assert.NotNull(result); Assert.Equal("就诊编号", result.StringValue); Assert.Equal(101, result.Int32Value); Assert.Equal(1111119999L, result.Int64Value); Assert.Equal(new DateTime(1956, 9, 10, 4, 45, 55), result.DateTimeValue); Assert.Equal(56652333.56M, result.DecimalValue); Assert.Equal("就诊编号", result.StringValue); Assert.Equal(102, result.NullableInt32Value); Assert.Equal(1111129999L, result.NullableInt64Value); Assert.Equal(new DateTime(1956, 9, 20, 4, 45, 55), result.NullableDateTimeValue); Assert.Equal(256652333.56M, result.NullableDecimalValue); }
public static bool SaveConfig <T>(T t) where T : class, new() { ConfigFileAttribute attribute = AttributeHelper.GetConfigAttribute <ConfigFileAttribute>(typeof(T)); if (attribute == null) { ConfigThrowHelper.ThrowConfigException( R.ConfigError_NoConfigAttribute, typeof(T).FullName, typeof(ConfigFileAttribute).FullName); } ConfigSettings configSettings = FrameworkConfig.GetConfig <ConfigSettings>(); string configFilePath = string.Empty; switch (attribute.ConfigPathType) { case ConfigPathType.FullPhysicalPath: configFilePath = attribute.FileName; break; case ConfigPathType.ServerPath: configFilePath = HttpContext.Current.Server.MapPath(attribute.FileName); break; default: configFilePath = configSettings.GetConfigFilePath <T>(); break; } XmlConfigGetParameter getParameter = new XmlConfigGetParameter(configFilePath, attribute.IncludeSubdirectories); return(ObjectXmlSerializer.SaveXmlToFlie <T>(getParameter.FilePaths, t)); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "XML files (*.xml)|*.xml"; if (openFileDialog.ShowDialog() == DialogResult.OK) { recognizer = (IsolatedWordRecognizer)ObjectXmlSerializer.ObtainSerializedObject(openFileDialog.FileName, typeof(IsolatedWordRecognizer)); recognizer.AvailableSoundsChanged += new EventHandler(HandleAvailableSoundsChanged); ShowParameters(); ToggleParametersEditable(false); speechRecognizerEditingToolStrip.Visible = true; saveToolStripMenuItem.Enabled = true; featurePlotPanel.Clear(); HandleAvailableSoundsChanged(this, EventArgs.Empty); // A bit ugly, but OK... clones.Clear(); //NUMBER OF INDIVIDUALS for (int i = 0; i < 100; i++) { IsolatedWordRecognizer clone = (IsolatedWordRecognizer)ObjectXmlSerializer.ObtainSerializedObject(openFileDialog.FileName, typeof(IsolatedWordRecognizer)); clones.Add(clone); } } }
public ActionResult LostCoffee(CoffeeInit req) { var clientInfo = this.TempData["ClientInfo"] as ClientInfo; string EtmID = clientInfo.EtmCode; //string EtmID = "ETM0027"; var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml")); if (list.Find(o => o.EtmID == EtmID).CupNumber < req.CupNumber) { return(this.Json(new { retCode = 1, Message = "提交失败,饮品剩余数量不足!" })); } list.Find(o => o.EtmID == EtmID).CupNumber -= req.CupNumber; //检测剩余杯数,发短信 try { if (list.Find(o => o.EtmID == EtmID).CupNumber <= int.Parse(ConfigurationManager.AppSettings["EnableSmsCupNumber"]) && list.Find(o => o.EtmID == EtmID).SendSMS == "0" && ConfigurationManager.AppSettings["EnableSms"] == "true") { list.Find(o => o.EtmID == EtmID).CupNumber = 1; const string takedateUrl = "api/Coffee/SendSms"; var fullPath = ETong.Coffee.Web.Models.Config.GetApiFullPath(takedateUrl); var client = new HttpClientUtility(new Uri(fullPath)); Logger.Write(Log.Log_Type.Info, string.Format("调用{0}", fullPath)); var resultT = SecurityHttpClient.Post <string, ResponseData <string> >(fullPath, EtmID); Logger.Write(Log.Log_Type.Info, string.Format("{0}结束,result={1}", fullPath, Json(resultT.dataMap))); } } catch (Exception ex) { Logger.Write(Log.Log_Type.Info, string.Format("短信发送失败etmid={0},err={1}", EtmID, ex.ToString())); } Logger.Write(Log.Log_Type.Info, string.Format("减库存etmid={0},CupNumber={1}", EtmID, req.CupNumber)); ObjectXmlSerializer.SaveToXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml"), list); return(this.Json(new { retCode = 0, Message = "成功" })); }
private void MnuAppSaveNew_Click() { Microsoft.Win32.SaveFileDialog sXml = new Microsoft.Win32.SaveFileDialog(); string dir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); sXml.InitialDirectory = dir; sXml.Title = "Select a folder for creating a new projectfile!"; sXml.Filter = "XML (*.xml)|*.xml"; // pressed OK: if (sXml.ShowDialog() == true) { this._pfadKonfigurationsdatei = sXml.FileName.ToString(); } //if (File.Exists(this.txtKonfigurationsdatei.Text)) if (this._pfadKonfigurationsdatei != String.Empty) { // Create customer object based on Form values. FormularData formdata = this.FormData;//this.CreateFormularData(); //Save form object to XML file using our ObjectXMLSerializer class... try { ObjectXmlSerializer <FormularData> .Save(formdata, this._pfadKonfigurationsdatei); this.Title = "Legend Generator 5.0 für ArcMap 10.0 - " + this._pfadKonfigurationsdatei; } catch (Exception ex) { MessageBox.Show("Unable to save formular data object!" + Environment.NewLine + Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void Int_Empty_Element_Deserialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output>0</output>"; var result = xmlSerializer.Deserialize <int>(input); Assert.Equal(0, result); input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <value></value> </output>"; var objectResult = xmlSerializer.Deserialize <ComplexPropertyObject <int> >(input); Assert.NotNull(objectResult); Assert.Equal(0, objectResult.Value); input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <value /> </output>"; objectResult = xmlSerializer.Deserialize <ComplexPropertyObject <int> >(input); Assert.NotNull(objectResult); Assert.Equal(0, objectResult.Value); }
public void Complex_Property_Deserialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> <value> <stringvalue>就诊编号</stringvalue> <int32value>101</int32value> <int64value>1111119999</int64value> <datetimevalue>1956-09-10 04:45:55</datetimevalue> <decimalvalue>56652333.56</decimalvalue> <nullableint32value>102</nullableint32value> <nullableint64value>1111129999</nullableint64value> <nullabledatetimevalue>1956-09-20 04:45:55</nullabledatetimevalue> <nullabledecimalvalue>256652333.56</nullabledecimalvalue> </value> </output>"; var result = xmlSerializer.Deserialize <ComplexPropertyObject <MyEntity> >(input); Assert.NotNull(result); Assert.NotNull(result.Value); Assert.Equal("就诊编号", result.Value.StringValue); }
public void DateTime_Serialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var output = xmlSerializer.Serialize(new DateTime(1956, 1, 2, 3, 4, 5)); var expected = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <input>1956-01-02 03:04:05</input>"; Assert.Equal(expected, output); }
public void ReadProduct() { string filePath = @"..\..\Utils\Xml\Serialization\TestData\SomeProduct.xml"; Product product = ObjectXmlSerializer <Product> .Load(filePath); Assert.AreEqual(product.ProductID, 10); Assert.AreEqual(product.Name, "testname"); Assert.AreEqual(product.ListPrice, 10.0m); }
public void Complex_Null_Serialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var output = xmlSerializer.Serialize(null); var expected = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <input />"; Assert.Equal(expected, output); }
public void String_Serialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var output = xmlSerializer.Serialize("就诊编号"); var expected = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <input>就诊编号</input>"; Assert.Equal(expected, output); }
public void String_Deserialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output>就诊编号</output>"; var result = xmlSerializer.Deserialize <string>(input); Assert.Equal("就诊编号", result); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XML files (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, recognizer); } }
public void GetData(Action <FormularData, Exception> callback) { // Code runs "for real" //string folder = Environment.CurrentDirectory; string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string path = Path.Combine(folder, @"Data\FormData.xml"); FormularData formData = ObjectXmlSerializer <FormularData> .Load(path); callback(formData, null); }
private void SaveTrainingData(object sender, EventArgs e) { string trainingDataXMLPath = EigenfaceProcessorParameters.RELATIVE_PATH_TRAINING_DATA_XML; ObjectXmlSerializer.SerializeObject(trainingDataXMLPath, eigenfaceProcessor, new List <Type>() { typeof(SangersAlgorithm) }); richTextBox1.Text += "Eigenface vectors saved\n"; }
//save agent object with serialize private void SaveAccountMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "XML files (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, agent); } } }
private void saveSpeechSynthesizerToolStripMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "XML files (*.xml)|*xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, speechSynthesizer); } } }
public void WriteSetting() { try { ObjectXmlSerializer.SaveToXml <RegSetting>(this.SETTING_PATH, RegSetting._instance); } catch (System.Exception err) { Log.WriteError("写入配置信息错误", err); } }
private void saveObjectToolStripMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = ".XML files (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, serializationTestObject); } } }
public void WriteProduct() { string filePath = "xmltest.xml"; Product product = new Product(); product.ListPrice = 10.0m; product.Name = "testname"; product.ProductID = 10; ObjectXmlSerializer <Product> .Save(product, filePath); }
private void saveLongtermMemoryToolStripMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "XML files (*.xml)|*.xml"; saveFileDialog.InitialDirectory = Path.GetDirectoryName(Path.GetDirectoryName(Application.ExecutablePath) + "\\" + DEFAULT_LONGTERM_MEMORY_RELATIVE_PATH); if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, agent.LongTermMemory); } } }
public ActionResult Rest() { var clientInfo = this.TempData["ClientInfo"] as ClientInfo; string EtmID = clientInfo.EtmCode; //string EtmID = "ETM0027"; var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml")); list.Find(o => o.EtmID == EtmID).SendSMS = "0"; list.Find(o => o.EtmID == EtmID).CupNumber = list.Find(o => o.EtmID == "ETMDefault").CupNumber; ObjectXmlSerializer.SaveToXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml"), list); return(this.Json(new { retCode = 0, Message = "" })); }
public void Complex_Null_Deserialize() { var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output> </output>"; ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var result = xmlSerializer.Deserialize <MyEntity>(input); Assert.Null(result); }
public void DateTime_Deserialize() { ObjectXmlSerializer xmlSerializer = new ObjectXmlSerializer(); var input = @"<?xml version=""1.0"" encoding=""GBK"" standalone=""yes""?> <output>1956-01-02 03:04:05</output>"; var result = xmlSerializer.Deserialize <DateTime>(input); var expected = new DateTime(1956, 1, 2, 3, 4, 5); Assert.Equal(expected, result); }
private void generateAgentToolStripMenuItem_Click(object sender, EventArgs e) { // 20180112: this.Width = Screen.GetBounds(this).Width / 2; this.Location = new Point((Screen.GetBounds(this).Width - this.Width) / 2, 0); generateAgentToolStripMenuItem.Enabled = false; // Generate the agent instance, and set the search paths to the constituent programs: agent = new Agent(); agent.LongTermMemoryRelativePath = DEFAULT_LONGTERM_MEMORY_RELATIVE_PATH; agent.ClientProcessRelativePathList.Add("..\\..\\..\\FaceApplication\\bin\\Debug\\FaceApplication.exe"); agent.ClientProcessRelativePathList.Add("..\\..\\..\\ListenerApplication\\bin\\Debug\\ListenerApplication.exe"); agent.ClientProcessRelativePathList.Add("..\\..\\..\\SpeechApplication\\bin\\Debug\\SpeechApplication.exe"); agent.ClientProcessRelativePathList.Add("..\\..\\..\\InternetDataAcquisitionApplication\\bin\\Debug\\InternetDataAcquisitionApplication.exe"); agent.ClientProcessRelativePathList.Add("..\\..\\..\\VisionApplication\\bin\\Debug\\VisionApplication.exe"); agent.Server.Progress += new EventHandler <CommunicationProgressEventArgs>(HandleAgentServerProgress); agent.Server.Error += new EventHandler <CommunicationErrorEventArgs>(HandleAgentServerError); // Generate the agent's dialogues GenerateWakeUpDialogue(); GenerateTimeDialogue(); GenerateAttentionDialogue(); // GenerateNameDialogue(); GenerateWhoIsDialogue(); GenerateWhatIsDialogue(); GenerateIntegerArithmeticDialogue(); GenerateGreetingDialogue(); //NEW GenerateTravelDialogue(); GenerateTravelInterestDialogue(); GenerateShortcutDialogue(); ShowDialogueList(); importMemoryItemsButton.Enabled = true; saveLongTermMemoryButton.Enabled = true; // Prepare for starting the agent: Load the long-term memory already here, so that it can be viewed and edited before starting the agent string longTermMemoryFilePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + agent.LongTermMemoryRelativePath; if (!File.Exists(longTermMemoryFilePath)) { MessageBox.Show("No long-term memory found"); agent.LongTermMemory = new Memory(); generateAgentToolStripMenuItem.Enabled = true; } else { agent.LongTermMemory = (Memory)ObjectXmlSerializer.ObtainSerializedObject(longTermMemoryFilePath, typeof(Memory)); longTermMemoryViewer.SetMemory(agent.LongTermMemory); } startButton.Enabled = true; }
private void saveLongTermMemoryButton_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = Path.GetDirectoryName(Path.GetDirectoryName(Application.ExecutablePath) + "\\" + agent.LongTermMemoryRelativePath); saveFileDialog.Filter = "XML files (*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ObjectXmlSerializer.SerializeObject(saveFileDialog.FileName, agent.LongTermMemory); } } }