Ejemplo n.º 1
0
        protected virtual bool ContextEqual(string contextPlain)
        {
            if (Size == 0 && (string.IsNullOrEmpty(contextPlain) || contextPlain == "0"))
            {
                return(true);
            }

            try
            {
                XmlDocument msnObjectDocument = new XmlDocument();
                msnObjectDocument.LoadXml(contextPlain);
                XmlNode       msnObjectNode = msnObjectDocument.SelectSingleNode("msnobj");
                string        sha           = msnObjectNode.Attributes["SHA1D"].InnerText;
                string        creator       = msnObjectNode.Attributes["Creator"].InnerText;
                MSNObjectType type          = (MSNObjectType)int.Parse(msnObjectNode.Attributes["Type"].InnerText);

                return(Sha == sha && Creator == creator && type == ObjectType);
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "MSNObject compare error: context " +
                                  contextPlain + " is not a valid context for MSNObject.\r\n  Error description: " +
                                  ex.Message + "\r\n  Stack Trace: " + ex.StackTrace);
                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a MSN object based on a (memory)stream. The client programmer is responsible for inserting this object in the global msn object collection.
        /// The stream must remain open during the whole life-length of the application.
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="inputStream"></param>
        /// <param name="type"></param>
        /// <param name="location"></param>
        public MSNObject(string creator, Stream inputStream, MSNObjectType type, string location)
        {
            this.creator  = creator;
            this.size     = (int)inputStream.Length;
            this.type     = type;
            this.location = location;

            this.sha = GetStreamHash(inputStream);

            this.DataStream = new PersistentStream(inputStream);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a MSN object based on a physical file. The client programmer is responsible for inserting this object in the global msn object collection.
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="type"></param>
        /// <param name="fileLocation"></param>
        public MSNObject(string creator, string fileLocation, MSNObjectType type)
        {
            this.location  = Path.GetFullPath(fileLocation).Replace(Path.GetPathRoot(fileLocation), "");
            this.location += new Random().Next().ToString(CultureInfo.InvariantCulture);

            this.fileLocation = fileLocation;

            Stream stream = OpenStream();

            this.creator = creator;
            this.size    = (int)stream.Length;
            this.type    = type;

            this.sha = GetStreamHash(stream);
            stream.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses a context send by the remote contact and set the corresponding class variables.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="base64Encoded"></param>
        public virtual void SetContext(string context, bool base64Encoded)
        {
            if (base64Encoded)
                context = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(context));

            string xmlString = GetDecodeString(context);

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlString);
                XmlNode msnObjNode = xmlDoc.SelectSingleNode("//msnobj");

                foreach (XmlNode attr in msnObjNode.Attributes)
                {
                    string val = attr.Value;
                    switch (attr.Name.ToLowerInvariant())
                    {
                        case "creator":
                            this.creator = val;
                            break;
                        case "size":
                            this.size = int.Parse(val, System.Globalization.CultureInfo.InvariantCulture);
                            break;
                        case "type":
                            {
                                switch (val)
                                {
                                    case "2":
                                        type = MSNObjectType.Emoticon;
                                        break;
                                    case "3":
                                        type = MSNObjectType.UserDisplay;
                                        break;
                                    case "5":
                                        type = MSNObjectType.Background;
                                        break;
                                    case "8":
                                        type = MSNObjectType.Wink;
                                        break;
                                    case "16":
                                        type = MSNObjectType.Scene;
                                        break;
                                }
                                break;
                            }
                        case "location":
                            this.location = val;
                            break;
                        case "sha1d":
                            this.sha = val.Replace(' ', '+');
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "MSNObject Set Conext error: context " +
                    xmlString + " is not a valid context for MSNObject.\r\n  Error description: " +
                    ex.Message + "\r\n  Stack Trace: " + ex.StackTrace);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructs a MSN object based on a physical file. The client programmer is responsible for inserting this object in the global msn object collection.
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="type"></param>
        /// <param name="fileLocation"></param>
        public MSNObject(string creator, string fileLocation, MSNObjectType type)
        {
            this.location = Path.GetFullPath(fileLocation).Replace(Path.GetPathRoot(fileLocation), "");
            this.location += new Random().Next().ToString(CultureInfo.InvariantCulture);

            this.fileLocation = fileLocation;

            Stream stream = OpenStream();

            this.creator = creator;
            this.size = (int)stream.Length;
            this.type = type;

            this.sha = GetStreamHash(stream);
            stream.Close();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs a MSN object based on a (memory)stream. The client programmer is responsible for inserting this object in the global msn object collection.
        /// The stream must remain open during the whole life-length of the application.
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="inputStream"></param>
        /// <param name="type"></param>
        /// <param name="location"></param>
        public MSNObject(string creator, Stream inputStream, MSNObjectType type, string location)
        {
            this.creator = creator;
            this.size = (int)inputStream.Length;
            this.type = type;
            this.location = location;

            this.sha = GetStreamHash(inputStream);

            this.DataStream = new PersistentStream(inputStream);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Parses a context send by the remote contact and set the corresponding class variables.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="base64Encoded"></param>
        public virtual void SetContext(string context, bool base64Encoded)
        {
            if (base64Encoded)
            {
                context = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(context));
            }

            string xmlString = GetDecodeString(context);

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlString);
                XmlNode msnObjNode = xmlDoc.SelectSingleNode("//msnobj");

                foreach (XmlNode attr in msnObjNode.Attributes)
                {
                    string val = attr.Value;
                    switch (attr.Name.ToLowerInvariant())
                    {
                    case "creator":
                        this.creator = val;
                        break;

                    case "size":
                        this.size = int.Parse(val, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "type":
                    {
                        switch (val)
                        {
                        case "2":
                            type = MSNObjectType.Emoticon;
                            break;

                        case "3":
                            type = MSNObjectType.UserDisplay;
                            break;

                        case "5":
                            type = MSNObjectType.Background;
                            break;

                        case "8":
                            type = MSNObjectType.Wink;
                            break;

                        case "16":
                            type = MSNObjectType.Scene;
                            break;
                        }
                        break;
                    }

                    case "location":
                        this.location = val;
                        break;

                    case "sha1d":
                        this.sha = val.Replace(' ', '+');
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "MSNObject Set Conext error: context " +
                                  xmlString + " is not a valid context for MSNObject.\r\n  Error description: " +
                                  ex.Message + "\r\n  Stack Trace: " + ex.StackTrace);
            }
        }