Exemplo n.º 1
0
        /// <summary>
        /// Processes a download reply - SNAC(10,07)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,07)</param>
        private void ProcessDownloadReply(DataPacket dp)
        {
            string screenName = dp.Data.ReadString(dp.Data.ReadByte(), Encoding.ASCII);
            BartID queriedId  = new BartID(dp.Data);

            currentlyDownloading.Remove(queriedId);

            BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte();

            if (responseCode == BartReplyCode.Success)
            {
                BartID replyId    = new BartID(dp.Data);
                ushort dataLength = dp.Data.ReadUshort();
                byte[] data       = dp.Data.ReadByteArray(dataLength);

                if (!Directory.Exists(AutoSaveLocation))
                {
                    MemoryStream iconStream = new MemoryStream(data);
                    if (BuddyIconReceived != null)
                    {
                        BuddyIconReceived(this, new BuddyIconReceivedEventArgs(screenName, replyId, iconStream));
                    }
                }
                else
                {
                    string saveLocation = Path.Combine(AutoSaveLocation, replyId.ToString());
                    using (FileStream writer = new FileStream(saveLocation, FileMode.Create, FileAccess.Write))
                    {
                        writer.Write(data, 0, data.Length);
                    }
                    OnBuddyIconDownloaded(screenName, replyId, saveLocation);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Raises the <see cref="BuddyIconDownloaded"/> event
 /// </summary>
 protected internal void OnBuddyIconDownloaded(string screenName, BartID iconId, string iconPath)
 {
     if (BuddyIconDownloaded != null)
     {
         BuddyIconDownloaded(this, new BuddyIconDownloadedEventArgs(screenName, iconId, iconPath));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        public int CompareTo(object obj)
        {
            BartID other = obj as BartID;

            if (other != null)
            {
                return(ToString().CompareTo(other.ToString()));
            }
            return(-1);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Processes an upload reply - SNAC(10,03)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,03)</param>
        private void ProcessUploadReply(DataPacket dp)
        {
            BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte();

            if (responseCode == BartReplyCode.Success)
            {
                BartID uploadedItem = new BartID(dp.Data);
                if (BuddyIconUploadCompleted != null)
                {
                    BuddyIconUploadCompleted(this, new BuddyIconUploadCompletedArgs(uploadedItem));
                }
            }
            else
            {
                OnBuddyIconUploadFailed(responseCode);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Downloads a buddy icon from the AIM servers
        /// </summary>
        /// <param name="screenName">The screenname to which the icon belongs</param>
        /// <param name="iconId">The ID of the icon stored on the server</param>
        public void DownloadBuddyIcon(string screenName, BartID iconId)
        {
            // Check to make sure the icon ID is valid and actually a buddy icon
            if (iconId == null || iconId.Data == null ||
                !(iconId.Type == BartTypeId.BuddyIcon || iconId.Type == BartTypeId.BigBuddyIcon))
            {
                return;
            }

            // Check to see if the icon's cached, if the cache location is set
            if (!String.IsNullOrEmpty(AutoSaveLocation))
            {
                string saveLocation = Path.Combine(AutoSaveLocation, iconId.ToString());
                if (File.Exists(saveLocation))
                {
                    OnBuddyIconDownloaded(screenName, iconId, saveLocation);
                    return;
                }
            }

            // Check to see if there's already a request in progress for this icon ID
            if (currentlyDownloading.Contains(iconId))
            {
                return;
            }
            currentlyDownloading.Add(iconId);

            SNACHeader sh = new SNACHeader();

            sh.FamilyServiceID = SNAC_BART_FAMILY;
            sh.FamilySubtypeID = BART_DOWNLOAD;
            sh.Flags           = 0;


            ByteStream stream = new ByteStream();

            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenName));
            stream.WriteString(screenName, Encoding.ASCII);
            stream.WriteByte(0x01);
            stream.WriteBartID(iconId);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            BartID other = obj as BartID;

            return(other != null && ToString() == other.ToString());
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new BuddyIconDownloadedEventArgs
 /// </summary>
 public BuddyIconDownloadedEventArgs(string screenName, BartID iconId, string iconFile)
 {
     this.screenName = screenName;
     this.iconId     = iconId;
     this.iconFile   = iconFile;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new BuddyIconReceivedEventArgs
 /// </summary>
 public BuddyIconReceivedEventArgs(string screenName, BartID iconId, MemoryStream iconStream)
 {
     this.screenName = screenName;
     this.iconId     = iconId;
     this.iconStream = iconStream;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new BuddyIconUploadCompletedArgs
 /// </summary>
 public BuddyIconUploadCompletedArgs(BartID bartId)
 {
     this.bartId = bartId;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Processes a download reply - SNAC(10,07)
        /// </summary>
        /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,07)</param>
        private void ProcessDownloadReply(DataPacket dp)
        {
            string screenName = dp.Data.ReadString(dp.Data.ReadByte(), Encoding.ASCII);
            BartID queriedId = new BartID(dp.Data);
            currentlyDownloading.Remove(queriedId);

            BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte();
            if (responseCode == BartReplyCode.Success)
            {
                BartID replyId = new BartID(dp.Data);
                ushort dataLength = dp.Data.ReadUshort();
                byte[] data = dp.Data.ReadByteArray(dataLength);

                if (!Directory.Exists(AutoSaveLocation))
                {
                    MemoryStream iconStream = new MemoryStream(data);
                    if(BuddyIconReceived != null)
                    {
                        BuddyIconReceived(this, new BuddyIconReceivedEventArgs(screenName, replyId, iconStream));
                    }
                }
                else
                {
                    string saveLocation = Path.Combine(AutoSaveLocation, replyId.ToString());
                    using (FileStream writer = new FileStream(saveLocation, FileMode.Create, FileAccess.Write))
                    {
                        writer.Write(data, 0, data.Length);
                    }
                    OnBuddyIconDownloaded(screenName, replyId, saveLocation);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Processes an upload reply - SNAC(10,03)
 /// </summary>
 /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,03)</param>
 private void ProcessUploadReply(DataPacket dp)
 {
     BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte();
     if (responseCode == BartReplyCode.Success)
     {
         BartID uploadedItem = new BartID(dp.Data);
         if (BuddyIconUploadCompleted != null)
         {
             BuddyIconUploadCompleted(this, new BuddyIconUploadCompletedArgs(uploadedItem));
         }
     }
     else
     {
         OnBuddyIconUploadFailed(responseCode);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Raises the <see cref="BuddyIconDownloaded"/> event
 /// </summary>
 protected internal void OnBuddyIconDownloaded(string screenName, BartID iconId, string iconPath)
 {
     if (BuddyIconDownloaded != null)
     {
         BuddyIconDownloaded(this, new BuddyIconDownloadedEventArgs(screenName, iconId, iconPath));
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Downloads a buddy icon from the AIM servers
        /// </summary>
        /// <param name="screenName">The screenname to which the icon belongs</param>
        /// <param name="iconId">The ID of the icon stored on the server</param>
        public void DownloadBuddyIcon(string screenName, BartID iconId)
        {
            // Check to make sure the icon ID is valid and actually a buddy icon
            if (iconId == null || iconId.Data == null ||
                !(iconId.Type == BartTypeId.BuddyIcon || iconId.Type == BartTypeId.BigBuddyIcon))
            {
                return;
            }

            // Check to see if the icon's cached, if the cache location is set
            if (!String.IsNullOrEmpty(AutoSaveLocation))
            {
                string saveLocation = Path.Combine(AutoSaveLocation, iconId.ToString());
                if (File.Exists(saveLocation))
                {
                    OnBuddyIconDownloaded(screenName, iconId, saveLocation);
                    return;
                }
            }

            // Check to see if there's already a request in progress for this icon ID
            if (currentlyDownloading.Contains(iconId))
            {
                return;
            }
            currentlyDownloading.Add(iconId);

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_BART_FAMILY;
            sh.FamilySubtypeID = BART_DOWNLOAD;
            sh.Flags = 0;

            ByteStream stream = new ByteStream();
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenName));
            stream.WriteString(screenName, Encoding.ASCII);
            stream.WriteByte(0x01);
            stream.WriteBartID(iconId);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new BuddyIconUploadCompletedArgs
 /// </summary>
 public BuddyIconUploadCompletedArgs(BartID bartId)
 {
     this.bartId = bartId;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new BuddyIconReceivedEventArgs
 /// </summary>
 public BuddyIconReceivedEventArgs(string screenName, BartID iconId, MemoryStream iconStream)
 {
     this.screenName = screenName;
     this.iconId = iconId;
     this.iconStream = iconStream;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new BuddyIconDownloadedEventArgs
 /// </summary>
 public BuddyIconDownloadedEventArgs(string screenName, BartID iconId, string iconFile)
 {
     this.screenName = screenName;
     this.iconId = iconId;
     this.iconFile = iconFile;
 }