OpenMetaverse.GroupNotice.SerializeAttachment C# (CSharp) Method

SerializeAttachment() public method

public SerializeAttachment ( ) : byte[]
return byte[]
        public byte[] SerializeAttachment()
        {
            if (OwnerID == UUID.Zero || AttachmentID == UUID.Zero)
                return new byte[0];

            OpenMetaverse.StructuredData.OSDMap att = new OpenMetaverse.StructuredData.OSDMap();
            att.Add("item_id", OpenMetaverse.StructuredData.OSD.FromUUID(AttachmentID));
            att.Add("owner_id", OpenMetaverse.StructuredData.OSD.FromUUID(OwnerID));

            return OpenMetaverse.StructuredData.OSDParser.SerializeLLSDXmlBytes(att);

            /*
            //I guess this is how this works, no gaurentees
            string lsd = "<llsd><item_id>" + AttachmentID.ToString() + "</item_id><owner_id>"
                + OwnerID.ToString() + "</owner_id></llsd>";
            return Utils.StringToBytes(lsd);
             */
        }

Usage Example

Example #1
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            string message;
            string subject;
            UUID groupUUID = UUID.Zero;
            UUID attachmentUUID = UUID.Zero;
            GroupNotice notice;

            try
            {
                if ( Parameters.ContainsKey("subject") )
                {
                    subject = Parameters["subject"].ToString().Replace("%20"," ").Replace("+"," ");
                }
                else
                {
                    return "<error>No notice subject</error>";
                }

                if ( Parameters.ContainsKey("message") )
                {
                    message = Parameters["message"].ToString().Replace("%20"," ").Replace("+"," ");
                }
                else
                {
                    return "<error>No notice message</error>";
                }

                if ( Parameters.ContainsKey("group") )
                {
                    if (! UUID.TryParse(Parameters["group"].ToString().Replace("_"," "), out groupUUID) )
                    {
                        return "<error>parsekey group</error>";
                    }
                }
                else
                {
                    return "<error>arguments: no group key</error>";
                }

                if ( Parameters.ContainsKey("attachment") )
                {
                    if (!  UUID.TryParse(Parameters["attachment"].ToString().Replace("_"," "), out attachmentUUID) )
                    {
                        return "<error>parsekey attachment</error>";
                    }
                }
                else
                {
                    // just a warning, attachment can be empty
                    DebugUtilities.WriteWarning(session + " " + MethodName + " Notice has no attachment (no problem)");
                }

                DebugUtilities.WriteDebug(session + " " + MethodName + " Attempting to create a notice");

                /* This doesn't work as it should!
                if (! b.Client.Inventory.Store.Contains(attachmentUUID))
                {
                    DebugUtilities.WriteWarning(session + " " + MethodName + " Item UUID " + attachmentUUID.ToString() + " not found on inventory (are you using an Asset UUID by mistake?)");
                    attachmentUUID = UUID.Zero;
                }
                */

                notice = new GroupNotice();

                notice.Subject = subject;
                notice.Message = message;
                notice.AttachmentID = attachmentUUID; // this is the inventory UUID, not the asset UUID
                notice.OwnerID = b.Client.Self.AgentID;

                b.Client.Groups.SendGroupNotice(groupUUID, notice);

                DebugUtilities.WriteDebug(session + " " + MethodName + " Sent Notice from avatar " + notice.OwnerID.ToString() + " to group: " + groupUUID.ToString() + " subject: '" + notice.Subject.ToString() + "' message: '" + notice.Message.ToString() + "' Optional attachment: " + notice.AttachmentID.ToString() + " Serialisation: " + Utils.BytesToString(notice.SerializeAttachment()));

                return "<notice>sent</notice>\n";
            }
            catch ( Exception e )
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>loads of errors</error>";
            }
        }
All Usage Examples Of OpenMetaverse.GroupNotice::SerializeAttachment