/// <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; }
public override string ToString() { StringWriter sw = new StringWriter(); XmlTextWriter tw = new XmlTextWriter(sw); tw.WriteBase64(BinaryValue, 0, BinaryValue.Length); tw.Close(); return sw.ToString(); }
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(); }
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 }
/// <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 ); } }
static void SOPToXml(XmlTextWriter writer, PrimObject prim, PrimObject 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.CreatorID); WriteUUID(writer, "FolderID", prim.FolderID); writer.WriteElementString("InventorySerial", (prim.Inventory != null) ? prim.Inventory.Serial.ToString() : "0"); // FIXME: Task inventory writer.WriteStartElement("TaskInventory"); if (prim.Inventory != null) { foreach (PrimObject.InventoryBlock.ItemBlock item in prim.Inventory.Items) { writer.WriteStartElement("", "TaskInventoryItem", ""); WriteUUID(writer, "AssetID", item.AssetID); writer.WriteElementString("BasePermissions", item.PermsBase.ToString()); writer.WriteElementString("CreationDate", (item.CreationDate.ToUniversalTime() - Utils.Epoch).TotalSeconds.ToString()); WriteUUID(writer, "CreatorID", item.CreatorID); writer.WriteElementString("Description", item.Description); writer.WriteElementString("EveryonePermissions", item.PermsEveryone.ToString()); writer.WriteElementString("Flags", item.Flags.ToString()); WriteUUID(writer, "GroupID", item.GroupID); writer.WriteElementString("GroupPermissions", item.PermsGroup.ToString()); writer.WriteElementString("InvType", ((int)item.InvType).ToString()); WriteUUID(writer, "ItemID", item.ID); WriteUUID(writer, "OldItemID", UUID.Zero); WriteUUID(writer, "LastOwnerID", item.LastOwnerID); writer.WriteElementString("Name", item.Name); writer.WriteElementString("NextPermissions", item.PermsNextOwner.ToString()); WriteUUID(writer, "OwnerID", item.OwnerID); writer.WriteElementString("CurrentPermissions", item.PermsOwner.ToString()); WriteUUID(writer, "ParentID", prim.ID); WriteUUID(writer, "ParentPartID", prim.ID); WriteUUID(writer, "PermsGranter", item.PermsGranterID); writer.WriteElementString("PermsMask", "0"); writer.WriteElementString("Type", ((int)item.Type).ToString()); writer.WriteElementString("OwnerChanged", "false"); writer.WriteEndElement(); } } writer.WriteEndElement(); PrimFlags flags = PrimFlags.None; if (prim.UsePhysics) flags |= PrimFlags.Physics; if (prim.Phantom) flags |= PrimFlags.Phantom; if (prim.DieAtEdge) flags |= PrimFlags.DieAtEdge; if (prim.ReturnAtEdge) flags |= PrimFlags.ReturnAtEdge; if (prim.Temporary) flags |= PrimFlags.Temporary; if (prim.Sandbox) flags |= PrimFlags.Sandbox; writer.WriteElementString("ObjectFlags", ((int)flags).ToString()); WriteUUID(writer, "UUID", prim.ID); writer.WriteElementString("LocalId", prim.LocalID.ToString()); writer.WriteElementString("Name", prim.Name); writer.WriteElementString("Material", ((int)prim.Material).ToString()); writer.WriteElementString("RegionHandle", prim.RegionHandle.ToString()); writer.WriteElementString("ScriptAccessPin", prim.RemoteScriptAccessPIN.ToString()); 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(); }
////////// 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(); }
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(); } else { string objectString = _converter.ObjectToString(propertyInfo.Value); if (objectString != null) { xmlTextWriter.WriteStartElement(propertyName); xmlTextWriter.WriteString(objectString); xmlTextWriter.WriteEndElement(); } } }
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()); writer.WriteEndElement(); // Shape } }
/// <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 }
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(); }
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(); }
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(); }
/// <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); }
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 } }
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()); writer.WriteElementString("Category", ((int)prim.Properties.Category).ToString()); writer.WriteElementString("SalePrice", prim.Properties.SalePrice.ToString()); writer.WriteElementString("ObjectSaleType", ((int)prim.Properties.SaleType).ToString()); writer.WriteElementString("OwnershipCost", prim.Properties.OwnershipCost.ToString()); WriteUUID(writer, "GroupID", prim.GroupID); WriteUUID(writer, "OwnerID", prim.OwnerID); WriteUUID(writer, "LastOwnerID", prim.Properties.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(); }
private void WriteXmlValue(XmlTextWriter writer, object value) { writer.WriteStartElement(XmlRpcElements.value); if (value != null) { if (value is byte[]) { byte[] ba = (byte[])value; writer.WriteStartElement(XmlRpcElements.base64); writer.WriteBase64(ba, 0, ba.Length); writer.WriteEndElement(); } else if (value is String) writer.WriteElementString(XmlRpcElements.string_, value.ToString()); else if (value is Int32) writer.WriteElementString(XmlRpcElements.int_, value.ToString()); else if (value is DateTime) writer.WriteElementString(XmlRpcElements.dateTime, ((DateTime)value).ToString(XmlRpcRequest.datetimeFormat)); else if (value is Double) writer.WriteElementString(XmlRpcElements.double_, value.ToString()); else if (value is Boolean) writer.WriteElementString(XmlRpcElements.boolean, (Boolean)value == true ? "1" : "0"); else if (value is IList) { writer.WriteStartElement(XmlRpcElements.array); writer.WriteStartElement(XmlRpcElements.data); if (((IList)value).Count > 0) { foreach (Object member in ((IList)value)) WriteXmlValue(writer, member); } writer.WriteEndElement(); writer.WriteEndElement(); } else if (value is IDictionary) { IDictionary h = (IDictionary)value; writer.WriteStartElement(XmlRpcElements.struct_); foreach (String key in h.Keys) { writer.WriteStartElement(XmlRpcElements.member); writer.WriteElementString(XmlRpcElements.name, key); WriteXmlValue(writer, h[key]); writer.WriteEndElement(); } writer.WriteEndElement(); } } writer.WriteEndElement(); }
internal void RespondToMessage(int p, int p_2) { // Check for the return type for capture switch (p_2) { case (int)DSHOW_MESSAGE.MESSAGE_FILECAPTURED: // Show the value on the screen this.LastImage.Image = new Bitmap(ImageStoreLocation); Captured++; UpdateCapturedSentDisplay(); // Send it over to the web server StringBuilder sb = new StringBuilder(); XmlTextWriter writter = new XmlTextWriter(new StringWriter(sb)); using (FileStream fs = File.OpenRead(ImageStoreLocation)) { byte[] bufferSize = new byte[fs.Length]; fs.Read(bufferSize, 0, (int)fs.Length); writter.WriteBase64(bufferSize, 0, (int)fs.Length); fs.Close(); } try { SVC.AcceptImage(DateTime.Now, sb.ToString()); Sent++; UpdateCapturedSentDisplay(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Failed to send Image"); } break; case (int)DSHOW_MESSAGE.MESSAGE_ERROR: // MessageBox.Show("Error from capture"); break; case (int)DSHOW_MESSAGE.MESSAGE_INFO: // MessageBox.Show("Something not too bad happened"); break; } }
/// <remarks>Serialize the object to the output stream.</remarks> /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param> /// <param name="obj">An <c>Object</c> to serialize.</param> public void SerializeObject(XmlTextWriter output, Object obj) { if (obj == null) return; if (obj is byte[]) { byte[] ba = (byte[])obj; output.WriteStartElement(BASE64); output.WriteBase64(ba, 0, ba.Length); output.WriteEndElement(); } else if (obj is String) { output.WriteElementString(STRING, obj.ToString()); } else if (obj is Int32) { output.WriteElementString(INT, obj.ToString()); } else if (obj is DateTime) { output.WriteElementString(DATETIME, ((DateTime)obj).ToString(ISO_DATETIME)); } else if (obj is Double) { output.WriteElementString(DOUBLE, obj.ToString()); } else if (obj is Boolean) { output.WriteElementString(BOOLEAN, ((((Boolean)obj) == true) ? "1" : "0")); } else if (obj is IList) { output.WriteStartElement(ARRAY); output.WriteStartElement(DATA); if (((ArrayList)obj).Count > 0) { foreach (Object member in ((IList)obj)) { output.WriteStartElement(VALUE); SerializeObject(output, member); output.WriteEndElement(); } } output.WriteEndElement(); output.WriteEndElement(); } else if (obj is IDictionary) { IDictionary h = (IDictionary)obj; output.WriteStartElement(STRUCT); foreach (String key in h.Keys) { output.WriteStartElement(MEMBER); output.WriteElementString(NAME, key); output.WriteStartElement(VALUE); SerializeObject(output, h[key]); output.WriteEndElement(); output.WriteEndElement(); } output.WriteEndElement(); } }
protected void Page_Command(object sender, CommandEventArgs e) { try { if ( e.CommandName == "Clear" ) { ctlSearch.ClearForm(); Server.Transfer("default.aspx"); } else if ( e.CommandName == "Search" ) { // 10/13/2005 Paul. Make sure to clear the page index prior to applying search. grdMain.CurrentPageIndex = 0; grdMain.ApplySort(); grdMain.DataBind(); } else if ( e.CommandName == "Export" ) { string[] arrTABLES = Request.Form.GetValues("chkMain"); if ( arrTABLES != null ) { DbProviderFactory dbf = DbProviderFactories.GetFactory(); using ( IDbConnection con = dbf.CreateConnection() ) { con.Open(); int nErrors = 0 ; MemoryStream stm = new MemoryStream(); XmlTextWriter xw = new XmlTextWriter(stm, Encoding.UTF8); xw.Formatting = Formatting.Indented; xw.IndentChar = ControlChars.Tab; xw.Indentation = 1; xw.WriteStartDocument(); xw.WriteStartElement("splendidcrm"); foreach ( string sTABLE_NAME in arrTABLES ) { vwMain.RowFilter = "TABLE_NAME = '" + sTABLE_NAME + "'"; if ( vwMain.Count > 0 ) { try { using ( IDbCommand cmd = con.CreateCommand() ) { cmd.CommandText = "select * from " + sTABLE_NAME; using ( IDataReader rdr = cmd.ExecuteReader() ) { int nRecordCount = 0; while ( rdr.Read() ) { nRecordCount++; xw.WriteStartElement(sTABLE_NAME.ToLower()); for ( int nColumn = 0; nColumn < rdr.FieldCount; nColumn++ ) { xw.WriteStartElement(rdr.GetName(nColumn).ToLower()); if ( !rdr.IsDBNull(nColumn) ) { switch ( rdr.GetFieldType(nColumn).FullName ) { case "System.Boolean" : xw.WriteString(rdr.GetBoolean (nColumn) ? "1" : "0"); break; case "System.Single" : xw.WriteString(rdr.GetDouble (nColumn).ToString() ); break; case "System.Double" : xw.WriteString(rdr.GetDouble (nColumn).ToString() ); break; case "System.Int16" : xw.WriteString(rdr.GetInt16 (nColumn).ToString() ); break; case "System.Int32" : xw.WriteString(rdr.GetInt32 (nColumn).ToString() ); break; case "System.Int64" : xw.WriteString(rdr.GetInt64 (nColumn).ToString() ); break; case "System.Decimal" : xw.WriteString(rdr.GetDecimal (nColumn).ToString() ); break; case "System.DateTime": xw.WriteString(rdr.GetDateTime(nColumn).ToUniversalTime().ToString(CalendarControl.SqlDateTimeFormat)); break; case "System.Guid" : xw.WriteString(rdr.GetGuid (nColumn).ToString().ToUpper()); break; case "System.String" : xw.WriteString(rdr.GetString (nColumn)); break; case "System.Byte[]" : { Byte[] buffer = rdr.GetValue(nColumn) as Byte[]; xw.WriteBase64(buffer, 0, buffer.Length); break; } default: throw(new Exception("Unsupported field type: " + rdr.GetFieldType(nColumn).FullName)); } } xw.WriteEndElement(); } xw.WriteEndElement(); } vwMain[0]["TABLE_STATUS"] = String.Format(L10n.Term("Export.LBL_RECORDS"), nRecordCount); } } } catch(Exception ex) { nErrors++; vwMain[0]["TABLE_STATUS"] = ex.Message; } } } xw.WriteEndElement(); xw.WriteEndDocument(); xw.Flush(); if ( nErrors == 0 ) { Response.ContentType = "text/xml"; Response.AddHeader("Content-Disposition", "attachment;filename=Export.xml"); stm.WriteTo(Response.OutputStream); Response.End(); } vwMain.RowFilter = null; grdMain.DataBind(); } } } else if ( e.CommandName == "Cancel" ) { Response.Redirect("~/Administration/default.aspx"); } } catch(Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = Server.HtmlEncode(ex.Message); } }
/// <summary> /// Creates a challenge element for SASL DIGEST-MD5 authentication /// </summary> /// <param name="data">The SASL challenge key/value pairs</param> /// <returns>A new SASL challenge element</returns> public static SaslResponseElement GetSaslChallengeElement(Hashtable data) { StringWriter xmlString = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(xmlString); writer.WriteStartElement("challenge"); writer.WriteAttributeString("xmlns", SASL_NAMESPACE); string responseStr = buildSaslDataString(data); byte[] bytes = Encoding.UTF8.GetBytes(responseStr); writer.WriteBase64(bytes, 0, bytes.Length); writer.WriteEndElement(); XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlString.ToString()); return new SaslResponseElement(xml.DocumentElement, data); }
public static void ExportExcel(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.WriteProcessingInstruction("mso-application", "progid=\"Excel.Sheet\""); xw.WriteStartElement("Workbook"); xw.WriteAttributeString("xmlns", "urn:schemas-microsoft-com:office:spreadsheet"); xw.WriteAttributeString("xmlns:o", "urn:schemas-microsoft-com:office:office"); xw.WriteAttributeString("xmlns:x", "urn:schemas-microsoft-com:office:excel"); xw.WriteAttributeString("xmlns:ss", "urn:schemas-microsoft-com:office:spreadsheet"); xw.WriteAttributeString("xmlns:html", "http://www.w3.org/TR/REC-html40"); xw.WriteStartElement("DocumentProperties"); xw.WriteAttributeString("xmlns", "urn:schemas-microsoft-com:office:office"); xw.WriteStartElement("Author"); xw.WriteString(Security.FULL_NAME); xw.WriteEndElement(); xw.WriteStartElement("Created"); xw.WriteString(DateTime.Now.ToUniversalTime().ToString("s")); xw.WriteEndElement(); xw.WriteStartElement("Version"); xw.WriteString("11.6568"); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteStartElement("ExcelWorkbook"); xw.WriteAttributeString("xmlns", "urn:schemas-microsoft-com:office:excel"); xw.WriteStartElement("WindowHeight"); xw.WriteString("15465"); xw.WriteEndElement(); xw.WriteStartElement("WindowWidth"); xw.WriteString("23820"); xw.WriteEndElement(); xw.WriteStartElement("WindowTopX"); xw.WriteString("120"); xw.WriteEndElement(); xw.WriteStartElement("WindowTopY"); xw.WriteString("75"); xw.WriteEndElement(); xw.WriteStartElement("ProtectStructure"); xw.WriteString("False"); xw.WriteEndElement(); xw.WriteStartElement("ProtectWindows"); xw.WriteString("False"); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteStartElement("Styles"); xw.WriteStartElement("Style"); xw.WriteAttributeString("ss:ID", "Default"); xw.WriteAttributeString("ss:Name", "Normal"); xw.WriteStartElement("Alignment"); xw.WriteAttributeString("ss:Vertical", "Bottom"); xw.WriteEndElement(); xw.WriteStartElement("Borders"); xw.WriteEndElement(); xw.WriteStartElement("Font"); xw.WriteEndElement(); xw.WriteStartElement("Interior"); xw.WriteEndElement(); xw.WriteStartElement("NumberFormat"); xw.WriteEndElement(); xw.WriteStartElement("Protection"); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteStartElement("Style"); xw.WriteAttributeString("ss:ID", "s21"); xw.WriteStartElement("NumberFormat"); xw.WriteAttributeString("ss:Format", "General Date"); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndElement(); DataTable tbl = vw.Table; xw.WriteStartElement("Worksheet"); xw.WriteAttributeString("ss:Name", sModuleName); xw.WriteStartElement("Table"); xw.WriteAttributeString("ss:ExpandedColumnCount", tbl.Columns.Count.ToString()); xw.WriteAttributeString("ss:FullColumns" , tbl.Columns.Count.ToString()); // 11/03/2006 Add one row for the header. xw.WriteAttributeString("ss:ExpandedRowCount" , (nEndRecord - nStartRecord + 1).ToString()); xw.WriteStartElement("Row"); for ( int nColumn = 0; nColumn < tbl.Columns.Count; nColumn++ ) { DataColumn col = tbl.Columns[nColumn]; xw.WriteStartElement("Cell"); xw.WriteStartElement("Data"); xw.WriteAttributeString("ss:Type", "String"); xw.WriteString(col.ColumnName.ToLower()); xw.WriteEndElement(); xw.WriteEndElement(); } xw.WriteEndElement(); for ( int i = nStartRecord; i < nEndRecord; i++ ) { xw.WriteStartElement("Row"); DataRowView row = vw[i]; for ( int nColumn = 0; nColumn < tbl.Columns.Count; nColumn++ ) { DataColumn col = tbl.Columns[nColumn]; xw.WriteStartElement("Cell"); // 11/03/2006 The style must be set in order for a date to be displayed properly. if ( col.DataType.FullName == "System.DateTime" && row[nColumn] != DBNull.Value ) xw.WriteAttributeString("ss:StyleID", "s21"); xw.WriteStartElement("Data"); if ( row[nColumn] != DBNull.Value ) { switch ( col.DataType.FullName ) { case "System.Boolean" : xw.WriteAttributeString("ss:Type", "String"); xw.WriteString(Sql.ToBoolean (row[nColumn]) ? "1" : "0"); break; case "System.Single" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToDouble (row[nColumn]).ToString() ); break; case "System.Double" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToDouble (row[nColumn]).ToString() ); break; case "System.Int16" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToInteger (row[nColumn]).ToString() ); break; case "System.Int32" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToInteger (row[nColumn]).ToString() ); break; case "System.Int64" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToLong (row[nColumn]).ToString() ); break; case "System.Decimal" : xw.WriteAttributeString("ss:Type", "Number"); xw.WriteString(Sql.ToDecimal (row[nColumn]).ToString() ); break; case "System.DateTime": xw.WriteAttributeString("ss:Type", "DateTime"); xw.WriteString(Sql.ToDateTime(row[nColumn]).ToUniversalTime().ToString("s")); break; case "System.Guid" : xw.WriteAttributeString("ss:Type", "String"); xw.WriteString(Sql.ToGuid (row[nColumn]).ToString().ToUpper()); break; case "System.String" : xw.WriteAttributeString("ss:Type", "String"); xw.WriteString(Sql.ToString (row[nColumn])); break; case "System.Byte[]" : { xw.WriteAttributeString("ss:Type", "String"); 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)); // 11/03/2006 We need to write the type even for empty cells. xw.WriteAttributeString("ss:Type", "String"); break; } } else { // 11/03/2006 We need to write the type even for empty cells. xw.WriteAttributeString("ss:Type", "String"); } xw.WriteEndElement(); xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); // Table xw.WriteStartElement("WorksheetOptions"); xw.WriteAttributeString("xmlns", "urn:schemas-microsoft-com:office:excel"); xw.WriteStartElement("Selected"); xw.WriteEndElement(); xw.WriteStartElement("ProtectObjects"); xw.WriteString("False"); xw.WriteEndElement(); xw.WriteStartElement("ProtectScenarios"); xw.WriteString("False"); xw.WriteEndElement(); xw.WriteEndElement(); // WorksheetOptions xw.WriteEndElement(); // Worksheet xw.WriteEndElement(); // Workbook xw.WriteEndDocument(); xw.Flush(); }
private static void WriteSpriteToXML(int spriteNumber, XmlTextWriter writer) { if (spriteNumber > 0) { Sprite sprite = Factory.AGSEditor.CurrentGame.RootSpriteFolder.FindSpriteByID(spriteNumber, true); if (sprite == null) { throw new AGSEditorException("Sprite not found: " + spriteNumber); } writer.WriteStartElement(GUI_XML_SPRITE_NODE); writer.WriteAttributeString(GUI_XML_SPRITE_NUMBER, spriteNumber.ToString()); Bitmap bmp = Factory.NativeProxy.GetBitmapForSprite(spriteNumber); int colDepth = GetColorDepthForPixelFormat(bmp.PixelFormat); writer.WriteAttributeString(GUI_XML_SPRITE_COLOR_DEPTH, colDepth.ToString()); writer.WriteAttributeString(GUI_XML_SPRITE_ALPHA_CHANNEL, (bmp.PixelFormat == PixelFormat.Format32bppArgb).ToString()); writer.WriteAttributeString(GUI_XML_SPRITE_WIDTH, bmp.Width.ToString()); writer.WriteAttributeString(GUI_XML_SPRITE_HEIGHT, bmp.Height.ToString()); writer.WriteAttributeString(GUI_XML_SPRITE_RESOLUTION, sprite.Resolution.ToString()); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, bmp.PixelFormat); int memoryAddress = bmpData.Scan0.ToInt32(); for (int y = 0; y < bmp.Height; y++) { byte[] line = new byte[bmp.Width * ((colDepth + 1) / 8)]; Marshal.Copy(new IntPtr(memoryAddress), line, 0, line.Length); writer.WriteBase64(line, 0, line.Length); memoryAddress += bmpData.Stride; } bmp.UnlockBits(bmpData); bmp.Dispose(); writer.WriteEndElement(); } }
/// <summary> /// Creates a response element for SASL DIGEST-MD5 authentication /// </summary> /// <param name="data">The SASL response key/value pairs</param> /// <returns>A new SASL response element</returns> public static SaslResponseElement GetSaslResponseElement(string username, string password, string realm, string nonce, string qop) { StringWriter xmlString = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(xmlString); writer.WriteStartElement("response"); writer.WriteAttributeString("xmlns", SASL_NAMESPACE); Hashtable data = new Hashtable(); data["username"] = username; data["realm"] = realm; data["nonce"] = nonce; data["qop"] = qop; data["nc"] = "00000001"; data["digest-uri"] = "xmpp/"+realm; data["charset"] = "utf-8"; calcSaslMD5Response(data, password); string responseStr = buildSaslDataString(data); byte[] bytes = Encoding.UTF8.GetBytes(responseStr); writer.WriteBase64(bytes, 0, bytes.Length); writer.WriteEndElement(); XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlString.ToString()); return new SaslResponseElement(xml.DocumentElement, data); }
//#if (DEBUG) //#endif public void Serialize( XmlTextWriter xtw, Object o, MappingAction mappingAction, ArrayList 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 = XmlRpcServiceInfo.GetXmlRpcType(o.GetType()); 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); } xtw.WriteEndElement(); xtw.WriteEndElement(); } 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); xtw.WriteEndElement(); } else if (xType == XmlRpcType.tBoolean) { bool boolVal; if (o is bool) boolVal = (bool)o; else boolVal = (bool)(XmlRpcBoolean)o; if (boolVal) xtw.WriteElementString("boolean", "1"); else xtw.WriteElementString("boolean", "0"); } else if (xType == XmlRpcType.tDateTime) { DateTime dt; if (o is DateTime) dt = (DateTime)o; else dt = (XmlRpcDateTime)o; string sdt = dt.ToString("yyyyMMdd'T'HH':'mm':'ss", DateTimeFormatInfo.InvariantInfo); xtw.WriteElementString("dateTime.iso8601", sdt); } else if (xType == XmlRpcType.tDouble) { double doubleVal; if (o is double) doubleVal = (double)o; else doubleVal = (XmlRpcDouble)o; xtw.WriteElementString("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", ""); xtw.WriteElementString("name", skey); Serialize(xtw, xrs[skey], mappingAction, nestedObjs); xtw.WriteEndElement(); } xtw.WriteEndElement(); } else if (xType == XmlRpcType.tInt32) { if (UseIntTag) xtw.WriteElementString("int", o.ToString()); else xtw.WriteElementString("i4", o.ToString()); } else if (xType == XmlRpcType.tString) { if (UseStringTag) xtw.WriteElementString("string", (string)o); else xtw.WriteString((string)o); } else if (xType == XmlRpcType.tStruct) { MappingAction structAction = StructMappingAction(o.GetType(), mappingAction); xtw.WriteStartElement("", "struct", ""); MemberInfo[] mis = o.GetType().GetMembers(); foreach (MemberInfo mi in mis) { if (mi.MemberType == MemberTypes.Field) { FieldInfo fi = (FieldInfo)mi; string member = fi.Name; Attribute attrchk = Attribute.GetCustomAttribute(fi, typeof(XmlRpcMemberAttribute)); if (attrchk != null && attrchk is XmlRpcMemberAttribute) { string mmbr = ((XmlRpcMemberAttribute)attrchk).Member; if (mmbr != "") member = mmbr; } if (fi.GetValue(o) == null) { MappingAction memberAction = MemberMappingAction(o.GetType(), fi.Name, structAction); if (memberAction == MappingAction.Ignore) continue; throw new XmlRpcMappingSerializeException(@"Member """ + member + @""" of struct """ + o.GetType().Name + @""" cannot be null."); } xtw.WriteStartElement("", "member", ""); xtw.WriteElementString("name", member); Serialize(xtw, fi.GetValue(o), mappingAction, nestedObjs); xtw.WriteEndElement(); } else if (mi.MemberType == MemberTypes.Property) { PropertyInfo pi = (PropertyInfo)mi; string member = pi.Name; Attribute attrchk = Attribute.GetCustomAttribute(pi, typeof(XmlRpcMemberAttribute)); if (attrchk != null && attrchk is XmlRpcMemberAttribute) { string mmbr = ((XmlRpcMemberAttribute)attrchk).Member; if (mmbr != "") member = mmbr; } if (pi.GetValue(o, null) == null) { MappingAction memberAction = MemberMappingAction(o.GetType(), pi.Name, structAction); if (memberAction == MappingAction.Ignore) continue; } xtw.WriteStartElement("", "member", ""); xtw.WriteElementString("name", member); Serialize(xtw, pi.GetValue(o, null), mappingAction, nestedObjs); xtw.WriteEndElement(); } } xtw.WriteEndElement(); } else if (xType == XmlRpcType.tVoid) xtw.WriteElementString("string", ""); else throw new XmlRpcUnsupportedTypeException(o.GetType()); xtw.WriteEndElement(); } catch(System.NullReferenceException) { throw new XmlRpcNullReferenceException("Attempt to serialize data " + "containing null reference"); } finally { nestedObjs.RemoveAt(nestedObjs.Count - 1); } }
public static void SerializeImage(System.Drawing.Image image, XmlElement xml) { if (image == null) return; System.IO.MemoryStream mem = new System.IO.MemoryStream(1024); // TODO: Beta 2 issue with the ImageFormat. RawFormat on image object does not return the actual image format // Right now it is hard coded to PNG but in final version we should get the original image format image.Save(mem, System.Drawing.Imaging.ImageFormat.Png); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); System.Xml.XmlTextWriter xt = new System.Xml.XmlTextWriter(sw); xt.WriteBase64(mem.GetBuffer(), 0, (int)mem.Length); xml.InnerText = sb.ToString(); }