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


C# XmlTextReader.ReadElementContentAsBinHex方法代码示例

本文整理汇总了C#中XmlTextReader.ReadElementContentAsBinHex方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadElementContentAsBinHex方法的具体用法?C# XmlTextReader.ReadElementContentAsBinHex怎么用?C# XmlTextReader.ReadElementContentAsBinHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.ReadElementContentAsBinHex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: ImportScheduledTask

 public static bool ImportScheduledTask(string fileName)
 {
     FileStream fileStream = null;
     bool bRet = false;
     try
     {
         int buffSize = 512;
         byte[] taskData;
         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("Task"))
             {
                 //读Name
                 reader.Read();                    
                 reader.MoveToContent();
                 string name = reader.ReadElementContentAsString();
                 //读Comment
                 reader.Read();
                 reader.MoveToContent();
                 string comment = reader.ReadElementContentAsString();
                 //读Data
                 reader.Read();
                 reader.MoveToContent();
                 
                 int realLength = 0;
                 taskData = new byte[buffSize];                    
                 byte[] tempBuff = new byte[buffSize];
                 int readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                 Array.Copy(tempBuff, 0, taskData, realLength, readCount);
                 realLength += readCount;
                 while (tempBuff.Length == readCount)
                 {
                     Array.Resize<byte>(ref taskData, taskData.Length + buffSize);
                     readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                     Array.Copy(tempBuff, 0, taskData, realLength, readCount);
                     realLength += readCount;
                 }
                 Array.Resize<byte>(ref taskData, realLength);
                 MemoryStream taskDataStream = new MemoryStream(taskData);
                 IFormatter formatter = new BinaryFormatter();
                 IScheduledTask task = (IScheduledTask)formatter.Deserialize(taskDataStream);
                 AdminServer.TheInstance.ScheduledTaskManager.Add(task, name, comment);
             }
         }
         bRet = true;
     }
     catch (Exception)
     {
         bRet = false;
     }
     finally
     {
         if (fileStream != null) fileStream.Close();
     }
     return bRet;
 }
开发者ID:viticm,项目名称:pap2,代码行数:61,代码来源:WebUtil.cs


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