private void UpdateTemplatesXml(string xmlPath, string version) { try { // выбираем уже существующие данные из Templates.xml var templates = CustomXmlSerializer.GetAllTemplatesFromXml(xmlPath); // из этих данных выбираем нужный шаблон var selectedTemplate = templates.Templates.FirstOrDefault(x => x.Detail.IbName == _templateDetail.IbName); selectedTemplate.Detail.LastUpdateDate = DateTime.Now.ToString("s"); // s: 2008-06-15T21:15:07 selectedTemplate.Detail.CurrentVersion = version; _log.Info("Updated current version - {0}", version); selectedTemplate.Detail.UpdatesCount = GetAllowedUpdates(version); // сериализуем обновлённый список шаблонов снова в Templates.xml CustomXmlSerializer.WriteAllTemplatesToXml(templates, xmlPath); } catch (Exception ex) { _log.Error("Error during updating templatex XML {0}", ex.Message); } }
public virtual void Save(string TaskPath) { this.SelectedKeywordsCount = 0; this.Random = null; this.Keywords = null; this.FileTokens = null; this.Context = null; this.Logger = null; try { CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(TaskPath, "task.xml")); // Saving text maker if (this.TextMaker != null) { this.TextMaker.Save(TaskPath); } // Saving image maker if (this.ImageMaker != null) { this.ImageMaker.Save(TaskPath); } } catch (Exception) { } }
public bool setSharedObject(T obj) { try { lock (this._synLock) { XmlDocument xmlDocument = CustomXmlSerializer.Serialize(obj, 8, "SharedObject"); string outerXml = xmlDocument.OuterXml; byte[] bytes = Encoding.UTF8.GetBytes(outerXml); if ((long)bytes.Length < this._shareMemSize) { long value = (long)bytes.Length; byte[] bytes2 = BitConverter.GetBytes(value); byte[] array = new byte[8 + bytes.Length]; Array.Copy(bytes2, 0, array, 0, 8); Array.Copy(bytes, 0, array, 8, bytes.Length); this.WriteShareArray(0L, array); return(true); } } } catch (Exception) { } return(false); }
public void Deserialize_ShouldDeserializeStringToListOfFoodObjects_PopulatesListWithRightValues() { ObservableCollection <Food> foods = new ObservableCollection <Food>(); CustomXmlSerializer serializer = new CustomXmlSerializer(foods); serializer.Deserialize("<?xml version=\"1.0\" encoding=\"utf-16\"?><Meal><Ingredient><Name>Apple</Name><Calories>15</Calories><Carbohydrates>10</Carbohydrates><Fat>5</Fat><Proteins>13</Proteins><Weight>100</Weight></Ingredient><Ingredient><Name>Melon</Name><Calories>8</Calories><Carbohydrates>12</Carbohydrates><Fat>22</Fat><Proteins>33</Proteins><Weight>100</Weight></Ingredient><Ingredient><Name>Orange</Name><Calories>1</Calories><Carbohydrates>2</Carbohydrates><Fat>3</Fat><Proteins>4</Proteins><Weight>100</Weight></Ingredient></Meal>"); Assert.AreEqual(_foods[0].Name, foods[0].Name); Assert.AreEqual(_foods[0].Calories, foods[0].Calories); Assert.AreEqual(_foods[0].Carbohydrates, foods[0].Carbohydrates); Assert.AreEqual(_foods[0].Fat, foods[0].Fat); Assert.AreEqual(_foods[0].Proteins, foods[0].Proteins); Assert.AreEqual(_foods[0].Weight, foods[0].Weight); Assert.AreEqual(_foods[1].Name, foods[1].Name); Assert.AreEqual(_foods[1].Calories, foods[1].Calories); Assert.AreEqual(_foods[1].Carbohydrates, foods[1].Carbohydrates); Assert.AreEqual(_foods[1].Fat, foods[1].Fat); Assert.AreEqual(_foods[1].Proteins, foods[1].Proteins); Assert.AreEqual(_foods[1].Weight, foods[1].Weight); Assert.AreEqual(_foods[2].Name, foods[2].Name); Assert.AreEqual(_foods[2].Calories, foods[2].Calories); Assert.AreEqual(_foods[2].Carbohydrates, foods[2].Carbohydrates); Assert.AreEqual(_foods[2].Fat, foods[2].Fat); Assert.AreEqual(_foods[2].Proteins, foods[2].Proteins); Assert.AreEqual(_foods[2].Weight, foods[2].Weight); }
public static InputBindingDevices LoadFromFile(string fileName) { if (!File.Exists(fileName)) { return(null); } var result = new InputBindingDevices(); var serializer = new CustomXmlSerializer(); serializer.ReadXml(fileName, result); // If there was no format version, assume it was version 1. if (result.FormatVersion <= 0) { result.FormatVersion = 1; } // Format Version 1 skipped the "Console" device. if (result.FormatVersion == 1) { result.devices.Insert(0, new InputBindingDevice()); } return(result); }
/// <summary> /// Save settings to file /// </summary> /// <param name="ImagePath">File path</param> public virtual void Save(string ImagePath) { try { CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(ImagePath, "images.xml")); } catch (Exception) { } }
public void Deserialize_ShouldNotAddFoodToListIfProvidedStringIsInvalid_ListDoesntContainAnyObjects() { ObservableCollection <Food> foods = new ObservableCollection <Food>(); CustomXmlSerializer serializer = new CustomXmlSerializer(foods); serializer.Deserialize("<?xml version=\"1.0\" encoding=\"utf-16\"?><Meal><Ingredient><Name>Apple</Name><Carbohydrates>10</Carbohydrates><Fat>5</Fat><Proteins>13</Proteins><Weight>100</Weight></Ingredient></Meal>"); Assert.IsTrue(foods.Count == 0); }
public void Serialize_ShouldSerializeListOfFoodObjectsToXml_ReturnsXmlSerializedString() { CustomXmlSerializer serializer = new CustomXmlSerializer(_foods); string result = serializer.Serialize(); Assert.IsTrue(result.Contains("<Name>Apple</Name><Calories>15</Calories><Carbohydrates>10</Carbohydrates><Fat>5</Fat><Proteins>13</Proteins><Weight>100</Weight>")); Assert.IsTrue(result.Contains("<Name>Melon</Name><Calories>8</Calories><Carbohydrates>12</Carbohydrates><Fat>22</Fat><Proteins>33</Proteins><Weight>100</Weight>")); Assert.IsTrue(result.Contains("<Name>Orange</Name><Calories>1</Calories><Carbohydrates>2</Carbohydrates><Fat>3</Fat><Proteins>4</Proteins><Weight>100</Weight>")); }
public void SerializeWithSummary_ShouldSerlizeListOfIFoodObjectsWithSummaryToXml_ReturnsXmlSerializedString() { CustomXmlSerializer serializer = new CustomXmlSerializer(_foods); string result = serializer.SerializeWithSummary(); Assert.IsTrue(result.Contains("<Name>Apple</Name><Calories>15</Calories><Carbohydrates>10</Carbohydrates><Fat>5</Fat><Proteins>13</Proteins><Weight>100</Weight>")); Assert.IsTrue(result.Contains("<Name>Melon</Name><Calories>8</Calories><Carbohydrates>12</Carbohydrates><Fat>22</Fat><Proteins>33</Proteins><Weight>100</Weight>")); Assert.IsTrue(result.Contains("<Name>Orange</Name><Calories>1</Calories><Carbohydrates>2</Carbohydrates><Fat>3</Fat><Proteins>4</Proteins><Weight>100</Weight>")); Assert.IsTrue(result.Contains("<Summary><Total_Calories>24</Total_Calories><Total_Carbohydrates>24</Total_Carbohydrates><Total_Fat>30</Total_Fat><Total_Proteins>50</Total_Proteins><Total_Weight>300</Total_Weight></Summary>")); }
/// <summary> /// Save Settings /// </summary> /// <param name="TextPath">Path to the configuration file</param> public virtual void Save(string TextPath) { this.TextData = null; try { CustomXmlSerializer.Serialize(this.Settings, 1, this.Settings.Name).Save(IO.Path.Combine(TextPath, "text.xml")); } catch (Exception) { } }
private void TestSerialization <T>(T message) where T : class { CustomXmlSerializer serializer = new CustomXmlSerializer(); byte[] data = serializer.Serialize(message); Trace.WriteLine("Result XML:"); Trace.WriteLine(Encoding.UTF8.GetString(data)); serializer.Deserialize(data); }
public MainWindow() { InitializeComponent(); string xmlFile = File.ReadAllText("FoodDatabase.xml"); CustomXmlSerializer serializer = new CustomXmlSerializer(App.Foods); serializer.Deserialize(xmlFile); listBoxFood.ItemsSource = App.Foods; userFoodListView.ItemsSource = App.UserFoods; }
private void UpdateTemplate_Click(object sender, RoutedEventArgs e) { var xmlSelectedItem = TemplateSelector.SelectedItem as XmlLinkedNode; var selectedTemplate = CustomXmlSerializer.GetSelectedTemplateInfoFromXml(xmlSelectedItem.InnerXml); var textResult = string.Format(@"Template Name is {0}\n CurVersion: {1}\n LastVersion: {2}\n", selectedTemplate.IbName, selectedTemplate.CurrentVersion, selectedTemplate.ActualVersion); UpdatingProcess(xmlSelectedItem.InnerXml); RefreshXmlProvider(); }
private void exportToXmlButton_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Xml files(*.xml) | *.xml"; if (saveFileDialog.ShowDialog() == true) { CustomXmlSerializer serialize = new CustomXmlSerializer(App.UserFoods); string result = serialize.SerializeWithSummary(); File.WriteAllText(saveFileDialog.FileName, result); } }
public void Setup() { tracer = new Tracer(); shortCalc = new Program.ShortCalcClass(tracer); longCalc = new Program.LongCalcClass(tracer); serializer = new CustomXmlSerializer(); threads = new Thread[2] { new Thread(longCalc.LongRecursiveMethod), new Thread(shortCalc.SimpleMethodWithAnotherSimleMethod) }; }
/// <summary> /// Saves provided settings to data source. /// </summary> protected static void Save(Settings settings) { try { XmlDocument doc = CustomXmlSerializer.Serialize(settings, 1, "Test1"); doc.Save(Settings.FilePath); //Helper.Serialize(settings, FilePath); } catch (Exception exception) { Common.Logging.AddExceptionLog(exception); } }
public void WriteConfig() { try { CustomXmlSerializer xmlser = new CustomXmlSerializer(); xmlser.IncludeClassNameAttribute = true; xmlser.Method = SerializationMethod.Shallow; xmlser.WriteFile(this._appsettings, this._configfile, true); } catch (Exception ex) { throw ex; } }
private void addButton_Click(object sender, RoutedEventArgs e) { if (int.TryParse(caloriesTextBox.Text, out int calories) && int.TryParse(carbohydratesTextBox.Text, out int carbohydrates) && int.TryParse(fatTextBox.Text, out int fat) && int.TryParse(proteinsTextBox.Text, out int proteins) && int.TryParse(weightTextBox.Text, out int weight)) { App.Foods.Add(new Food(nameTextBox.Text, calories, carbohydrates, fat, proteins, weight)); CustomXmlSerializer serializer = new CustomXmlSerializer(App.Foods); string output = serializer.Serialize(); File.WriteAllText("FoodDatabase.xml", output); } else { MessageBox.Show("Please input correct data"); } }
private static void Main(string[] args) { // We'll dump the resulting HTML body in a file var file = File.Create(Path.Combine(Environment.CurrentDirectory, "output.html")); var streamWriter = new StreamWriter(file, Encoding.UTF8); var emailSender = new DummyEmailSender(message => streamWriter.Write(message.Body)); // or new DummyEmailSender(Dump) var templateCompiler = new TemplateCompiler(); var xmlSerializer = new CustomXmlSerializer(); var templateDirectory = Path.Combine(Environment.CurrentDirectory, "Templates"); var layoutFile = Path.Combine(templateDirectory, "layout.html"); var xsltFilePath = Path.Combine(templateDirectory, "ActivateAccount.xslt"); var variables = new { FirstName = "Axel", LastName = "Zarate", Username = "******", Ignored = default(object), Logo = "http://www.logotree.com/images/single-logo-design/logo-design-sample-14.jpg", ActivationLink = "http://localhost/Account/Activate/azarate", Benefits = new[] { "Free support", "Great discounts", "Unlimited access" }, IsPremiumUser = true }; var templateEmailSender = new TemplateEmailSender(emailSender, templateCompiler, xmlSerializer) { LayoutFilePath = layoutFile }; templateEmailSender.Send(xsltFilePath, variables, "*****@*****.**", "This is a template test"); // Close the file streamWriter.Dispose(); file.Close(); Console.WriteLine("Ready."); Console.Read(); }
private static void Main(string[] args) { // We'll dump the resulting HTML body in a file var file = File.Create(Path.Combine(Environment.CurrentDirectory, "output.html")); var streamWriter = new StreamWriter(file, Encoding.UTF8); var emailSender = new DummyEmailSender(message => streamWriter.Write(message.Body)); // or new DummyEmailSender(Dump) var templateCompiler = new TemplateCompiler(); var xmlSerializer = new CustomXmlSerializer(); var templateDirectory = Path.Combine(Environment.CurrentDirectory, "Templates"); var layoutFile = Path.Combine(templateDirectory, "layout.html"); var xsltFilePath = Path.Combine(templateDirectory, "ActivateAccount.xslt"); var variables = new { FirstName = "Axel", LastName = "Zarate", Username = "******", Ignored = default(object), Logo = "http://www.logotree.com/images/single-logo-design/logo-design-sample-14.jpg", ActivationLink = "http://localhost/Account/Activate/azarate", Benefits = new[] { "Free support", "Great discounts", "Unlimited access" }, IsPremiumUser = true }; var templateEmailSender = new TemplateEmailSender(emailSender, templateCompiler, xmlSerializer) { LayoutFilePath = layoutFile }; templateEmailSender.Send(xsltFilePath, variables, "*****@*****.**", "This is a template test"); // Close the file streamWriter.Dispose(); file.Close(); Console.WriteLine("Ready."); Console.Read(); }
public void Should_use_custom_xml_serializer() { using (SimpleServer.Create(BASE_URL)) { var client = new RestClient(BASE_URL); var serializer = new CustomXmlSerializer(); var body = new { Text = "text" }; var request = new RestRequest("/") { XmlSerializer = serializer }; request.AddXmlBody(body); client.Execute(request); serializer.BodyString.ShouldBe(body.ToString()); } }
public void ReadConfig() { try { if (!File.Exists(this._configfile)) { return; } CustomXmlSerializer xmlser = new CustomXmlSerializer(); xmlser.IncludeClassNameAttribute = true; xmlser.Method = SerializationMethod.Shallow; xmlser.ReadXml(this._configfile, this._appsettings); } catch (Exception ex) { throw ex; } }
public void SaveToFile(string fileName) { // Create the directory if necessary. string directoryName = Path.GetDirectoryName(fileName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // We're at version #2. this.FormatVersion = 2; // Save it. var serializer = new CustomXmlSerializer(); serializer.IncludeClassNameAttribute = true; serializer.WriteFile(this, fileName, true); }
public async Task <List <Currency> > GetCurrencyAsync() { List <Currency> currencyList = new List <Currency>(); using (var client = new HttpClient()){ var response = await client.GetAsync(tcmbUrl); using (HttpContent content = response.Content){ var result = await content.ReadAsStreamAsync(); CustomXmlSerializer <Currency> serializer = new CustomXmlSerializer <Currency>(); currencyList = serializer.Build("Tarih_Date").GetList(result); } } currencyList.ForEach(p => { p.CurrencyDate = date; }); return(currencyList); }
private bool OpenInterProcessShared() { Semaphore semaphore = InterProcessBase.OpenGlobalSemaphore(this._semaphoreName, 1, 1); if (semaphore == null) { return(false); } this._semaphoreEcoInstance = semaphore; int num = (int)this._shareMemSize + 8; this._semaphoreEcoInstance.WaitOne(); int num2 = InterProcessBase.SetupShareMemoryWithSercurity(this._strMapFileName, num, ref this._hMapFile, ref this._pMapBuf); if (num2 < 0) { this._semaphoreEcoInstance.Release(); this._semaphoreEcoInstance = null; return(false); } if (num2 <= 0) { byte[] array = new byte[num]; Array.Clear(array, 0, array.Length); this.WriteShareArray(0L, array); T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T); XmlDocument xmlDocument = CustomXmlSerializer.Serialize(t, 8, "SharedObject"); string outerXml = xmlDocument.OuterXml; byte[] bytes = Encoding.UTF8.GetBytes(outerXml); if ((long)bytes.Length < this._shareMemSize) { long value = (long)bytes.Length; byte[] bytes2 = BitConverter.GetBytes(value); byte[] array2 = new byte[8 + bytes.Length]; Array.Copy(bytes2, 0, array2, 0, 8); Array.Copy(bytes, 0, array2, 8, bytes.Length); this.WriteShareArray(0L, array2); } } this._semaphoreEcoInstance.Release(); return(true); }
public void CustomSerializerWorksWithXmlFields() { var customSerializer = new CustomXmlSerializer(); DbSerializationRule.Serialize <EncodedInt>(customSerializer); var e = new EncodedInt() { Encoded = "Two" }; using (var c = Connection().OpenWithTransaction()) { c.ExecuteSql("CREATE PROC TestEncodedXml(@Encoded [Xml]) AS SELECT Encoded=@Encoded"); var e2 = c.Query <TestWithSerializedObject>("TestEncodedXml", new { Encoded = e }).First(); Assert.AreEqual(e.Encoded, e2.Encoded.Encoded); } Assert.IsTrue(customSerializer.DidSerialize); Assert.IsTrue(customSerializer.DidDeserialize); }
private void ImportBomExample2Btn_Click(object sender, RibbonControlEventArgs e) { try { var treeBomStructure = CreateDataModelForStructureFromExample2() .GenerateTreeFromList(x => x.PartNumber, x => x.Parent, rootNodeId: "-"); var body = CustomXmlSerializer.SerializeObject(new TreeItemWrapper <CustomBomStructureEx2>(treeBomStructure), new XmlRootAttribute("ArrayOfLeafNodesOfCustomBomStructure")); var res = Globals.ThisAddIn.Innovator.applyMethod("TestExcelAddInExample", body); if (res.isError()) { throw new Exception(res.getErrorString()); } MessageBox.Show("Bom Structure was successfully created!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exc) { MessageBox.Show(exc.Message, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { ITracer tracer = new Tracer(); Thread[] threads = { new Thread(new LongCalcClass(tracer).ShortRecursiveMethod), new Thread(new LongCalcClass(tracer).LongRecursiveMethod), new Thread(new ShortCalcClass(tracer).SimpleMethodWithAnotherSimleMethod) }; foreach (Thread th in threads) { th.Start(); } ShortCalcClass c1 = new ShortCalcClass(tracer); c1.SimpleMethod(); LongCalcClass c2 = new LongCalcClass(tracer); c2.ShortRecursiveMethod(null); foreach (Thread th in threads) { th.Join(); } ISerialization serializer = new CustomXmlSerializer(); string xmlStr = serializer.Serialize(tracer.GetTraceResult()); serializer = new JsonSerialization(); string jsonStr = serializer.Serialize(tracer.GetTraceResult()); Displayer displ = new Displayer(); displ.Display(Console.Out, jsonStr + "\n" + xmlStr); displ.Display(new FileStream("methods.json", FileMode.Create), jsonStr); displ.Display(new FileStream("methods.xml", FileMode.Create), xmlStr); }
public TestHarnessMemoryFactStore(CustomXmlSerializer serializer, CustomXmlSerializer deserializer) { _serializer = serializer; _deserializer = deserializer; }
public static MailMessage ProductHtmlMailContent(List <ProductEmailDetails> productsToEmail, AmazonProductAPIContext.Regions region) { //StringWriter stringWriter = new StringWriter(); //using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter)) //{ // writer.RenderBeginTag(HtmlTextWriterTag.Html);//Html open // writer.RenderBeginTag(HtmlTextWriterTag.Body);//Body open // writer.Write(GetAmazonLogoAndLink(region));//Insert logo and link // writer.RenderBeginTag(HtmlTextWriterTag.Ul);//Unordered list open // foreach(var key in productsToMail.Keys) // { // string product = key; // string link = productsToMail[key]; // var tempWriter = GetLinkForProduct(product, link); // writer.Write(tempWriter); // } // writer.RenderEndTag();//Unorder List close // writer.RenderEndTag();//Body Close // writer.RenderEndTag();//Html Close //} //return stringWriter.ToString(); // We'll dump the resulting HTML body in a file string status = string.Empty;; MailMessage mailMessage = null; try { status = "Entered try bloc"; var templateCompiler = new TemplateCompiler(); var xmlSerializer = new CustomXmlSerializer(); var layoutFileName = "EmailLayout.html"; var xslFileName = "EmailTemplate.xslt"; status = "Getting files from S3;"; var layoutFile = GetFileFromS3(layoutFileName); var xsltFilePath = GetFileFromS3(xslFileName); status = "Got files from S3"; //var layoutFile = Path.Combine(templateDirectory, "EmailLayout.html"); //var xsltFilePath = Path.Combine(templateDirectory, "EmailTemplate.xslt"); var variables = new { ProductsToEmail = productsToEmail.ToArray() }; var templateEmailSender = new TemplateEmailSender(templateCompiler, xmlSerializer) { LayoutFilePath = layoutFile }; status = "Calling construct message"; mailMessage = templateEmailSender.ConstructMailMessage(xsltFilePath, variables); return(mailMessage); // Close the file } catch (Exception ex) { throw new Exception("Send email failed with exception " + status + ex.Message, ex); } }
public static byte[] AppProtResponse_Srv(int protocal_ID, string para, int fromUID) { XmlDocument xmlDocument = null; if (protocal_ID == 1) { try { List <int> list = new List <int>(); DataTable dataTable = DBTools.CreateDataTable(para); for (int i = 0; i < dataTable.Rows.Count; i++) { for (int j = 0; j < dataTable.Columns.Count; j++) { if (dataTable.Rows[i].ItemArray[j] == DBNull.Value) { list.Add(i); break; } } } if (list.Count > 0) { for (int k = list.Count - 1; k >= 0; k--) { dataTable.Rows.RemoveAt(list[k]); } } dataTable.TableName = "RCI"; xmlDocument = CustomXmlSerializer.Serialize(dataTable, 8, "RCI"); goto IL_59A; } catch (Exception ex) { Common.WriteLine("AppProtResponse_Srv---[RCI]: {0}", new string[] { ex.Message }); goto IL_59A; } } if (protocal_ID == 2) { try { ArrayList curRacks = DataSetManager.getCurRacks(); Dictionary <long, string> obj = AppData.LoadheatLoadDissipation(curRacks, Convert.ToInt32(para)); xmlDocument = CustomXmlSerializer.Serialize(obj, 8, "HEAT"); goto IL_59A; } catch (Exception ex2) { Common.WriteLine("AppProtResponse_Srv---[HEAT]: {0}", new string[] { ex2.Message }); goto IL_59A; } } if (protocal_ID == 3) { try { DeviceInfo deviceByID = DeviceOperation.getDeviceByID(Convert.ToInt32(para)); xmlDocument = CustomXmlSerializer.Serialize(deviceByID, 8, "RemoteCall_getDeviceByID"); goto IL_59A; } catch (Exception ex3) { Common.WriteLine("AppProtResponse_Srv---[RemoteCall_getDeviceByID]: {0}", new string[] { ex3.Message }); goto IL_59A; } } if (protocal_ID == 4) { try { DeviceInfo deviceByID2 = DeviceOperation.getDeviceByID(Convert.ToInt32(para)); List <PortInfo> obj2 = null; if (deviceByID2 != null) { obj2 = deviceByID2.GetPortInfo(); } xmlDocument = CustomXmlSerializer.Serialize(obj2, 8, "RemoteCall_AllPort_in1Dev"); goto IL_59A; } catch (Exception ex4) { Common.WriteLine("AppProtResponse_Srv---[RemoteCall_AllPort_in1Dev]: {0}", new string[] { ex4.Message }); goto IL_59A; } } if (protocal_ID == 7) { try { List <DeviceInfo> list2 = new List <DeviceInfo>(); string[] array = para.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; for (int l = 0; l < array2.Length; l++) { string text = array2[l]; string value = text.Trim(); if (!string.IsNullOrEmpty(value)) { DeviceInfo deviceByID3 = DeviceOperation.getDeviceByID(Convert.ToInt32(value)); if (deviceByID3 != null) { list2.Add(deviceByID3); } } } xmlDocument = CustomXmlSerializer.Serialize(list2, 8, "RemoteCall_getDeviceInfoList"); goto IL_59A; } catch (Exception ex5) { Common.WriteLine("AppProtResponse_Srv---[RemoteCall_getDeviceInfoList]: {0}", new string[] { ex5.Message }); goto IL_59A; } } if (protocal_ID == 100) { try { string[] array3 = para.Split(new char[] { '\n' }); switch (array3.Length) { case 1: LogAPI.writeEventLog(array3[0], new string[0]); break; case 2: { string user = SessionAPI.getUser((long)fromUID); string remoteIP = SessionAPI.getRemoteIP((long)fromUID); string remoteType = SessionAPI.getRemoteType((long)fromUID); if (array3[0].Equals("0230003", StringComparison.InvariantCultureIgnoreCase)) { LogAPI.writeEventLog("0230003", new string[] { user, remoteIP }); } else { if (!remoteType.Equals("remote", StringComparison.InvariantCultureIgnoreCase)) { LogAPI.writeEventLog(array3[0], new string[] { array3[1] }); } } break; } case 3: LogAPI.writeEventLog(array3[0], new string[] { array3[1], array3[2] }); break; case 4: LogAPI.writeEventLog(array3[0], new string[] { array3[1], array3[2], array3[3] }); break; case 5: LogAPI.writeEventLog(array3[0], new string[] { array3[1], array3[2], array3[3], array3[4] }); break; case 6: LogAPI.writeEventLog(array3[0], new string[] { array3[1], array3[2], array3[3], array3[4], array3[5] }); break; case 7: LogAPI.writeEventLog(array3[0], new string[] { array3[1], array3[2], array3[3], array3[4], array3[5], array3[6] }); break; } int num = 1; xmlDocument = CustomXmlSerializer.Serialize(num, 8, "RemoteCall_writeEventLog"); goto IL_59A; } catch (Exception ex6) { Common.WriteLine("AppProtResponse_Srv---[RemoteCall_AllPort_in1Dev]: {0}", new string[] { ex6.Message }); goto IL_59A; } } if (protocal_ID == 101) { try { int num2 = 1; xmlDocument = CustomXmlSerializer.Serialize(num2, 8, "RemoteCall_setEventFlag"); goto IL_59A; } catch (Exception ex7) { Common.WriteLine("AppProtResponse_Srv---[RemoteCall_setEventFlag]: {0}", new string[] { ex7.Message }); goto IL_59A; } } if (protocal_ID == 102) { DataTable allSessions = SessionAPI.getAllSessions(); xmlDocument = CustomXmlSerializer.Serialize(allSessions, 8, "Sessions"); } else { if (protocal_ID == 103) { string obj3 = "Success"; if (!SessionAPI.KillSessions(fromUID, para)) { obj3 = "Failed"; } xmlDocument = CustomXmlSerializer.Serialize(obj3, 8, "KillSession"); } else { if (protocal_ID == 104) { DateTime now = DateTime.Now; xmlDocument = CustomXmlSerializer.Serialize(now, 8, "RemoteCall_getSrvDateTime"); } else { if (protocal_ID == 8) { Dictionary <long, List <long> > dictionary = SessionAPI.getDeviceListClone((long)fromUID); if (dictionary == null) { dictionary = new Dictionary <long, List <long> >(); } xmlDocument = CustomXmlSerializer.Serialize(dictionary, 8, "RemoteCall_UACDev2Port"); } } } } IL_59A: if (xmlDocument == null) { return(null); } byte[] result; try { string outerXml = xmlDocument.OuterXml; byte[] bytes = Encoding.UTF8.GetBytes(outerXml); result = bytes; } catch (Exception ex8) { Common.WriteLine("AppProtResponse_Srv: #{0}({1}), {2}", new string[] { protocal_ID.ToString(), para, ex8.Message }); result = null; } return(result); }
public void WriteXml(System.Xml.XmlWriter writer) { CustomXmlSerializer XmlWriter = new CustomXmlSerializer(); XmlWriter.WriteXml(this, writer); }