本文整理汇总了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();
}
示例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;
}
示例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();
}
//.........这里部分代码省略.........