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


C# XmlReader.ReadContentAsBase64方法代码示例

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


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

示例1: Restore

        public void Restore(XmlReader reader)
        {
            for (int i = 0; i < reader.AttributeCount; ++i)
            {
                reader.MoveToAttribute(i);
                switch (reader.Name)
                {
                    case "checkforupdates":
                        CheckForUpdates = reader.ReadContentAsBool();
                        break;

                    case "automaticallyinstallupdates":
                        AutomaticallyInstallUpdates = reader.ReadContentAsBool();
                        break;

                    case "passwordsalt":
                        _passwordSalt = reader.ReadContentAsBase64();
                        break;

                    case "proxyserver":
                        ProxyServer = reader.ReadContentAsString();
                        break;

                    case "proxyusername":
                        ProxyUsername = reader.ReadContentAsString();
                        break;

                    case "proxypassword":
                        _password = reader.ReadContentAsBase64();
                        break;

                    default:
                        Log.WarnFormat("Skipping unknown attribute '{0}'", reader.Name);
                        break;
                }
            }

            CreatePasswordSaltIfNecessary();
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:39,代码来源:AutoUpdateSettings.cs

示例2: ProcessEntropyElement

        /// <summary>
        /// Reads a wst:Entropy element and constructs a SecurityToken
        /// Assumes that the provided entropy is never more than 1Kb in size.
        /// </summary>
        /// <param name="xr">An XmlReader positioned on the start tag of wst:Entropy</param>
        /// <returns>A SecurityToken that contains the entropy value.</returns>
        private static SecurityToken ProcessEntropyElement(XmlReader xr)
        {
            // If provided XmlReader is null, throw an exception
            if (xr == null)
                throw new ArgumentNullException("xr");

            // If the wst:Entropy element is empty, then throw an exception.
            if (xr.IsEmptyElement)
                throw new ArgumentException("wst:Entropy element was empty. Unable to create SecurityToken object");

            // Store the initial depth so we can exit this function when we reach the corresponding end-tag            
            int initialDepth = xr.Depth;

            // Set our return value to null
            SecurityToken st = null;

            // Enter a read loop...
            while (xr.Read())
            {
                // Look for a non-empty wst:BinarySecret element
                if (Constants.Trust.Elements.BinarySecret == xr.LocalName &&
                         Constants.Trust.NamespaceUri == xr.NamespaceURI &&
                         !xr.IsEmptyElement &&
                         XmlNodeType.Element == xr.NodeType)
                {
                    // Allocate a 1024 byte buffer for the entropy
                    byte[] temp = new byte[1024];

                    // Move reader to content of wst:BinarySecret element...
                    xr.Read();

                    // ...and read that content as base64. Store the actual number of bytes we get.                    
                    int nBytes = xr.ReadContentAsBase64(temp, 0, temp.Length);

                    // Allocate a new array of the correct size to hold the provided entropy
                    byte[] entropy = new byte[nBytes];

                    // Copy the entropy from the temporary array into the new array.
                    for (int i = 0; i < nBytes; i++)
                        entropy[i] = temp[i];

                    // Create new BinarySecretSecurityToken from the provided entropy
                    st = new BinarySecretSecurityToken(entropy);
                }

                // Look for the end-tag that corresponds to the start-tag the reader was positioned 
                // on when the method was called. When we find it, break out of the read loop.
                if (Constants.Trust.Elements.Entropy == xr.LocalName &&
                    Constants.Trust.NamespaceUri == xr.NamespaceURI &&
                    xr.Depth == initialDepth &&
                    XmlNodeType.EndElement == xr.NodeType)
                    break;
            }

            return st;
        }
开发者ID:ssickles,项目名称:archive,代码行数:62,代码来源:RequestSecurityToken.cs

示例3: ToObject

        private static TableStorageField ToObject(XmlReader reader, string edmType, bool isNull, string propertyName)
        {
            object value;
            Type dataType;
            string formatString;

            if(edmType == TableStorageConstants.Edm.TYPE_BINARY)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    using(Stream stream = new MemoryStream())
                    {
                        const int size = 256;
                        byte[] buffer = new byte[size];
                        int count;

                        while((count = reader.ReadContentAsBase64(buffer, 0, size)) > 0)
                        {
                            stream.Write(buffer, 0, count);
                        }

                        stream.Seek(0, SeekOrigin.Begin);

                        value = stream;
                    }
                }

                dataType = typeof(byte[]);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_BOOLEAN)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsBoolean();
                }

                dataType = typeof(bool);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_DATETIME)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsDateTime();
                }

                dataType = typeof(DateTime);
                formatString = TableStorageConstants.Edm.DATE_TIME_FORMAT;
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_DOUBLE)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsDouble();
                }

                dataType = typeof(double);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_GUID)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = Guid.Parse(reader.ReadContentAsString());
                }

                dataType = typeof(Guid);
                formatString = "{0:D}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_INT)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsInt();
                }
//.........这里部分代码省略.........
开发者ID:heymagurany,项目名称:TableStorageDataProvider,代码行数:101,代码来源:TableStorageDataReader.cs


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