def onUpdate(): if NetworkInterface.GetIsNetworkAvailable(): try: response = None stream = None try: response = request.GetResponse() stream = response.GetResponseStream() doc = XmlDocument() doc.Load(stream) for itemXmlNode in doc.GetElementsByTagName("item"): entry = Entry() epicenter = None maxLevel = None for xmlNode in itemXmlNode.ChildNodes: if xmlNode.Name.Equals("link"): entry.Resource = Uri(xmlNode.InnerText) elif xmlNode.Name.Equals("description"): entry.Description = xmlNode.InnerText elif xmlNode.Name.Equals("tenkiJP:earthquake"): for attribute in xmlNode.Attributes: if attribute.Name.Equals("epicenter"): epicenter = attribute.Value elif attribute.Name.Equals("max_level"): maxLevel = attribute.Value elif attribute.Name.Equals( "outbreak_datetime"): entry.Created = entry.Modified = DateTime.Parse( attribute.Value) if epicenter is not None: if String.IsNullOrEmpty(maxLevel): maxLevel = "N/A" if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): entry.Title = String.Format( "震度{0} - {1}", maxLevel, epicenter) else: entry.Title = String.Format( "Intensity {0} - {1}", maxLevel, epicenter) entryList.Add(entry) finally: if stream is not None: stream.Close() if response is not None: response.Close() except Exception, e: Trace.WriteLine(e.clsException.Message) Trace.WriteLine(e.clsException.StackTrace)
def SaveSettings(self): import clr clr.AddReference("System.Xml") from System.Xml import XmlDocument import nt xmldoc = XmlDocument() try: xmldoc.Load(nt.getcwd() + "\load.xml") except: print "Error reading load.xml" return nodelist = xmldoc.GetElementsByTagName("Cache") a = xmldoc.CreateAttribute("allow") if self.checkCache.Checked is True: a.Value = "true" else: a.Value = "false" nodelist.Item(0).Attributes.Append(a) nodelist = xmldoc.GetElementsByTagName("TopLeftPreviewTile") a = xmldoc.CreateAttribute("x") a.Value = str(self.previewTile[0][0].tile[0]) nodelist.Item(0).Attributes.Append(a) a = xmldoc.CreateAttribute("y") a.Value = str(self.previewTile[0][0].tile[1]) nodelist.Item(0).Attributes.Append(a) a = xmldoc.CreateAttribute("dimension") if self.radio3x3.Checked is True: a.Value = "3" else: a.Value = "4" nodelist.Item(0).Attributes.Append(a) a = xmldoc.CreateAttribute("level") a.Value = str(self.scrollZoom.Value) nodelist.Item(0).Attributes.Append(a) try: xmldoc.Save(nt.getcwd() + "\load.xml") except: print "Error writing load.xml"
def onUpdate(): if NetworkInterface.GetIsNetworkAvailable(): try: response = None stream = None try: response = request.GetResponse() stream = response.GetResponseStream() doc = XmlDocument() doc.Load(stream) for entryXmlNode in doc.GetElementsByTagName("entry"): entry = Entry() for xmlNode in entryXmlNode.ChildNodes: if xmlNode.Name.Equals("title"): entry.Title = xmlNode.InnerText elif xmlNode.Name.Equals("issued"): entry.Created = DateTime.Parse( xmlNode.InnerText) elif xmlNode.Name.Equals("modified"): entry.Modified = DateTime.Parse( xmlNode.InnerText) elif xmlNode.Name.Equals("link"): for attribute in xmlNode.Attributes: if attribute.Name.Equals("href"): entry.Resource = Uri(attribute.Value) elif xmlNode.Name.Equals("author"): for childXmlNode in xmlNode.ChildNodes: if childXmlNode.Name.Equals("name"): entry.Author = childXmlNode.InnerText entry.Image = Uri( "http://www.google.co.jp/options/icons/gmail.gif") entryList.Add(entry) finally: if stream is not None: stream.Close() if response is not None: response.Close() except Exception, e: Trace.WriteLine(e.clsException.Message) Trace.WriteLine(e.clsException.StackTrace)
def read_config(cls, config_file): """Read and process config file """ if not os.path.isfile(config_file): raise Log4NetError('Failed to find config file "%s"' % config_file) # Read document doc = XmlDocument() try: doc.Load(config_file) except Exception as e: raise Log4NetError(str(e)) # Obtain 1st element with log4net tag for element in doc.GetElementsByTagName('log4net'): XmlConfigurator.Configure(element) break
def SaveCurrentGame(self, caption): import clr clr.AddReference("System.Xml") from System.Xml import * import nt xmldoc = XmlDocument() try: xmldoc.Load(nt.getcwd() + "\load.xml") except: print "Error reading load.xml" return nodeSavedGames = xmldoc.GetElementsByTagName("SavedGames") nodeNewGame = xmldoc.CreateElement("Game") a = xmldoc.CreateAttribute("caption") a.Value = caption nodeNewGame.Attributes.Append(a) a = xmldoc.CreateAttribute("type") a.Value = self.currentGameState[0] nodeNewGame.Attributes.Append(a) a = xmldoc.CreateAttribute("x") a.Value = str(self.currentGameState[1]) nodeNewGame.Attributes.Append(a) a = xmldoc.CreateAttribute("y") a.Value = str(self.currentGameState[2]) nodeNewGame.Attributes.Append(a) a = xmldoc.CreateAttribute("level") a.Value = str(self.currentGameState[3]) nodeNewGame.Attributes.Append(a) a = xmldoc.CreateAttribute("dimension") a.Value = str(self.currentGameState[4]) nodeNewGame.Attributes.Append(a) nodeSavedGames[0].AppendChild(nodeNewGame) try: xmldoc.Save(nt.getcwd() + "\load.xml") except: print "Error writing load.xml"