private static void LoadSql(string fileName, string sql, long elapsed) { try { System.Xml.Linq.XDocument xmlDoc = null; System.Xml.Linq.XElement rootElement = null; const string RootName = "SQL"; if (File.Exists(fileName)) { xmlDoc = System.Xml.Linq.XDocument.Load(fileName); rootElement = xmlDoc.Element(RootName); } else { xmlDoc = new System.Xml.Linq.XDocument(); rootElement = new System.Xml.Linq.XElement(RootName); xmlDoc.Add(rootElement); } var parentElement = new System.Xml.Linq.XElement("Entry", new System.Xml.Linq.XAttribute("datetime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")), new System.Xml.Linq.XAttribute("elapsed", elapsed.ToString())); parentElement.Add(new System.Xml.Linq.XElement("sql", new System.Xml.Linq.XCData(sql))); rootElement.Add(parentElement); xmlDoc.Save(fileName); } catch (Exception ex) { //Do Nothing } }
/// <summary> /// 解析 /// </summary> /// <param name="document"></param> private static void Analysis(System.Xml.Linq.XDocument document) { //解析普通配置项 xml: Mobile var element = document.Element("appSettings"); if (null == element) { return; } var folders = element.Elements("add"); mConfigs = new Dictionary <string, string>(); foreach (var item in folders) { var key = item.Attribute("key"); var value = item.Attribute("value"); mConfigs.Add(key.Value, value.Value); } //quos mQuos = new Dictionary <string, string>(); var quos = element.Elements("Quo"); foreach (var quo in quos) { var key = quo.Attribute("key"); var value = quo.Attribute("value"); mQuos.Add(key.Value, value.Value); } }
public static VirtualRSSXmlFile Load(string FilePath) { VirtualRSSXmlFile LoadedVirtualRSSXmlFile; try { System.Xml.Linq.XDocument RSSXmlFile = System.Xml.Linq.XDocument.Load(FilePath); System.Xml.Linq.XElement RSS_Channel = RSSXmlFile.Element("rss").Element("channel"); LoadedVirtualRSSXmlFile = new VirtualRSSXmlFile( RSS_Channel.Element("title").Value, RSS_Channel.Element("link").Value, RSS_Channel.Element("description").Value, RSS_Channel.Element("generator").Value, RSS_Channel.Element("docs").Value, RSS_Channel.Element("language").Value, RSS_Channel.Element("pubDate").Value, RSS_Channel.Element("lastBuildDate").Value ); System.Xml.Linq.XElement[] ItemArray = RSS_Channel.Elements("item").ToArray(); foreach (System.Xml.Linq.XElement Item in ItemArray) { item CurrentItem = new item(Item.Element("title").Value, Item.Element("link").Value, Item.Element("description").Value, Item.Element("pubDate").Value); LoadedVirtualRSSXmlFile.ItemList.Add(CurrentItem); } } catch { LoadedVirtualRSSXmlFile = null; throw; } return(LoadedVirtualRSSXmlFile); }
private void _ReadXDocument(System.Xml.Linq.XDocument xDoc) { if (xDoc == null) { return; } System.Xml.Linq.XElement xResult = xDoc.Element("RUNRESULT"); if (xResult == null) { return; } this.ResultState = _ReadAttributeString(xResult, "STATE"); this.Start = _ReadAttributeDateTime(xResult, "START"); this.Stop = _ReadAttributeDateTime(xResult, "STOP"); this.DatabaseId = _ReadAttributeString(xResult, "DATABASENUMBER"); System.Xml.Linq.XElement xDetail = _GetElement(xResult, "DETAIL"); this.DetailLevel = _ReadAttributeString(xDetail, "LEVEL"); this.DetailErrorMessage = _ReadAttributeString(xDetail, "errorMessage"); this.DetailTime = _ReadAttributeDateTime(xDetail, "WHEN"); System.Xml.Linq.XElement xText = _GetElement(xDetail, "TEXT"); this.DetailText = _ReadElementValue(xText); System.Xml.Linq.XElement xUserData = _GetElement(xResult, "USERDATA"); this.UserDataIsExists = (xUserData != null); this.UserDataIsBase64 = _ReadAttributeString(xUserData, "Base64Conversion"); this.UserDataContent = _ReadElementValue(xUserData); System.Xml.Linq.XElement xAuditlog = _GetElement(xResult, "auditlog"); this.AuditlogId = _ReadAttributeString(xAuditlog, "id"); this.AuditlogState = _ReadAttributeString(xAuditlog, "state"); this.IsValid = true; }
/// <summary> /// 解析移动服务配置相关信息 /// </summary> /// <param name="xdocument"></param> static void GetMobileHelpers(System.Xml.Linq.XDocument xdocument) { //解析普通配置项 xml: Mobile var element = xdocument.Element("items"); if (null == element) { return; } var items = element.Elements("item"); mRadioHelpers = new Dictionary <int[], RadioHelper>(); foreach (var item in items) { var helperItem = new RadioHelper(); Async(item, helperItem); var pattern = item.Element("pattern"); if (pattern != null) { helperItem.Childrens = new List <RadioHelper>(); var patternChildrens = pattern.Elements("item"); foreach (var cd in patternChildrens) { var cdItem = new RadioHelper(); Async(cd, cdItem); helperItem.Childrens.Add(cdItem); } } mRadioHelpers.Add(helperItem.Key, helperItem); } }
//hplCheckForUpdate_Click private void hplCheckForUpdate_Click(object sender, RoutedEventArgs e) { //check version if (thread_checkversion != null && thread_checkversion.ThreadState == ThreadState.Running) { } else { thread_checkversion = new Thread(() => { try { this.Dispatcher.Invoke((Action)(() => { this.tblCheckForUpdate.Visibility = System.Windows.Visibility.Collapsed; this.stpCheckForUpdate.Visibility = System.Windows.Visibility.Visible; })); System.Xml.Linq.XDocument xdocument = System.Xml.Linq.XDocument.Load(StaticClass.GeneralClass.isPreActiveVersion? "http://ipcamsoft.com/CashRegister/versionPro":"http://ipcamsoft.com/CashRegister/version"); System.Xml.Linq.XElement xelement = xdocument.Element("CurrentVersion"); var new_version = xelement.Value; if (new_version.CompareTo(old_version) == 1) { this.Dispatcher.Invoke((Action)(() => { stpCheckForUpdate.Visibility = System.Windows.Visibility.Collapsed; stpClickToDownload.Visibility = System.Windows.Visibility.Visible; })); } else { this.Dispatcher.Invoke((Action)(() => { stpCheckForUpdate.Visibility = System.Windows.Visibility.Collapsed; tblOldVersion.Visibility = System.Windows.Visibility.Visible; })); } } catch (Exception ex) { this.Dispatcher.Invoke((Action)(() => { ModernDialog md = new ModernDialog(); md.Title = FindResource("notification").ToString(); md.Content = ex.Message; md.CloseButton.Content = FindResource("close").ToString(); md.ShowDialog(); })); } }); thread_checkversion.Start(); } }
public void TestMethod1() { System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load(@"C:\Temp\Form.xml"); IEnumerable <System.Xml.Linq.XNode> nodes = doc.Nodes(); System.Xml.Linq.XNode next = nodes.Last(); System.Xml.Linq.XDocument docx = new System.Xml.Linq.XDocument(next); System.Xml.Linq.XName xname = System.Xml.Linq.XName.Get("statusReport", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-09-22T20:42:56"); System.Xml.Linq.XName xnames = System.Xml.Linq.XName.Get("reportDate", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-09-22T20:42:56"); System.Xml.Linq.XElement hh = docx.Element(xname).Element(xnames); string data = hh.Value; }
/// <summary> /// 根据银行名称获取银行图标路径或名称 /// </summary> /// <param name="bankName">银行名称</param> /// <returns></returns> string getBankIconUrlByName(string bankName) { string iconName = string.Empty; string bankFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "Files\\BankIcon.xml"; System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(bankFilePath); var icons = from bankNode in xdoc.Element("banks").Elements("bank") where bankNode.Value.Contains(bankName) || bankName.Contains(bankNode.Value) || bankNode.Value == "其他银行" select bankNode.Attribute("iconName").Value; if (icons != null && icons.Count() > 0) { iconName = icons.First(); } return(iconName); }
/// <summary> /// 解析移动服务配置相关信息 /// </summary> /// <param name="xdocument"></param> private static void GetMobileSetting(System.Xml.Linq.XDocument xdocument) { //解析普通配置项 xml: Mobile var element = xdocument.Element("Settings").Elements("JSONServer").FirstOrDefault(); if (null == element) { return; } var folders = element.Elements("Folder"); mMobileInititalSettings = new Dictionary <string, MobileSettingItemInfo>(); foreach (var item in folders) { var folderNameAttribute = item.Attribute("name"); if (null == folderNameAttribute) { throw new ArgumentNullException("Folder attribute is null!"); } if (!item.HasElements) { throw new ArgumentNullException("Folder is not childrens!"); } var nameItems = item.Elements("item"); foreach (var nameItem in nameItems) { var pageAttribute = nameItem.Attribute("page"); var classAttribute = nameItem.Attribute("class"); if (null == pageAttribute || null == classAttribute) { continue; } MobileSettingItemInfo settingItem = new MobileSettingItemInfo(); settingItem.Page = folderNameAttribute.Value + pageAttribute.Value; settingItem.ClassFullName = classAttribute.Value; if (mMobileInititalSettings.ContainsKey(settingItem.Page)) { continue; } mMobileInititalSettings.Add(settingItem.Page, settingItem); } } }
/// <summary> /// 解析 /// </summary> /// <param name="document"></param> private static void Analysis(System.Xml.Linq.XDocument document) { //解析普通配置项 xml: Mobile var element = document.Element("Items"); if (null == element) { return; } var folders = element.Elements("Item"); addPointsAttributes = new List <AddPointsAttribute>(); foreach (var item in folders) { var folderNameAttribute = item.Attribute("Day"); var titleAttribute = item.Attribute("Title"); string day = folderNameAttribute.Value; var title = titleAttribute.Value; var nameItems = item.Elements("Children"); foreach (var nameItem in nameItems) { var salesStandAttribute = nameItem.Attribute("SalesStand"); var sSCAttribute = nameItem.Attribute("SSC"); var elevenAttribute = nameItem.Attribute("Eleven"); var tdAttribute = nameItem.Attribute("Td"); var targer = nameItem.Attribute("targer"); AddPointsAttribute addPoints = new AddPointsAttribute(); if (targer != null) { addPoints.targer = Convert.ToDouble(targer.Value); } addPoints.Day = day; addPoints.Title = title; addPoints.SalesStand = salesStandAttribute.Value; addPoints.SSC = sSCAttribute.Value; addPoints.Eleven = elevenAttribute.Value; addPoints.Td = tdAttribute.Value; addPointsAttributes.Add(addPoints); } } }
private void btnSelect_Click(object sender, EventArgs e) { try { if (System.IO.Directory.Exists(@"D:\")) { if (!System.IO.Directory.Exists(@"D:\EmrCheckup")) { System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(@"D:\EmrCheckup"); di.Attributes = System.IO.FileAttributes.Directory | System.IO.FileAttributes.Hidden; } if (!System.IO.File.Exists(@"D:\EmrCheckup\PrinterSticker.xml")) { PrinterName = ""; PaperName = ""; } else { System.Xml.Linq.XDocument xml = System.Xml.Linq.XDocument.Load(@"D:\EmrCheckup\PrinterSticker.xml"); var wb = xml.Element("PrinterCls").Elements("Report").Where(x => x.Attribute("id").Value == "Wristband").FirstOrDefault(); if (wb != null) { PrinterName = wb.Element("Printer").Value; PaperName = wb.Element("Paper").Value; } } } } catch { PrinterName = ""; PaperName = ""; } //try //{ // if (!System.IO.Directory.Exists(@"D:\")) // { // Program.MessageError("Sticker", "Drive D:", "Not found.", false); // } // else // { // if (!System.IO.Directory.Exists(@"D:\EmrCheckup")) // { // System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(@"D:\EmrCheckup"); // di.Attributes = System.IO.FileAttributes.Directory | System.IO.FileAttributes.Hidden; // } // if (!System.IO.File.Exists(@"D:\EmrCheckup\PrintSticker.xml")) // { // new System.Xml.Linq.XDocument( // new System.Xml.Linq.XElement("PrinterCls", // new System.Xml.Linq.XElement("SelectedPrinter", comboBox1.SelectedItem.ToString()) // ) // ).Save(@"D:\EmrCheckup\PrintSticker.xml"); // SelectedPrinter = comboBox1.SelectedItem.ToString(); // } // else // { // System.Xml.Linq.XDocument xml = System.Xml.Linq.XDocument.Load(@"D:\EmrCheckup\PrintSticker.xml"); // xml.Root.Element("SelectedPrinter").Value = comboBox1.SelectedItem.ToString(); // xml.Save(@"D:\EmrCheckup\PrintSticker.xml"); // SelectedPrinter = comboBox1.SelectedItem.ToString(); // } // } //} //catch (Exception ex) //{ //} copyValue = Convert.ToInt32(cbPrintCopy.SelectedValue); DialogResult = DialogResult.OK; }