当前位置: 首页>>代码示例>>C#>>正文


C# XmlTextReader.ReadElementContentAsInt方法代码示例

本文整理汇总了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();
        }
    }
开发者ID:ACReeser,项目名称:rKnightsOfNew,代码行数:74,代码来源:RedditAPI.cs

示例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;
    }    
开发者ID:viticm,项目名称:pap2,代码行数:67,代码来源:WebUtil.cs


注:本文中的XmlTextReader.ReadElementContentAsInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。