예제 #1
0
        public static void RemoveImages(string userId, List <string> listOfTheNamesOfPhotosToBeRemoveWithExtension)
        {
            DBManager    dbm = new DBManager();
            ConnectionBS cbs = new ConnectionBS(userId);

            List <string> photosNameNoExtension = new List <string>();

            foreach (string nameWithExtesion in listOfTheNamesOfPhotosToBeRemoveWithExtension)
            {
                int indexOfPoint = nameWithExtesion.IndexOf('.');

                if (!nameWithExtesion.Contains("_Preview"))
                {
                    photosNameNoExtension.Add(nameWithExtesion.Substring(0, indexOfPoint));
                }

                // Log
                LogMaster.WriteOnLog("user " + userId + " have deleted an image with name " + nameWithExtesion);
            }

            Task removeFromMongoDB     = new Task(() => dbm.PhotoManager.RemovePhotos(photosNameNoExtension));
            Task RemoveFromBlobStorage = new Task(
                () => cbs.UserBSManager.RemovePhotoFromBlobStorage(listOfTheNamesOfPhotosToBeRemoveWithExtension));

            removeFromMongoDB.Start();
            RemoveFromBlobStorage.Start();

            Task.WhenAll(removeFromMongoDB, RemoveFromBlobStorage).Wait();
        }
예제 #2
0
        private List <Photo> GetPhotosForTheGallery(string tag = "")
        {
            ConnectionBS cbs    = new ConnectionBS((string)Session["user_id"]);
            string       sasKey = cbs.UserBSManager.GetContainerSasUri();

            List <Photo> photos = new List <Photo>();

            DBManager dbm = new DBManager();

            if (tag == "")
            {
                photos = dbm.PhotoManager.GetPhotosOfUser((string)Session["user_id"]);
            }
            else
            {
                photos = dbm.PhotoManager.GetPhotosWithTag((string)Session["user_id"], tag);
            }


            foreach (Photo photo in photos)
            {
                photo.PhotoPhatWhitSasKey = photo.PhotoPhatPreview + sasKey;
            }

            return(photos);
        }
예제 #3
0
        private static void UploadPhotoPToBlobStorage(string userId, Stream photo, string extension, ref Photo userPhoto)
        {
            string photoName = userPhoto._id.ToString() + "_Preview" + extension;

            userPhoto.PhotoNamePreview = photoName;

            userPhoto.PhotoPhatPreview = string.Format("https://{0}.blob.core.windows.net/{1}/{2}",
                                                       Variables.ACCOUNT_NAME_FOR_BLOB_STORAGE, userId, photoName);

            ConnectionBS cbs = new ConnectionBS(userId);

            cbs.UserBSManager.AddPhotoToUserContainer(photo, photoName);
        }
예제 #4
0
        private static void UploadPhotoOSToBlobStorage(string userId, Stream photo, string extension, ref Photo userPhoto)
        {
            userPhoto._id = ObjectId.GenerateNewId();

            string photoName = userPhoto._id + extension;

            userPhoto.PhotoNameOriginalSize = photoName;

            userPhoto.PhotoPhatOriginalSize = string.Format("https://{0}.blob.core.windows.net/{1}/{2}",
                                                            Variables.ACCOUNT_NAME_FOR_BLOB_STORAGE, userId, photoName);

            ConnectionBS cbs = new ConnectionBS(userId);

            cbs.UserBSManager.AddPhotoToUserContainer(photo, photoName);
        }
예제 #5
0
        public ActionResult SinglePhoto(string photoId)
        {
            if (Session["login"] == null)
            {
                return(RedirectToAction("Login", "Auth"));
            }

            DBManager  dbm = new DBManager();
            PhotoShare p   = new PhotoShare();

            p.PhotoToShare = dbm.PhotoManager.GetPhotoForDetails((string)Session["user_id"], photoId);

            ConnectionBS cbs = new ConnectionBS((string)Session["user_id"]);

            p.PhotoToShare.PhotoPhatWhitSasKey = p.PhotoToShare.PhotoPhatOriginalSize + cbs.UserBSManager.GetContainerSasUri();

            return(View(p));
        }
예제 #6
0
        private void ClearUserData()
        {
            DBManager    dbm           = new DBManager();
            List <Photo> allUserPhotos = dbm.PhotoManager.GetPhotosOfUser((string)Session["user_id"]);

            List <string> photoToDelete = new List <string>();

            foreach (Photo photo in allUserPhotos)
            {
                photoToDelete.Add(photo.PhotoNameOriginalSize);
                photoToDelete.Add(photo.PhotoNamePreview);
            }

            AsyncFunctionToUse.RemoveImages((string)Session["user_id"], photoToDelete);

            ConnectionBS cbs = new ConnectionBS((string)Session["user_id"]);

            cbs.UserBSManager.DeleteUserContainer();

            dbm.UserManager.DeleteUserFromDB((string)Session["user_id"]);
        }
예제 #7
0
        public ActionResult SharePhoto(string photoPath, PhotoShare photoShare)
        {
            DateTime finalDate = new DateTime(
                photoShare.DateOfExpire.Year,
                photoShare.DateOfExpire.Month,
                photoShare.DateOfExpire.Day,
                photoShare.TimeOfExpire.Hours,
                photoShare.TimeOfExpire.Minutes,
                photoShare.TimeOfExpire.Seconds);

            int totalMinutes = (int)finalDate.Subtract(DateTime.Now).TotalMinutes;

            totalMinutes = totalMinutes <= 0 ? 0 : totalMinutes;

            ConnectionBS cbs    = new ConnectionBS((string)Session["user_id"]);
            string       sasKey = cbs.UserBSManager.GetContainerSasUri(totalMinutes);

            // Log
            string[] urlParts = photoPath.Split('/');
            LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " has share an image named " + urlParts.Last() + " for " + totalMinutes + " minutes ");

            return(Content(photoPath + sasKey));
        }