public static string GetUrlInfo(BlobFile blobFile)
        {
            if (blobFile == null || string.IsNullOrEmpty(blobFile.BlobKey))
                return string.Empty;

            CloudBlobContainer container = GetCloudBlobContainer(((BlobFileType)blobFile.Container).ToString());
            CloudBlockBlob blob = container.GetBlockBlobReference(blobFile.BlobKey);
            if (blob == null || !blob.Exists())
                return string.Empty;
            return blob.Uri.ToString();
        }
Esempio n. 2
0
        public BlobFile AddWatermark(string userId, BlobFile blobFileOriginal,  HttpPostedFileBase file)
        {
            Stream stream = AddWaterMarkToImage(file);

            BlobFileModel blobWatermark = new BlobFileModel(stream, string.Format("{0}", blobFileOriginal.Filename), "image/png");
            BlobFile blobFile = new BlobFile
            {
                Container = (int)BlobFileType.ImagesWaterMark,
                CreatedBy = userId,
                Filename = blobWatermark.FileName,
                BlobKey = Common.GetGuid(),
                dtCreated = DateTime.Now
            };

            CloudStorageManagerHelper.InsertFileWithStaticName((BlobFileType)blobFile.Container, blobFile.BlobKey, blobWatermark, userId);

            return blobFile;
        }
Esempio n. 3
0
        /// <summary>
        /// insert File in the Blob.
        /// Modify the image to add a watermark and add to a Blob.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="file"></param>
        /// <returns>return List of blobs relationship with the image</returns>
        public List<BlobFile> CreateImage(string userId, HttpPostedFileBase file)
        {
            BlobFileModel blobOriginal = new BlobFileModel(file);
            BlobFile blobFile = new BlobFile
            {
                Container = (int)BlobFileType.ImagesOriginal,
                CreatedBy = userId,
                Filename = blobOriginal.FileName,
                BlobKey = Common.GetGuid(),
                dtCreated = DateTime.Now
            };

            CloudStorageManagerHelper.InsertFileWithStaticName(BlobFileType.ImagesOriginal, blobFile.BlobKey, blobOriginal, userId);

            List<BlobFile> lst = new List<BlobFile>();
            lst.Add(blobFile);
            lst.Add(AddWatermark(userId,blobFile, file));

            return lst;
        }
Esempio n. 4
0
        /// <summary>
        /// Save the Shopping Cart Data
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="shopCart"></param>
        private static void SaveCart(string userId, ShoppingCartModel shopCart)
        {
            // Serialize the object Shopping Cart model to json
            var serializer = new JavaScriptSerializer();
            string content = serializer.Serialize(shopCart);

            string key = string.Format("{0}_Cart", userId);

            // Create the blob model
            BlobFilesHelper blobFileHelper = new BlobFilesHelper();
            BlobFileModel blob = new BlobFileModel(content, key, "String");
            BlobFile blobFile = null;

            if (blobFileHelper.Exist(key))
            {
                // Get the blob File
                blobFile = blobFileHelper.GetByKey(key);

                blobFileHelper.Update(blobFile);
            }
            else
            {
                // Create the blob File
                blobFile = new BlobFile
                {
                    Container = (int)BlobFileType.Cart,
                    CreatedBy = userId,
                    Filename = blob.FileName,
                    BlobKey = blob.FileName,
                    dtCreated = DateTime.Now
                };
                blobFileHelper.Add(blobFile);
            }

            // Save the Blob model in Azure Storage
            CloudStorageManagerHelper.InsertFileWithStaticName((BlobFileType)blobFile.Container, key, blob);
        }