Example #1
0
        private URITag CreateURITag(string uri)
        {
            URITag uriTag = new URITag();

            uriTag.MedFiUrl     = uri;
            uriTag.Title        = TagName;
            uriTag.UTCStartDate = DateTime.Now;
            uriTag.UTCEndDate   = new DateTime(2012, 01, 01);
            return(uriTag);
        }
Example #2
0
        /// <summary>
        /// Creates an MS tag for a given URL.
        /// </summary>
        /// <param name="credential">The API credential.</param>
        /// <param name="category">The tag category.</param>
        /// <param name="link">The link to encode in the tag.</param>
        /// <returns>The tag image.</returns>
        private BitmapSource CreateTag(UserCredential credential, string category, Uri link)
        {
            // Hash the URL for use in the title, because if the URL is too long, the tag service gets angry.
            string hash = GetMD5Hash(link.OriginalString);

            // Define the range for which the tag is valid.
            DateTime tagStartDate = DateTime.UtcNow.AddDays(-1);
            DateTime tagEndDate = DateTime.UtcNow.AddDays(90);

            MIBPContractClient client = new MIBPContractClient();
            Tag tag = null;

            try
            {
                // See if this tag already exists.
                tag = client.GetTagByTagName(credential, category, hash);

                if (tag.UTCEndDate > tagEndDate)
                {
                    // If the tag is expired, change the end date so that it will work again.
                    tag.UTCStartDate = tagStartDate;
                    tag.UTCEndDate = tagEndDate;

                    try
                    {
                        client.UpdateTag(credential, category, hash, tag);
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
            catch
            {
                // The tag wasn't found, so create a new one.
                tag = new URITag
                {
                    MedFiUrl = link.OriginalString,
                    Title = hash,
                    UTCStartDate = tagStartDate,
                    UTCEndDate = tagEndDate,
                };

                try
                {
                    client.CreateTag(credential, category, tag);
                }
                catch
                {
                    return null;
                }
            }

            try
            {
                byte[] barcode = client.GetBarcode(credential, category, hash, ImageTypes.png, .8f, DecorationType.HCCBRP_DECORATION_NONE, false);
                BitmapSource bmp = new PngBitmapDecoder(new MemoryStream(barcode), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                return bmp;
            }
            catch
            {
                return null;
            }
        }
Example #3
0
        /// <summary>
        /// Creates an MS tag for a given URL.
        /// </summary>
        /// <param name="credential">The API credential.</param>
        /// <param name="category">The tag category.</param>
        /// <param name="link">The link to encode in the tag.</param>
        /// <returns>The tag image.</returns>
        private BitmapSource CreateTag(UserCredential credential, string category, Uri link)
        {
            // Hash the URL for use in the title, because if the URL is too long, the tag service gets angry.
            string hash = GetMD5Hash(link.OriginalString);

            // Define the range for which the tag is valid.
            DateTime tagStartDate = DateTime.UtcNow.AddDays(-1);
            DateTime tagEndDate   = DateTime.UtcNow.AddDays(90);

            MIBPContractClient client = new MIBPContractClient();
            Tag tag = null;

            try
            {
                // See if this tag already exists.
                tag = client.GetTagByTagName(credential, category, hash);

                if (tag.UTCEndDate > tagEndDate)
                {
                    // If the tag is expired, change the end date so that it will work again.
                    tag.UTCStartDate = tagStartDate;
                    tag.UTCEndDate   = tagEndDate;

                    try
                    {
                        client.UpdateTag(credential, category, hash, tag);
                    }
                    catch
                    {
                        return(null);
                    }
                }
            }
            catch
            {
                // The tag wasn't found, so create a new one.
                tag = new URITag
                {
                    MedFiUrl     = link.OriginalString,
                    Title        = hash,
                    UTCStartDate = tagStartDate,
                    UTCEndDate   = tagEndDate,
                };

                try
                {
                    client.CreateTag(credential, category, tag);
                }
                catch
                {
                    return(null);
                }
            }

            try
            {
                byte[]       barcode = client.GetBarcode(credential, category, hash, ImageTypes.png, .8f, DecorationType.HCCBRP_DECORATION_NONE, false);
                BitmapSource bmp     = new PngBitmapDecoder(new MemoryStream(barcode), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                return(bmp);
            }
            catch
            {
                return(null);
            }
        }
 private URITag CreateURITag(string uri)
 {
     URITag uriTag = new URITag();
     uriTag.MedFiUrl = uri;
     uriTag.Title = TagName;
     uriTag.UTCStartDate = DateTime.Now;
     uriTag.UTCEndDate = new DateTime(2012, 01, 01);
     return uriTag;
 }