本文整理汇总了C#中XmlTextReader.ReadElementContentAsInt方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadElementContentAsInt方法的具体用法?C# XmlTextReader.ReadElementContentAsInt怎么用?C# XmlTextReader.ReadElementContentAsInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadElementContentAsInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadConfigFile
void LoadConfigFile()
{
try
{
XmlTextReader doc = new XmlTextReader("reddit_api.xml");
while (doc.Read())
{
if (doc.NodeType == XmlNodeType.Element)
{
switch (doc.Name)
{
case "seconds_between_api_calls":
m_seconds_between_calls = doc.ReadElementContentAsDouble();
break;
case "seconds_before_cache_invalid":
m_seconds_before_cache_invalid = doc.ReadElementContentAsDouble();
break;
case "default_content_limit":
m_content_limit = doc.ReadElementContentAsInt();
break;
case "object_mappings":
string kind = "", objectname = "";
while (doc.MoveToNextAttribute())
{
if (doc.Name == "kind")
{
kind = doc.Value;
}
else if (doc.Name == "object")
{
objectname = doc.Value;
}
}
if (m_object_mapping.ContainsKey(kind))
m_object_mapping["kind"] = objectname;
else
m_object_mapping.Add(kind, objectname);
break;
case "domain":
m_domain = doc.ReadElementContentAsString();
break;
}
}
}
doc.Close();
}
catch (FileNotFoundException)
{
StreamWriter s = new StreamWriter("reddit_api.xml");
s.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
s.WriteLine("<reddit_api_config>");
s.WriteLine("<seconds_between_api_calls>2</seconds_between_api_calls>" );
s.WriteLine("<seconds_before_cache_invalid>30</seconds_before_cache_invalid>");
s.WriteLine("<default_content_limit>25</default_content_limit>");
s.WriteLine("<object_mappings kind=\"comment_kind\" object=\"t1\"/>");
s.WriteLine("<object_mappings kind=\"message_kind\" object=\"t4\"/>");
s.WriteLine("<object_mappings kind=\"more_kind\" object =\"more\"/>");
s.WriteLine("<object_mappings kind=\"redditor_kind\" object=\"t2\"/>");
s.WriteLine("<object_mappings kind=\"submission_kind\" object=\"t3\"/>");
s.WriteLine("<object_mappings kind=\"subreddit_kind\" object=\"t5\"/>");
s.WriteLine("<object_mappings kind=\"userlist_kind\" object=\"UserList\"/>");
s.WriteLine("<domain>http://www.reddit.com/</domain>");
s.WriteLine("<!--");
s.WriteLine("message_kind: t7");
s.WriteLine("submission_kind: t6");
s.WriteLine("subreddit_kind: t5");
s.WriteLine(" -->");
s.WriteLine("</reddit_api_config>");
s.Close();
LoadConfigFile();
}
}
示例2: ImportStrategy
public static bool ImportStrategy(string fileName)
{
FileStream fileStream = null;
bool bRet = false;
try
{
int buffSize = 512;
byte[] automationData;
fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
XmlTextReader reader = new XmlTextReader(fileStream);
reader.MoveToElement();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("Strategy"))
{
//读Name
reader.Read();
reader.MoveToContent();
string name = reader.ReadElementContentAsString();
//读Comment
reader.Read();
reader.MoveToContent();
string comment = reader.ReadElementContentAsString();
Strategy strategyToAdd = new Strategy();
//读Event
reader.Read();
reader.MoveToContent();
strategyToAdd.Event = (FSEyeEvent)reader.ReadElementContentAsInt();
//读Automation
reader.Read();
reader.MoveToContent();
int realLength = 0;
automationData = new byte[buffSize];
byte[] tempBuff = new byte[buffSize];
int readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
Array.Copy(tempBuff, 0, automationData, realLength, readCount);
realLength += readCount;
while (tempBuff.Length == readCount)
{
Array.Resize<byte>(ref automationData, automationData.Length + buffSize);
readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
Array.Copy(tempBuff, 0, automationData, realLength, readCount);
realLength += readCount;
}
Array.Resize<byte>(ref automationData, realLength);
strategyToAdd.Automation = AdminServer.TheInstance.AutomationManager.Load(automationData);
//读Enable
reader.Read();
reader.MoveToContent();
strategyToAdd.Enabled = reader.ReadElementContentAsInt() == 1 ? true : false;
AdminServer.TheInstance.StrategyManager.Add(strategyToAdd, name, comment);
}
}
bRet = true;
}
catch (Exception)
{
bRet = false;
}
finally
{
if (fileStream != null) fileStream.Close();
}
return bRet;
}