本文整理汇总了C#中System.Xml.XmlWriter.WriteBase64方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.WriteBase64方法的具体用法?C# XmlWriter.WriteBase64怎么用?C# XmlWriter.WriteBase64使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.WriteBase64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteXml
public void WriteXml( XmlWriter writer )
{
writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace );
writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherValue, XmlEncryptionConstants.Namespace );
if ( _iv != null )
writer.WriteBase64( _iv, 0, _iv.Length );
writer.WriteBase64( _cipherText, 0, _cipherText.Length );
writer.WriteEndElement(); // CipherValue
writer.WriteEndElement(); // CipherData
}
示例2: WriteValue
protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
{
if (strNamespace != null)
{
mXmlWriter.WriteStartElement(valueElt, strNamespace);
}
else
{
mXmlWriter.WriteStartElement(valueElt);
}
if (value.IsBinary && value.BinaryVal != null)
{
mXmlWriter.WriteAttributeString("xsi", "type", DsmlConstants.XsiUri,
DsmlConstants.AttrBinaryTypePrefixedValue);
mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
}
else
{
//note that the WriteString method handles a null argument correctly
mXmlWriter.WriteString(value.StringVal);
}
mXmlWriter.WriteEndElement();
}
示例3: WriteModulusAsBase64
public void WriteModulusAsBase64(XmlWriter writer)
{
if (writer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
}
writer.WriteBase64(this.rsaParameters.Modulus, 0, this.rsaParameters.Modulus.Length);
}
示例4: ExportAdditionalFile
private void ExportAdditionalFile(XmlWriter writer, ReleaseAdditionalFile additionalFile)
{
writer.WriteStartElement(Keys.AdditionalFile);
writer.WriteAttributeString(Keys.Type, additionalFile.Type.ToString());
writer.WriteAttributeString(Keys.Description, additionalFile.Description);
writer.WriteAttributeString(Keys.OriginalFilename, additionalFile.OriginalFilename);
writer.WriteBase64(additionalFile.File, 0, additionalFile.File.Length);
writer.WriteEndElement();
}
示例5: WriteXml
public void WriteXml(XmlWriter writer)
{
// TODO: Implement more robust serialization
Type type = GetType();
TypeAccessor accessor = ObjectHydrator.GetAccessor(type);
writer.WriteElementString("type", type.GetName());
IList<string> fieldsToNull = new List<string>();
foreach (PropertyInfo info in from info in type.FilterProperties<SalesforceReadonly>()
let ignoreAttribute = info.GetCustomAttribute<SalesforceIgnore>()
where ignoreAttribute == null || !ignoreAttribute.IfEmpty
select info)
{
object value = accessor[this, info.Name];
string salesforceName = info.GetName();
if (value == null)
{
fieldsToNull.Add(salesforceName);
continue;
}
var xmlValue = value is DateTime
? ((DateTime) value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") // Contributed by: Murillo.Mike - Salesforce requires UTC dates
: value.ToString();
//Added additional routine for when value is Byte[] ---bnewbold 22OCT2014
if ((value as byte[]) != null)
{
//When value is passed in a byte array, as when uploading a filestream file, we need to read the value in rather than cast it to a string.
byte[] byteArray = (byte[])value; //Cast value as byte array into temp variable
writer.WriteStartElement(info.GetName()); //Not using WriteElementsString so need to preface with the XML Tag
writer.WriteBase64(byteArray, 0, byteArray.Length); //Just use base64 XML Writer
writer.WriteEndElement(); //Close the xml tag
continue;
}
writer.WriteElementString(salesforceName, SalesforceNamespaces.SObject, xmlValue);
}
if (OperationType != CrudOperations.Insert)
{
foreach (string field in fieldsToNull)
writer.WriteElementString("fieldsToNull", SalesforceNamespaces.SObject, field);
}
}
示例6: WriteArrayBase64
internal static void WriteArrayBase64(XmlWriter writer, byte[] inData, int start, int count)
{
if (inData == null || count == 0)
{
return;
}
writer.WriteBase64(inData, start, count);
}
示例7: WriteToken
/// <summary>
/// Serializes an RSA security token to XML.
/// </summary>
/// <param name="writer">The XML writer.</param>
/// <param name="token">An RSA security token.</param>
/// <exception cref="ArgumentNullException">The input argument 'writer' is null.</exception>
/// <exception cref="InvalidOperationException">The input argument 'token' is either null or not of type
/// <see cref="RsaSecurityToken"/>.</exception>
public override void WriteToken(XmlWriter writer, SecurityToken token)
{
if (writer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
}
if (token == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("token");
}
RsaSecurityToken rsaToken = token as RsaSecurityToken;
if (rsaToken == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("token", SR.GetString(SR.ID0018, typeof(RsaSecurityToken)));
}
RSAParameters rsaParams = rsaToken.Rsa.ExportParameters(false);
writer.WriteStartElement(XmlSignatureConstants.Elements.KeyInfo, XmlSignatureConstants.Namespace);
writer.WriteStartElement(XmlSignatureConstants.Elements.KeyValue, XmlSignatureConstants.Namespace);
//
// RSA.ToXmlString shouldn't be used here because it doesn't write namespaces. The modulus and exponent are written manually.
//
writer.WriteStartElement(XmlSignatureConstants.Elements.RsaKeyValue, XmlSignatureConstants.Namespace);
writer.WriteStartElement(XmlSignatureConstants.Elements.Modulus, XmlSignatureConstants.Namespace);
byte[] modulus = rsaParams.Modulus;
writer.WriteBase64(modulus, 0, modulus.Length);
writer.WriteEndElement(); // </modulus>
writer.WriteStartElement(XmlSignatureConstants.Elements.Exponent, XmlSignatureConstants.Namespace);
byte[] exponent = rsaParams.Exponent;
writer.WriteBase64(exponent, 0, exponent.Length);
writer.WriteEndElement(); // </exponent>
writer.WriteEndElement(); // </RsaKeyValue>
writer.WriteEndElement(); // </KeyValue>
writer.WriteEndElement(); // </KeyInfo>
}
示例8: WriteImageElement
public static void WriteImageElement(XmlWriter writer, string nodeName, bool includeImages, string imageUrl)
{
writer.WriteStartElement(nodeName);
if (includeImages)
{
byte[] buffer = ConvertToBytes(imageUrl);
writer.WriteBase64(buffer, 0, buffer.Length);
}
else
{
writer.WriteString(imageUrl);
}
writer.WriteEndElement();
}
示例9: WriteToken
/// <summary>
/// Writes the X509SecurityToken to the given XmlWriter.
/// </summary>
/// <param name="writer">XmlWriter to write the token into.</param>
/// <param name="token">The SecurityToken of type X509SecurityToken to be written.</param>
/// <exception cref="ArgumentNullException">The parameter 'writer' or 'token' is null.</exception>
/// <exception cref="ArgumentException">The token is not of type X509SecurityToken.</exception>
public override void WriteToken(XmlWriter writer, SecurityToken token)
{
if (writer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
}
if (token == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("token");
}
X509SecurityToken x509Token = token as X509SecurityToken;
if (x509Token == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("token", SR.GetString(SR.ID0018, typeof(X509SecurityToken)));
}
writer.WriteStartElement(WSSecurity10Constants.Elements.BinarySecurityToken, WSSecurity10Constants.Namespace);
if (!String.IsNullOrEmpty(x509Token.Id))
{
writer.WriteAttributeString(WSSecurityUtilityConstants.Attributes.Id, WSSecurityUtilityConstants.Namespace, x509Token.Id);
}
writer.WriteAttributeString(WSSecurity10Constants.Attributes.ValueType, null, WSSecurity10Constants.X509TokenType);
writer.WriteAttributeString(WSSecurity10Constants.Attributes.EncodingType, WSSecurity10Constants.Base64EncodingType);
byte[] rawData = x509Token.Certificate.GetRawCertData();
writer.WriteBase64(rawData, 0, rawData.Length);
writer.WriteEndElement();
}
示例10: WriteTo
public void WriteTo(XmlWriter writer)
{
writer.WriteStartElement(XmlEncryptionStrings.Prefix, XmlEncryptionStrings.CipherData, XmlEncryptionStrings.Namespace);
writer.WriteStartElement(XmlEncryptionStrings.Prefix, XmlEncryptionStrings.CipherValue, XmlEncryptionStrings.Namespace);
if (this.m_iv != null)
writer.WriteBase64(this.m_iv, 0, this.m_iv.Length);
writer.WriteBase64(this.m_cipherText, 0, this.m_cipherText.Length);
writer.WriteEndElement(); // CipherValue
writer.WriteEndElement(); // CipherData
}
示例11: Serialize
/// <summary>
///
/// </summary>
/// <param name="xtw"></param>
/// <param name="o"></param>
/// <param name="mappingAction"></param>
/// <param name="nestedObjs"></param>
public void Serialize(
XmlWriter xtw,
Object o,
NullMappingAction mappingAction,
List<object> nestedObjs)
{
if (nestedObjs.Contains(o))
throw new XmlRpcUnsupportedTypeException(nestedObjs[0].GetType(),
"Cannot serialize recursive data structure");
nestedObjs.Add(o);
try
{
xtw.WriteStartElement("", "value", "");
XmlRpcType xType = XmlRpcTypeInfo.GetXmlRpcType(o);
if (xType == XmlRpcType.tArray)
{
xtw.WriteStartElement("", "array", "");
xtw.WriteStartElement("", "data", "");
Array a = (Array)o;
foreach (Object aobj in a)
{
//if (aobj == null)
// throw new XmlRpcMappingSerializeException(String.Format(
// "Items in array cannot be null ({0}[]).",
//o.GetType().GetElementType()));
Serialize(xtw, aobj, mappingAction, nestedObjs);
}
WriteFullEndElement(xtw);
WriteFullEndElement(xtw);
}
else if (xType == XmlRpcType.tMultiDimArray)
{
Array mda = (Array)o;
int[] indices = new int[mda.Rank];
BuildArrayXml(xtw, mda, 0, indices, mappingAction, nestedObjs);
}
else if (xType == XmlRpcType.tBase64)
{
byte[] buf = (byte[])o;
xtw.WriteStartElement("", "base64", "");
xtw.WriteBase64(buf, 0, buf.Length);
WriteFullEndElement(xtw);
}
else if (xType == XmlRpcType.tBoolean)
{
bool boolVal = (bool)o;
if (boolVal)
WriteFullElementString(xtw, "boolean", "1");
else
WriteFullElementString(xtw, "boolean", "0");
}
else if (xType == XmlRpcType.tDateTime)
{
DateTime dt = (DateTime)o;
string sdt = dt.ToString("yyyyMMdd'T'HH':'mm':'ss",
DateTimeFormatInfo.InvariantInfo);
WriteFullElementString(xtw, "dateTime.iso8601", sdt);
}
else if (xType == XmlRpcType.tDouble)
{
double doubleVal = (double)o;
WriteFullElementString(xtw, "double", doubleVal.ToString(null,
CultureInfo.InvariantCulture));
}
else if (xType == XmlRpcType.tHashtable)
{
xtw.WriteStartElement("", "struct", "");
XmlRpcStruct xrs = o as XmlRpcStruct;
foreach (object obj in xrs.Keys)
{
string skey = obj as string;
xtw.WriteStartElement("", "member", "");
WriteFullElementString(xtw, "name", skey);
Serialize(xtw, xrs[skey], mappingAction, nestedObjs);
WriteFullEndElement(xtw);
}
WriteFullEndElement(xtw);
}
else if (xType == XmlRpcType.tInt32)
{
if (o.GetType().IsEnum)
o = Convert.ToInt32(o);
if (UseIntTag)
WriteFullElementString(xtw, "int", o.ToString());
else
WriteFullElementString(xtw, "i4", o.ToString());
}
else if (xType == XmlRpcType.tInt64)
{
if (o.GetType().IsEnum)
o = Convert.ToInt64(o);
WriteFullElementString(xtw, "i8", o.ToString());
}
//.........这里部分代码省略.........
示例12: ExportImage
private void ExportImage(XmlWriter writer, Image image)
{
writer.WriteStartElement(Keys.Image);
writer.WriteAttributeString(Keys.Type, image.Type.ToString());
if (image.MimeType == "application/unknown")
{
image.MimeType = MimeHelper.GetMimeTypeForExtension(image.Extension);
}
writer.WriteAttributeString(Keys.MimeType, image.MimeType);
writer.WriteAttributeString(Keys.Extension, image.Extension);
writer.WriteAttributeString(Keys.Description, image.Description);
writer.WriteAttributeString(Keys.IsMain, image.IsMain.ToString());
byte[] imageBytes = this.collectionManager.ImageHandler.LoadImage(image);
writer.WriteBase64(imageBytes, 0, imageBytes.Length);
writer.WriteEndElement();
}
示例13: WriteValue
protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
{
if (strNamespace != null)
{
mXmlWriter.WriteStartElement(valueElt, strNamespace);
}
else
{
mXmlWriter.WriteStartElement(valueElt);
}
if (value.IsBinary && (value.BinaryVal != null))
{
mXmlWriter.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", "xsd:base64Binary");
mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
}
else
{
mXmlWriter.WriteString(value.StringVal);
}
mXmlWriter.WriteEndElement();
}
示例14: WriteXml
//.........这里部分代码省略.........
if (!string.IsNullOrEmpty(address.DisplayName))
writer.WriteAttributeString("DisplayName", address.DisplayName);
writer.WriteRaw(address.Address);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
// CC
if (this.Email.CC.Count > 0)
{
writer.WriteStartElement("CC");
writer.WriteStartElement("Addresses");
foreach (MailAddress address in this.Email.CC)
{
writer.WriteStartElement("Address");
if (!string.IsNullOrEmpty(address.DisplayName))
writer.WriteAttributeString("DisplayName", address.DisplayName);
writer.WriteRaw(address.Address);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
}
// Bcc
if (this.Email.Bcc.Count > 0)
{
writer.WriteStartElement("Bcc");
writer.WriteStartElement("Addresses");
foreach (MailAddress address in this.Email.Bcc)
{
writer.WriteStartElement("Address");
if (!string.IsNullOrEmpty(address.DisplayName))
writer.WriteAttributeString("DisplayName", address.DisplayName);
writer.WriteRaw(address.Address);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
}
// Subject
writer.WriteStartElement("Subject");
writer.WriteRaw(this.Email.Subject);
writer.WriteEndElement();
// Body
writer.WriteStartElement("Body");
writer.WriteCData(this.Email.Body);
writer.WriteEndElement();
// ReplyTo
if (this.Email.ReplyTo != null)
{
writer.WriteStartElement("ReplyTo");
if (!string.IsNullOrEmpty(this.Email.ReplyTo.DisplayName))
writer.WriteAttributeString("DisplayName", this.Email.ReplyTo.DisplayName);
writer.WriteRaw(this.Email.ReplyTo.Address);
writer.WriteEndElement();
}
// Sender
if (this.Email.Sender != null)
{
writer.WriteStartElement("Sender");
if (!string.IsNullOrEmpty(this.Email.Sender.DisplayName))
writer.WriteAttributeString("DisplayName", this.Email.Sender.DisplayName);
writer.WriteRaw(this.Email.Sender.Address);
writer.WriteEndElement();
}
// Attachments
if (this.Email.Attachments.Count > 0)
{
writer.WriteStartElement("Attachments");
foreach (Attachment attachment in this.Email.Attachments)
{
writer.WriteStartElement("Attachment");
if (!string.IsNullOrEmpty(attachment.Name))
writer.WriteAttributeString("ContentType", attachment.ContentType.ToString());
using (BinaryReader reader = new BinaryReader(attachment.ContentStream))
{
byte[] data = reader.ReadBytes((int)attachment.ContentStream.Length);
writer.WriteBase64(data, 0, data.Length);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}
示例15: WriteBinaryData
/// <summary>
/// Write binary chunk data according to encoding type to xml script.
/// </summary>
/// <param name="writer">Xml writer.</param>
/// <param name="chunkEncoding">Encoding of the chunk.</param>
/// <param name="chunkData">Chunk data.</param>
private static void WriteBinaryData(XmlWriter writer, ScriptAcousticChunkEncoding chunkEncoding,
Collection<float> chunkData)
{
Debug.Assert(writer != null);
Debug.Assert(chunkEncoding == ScriptAcousticChunkEncoding.Base64Binary ||
chunkEncoding == ScriptAcousticChunkEncoding.HexBinary);
int bufSize = chunkData.Count * sizeof(float);
byte[] bytes = new byte[bufSize];
int bytesIndex = 0;
for (int i = 0; i < chunkData.Count; i++)
{
byte[] floatBytes = BitConverter.GetBytes(chunkData[i]);
for (int j = 0; j < sizeof(float); j++)
{
bytes[bytesIndex] = floatBytes[j];
bytesIndex ++;
}
}
switch (chunkEncoding)
{
case ScriptAcousticChunkEncoding.Base64Binary:
writer.WriteBase64(bytes, 0, bufSize);
break;
case ScriptAcousticChunkEncoding.HexBinary:
writer.WriteBinHex(bytes, 0, bufSize);
break;
}
}