本文整理匯總了C#中System.Xml.XmlTextWriter.WriteBase64方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextWriter.WriteBase64方法的具體用法?C# XmlTextWriter.WriteBase64怎麽用?C# XmlTextWriter.WriteBase64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteBase64方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Save
/// <summary>
/// Only subscribed keys in the same namespace are saved.
/// </summary>
/// <param name="dict"></param>
/// <returns>XML file</returns>
public static MemoryStream Save(P2PDictionary dict)
{
MemoryStream writeStream = new MemoryStream();
System.Xml.XmlTextWriter writer = new XmlTextWriter(writeStream, Encoding.UTF8);
ICollection<string> keys = dict.Keys;
writer.WriteStartDocument();
writer.WriteStartElement("p2pdictionary");
writer.WriteStartElement("namespace");
writer.WriteAttributeString("name", dict.Namespace);
writer.WriteAttributeString("description", dict.Description);
IFormatter formatter = new BinaryFormatter();
foreach (string k in keys)
{
writer.WriteStartElement("entry");
writer.WriteAttributeString("key", k);
using (MemoryStream contents = new MemoryStream())
{
formatter.Serialize(contents, dict[k]);
writer.WriteBase64(contents.GetBuffer(), 0, (int)contents.Length);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
return writeStream;
}
示例2: ToXml
public void ToXml(XmlTextWriter writer)
{
writer.WriteStartElement("Plugin");
writer.WriteElementString("FileName", _fileName);
writer.WriteStartElement("Data");
writer.WriteBase64(_serializedData, 0, _serializedData.Length);
writer.WriteEndElement();
writer.WriteEndElement();
}
示例3: WriteBytes
static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
{
writer.WriteStartElement(name);
byte[] d;
if (data != null)
d = data;
else
d = Utils.EmptyBytes;
writer.WriteBase64(d, 0, d.Length);
writer.WriteEndElement(); // name
}
示例4: ToXml
/// <summary>
/// Converts the object passed in to its XML representation.
/// The XML string is written on the XmlTextWriter.
/// </summary>
public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context)
{
Type type = value.GetType();
if ( type.IsArray )
{
byte[] bytes = value as byte[];
context.WriteStartTag( __arrayType, field, xml );
xml.WriteBase64( bytes, 0, bytes.Length );
context.WriteEndTag( __arrayType, field, xml );
}
else
{
context.WriteStartTag( __type, field, xml );
xml.WriteString( value.ToString() );
context.WriteEndTag( __type, field, xml );
}
}
示例5: SOPToXml
//.........這裏部分代碼省略.........
Vector3 groupPosition;
if (parent == null)
groupPosition = prim.Position;
else
groupPosition = parent.Position;
WriteVector(writer, "GroupPosition", groupPosition);
if (prim.ParentID == 0)
WriteVector(writer, "OffsetPosition", Vector3.Zero);
else
WriteVector(writer, "OffsetPosition", prim.Position);
WriteQuaternion(writer, "RotationOffset", prim.Rotation);
WriteVector(writer, "Velocity", prim.Velocity);
WriteVector(writer, "RotationalVelocity", Vector3.Zero);
WriteVector(writer, "AngularVelocity", prim.AngularVelocity);
WriteVector(writer, "Acceleration", prim.Acceleration);
writer.WriteElementString("Description", prim.Description);
writer.WriteStartElement("Color");
writer.WriteElementString("R", prim.TextColor.R.ToString(Utils.EnUsCulture));
writer.WriteElementString("G", prim.TextColor.G.ToString(Utils.EnUsCulture));
writer.WriteElementString("B", prim.TextColor.B.ToString(Utils.EnUsCulture));
writer.WriteElementString("A", prim.TextColor.G.ToString(Utils.EnUsCulture));
writer.WriteEndElement();
writer.WriteElementString("Text", prim.Text);
writer.WriteElementString("SitName", prim.SitName);
writer.WriteElementString("TouchName", prim.TouchName);
writer.WriteElementString("LinkNum", prim.LinkNumber.ToString());
writer.WriteElementString("ClickAction", prim.ClickAction.ToString());
writer.WriteStartElement("Shape");
writer.WriteElementString("PathBegin", Primitive.PackBeginCut(prim.Shape.PathBegin).ToString());
writer.WriteElementString("PathCurve", prim.Shape.PathCurve.ToString());
writer.WriteElementString("PathEnd", Primitive.PackEndCut(prim.Shape.PathEnd).ToString());
writer.WriteElementString("PathRadiusOffset", Primitive.PackPathTwist(prim.Shape.PathRadiusOffset).ToString());
writer.WriteElementString("PathRevolutions", Primitive.PackPathRevolutions(prim.Shape.PathRevolutions).ToString());
writer.WriteElementString("PathScaleX", Primitive.PackPathScale(prim.Shape.PathScaleX).ToString());
writer.WriteElementString("PathScaleY", Primitive.PackPathScale(prim.Shape.PathScaleY).ToString());
writer.WriteElementString("PathShearX", ((byte)Primitive.PackPathShear(prim.Shape.PathShearX)).ToString());
writer.WriteElementString("PathShearY", ((byte)Primitive.PackPathShear(prim.Shape.PathShearY)).ToString());
writer.WriteElementString("PathSkew", Primitive.PackPathTwist(prim.Shape.PathSkew).ToString());
writer.WriteElementString("PathTaperX", Primitive.PackPathTaper(prim.Shape.PathTaperX).ToString());
writer.WriteElementString("PathTaperY", Primitive.PackPathTaper(prim.Shape.PathTaperY).ToString());
writer.WriteElementString("PathTwist", Primitive.PackPathTwist(prim.Shape.PathTwist).ToString());
writer.WriteElementString("PathTwistBegin", Primitive.PackPathTwist(prim.Shape.PathTwistBegin).ToString());
writer.WriteElementString("PCode", prim.PCode.ToString());
writer.WriteElementString("ProfileBegin", Primitive.PackBeginCut(prim.Shape.ProfileBegin).ToString());
writer.WriteElementString("ProfileEnd", Primitive.PackEndCut(prim.Shape.ProfileEnd).ToString());
writer.WriteElementString("ProfileHollow", Primitive.PackProfileHollow(prim.Shape.ProfileHollow).ToString());
WriteVector(writer, "Scale", prim.Scale);
writer.WriteElementString("State", prim.State.ToString());
AssetPrim.ProfileShape shape = (AssetPrim.ProfileShape)(prim.Shape.ProfileCurve & 0x0F);
HoleType hole = (HoleType)(prim.Shape.ProfileCurve & 0xF0);
writer.WriteElementString("ProfileShape", shape.ToString());
writer.WriteElementString("HollowShape", hole.ToString());
writer.WriteElementString("ProfileCurve", prim.Shape.ProfileCurve.ToString());
writer.WriteStartElement("TextureEntry");
byte[] te;
if (prim.Textures != null)
te = prim.Textures.GetBytes();
else
te = Utils.EmptyBytes;
writer.WriteBase64(te, 0, te.Length);
writer.WriteEndElement();
// FIXME: ExtraParams
writer.WriteStartElement("ExtraParams"); writer.WriteEndElement();
writer.WriteEndElement();
WriteVector(writer, "Scale", prim.Scale);
writer.WriteElementString("UpdateFlag", "0");
WriteVector(writer, "SitTargetOrientation", Vector3.UnitZ); // TODO: Is this really a vector and not a quaternion?
WriteVector(writer, "SitTargetPosition", prim.SitOffset);
WriteVector(writer, "SitTargetPositionLL", prim.SitOffset);
WriteQuaternion(writer, "SitTargetOrientationLL", prim.SitRotation);
writer.WriteElementString("ParentID", prim.ParentID.ToString());
writer.WriteElementString("CreationDate", ((int)Utils.DateTimeToUnixTime(prim.CreationDate)).ToString());
writer.WriteElementString("Category", "0");
writer.WriteElementString("SalePrice", prim.SalePrice.ToString());
writer.WriteElementString("ObjectSaleType", ((int)prim.SaleType).ToString());
writer.WriteElementString("OwnershipCost", "0");
WriteUUID(writer, "GroupID", prim.GroupID);
WriteUUID(writer, "OwnerID", prim.OwnerID);
WriteUUID(writer, "LastOwnerID", prim.LastOwnerID);
writer.WriteElementString("BaseMask", ((uint)PermissionMask.All).ToString());
writer.WriteElementString("OwnerMask", ((uint)PermissionMask.All).ToString());
writer.WriteElementString("GroupMask", ((uint)PermissionMask.All).ToString());
writer.WriteElementString("EveryoneMask", ((uint)PermissionMask.All).ToString());
writer.WriteElementString("NextOwnerMask", ((uint)PermissionMask.All).ToString());
writer.WriteElementString("Flags", "None");
WriteUUID(writer, "SitTargetAvatar", UUID.Zero);
writer.WriteEndElement();
}
示例6: SOGToXml2
////////// Write /////////
public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
{
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
SOPToXml2(writer, sog.RootPart, options);
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
sog.ForEachPart(delegate(SceneObjectPart sop)
{
if (sop.UUID != sog.RootPart.UUID)
SOPToXml2(writer, sop, options);
});
writer.WriteEndElement();
if (sog.RootPart.KeyframeMotion != null)
{
Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
writer.WriteBase64(data, 0, data.Length);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
示例7: SerializeProperty
private void SerializeProperty(XmlTextWriter xmlTextWriter, NuGenPropertyInfo propertyInfo)
{
string propertyName = XmlConvert.EncodeName(
NuGenSerializer.GetStringFromProperty(propertyInfo.Name)
);
if (propertyInfo.Value == null)
{
if (propertyInfo.DefaultValue != null)
{
xmlTextWriter.WriteStartElement(propertyName);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsNull, Resources.XmlValue_True);
xmlTextWriter.WriteEndElement();
}
}
else if (propertyInfo.IsKey)
{
if (propertyInfo.IsReference)
{
xmlTextWriter.WriteStartElement(propertyName);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsRef, propertyInfo.ReferenceCode.ToString(CultureInfo.InvariantCulture));
xmlTextWriter.WriteEndElement();
}
else
{
xmlTextWriter.WriteStartElement(propertyName);
if (propertyInfo.ReferenceCode != -1)
{
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_Ref, propertyInfo.ReferenceCode.ToString(CultureInfo.InvariantCulture));
}
if (propertyInfo.Value != null)
{
string typeString = (string)NuGenSerializer.TypeToString[propertyInfo.Value.GetType()];
if (typeString == null)
{
typeString = propertyInfo.Value.GetType().FullName;
}
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_Type, typeString);
}
if (propertyInfo.IsSerializable)
{
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsSer, Resources.XmlValue_True);
INuGenSerializable serializable = (INuGenSerializable)propertyInfo.Value;
serializable.Serialize(_converter, xmlTextWriter);
_graph.Add(serializable, propertyInfo.ReferenceCode);
}
else
{
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsKey, Resources.XmlValue_True);
this.SerializeObject(xmlTextWriter, propertyInfo.Properties);
}
xmlTextWriter.WriteEndElement();
}
}
else if (propertyInfo.IsList)
{
xmlTextWriter.WriteStartElement(propertyName);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsList, Resources.XmlValue_True);
if (propertyInfo.Value != null)
{
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_Count, propertyInfo.Count.ToString(CultureInfo.InvariantCulture));
}
this.SerializeObject(xmlTextWriter, propertyInfo.Properties);
xmlTextWriter.WriteEndElement();
}
else if (propertyInfo.Value is Metafile)
{
xmlTextWriter.WriteStartElement(propertyName);
Metafile metafile = (Metafile)propertyInfo.Value;
byte[] buffer = NuGenMetafileConverter.MetafileToBytes(metafile);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsEmfImage, Resources.XmlValue_True);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_Length, buffer.Length.ToString(CultureInfo.InvariantCulture));
xmlTextWriter.WriteBase64(buffer, 0, buffer.Length);
xmlTextWriter.WriteEndElement();
}
else if (propertyInfo.Value is Image)
{
xmlTextWriter.WriteStartElement(propertyName);
Image image = (Image)propertyInfo.Value;
byte[] buffer = NuGenImageConverter.ImageToBytes(image);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_IsImage, Resources.XmlValue_True);
xmlTextWriter.WriteAttributeString(Resources.XmlAttribute_Length, buffer.Length.ToString(CultureInfo.InvariantCulture));
xmlTextWriter.WriteBase64(buffer, 0, buffer.Length);
xmlTextWriter.WriteEndElement();
//.........這裏部分代碼省略.........
示例8: WriteShape
public static void WriteShape(XmlTextWriter writer, Primitive prim, Primitive.ObjectProperties props, Primitive.ConstructionData shp, ImportSettings options)
{
if (true /*shp != null*/)
{
writer.WriteStartElement("Shape");
WriteEnum(writer, "ProfileCurve", shp.ProfileCurve);
writer.WriteStartElement("TextureEntry");
byte[] te;
if (prim.Textures != null)
te = prim.Textures.GetBytes();
else
te = Utils.EmptyBytes;
writer.WriteBase64(te, 0, te.Length);
writer.WriteEndElement(); // TextureEntry
writer.WriteStartElement("ExtraParams");
byte[] ep;
if (prim.GetExtraParamsBytes() != null)
ep = prim.GetExtraParamsBytes();
else
ep = Utils.EmptyBytes;
writer.WriteBase64(ep, 0, ep.Length);
writer.WriteEndElement(); // ExtraParams
writer.WriteElementString("PathBegin", Primitive.PackBeginCut(shp.PathBegin).ToString());
WriteEnum(writer, "PathCurve", shp.PathCurve);
writer.WriteElementString("PathEnd", Primitive.PackEndCut(shp.PathEnd).ToString());
writer.WriteElementString("PathRadiusOffset", Primitive.PackPathTwist(shp.PathRadiusOffset).ToString());
writer.WriteElementString("PathRevolutions", Primitive.PackPathRevolutions(shp.PathRevolutions).ToString());
writer.WriteElementString("PathScaleX", Primitive.PackPathScale(shp.PathScaleX).ToString());
writer.WriteElementString("PathScaleY", Primitive.PackPathScale(shp.PathScaleY).ToString());
writer.WriteElementString("PathShearX", ((byte)Primitive.PackPathShear(shp.PathShearX)).ToString());
writer.WriteElementString("PathShearY", ((byte)Primitive.PackPathShear(shp.PathShearY)).ToString());
writer.WriteElementString("PathSkew", Primitive.PackPathTwist(shp.PathSkew).ToString());
writer.WriteElementString("PathTaperX", Primitive.PackPathTaper(shp.PathTaperX).ToString());
writer.WriteElementString("PathTaperY", Primitive.PackPathTaper(shp.PathTaperY).ToString());
writer.WriteElementString("PathTwist", Primitive.PackPathTwist(shp.PathTwist).ToString());
writer.WriteElementString("PathTwistBegin", Primitive.PackPathTwist(shp.PathTwistBegin).ToString());
writer.WriteElementString("ProfileBegin", Primitive.PackBeginCut(shp.ProfileBegin).ToString());
writer.WriteElementString("ProfileEnd", Primitive.PackEndCut(shp.ProfileEnd).ToString());
writer.WriteElementString("ProfileHollow", Primitive.PackProfileHollow(shp.ProfileHollow).ToString());
WriteEnum(writer, "PCode", shp.PCode);
// this is Attachment in a way?
WriteInt(writer, "State", shp.State);
//WriteEnum(writer, "State", shp.AttachmentPoint);
WriteFlags(writer, "ProfileShape", shp.ProfileCurve, options);
WriteFlags(writer, "HollowShape", shp.ProfileHole, options);
var Sculpt = prim.Sculpt;
if (Sculpt != null)
{
WriteUUID(writer, "SculptTexture", Sculpt.SculptTexture, options);
WriteEnum(writer, "SculptType", Sculpt.Type);
writer.WriteStartElement("SculptData");
byte[] sd;
if (prim.Sculpt != null)
sd = Sculpt.GetBytes();
else
sd = Utils.EmptyBytes;
writer.WriteBase64(sd, 0, sd.Length);
writer.WriteEndElement(); // SculptData
}
Primitive.FlexibleData Flexi = prim.Flexible;
if (Flexi != null)
{
WriteInt(writer,"FlexiSoftness", Flexi.Softness);
WriteFloat(writer,"FlexiTension", Flexi.Tension);
WriteFloat(writer,"FlexiDrag", Flexi.Drag);
WriteFloat(writer,"FlexiGravity", Flexi.Gravity);
WriteFloat(writer,"FlexiWind", Flexi.Wind);
WriteFloat(writer,"FlexiForceX", Flexi.Force.X);
WriteFloat(writer,"FlexiForceY", Flexi.Force.Y);
WriteFloat(writer,"FlexiForceZ", Flexi.Force.Z);
}
Primitive.LightData Light = prim.Light;
if (Light != null)
{
WriteFloat(writer,"LightColorR", Light.Color.R);
WriteFloat(writer,"LightColorG", Light.Color.G);
WriteFloat(writer,"LightColorB", Light.Color.B);
WriteFloat(writer,"LightColorA", Light.Color.A);
WriteFloat(writer,"LightRadius", Light.Radius);
WriteFloat(writer,"LightCutoff", Light.Cutoff);
WriteFloat(writer,"LightFalloff", Light.Falloff);
WriteFloat(writer,"LightIntensity", Light.Intensity);
}
WriteValue(writer,"FlexiEntry", (Flexi != null).ToString().ToLower());
WriteValue(writer,"LightEntry", (Light != null).ToString().ToLower());
WriteValue(writer,"SculptEntry", (Sculpt != null).ToString().ToLower());
//todo if (shp.Media != null) WES(writer,"Media", shp.Media.ToXml());
//.........這裏部分代碼省略.........
示例9: GetImageAsXml
/// <summary>
/// Takes an image and writes it as an Image element to the Xml stream provided.
/// </summary>
private void GetImageAsXml( Image img, XmlTextWriter xml )
{
xml.WriteStartElement( "Object" );
xml.WriteAttributeString( "guid", Guid.NewGuid().ToString("B") );
xml.WriteStartElement( "Position" );
xml.WriteAttributeString( "x", "0" );
xml.WriteAttributeString( "y", "0" );
xml.WriteEndElement(); // end Position
xml.WriteStartElement( "Image" );
xml.WriteAttributeString( "backgroundImage", "true" );
// Set size of image
SizeF imageSize = GetSlideSize( img );
xml.WriteAttributeString( "width", (imageSize.Width).ToString() );
xml.WriteAttributeString( "height", (imageSize.Height).ToString() );
// Write the image in the xml as Base64
xml.WriteStartElement( "Data" );
byte[] bits;
if( img.RawFormat.Equals( ImageFormat.Emf ) || img.RawFormat.Equals( ImageFormat.Wmf ) )
{
// The image goes bad during serialization, so we have to clone it.
Metafile mf = (Metafile)((Metafile)img).Clone();
IntPtr ptr = mf.GetHenhmetafile();
Debug.Assert(ptr != IntPtr.Zero, "Failed to get pointer to image.");
uint size = GetEnhMetaFileBits(ptr, 0, null);
bits = new byte[size];
uint numBits = GetEnhMetaFileBits(ptr, size, bits);
mf.Dispose();
Debug.Assert(size == numBits, "Improper serialization of metafile!");
}
else
{
MemoryStream imgMS = new MemoryStream();
img.Save(imgMS, System.Drawing.Imaging.ImageFormat.Jpeg);
bits = imgMS.ToArray();
}
xml.WriteBase64(bits, 0, bits.Length);
xml.WriteEndElement(); // end Data
xml.WriteEndElement(); // end Image
xml.WriteEndElement(); // end Object
}
示例10: buildNetBLOB
public static byte[] buildNetBLOB(Deck deck, int uploaderID)
{
Card curCard;
eObject curObj;
IEnumerator objEnum;
IEnumerator cardEnum;
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8);
//Use automatic indentation for readability.
writer.Formatting = Formatting.Indented;
//Write the root element
writer.WriteStartElement("eFlash-Network");
//Start an element
writer.WriteStartElement("Deck");
//Add attribute to Deck
writer.WriteAttributeString("cat", deck.category);
writer.WriteAttributeString("subcat", deck.subcategory);
writer.WriteAttributeString("title", deck.title);
writer.WriteAttributeString("type", deck.type);
writer.WriteAttributeString("nuid", Convert.ToString(uploaderID));
cardEnum = deck.cardList.GetEnumerator();
while (cardEnum.MoveNext())
{
//Load the cards belonging to this deck
curCard = (Card)cardEnum.Current;
writer.WriteStartElement("Card");
writer.WriteAttributeString("tag",curCard.tag);
objEnum = curCard.eObjectList.GetEnumerator();
while (objEnum.MoveNext())
{
curObj = (eObject)objEnum.Current;
writer.WriteStartElement("Object");
writer.WriteAttributeString("size", Convert.ToString(curObj.efile.size));
writer.WriteAttributeString("side", Convert.ToString(curObj.side));
writer.WriteAttributeString("type", Convert.ToString(curObj.type));
writer.WriteAttributeString("quizType", Convert.ToString(curObj.quizType));
writer.WriteAttributeString("x1", Convert.ToString(curObj.x1));
writer.WriteAttributeString("x2", Convert.ToString(curObj.x2));
writer.WriteAttributeString("y1", Convert.ToString(curObj.y1));
writer.WriteAttributeString("y2", Convert.ToString(curObj.y2));
writer.WriteBase64(curObj.efile.rawData, 0, curObj.efile.size);
// end the Object element
writer.WriteEndElement();
}
// end the Card element
writer.WriteEndElement();
}
// end the Deck element
writer.WriteEndElement();
// end the root element
writer.WriteFullEndElement();
//writer.WriteEndDocument();
//Close the writer and stream
writer.Close();
stream.Close();
return stream.ToArray();
}
示例11: Save
public static void Save(string filePath, object options)
{
Byte[] buffer = new Byte[80];
MemoryStream ms;
BinaryFormatter bf = new BinaryFormatter();
System.Xml.XmlTextWriter xmlwriter =
new XmlTextWriter(filePath, System.Text.Encoding.Default);
xmlwriter.Formatting = Formatting.Indented;
xmlwriter.WriteStartDocument();
//xmlwriter.WriteComment("Option File. Do not edit! (c)[email protected]");
xmlwriter.WriteStartElement(options.ToString());
PropertyInfo[] props = options.GetType().GetProperties(
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.SetField);
foreach (PropertyInfo prop in props)
{
xmlwriter.WriteStartElement(prop.Name);
object da = prop.GetValue(options, null);
if (da != null)
{
xmlwriter.WriteAttributeString("Value", da.ToString());
ms = new MemoryStream();
try
{
bf.Serialize(ms, da);
ms.Position = 0;
int count = 0;
do
{
count = ms.Read(buffer, 0, buffer.Length);
xmlwriter.WriteBase64(buffer, 0, count);
}
while ( count == buffer.Length);
}
catch (System.Runtime.Serialization.SerializationException)
{
Console.WriteLine("SERIALIZATION FAILED: {0}", prop.Name);
}
}
else xmlwriter.WriteAttributeString("Value", "null");
xmlwriter.WriteEndElement();
}
xmlwriter.WriteEndElement();
xmlwriter.WriteEndDocument();
xmlwriter.Flush();
xmlwriter.Close();
}
示例12: ExportXml
private static void ExportXml(Stream stm, DataView vw, string sModuleName, int nStartRecord, int nEndRecord)
{
XmlTextWriter xw = new XmlTextWriter(stm, Encoding.UTF8);
xw.Formatting = Formatting.Indented;
xw.IndentChar = ControlChars.Tab;
xw.Indentation = 1;
xw.WriteStartDocument();
xw.WriteStartElement("Taoqi");
DataTable tbl = vw.Table;
for ( int i = nStartRecord; i < nEndRecord; i++ )
{
xw.WriteStartElement(sModuleName);
DataRowView row = vw[i];
for ( int nColumn = 0; nColumn < tbl.Columns.Count; nColumn++ )
{
DataColumn col = tbl.Columns[nColumn];
xw.WriteStartElement(col.ColumnName.ToLower());
if ( row[nColumn] != DBNull.Value )
{
switch ( col.DataType.FullName )
{
case "System.Boolean" : xw.WriteString(Sql.ToBoolean (row[nColumn]) ? "1" : "0"); break;
case "System.Single" : xw.WriteString(Sql.ToDouble (row[nColumn]).ToString() ); break;
case "System.Double" : xw.WriteString(Sql.ToDouble (row[nColumn]).ToString() ); break;
case "System.Int16" : xw.WriteString(Sql.ToInteger (row[nColumn]).ToString() ); break;
case "System.Int32" : xw.WriteString(Sql.ToInteger (row[nColumn]).ToString() ); break;
case "System.Int64" : xw.WriteString(Sql.ToLong (row[nColumn]).ToString() ); break;
case "System.Decimal" : xw.WriteString(Sql.ToDecimal (row[nColumn]).ToString() ); break;
case "System.DateTime": xw.WriteString(Sql.ToDateTime(row[nColumn]).ToUniversalTime().ToString(CalendarControl.SqlDateTimeFormat)); break;
case "System.Guid" : xw.WriteString(Sql.ToGuid (row[nColumn]).ToString().ToUpper()); break;
case "System.String" : xw.WriteString(Sql.ToString (row[nColumn])); break;
case "System.Byte[]" :
{
byte[] buffer = Sql.ToByteArray((System.Array) row[nColumn]);
xw.WriteBase64(buffer, 0, buffer.Length);
break;
}
//default:
// throw(new Exception("Unsupported field type: " + rdr.GetFieldType(nColumn).FullName));
}
}
xw.WriteEndElement();
}
xw.WriteEndElement();
}
xw.WriteEndElement();
xw.WriteEndDocument();
xw.Flush();
}
示例13: GetAuthenticationElement
/// <summary>
/// Creates a new stream element for user authentication.
/// </summary>
/// <param name="mech">The SASL authentication mechanism to use.</param>
/// <param name="domain">The user's authentication domain (for PLAIN authentication)</param>
/// <param name="username">The user's name (for PLAIN authentication)</param>
/// <param name="password">The user's password (for PLAIN authentication)</param>
/// <returns>A new authorization stanza for the given SASL authentication mechanism.</returns>
public static AuthenticationElement GetAuthenticationElement(SaslAuthenticationMechanism mech, string domain, string username, string password)
{
StringWriter xmlString = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(xmlString);
writer.WriteStartElement("auth");
writer.WriteAttributeString("xmlns", SASL_NAMESPACE);
switch(mech)
{
case SaslAuthenticationMechanism.DIGEST_MD5:
writer.WriteAttributeString("mechanism", "DIGEST-MD5");
break;
case SaslAuthenticationMechanism.PLAIN:
writer.WriteAttributeString("mechanism", "PLAIN");
string authStr = string.Format("{0}@{1}\x00{2}\x00{3}", username, domain, username, password);
byte[] bytes = Encoding.UTF8.GetBytes(authStr);
writer.WriteBase64(bytes, 0, bytes.Length);
break;
default:
throw new OpenXMPPException("Cannot create authorization stanza for mechanism "+mech+".");
}
writer.WriteEndElement();
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlString.ToString());
return new AuthenticationElement(xml.DocumentElement, mech, domain, username, password);
}
示例14: WriteShape
public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
{
if (shp != null)
{
writer.WriteStartElement("Shape");
writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
writer.WriteStartElement("TextureEntry");
byte[] te;
if (shp.TextureEntry != null)
te = shp.TextureEntry;
else
te = Utils.EmptyBytes;
writer.WriteBase64(te, 0, te.Length);
writer.WriteEndElement(); // TextureEntry
writer.WriteStartElement("ExtraParams");
byte[] ep;
if (shp.ExtraParams != null)
ep = shp.ExtraParams;
else
ep = Utils.EmptyBytes;
writer.WriteBase64(ep, 0, ep.Length);
writer.WriteEndElement(); // ExtraParams
writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
writer.WriteElementString("PCode", shp.PCode.ToString());
writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
writer.WriteElementString("State", shp.State.ToString());
WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
writer.WriteElementString("SculptType", shp.SculptType.ToString());
writer.WriteStartElement("SculptData");
byte[] sd;
if (shp.SculptData != null)
sd = shp.SculptData;
else
sd = Utils.EmptyBytes;
writer.WriteBase64(sd, 0, sd.Length);
writer.WriteEndElement(); // SculptData
writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString());
writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString());
writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString());
writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString());
writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString());
writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString());
writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString());
writer.WriteElementString("LightColorR", shp.LightColorR.ToString());
writer.WriteElementString("LightColorG", shp.LightColorG.ToString());
writer.WriteElementString("LightColorB", shp.LightColorB.ToString());
writer.WriteElementString("LightColorA", shp.LightColorA.ToString());
writer.WriteElementString("LightRadius", shp.LightRadius.ToString());
writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString());
writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString());
writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString());
writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
if (shp.Media != null)
writer.WriteElementString("Media", shp.Media.ToXml());
writer.WriteEndElement(); // Shape
}
}
示例15: SOPToXml
static void SOPToXml(XmlTextWriter writer, Primitive prim, Primitive parent)
{
writer.WriteStartElement("SceneObjectPart");
writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
WriteUUID(writer, "CreatorID", prim.Properties.CreatorID);
WriteUUID(writer, "FolderID", prim.Properties.FolderID);
writer.WriteElementString("InventorySerial", prim.Properties.InventorySerial.ToString());
writer.WriteStartElement("TaskInventory"); writer.WriteEndElement();
writer.WriteElementString("ObjectFlags", ((int)prim.Flags).ToString());
WriteUUID(writer, "UUID", prim.ID);
writer.WriteElementString("LocalId", prim.LocalID.ToString());
writer.WriteElementString("Name", prim.Properties.Name);
writer.WriteElementString("Material", ((int)prim.PrimData.Material).ToString());
writer.WriteElementString("RegionHandle", prim.RegionHandle.ToString());
writer.WriteElementString("ScriptAccessPin", "0");
Vector3 groupPosition;
if (parent == null)
groupPosition = prim.Position;
else
groupPosition = parent.Position;
WriteVector(writer, "GroupPosition", groupPosition);
WriteVector(writer, "OffsetPosition", groupPosition - prim.Position);
WriteQuaternion(writer, "RotationOffset", prim.Rotation);
WriteVector(writer, "Velocity", Vector3.Zero);
WriteVector(writer, "RotationalVelocity", Vector3.Zero);
WriteVector(writer, "AngularVelocity", prim.AngularVelocity);
WriteVector(writer, "Acceleration", Vector3.Zero);
writer.WriteElementString("Description", prim.Properties.Description);
writer.WriteStartElement("Color");
writer.WriteElementString("R", prim.TextColor.R.ToString());
writer.WriteElementString("G", prim.TextColor.G.ToString());
writer.WriteElementString("B", prim.TextColor.B.ToString());
writer.WriteElementString("A", prim.TextColor.G.ToString());
writer.WriteEndElement();
writer.WriteElementString("Text", prim.Text);
writer.WriteElementString("SitName", prim.Properties.SitName);
writer.WriteElementString("TouchName", prim.Properties.TouchName);
uint linknum = 0;
//if (parent != null)
// linknum = prim.LocalID - parent.LocalID;
writer.WriteElementString("LinkNum", linknum.ToString());
writer.WriteElementString("ClickAction", ((int)prim.ClickAction).ToString());
writer.WriteStartElement("Shape");
writer.WriteElementString("PathBegin", Primitive.PackBeginCut(prim.PrimData.PathBegin).ToString());
writer.WriteElementString("PathCurve", ((byte)prim.PrimData.PathCurve).ToString());
writer.WriteElementString("PathEnd", Primitive.PackEndCut(prim.PrimData.PathEnd).ToString());
writer.WriteElementString("PathRadiusOffset", Primitive.PackPathTwist(prim.PrimData.PathRadiusOffset).ToString());
writer.WriteElementString("PathRevolutions", Primitive.PackPathRevolutions(prim.PrimData.PathRevolutions).ToString());
writer.WriteElementString("PathScaleX", Primitive.PackPathScale(prim.PrimData.PathScaleX).ToString());
writer.WriteElementString("PathScaleY", Primitive.PackPathScale(prim.PrimData.PathScaleY).ToString());
writer.WriteElementString("PathShearX", ((byte)Primitive.PackPathShear(prim.PrimData.PathShearX)).ToString());
writer.WriteElementString("PathShearY", ((byte)Primitive.PackPathShear(prim.PrimData.PathShearY)).ToString());
writer.WriteElementString("PathSkew", Primitive.PackPathTwist(prim.PrimData.PathSkew).ToString());
writer.WriteElementString("PathTaperX", Primitive.PackPathTaper(prim.PrimData.PathTaperX).ToString());
writer.WriteElementString("PathTaperY", Primitive.PackPathTaper(prim.PrimData.PathTaperY).ToString());
writer.WriteElementString("PathTwist", Primitive.PackPathTwist(prim.PrimData.PathTwist).ToString());
writer.WriteElementString("PathTwistBegin", Primitive.PackPathTwist(prim.PrimData.PathTwistBegin).ToString());
writer.WriteElementString("PCode", ((byte)prim.PrimData.PCode).ToString());
writer.WriteElementString("ProfileBegin", Primitive.PackBeginCut(prim.PrimData.ProfileBegin).ToString());
writer.WriteElementString("ProfileEnd", Primitive.PackEndCut(prim.PrimData.ProfileEnd).ToString());
writer.WriteElementString("ProfileHollow", Primitive.PackProfileHollow(prim.PrimData.ProfileHollow).ToString());
WriteVector(writer, "Scale", prim.Scale);
writer.WriteElementString("State", prim.PrimData.State.ToString());
ProfileShape shape = (ProfileShape)prim.PrimData.ProfileCurve;
writer.WriteElementString("ProfileShape", shape.ToString());
writer.WriteElementString("HollowShape", prim.PrimData.ProfileHole.ToString());
writer.WriteElementString("ProfileCurve", prim.PrimData.profileCurve.ToString());
writer.WriteStartElement("TextureEntry");
byte[] te;
if (prim.Textures != null)
te = prim.Textures.ToBytes();
else
te = new byte[0];
writer.WriteBase64(te, 0, te.Length);
writer.WriteEndElement();
// FIXME: ExtraParams
writer.WriteStartElement("ExtraParams"); writer.WriteEndElement();
writer.WriteEndElement();
WriteVector(writer, "Scale", prim.Scale);
writer.WriteElementString("UpdateFlag", "0");
WriteVector(writer, "SitTargetOrientation", Vector3.UnitZ);
WriteVector(writer, "SitTargetPosition", Vector3.Zero);
WriteVector(writer, "SitTargetPositionLL", Vector3.Zero);
WriteQuaternion(writer, "SitTargetOrientationLL", new Quaternion(0f, 0f, 1f, 0f));
writer.WriteElementString("ParentID", prim.ParentID.ToString());
writer.WriteElementString("CreationDate", ((int)Utils.DateTimeToUnixTime(prim.Properties.CreationDate)).ToString());
//.........這裏部分代碼省略.........