Describes how to connect to a particular S3 server.
Ejemplo n.º 1
0
        internal string ResizeAndUpload(int height, int width, HttpPostedFileBase file)
        {
            if (file == null || !Utilities.IsImageFile(file.FileName)) return null;

            var bitmapImage = new Bitmap(file.InputStream);

            const CannedAcl acl = CannedAcl.PublicRead;

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            Image fullPhoto = bitmapImage;

            string fileNameFull = Utilities.CreateUniqueContentFilename(file);

            fullPhoto = ImageResize.FixedSize(fullPhoto, width, height, Color.Black);

            Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

            s3.AddObject(
                maker,
                maker.Length,
                AmazonCloudConfigs.AmazonBucketName,
                fileNameFull,
                file.ContentType,
                acl);

            return fileNameFull;
        }
        public override System.Xml.XmlNode Decrypt(System.Xml.XmlNode encryptedNode)
        {
            //note: in order to verify the protected configuration route without going via s3, use the following line
            //string xmlRaw = "<sampleConfig><settings sampleConfigSetting=\"Sucess. This Setting came from code.\"></settings></sampleConfig>";

            //setup parameters we need to know (note: this could be extended to be further provider-based)
            string awsAccessKey, awsSecretKey, bucketName, objectKey;

            //collect parameter values
            XmlNode settingsNode = encryptedNode.SelectSingleNode("/EncryptedData/s3ProviderInfo");
            awsAccessKey = settingsNode.Attributes["s3AccessKey"].Value;
            awsSecretKey = settingsNode.Attributes["s3SecretKey"].Value;
            bucketName = settingsNode.Attributes["s3BucketName"].Value;
            objectKey = settingsNode.Attributes["objectKey"].Value;

            //get value from s3
            var service = new S3Service
            {
                AccessKeyID = awsAccessKey,
                SecretAccessKey = awsSecretKey,
                UseSsl = true,
                UseSubdomains = true
            };
            string xmlRaw = service.GetObjectString(bucketName, objectKey);

            //cast to XmlDocument
            var doc = new XmlDocument();
            doc.LoadXml(xmlRaw);

            //return node
            return doc.ChildNodes[0];
        }
Ejemplo n.º 3
0
 internal S3Request(S3Service service, string method, string bucketName, string objectKey,
                    string queryString)
 {
     this.Service    = service;
     this.bucketName = bucketName;
     this.WebRequest = CreateWebRequest(method, objectKey, queryString);
 }
Ejemplo n.º 4
0
        string bucketName; // remember this for signing the request later

        #endregion Fields

        #region Constructors

        internal S3Request(S3Service service, string method, string bucketName, string objectKey,
            string queryString)
        {
            this.Service = service;
            this.bucketName = bucketName;
            this.WebRequest = CreateWebRequest(method, objectKey, queryString);
        }
Ejemplo n.º 5
0
 public AddObjectRequest(S3Service service, string bucketName, string objectKey)
     : base(service, "PUT", bucketName, objectKey, null)
 {
     this.CannedAcl = CannedAcl.Private;
     // disabled for now - results in flaky behavior (see remarks on S3Request.ServicePoint)
     // WebRequest.ServicePoint.Expect100Continue = true;
     WebRequest.AllowWriteStreamBuffering = false; // important! we could be sending a LOT of data
 }
Ejemplo n.º 6
0
 /// <param name="createInEurope">
 /// True if you want to request that Amazon create this bucket in the Europe location. Otherwise,
 /// false to let Amazon decide.
 /// </param>
 public CreateBucketRequest(S3Service service, string bucketName, bool createInEurope)
     : base(service, "PUT", bucketName, null, null)
 {
     if (createInEurope)
     {
         WebRequest.ContentLength = EuropeConstraint.Length;
     }
 }
Ejemplo n.º 7
0
 public CopyObjectRequest(S3Service service, string sourceBucketName, string sourceObjectKey,
                          string destBucketName, string destObjectKey)
     : base(service, "PUT", destBucketName, destObjectKey, null)
 {
     this.CannedAcl         = CannedAcl.Private;
     this.MetadataDirective = MetadataDirective.Automatic;
     WebRequest.Headers[S3Headers.CopySource] = sourceBucketName + "/" + sourceObjectKey;
 }
Ejemplo n.º 8
0
        string bucketName; // remember this for signing the request later

        #endregion Fields

        #region Constructors

        internal S3Request(S3Service service, string method, string bucketName, string objectKey,
            string queryString)
        {
            this.Service = service;
            this.bucketName = bucketName;
            this.WebRequest = CreateWebRequest(method, objectKey, queryString);
            GreenQloud.Logger.LogInfo("INFO S3 REQUEST", this.WebRequest.RequestUri.AbsoluteUri);
        }
Ejemplo n.º 9
0
 /// <param name="createInEurope">
 /// True if you want to request that Amazon create this bucket in the Europe location. Otherwise,
 /// false to let Amazon decide.
 /// </param>
 public CreateBucketRequest(S3Service service, string bucketName, string location)
     : base(service, "PUT", bucketName, null, null)
 {
     if (!string.IsNullOrEmpty(location))
     {
         locationConstraint       = string.Format("<CreateBucketConfiguration><LocationConstraint>{0}</LocationConstraint></CreateBucketConfiguration>", location);
         WebRequest.ContentLength = locationConstraint.Length;
     }
 }
Ejemplo n.º 10
0
        /// <param name="createInEurope">
        /// True if you want to request that Amazon create this bucket in the Europe location. Otherwise,
        /// false to let Amazon decide.
        /// </param>
        public CreateBucketRequest(S3Service service, string bucketName, bool createInEurope)
            : base(service, "PUT", bucketName, null, null)
        {
            if (createInEurope)
#if PORTABLE
            { WebRequest.Headers["Content-Length"] = EuropeConstraint.Length.ToString(); }
#else
            { WebRequest.ContentLength = EuropeConstraint.Length; }
#endif
        }
Ejemplo n.º 11
0
        public S3Store()
        {
            _S3Service = new S3Service()
            {
                AccessKeyID = System.Environment.GetEnvironmentVariable("AMAZON_ACCESS_KEY_ID"),
                SecretAccessKey = System.Environment.GetEnvironmentVariable("AMAZON_SECRET_ACCESS_KEY")
            };

            if (_S3Service.QueryBucket(_bucketName) == BucketAccess.NoSuchBucket)
                _S3Service.CreateBucket(_bucketName);
        }
Ejemplo n.º 12
0
        public ActionResult Delete(int photoItemID)
        {
            _mu = MembershipWrapper.GetUser();

            _pitm = new PhotoItem(photoItemID);

            if (_mu == null || _pitm.CreatedByUserID != Convert.ToInt32(_mu.ProviderUserKey))
                return RedirectToAction("Index");

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            _pitm.Delete();

            if (string.IsNullOrEmpty(_pitm.FilePathStandard)) return RedirectToAction("Index");
            // delete the existing photos
            try
            {
                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathStandard))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathStandard);
                }

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathRaw))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathRaw);
                }

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathThumb))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathThumb);
                }
            }
            catch
            {
                // whatever
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 13
0
        public ActionResult EditArticle(
            FormCollection fc,
            int? contentID,
            HttpPostedFileBase imageFile,
            HttpPostedFileBase videoFile,
            HttpPostedFileBase videoFile2)
        {
            mu = Membership.GetUser();

            var model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content();

            if (contentID != null && contentID > 0)
            {
                model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content(
                    Convert.ToInt32(contentID));
            }

            TryUpdateModel(model);

            ////// begin: amazon
            var acl = CannedAcl.PublicRead;

            S3Service s3 = new S3Service();

            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

            if (string.IsNullOrWhiteSpace(model.Detail) )
            {
                ModelState.AddModelError(Messages.Required, Messages.Required + ": " + Messages.Details);
            }

            if (imageFile == null && string.IsNullOrWhiteSpace(model.ContentPhotoURL))
            {
                ModelState.AddModelError(Messages.Required, Messages.Required + ": " + Messages.Photo);
            }

            if (ModelState.IsValid)
            {
                model.ContentKey = FromString.URLKey(model.Title);

                if (model.ContentID == 0)
                {
                    mu = Membership.GetUser();
                    model.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);

                    if (model.ReleaseDate == DateTime.MinValue)
                    {
                        model.ReleaseDate = DateTime.UtcNow;
                    }
                }

                if (model.Set() <= 0) return View(model);

                if (imageFile != null)
                {

                    Bitmap b = new Bitmap(imageFile.InputStream);

                    System.Drawing.Image fullPhoto = (System.Drawing.Image)b;

                    string fileNameFull = Utilities.CreateUniqueContentFilename(imageFile);

                    System.Drawing.Image imgPhoto = ImageResize.FixedSize(b, 600, 400, System.Drawing.Color.Black);

                    Stream maker = imgPhoto.ToAStream(ImageFormat.Jpeg);

                    s3.AddObject(
                        maker,
                        maker.Length,
                        AmazonCloudConfigs.AmazonBucketName,
                        fileNameFull,
                        imageFile.ContentType,
                        acl);

                    if (!string.IsNullOrWhiteSpace(model.ContentPhotoURL))
                    {
                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL);
                        }
                    }

                    model.ContentPhotoURL = fileNameFull;

                    // resized

                    string fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile);

                    System.Drawing.Image imgPhotoThumb = ImageResize.FixedSize(b, 350, 250, System.Drawing.Color.Black);

                    maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg);

                    s3.AddObject(
                        maker,
                        maker.Length,
                        AmazonCloudConfigs.AmazonBucketName,
                        fileNameThumb,
                        imageFile.ContentType,
                        acl);

                    if (!string.IsNullOrWhiteSpace(model.ContentPhotoThumbURL))
                    {
                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL);
                        }
                    }

                    model.ContentPhotoThumbURL = fileNameThumb;

                    model.Set();

                }

                if (videoFile != null)
                {
                    // full
                    try
                    {
                        string fileName3 = Utilities.CreateUniqueContentFilename(videoFile);

                        // full
                        fileName3 = Utilities.CreateUniqueContentFilename(videoFile);

                        s3.AddObject(
                         videoFile.InputStream,
                         videoFile.ContentLength,
                         AmazonCloudConfigs.AmazonBucketName,
                         fileName3,
                         videoFile.ContentType,
                         acl);

                        if (!string.IsNullOrWhiteSpace(model.ContentVideoURL))
                        {

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL);
                            }
                        }

                        model.ContentVideoURL = fileName3;

                        model.Set();

                    }
                    catch { }

                }

                if (videoFile2 != null)
                {
                    // full
                    try
                    {
                        string fileName3 = Utilities.CreateUniqueContentFilename(videoFile2);

                        // full
                        fileName3 = Utilities.CreateUniqueContentFilename(videoFile2);

                        s3.AddObject(
                         videoFile2.InputStream,
                         videoFile2.ContentLength,
                         AmazonCloudConfigs.AmazonBucketName,
                         fileName3,
                         videoFile2.ContentType,
                         acl);

                        if (!string.IsNullOrWhiteSpace(model.ContentVideoURL2))
                        {

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2);
                            }
                        }

                        model.ContentVideoURL2 = fileName3;

                        model.Set();

                    }
                    catch { }

                }

                return RedirectToAction("Articles");
            }
            else
            {
                return View(model);
            }
        }
Ejemplo n.º 14
0
        public ActionResult RotateStatusImage(int statusUpdateID)
        {
            mu = Membership.GetUser();

            StatusUpdate su = new StatusUpdate(statusUpdateID);

            if (su.PhotoItemID != null && su.PhotoItemID > 0)
            {
                var acl = CannedAcl.PublicRead;

                S3Service s3 = new S3Service();

                s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
                s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

                PhotoItem pitm = new PhotoItem(Convert.ToInt32(su.PhotoItemID));

                // full
                Image imgFull = DownloadImage(Utilities.S3ContentPath(pitm.FilePathRaw));

                float angle = 90;

                Bitmap b = RotateImage(imgFull, angle);

                System.Drawing.Image fullPhoto = (System.Drawing.Image)b;

                string fileNameFull = Guid.NewGuid() + ".jpg";

                Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameFull,
                    "image/jpg",
                    acl);

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw);
                }

                pitm.FilePathRaw = fileNameFull;

                // resized
                System.Drawing.Image photoResized = (System.Drawing.Image)b;

                string fileNameResize = Guid.NewGuid() + ".jpg";

                photoResized = ImageResize.FixedSize(photoResized, 500, 375, System.Drawing.Color.Black);

                maker = photoResized.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameResize,
                    "image/jpg",
                    acl);

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard);
                }

                pitm.FilePathStandard = fileNameResize;

                // thumb
                System.Drawing.Image thumbPhoto = (System.Drawing.Image)b;

                thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center);

                string fileNameThumb = Guid.NewGuid() + ".jpg";

                maker = thumbPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameThumb,
                   "image/jpg",
                    acl);

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb);
                }

                pitm.FilePathThumb = fileNameThumb;

                pitm.Update();

            }

            return RedirectToAction("statusupdate", new { @statusUpdateID = statusUpdateID });
        }
Ejemplo n.º 15
0
        public ActionResult EditPhotoDelete()
        {
            string str = Request.Form["delete_photo"];

            mu = Membership.GetUser();
            uad = new UserAccountDetail();
            uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

            S3Service s3 = new S3Service();

            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

            if (str == "1")
            {
                try
                {

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL);
                    }

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL);
                    }

                }
                catch
                {
                    // whatever
                }

                uad.ProfileThumbPicURL = string.Empty;
                uad.ProfilePicURL = string.Empty;
                uad.Update();
            }
            else if (str == "2" || str == "3")
            {
                ups = new UserPhotos();
                ups.GetUserPhotos(uad.UserAccountID);

                foreach (UserPhoto up1 in ups)
                {
                    try
                    {
                        if ((up1.RankOrder == 1 && str == "2") || (up1.RankOrder == 2 && str == "3"))
                        {
                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL);
                            }

                            up1.Delete();
                        }
                    }
                    catch
                    {
                        // whatever
                    }
                }

                // update ranking
                ups = new UserPhotos();
                ups.GetUserPhotos(uad.UserAccountID);

                if (ups.Count == 1 && ups[0].RankOrder == 2)
                {
                    ups[0].RankOrder = 1;
                    ups[0].Update();
                }
            }

            Response.Redirect("~/account/editphoto");

            return new EmptyResult();
        }
Ejemplo n.º 16
0
 public GetObjectRequest(S3Service service, string bucketName, string key)
     : this(service, bucketName, key, false)
 {
 }
Ejemplo n.º 17
0
        public ActionResult EditArticle(
            FormCollection fc,
            int? contentID,
            HttpPostedFileBase imageFile,
            HttpPostedFileBase videoFile)
        {
            var model = new Content();
            var articleExists = contentID != null && contentID > 0;

            if (articleExists)
            {
                model = new Content(
                    Convert.ToInt32(contentID));
            }

            TryUpdateModel(model);

            if (articleExists &&
                Request.Form["approve_preview"] != null &&
                Request.Form["approve_preview"] == "on")
            {
                ApprovedPreview(model);
                model.CurrentStatus = Convert.ToChar(SiteEnums.ContentStatus.A.ToString());
                model.Set();
                return RedirectToAction("Articles", "SiteAdmin");
            }

            foreach (var itemLanguages in (SiteEnums.SiteLanguages[])Enum.GetValues(typeof(SiteEnums.SiteLanguages)))
            {
                HttpRuntime.Cache.DeleteCacheObj(
                               string.Concat(
                                   Lib.BOL.UserContent.Content.Key,
                                   model.ContentKey,
                                   itemLanguages.ToString()));
            }

            const CannedAcl acl = CannedAcl.PublicRead;

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            if (string.IsNullOrWhiteSpace(model.Detail))
            {
                ModelState.AddModelError(Messages.Required, Messages.Required + @": " + Messages.Details);
            }

            if (imageFile == null && string.IsNullOrWhiteSpace(model.ContentPhotoURL))
            {
                ModelState.AddModelError(Messages.Required, Messages.Required + @": " + Messages.Photo);
            }

            if (!ModelState.IsValid)
            {
                return View("EditArticle" , model);
            }

            model.ContentKey = model.CurrentStatus != Convert.ToChar(SiteEnums.ContentStatus.A.ToString()) ?
                                FromString.UrlKey(model.Title) :
                                model.ContentKey;

            if (model.ContentID == 0)
            {
                if (_mu != null)
                {
                    if (model.CreatedByUserID == 0)
                        model.CreatedByUserID = Convert.ToInt32(_mu.ProviderUserKey);
                }

                if (model.ReleaseDate == DateTime.MinValue)
                {
                    model.ReleaseDate = DateTime.UtcNow;
                }
            }

            if (model.Set() <= 0)
            {
                return View(model);
            }

            if (imageFile != null)
            {
                var b = new Bitmap(imageFile.InputStream);
                string fileNameFull = Utilities.CreateUniqueContentFilename(imageFile);
                Image imgPhoto = ImageResize.FixedSize(b, 600, 400, Color.Black);
                Stream maker = imgPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameFull,
                    imageFile.ContentType,
                    acl);

                if (!string.IsNullOrWhiteSpace(model.ContentPhotoURL))
                {
                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL);
                    }
                }

                model.ContentPhotoURL = fileNameFull;

                string fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile);
                Image imgPhotoThumb = ImageResize.FixedSize(b, 350, 250, Color.Black);

                maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameThumb,
                    imageFile.ContentType,
                    acl);

                if (!string.IsNullOrWhiteSpace(model.ContentPhotoThumbURL))
                {
                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL);
                    }
                }

                model.ContentPhotoThumbURL = fileNameThumb;

                model.Set();
            }

            if (videoFile != null)
            {
                // full
                try
                {
                    // full
                    string fileName3 = Utilities.CreateUniqueContentFilename(videoFile);

                    s3.AddObject(
                        videoFile.InputStream,
                        videoFile.ContentLength,
                        AmazonCloudConfigs.AmazonBucketName,
                        fileName3,
                        videoFile.ContentType,
                        acl);

                    if (!string.IsNullOrWhiteSpace(model.ContentVideoURL))
                    {
                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL);
                        }
                    }

                    model.ContentVideoURL = fileName3;

                    model.Set();
                }
                catch
                {
                }
            }

            return RedirectToAction("Articles", "SiteAdmin"); // TODO: ENABLE SELF ARTICLE PAGE
        }
Ejemplo n.º 18
0
 public ListObjectsRequest(S3Service service, string bucketName, ListObjectsArgs args)
     : base(service, "GET", bucketName, null, args != null ? args.ToQueryString() : null)
 {
     this.BucketName = bucketName;
 }
Ejemplo n.º 19
0
        public ActionResult EditPhotoDelete()
        {
            string str = Request.Form["delete_photo"];

            _uad = new UserAccountDetail();

            if (_mu != null) _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey));

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            switch (str)
            {
                case "1":
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(_uad.RawProfilePicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl);
                        }

                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL);
                        }

                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL);
                        }
                    }
                    catch
                    {
                        // whatever
                    }

                    // set to blank the profile images that were deleted
                    _uad.RawProfilePicUrl = string.Empty;
                    _uad.ProfileThumbPicURL = string.Empty;
                    _uad.ProfilePicURL = string.Empty;
                    _uad.Update();
                    break;
                case "3":
                case "2":
                    _ups = new UserPhotos();
                    _ups.GetUserPhotos(_uad.UserAccountID);
                    foreach (UserPhoto up1 in _ups)
                    {
                        try
                        {
                            if ((up1.RankOrder != 1 || str != "2") && (up1.RankOrder != 2 || str != "3")) continue;

                            if (!string.IsNullOrWhiteSpace(up1.RawPicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL);
                            }

                            up1.Delete();
                        }
                        catch
                        {
                            // whatever
                        }
                    }
                    _ups = new UserPhotos();
                    _ups.GetUserPhotos(_uad.UserAccountID);
                    if (_ups.Count == 1 && _ups[0].RankOrder == 2)
                    {
                        _ups[0].RankOrder = 1;
                        _ups[0].Update();
                    }
                    break;
            }

            return RedirectToAction("EditPhoto");
        }
Ejemplo n.º 20
0
 static void Main()
 {
     var service = new S3Service { AccessKeyID = Utilities.AwsAccessKey, SecretAccessKey = Utilities.AwsSecretKey };
     service.GetObject(Utilities.AppRootBucketName, "FacebookSampleMVC2Appv3.zip", @"C:\Users\Santhosh\Desktop\Facebook.zip");
     UnZipFile(@"C:\Users\Santhosh\Desktop\Facebook.zip");
 }
Ejemplo n.º 21
0
 public S3Authorizer(S3Service service)
 {
     this.service = service;
     this.signer  = new HMACSHA1(Encoding.UTF8.GetBytes(service.SecretAccessKey));
 }
Ejemplo n.º 22
0
 public DeleteObjectRequest(S3Service service, string bucketName, string key)
     : base(service, "DELETE", bucketName, key, null)
 {
 }
Ejemplo n.º 23
0
        public void ProcessRequest(HttpContext context)
        {
            if (string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()]))
                return;

            var ptyc = (SiteEnums.QueryStringNames) Enum.Parse(typeof (SiteEnums.QueryStringNames),
                context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()]);

            MembershipUser mu;

            switch (ptyc)
            {
                case SiteEnums.QueryStringNames.status_update:

                    #region status_update

                    string key = context.Request.QueryString[SiteEnums.QueryStringNames.status_update_id.ToString()];

                    if (string.IsNullOrEmpty(key))
                    {
                        key =
                            context.Request.QueryString[
                                SiteEnums.QueryStringNames.most_applauded_status_update_id.ToString()];
                    }

                    int statusUpdateID = Convert.ToInt32(key);

                    StatusUpdate statup;

                    if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]))
                    {
                        mu = MembershipWrapper.GetUser();

                        if (mu == null) return;
                        var ack = new Acknowledgement
                        {
                            CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey),
                            UserAccountID = Convert.ToInt32(mu.ProviderUserKey),
                            AcknowledgementType = Convert.ToChar(
                                context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]),
                            StatusUpdateID = statusUpdateID
                        };

                        statup = new StatusUpdate(statusUpdateID);

                        if (!Acknowledgement.IsUserAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)))
                        {
                            ack.Create();

                            var sun = new StatusUpdateNotification();

                            if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                            {
                                sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID,
                                    SiteEnums.ResponseType.A);
                            }

                            if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID)
                            {
                                sun.UserAccountID = statup.UserAccountID;

                                SiteEnums.ResponseType rspType;

                                if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                                {
                                    rspType = SiteEnums.ResponseType.A;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }
                                else
                                {
                                    rspType = SiteEnums.ResponseType.B;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }

                                sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.IsRead = false;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.IsRead = false;
                                    sun.Update();
                                }

                                SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey), rspType,
                                    sun.StatusUpdateID);
                            }

                            context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}",
                                HttpUtility.HtmlEncode(statup.StatusAcknowledgements)));
                        }
                        else
                        {
                            // reverse

                            ack.GetAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey));

                            ack.Delete();

                            // TODO: DELETE NOTIFICATION

                            context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}",
                                HttpUtility.HtmlEncode(statup.StatusAcknowledgements)));
                        }
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[
                                SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]))
                    {
                        mu = MembershipWrapper.GetUser();

                        if (mu == null) return;
                        var ack = new StatusCommentAcknowledgement
                        {
                            CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey),
                            UserAccountID = Convert.ToInt32(mu.ProviderUserKey),
                            AcknowledgementType = Convert.ToChar(
                                context.Request.QueryString[
                                    SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]),
                            StatusCommentID = statusUpdateID
                        };

                        var statcomup = new StatusComment(statusUpdateID);

                        statup = new StatusUpdate(statcomup.StatusUpdateID);

                        if (!StatusCommentAcknowledgement.IsUserCommentAcknowledgement(statcomup.StatusCommentID,
                            Convert.ToInt32(
                                mu.ProviderUserKey)))
                        {
                            ack.Create();

                            var sun = new StatusUpdateNotification();

                            sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID,
                                statcomup.StatusUpdateID,
                                ack.AcknowledgementType ==
                                Convert.ToChar(
                                    SiteEnums.ResponseType.A.ToString())
                                    ? SiteEnums.ResponseType.A
                                    : SiteEnums.ResponseType.B);

                            if (Convert.ToInt32(mu.ProviderUserKey) != statcomup.UserAccountID)
                            {
                                sun.UserAccountID = statcomup.UserAccountID;

                                SiteEnums.ResponseType rspType;

                                if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                                {
                                    rspType = SiteEnums.ResponseType.A;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }
                                else
                                {
                                    rspType = SiteEnums.ResponseType.B;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.IsRead = false;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.IsRead = false;
                                    sun.Update();
                                }

                                SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey), rspType,
                                    sun.StatusUpdateID);
                            }

                            context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode(
                                statcomup.StatusCommentAcknowledgementsOptions)));
                        }
                        else
                        {
                            // reverse

                            ack.GetCommentAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey));

                            ack.Delete();
                            // TODO: DELETE NOTIFICATION

                            context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode(
                                statcomup.StatusCommentAcknowledgementsOptions)));
                        }
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) &&
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()])
                        )
                    {
                        mu = MembershipWrapper.GetUser();

                        if (mu == null) return;

                        var statCom = new StatusComment
                        {
                            CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey),
                            Message = HttpUtility.HtmlEncode(
                                context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]),
                            StatusUpdateID = statusUpdateID,
                            UserAccountID = Convert.ToInt32(mu.ProviderUserKey)
                        };

                        // TODO: CHECK IF THERE IS A RECENT MESSAGE THAT IS THE SAME
                        if (statCom.StatusCommentID != 0) return;
                        //BUG: THERE IS AN EVENT HANDLER THAT HAS QUEUED UP TOO MANY
                        var suLast = new StatusUpdate();
                        suLast.GetMostRecentUserStatus(Convert.ToInt32(mu.ProviderUserKey));

                        if (suLast.Message.Trim() != statCom.Message.Trim() ||
                            (suLast.Message.Trim() == statCom.Message.Trim() &&
                             suLast.StatusUpdateID != statCom.StatusUpdateID))
                        {
                            statCom.Create();
                        }

                        statup = new StatusUpdate(statusUpdateID);

                        // create a status update notification for the post maker and all commenters
                        StatusUpdateNotification sun;

                        if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID)
                        {
                            sun = new StatusUpdateNotification();

                            sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID,
                                statusUpdateID,
                                SiteEnums.ResponseType.C);

                            if (sun.StatusUpdateNotificationID == 0)
                            {
                                sun.ResponseType = Convert.ToChar(SiteEnums.ResponseType.C.ToString());
                                sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                sun.IsRead = false;
                                sun.StatusUpdateID = statup.StatusUpdateID;
                                sun.UserAccountID = statup.UserAccountID;
                                sun.Create();
                            }
                            else
                            {
                                sun.IsRead = false;
                                sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                sun.Update();
                            }

                            SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey),
                                SiteEnums.ResponseType.C, sun.StatusUpdateID);
                        }

                        var statComs = new StatusComments();

                        statComs.GetAllStatusCommentsForUpdate(statusUpdateID);

                        foreach (StatusComment sc1 in statComs)
                        {
                            sun = new StatusUpdateNotification();

                            sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID,
                                statusUpdateID,
                                SiteEnums.ResponseType.C);

                            if (Convert.ToInt32(mu.ProviderUserKey) == sc1.UserAccountID ||
                                Convert.ToInt32(mu.ProviderUserKey) == statup.UserAccountID) continue;

                            if (sun.StatusUpdateNotificationID == 0)
                            {
                                sun.IsRead = false;
                                sun.StatusUpdateID = statusUpdateID;
                                sun.UserAccountID = sc1.UserAccountID;
                                sun.Create();
                            }
                            else
                            {
                                sun.IsRead = false;
                                sun.Update();
                            }
                        }
                        context.Response.Write(@"{""StatusAcks"": """ + @"""}");
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) &&
                        context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "P"
                        )
                    {
                        // delete post
                        statup = new StatusUpdate(statusUpdateID);

                        StatusUpdateNotifications.DeleteNotificationsForStatusUpdate(statup.StatusUpdateID);
                        Acknowledgements.DeleteStatusAcknowledgements(statup.StatusUpdateID);

                        var statComs = new StatusComments();
                        statComs.GetAllStatusCommentsForUpdate(statup.StatusUpdateID);

                        foreach (StatusComment sc1 in statComs)
                        {
                            StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(
                                sc1.StatusCommentID);
                        }
                        StatusComments.DeleteStatusComments(statup.StatusUpdateID);

                        statup.Delete();

                        if (statup.PhotoItemID != null)
                        {
                            var pitm = new PhotoItem(Convert.ToInt32(statup.PhotoItemID));

                            var s3 = new S3Service
                            {
                                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
                            };

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb);
                            }

                            pitm.Delete();
                        }
                        context.Response.Write(@"{""StatusAcks"": """ + @"""}");
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) &&
                        context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] ==
                        "C"
                        )
                    {
                        // delete comment

                        var statCom = new StatusComment(
                            Convert.ToInt32(
                                context.Request.QueryString[
                                    SiteEnums.QueryStringNames.status_com_id.ToString()]));

                        StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(
                            statCom.StatusCommentID);

                        statCom.Delete();

                        context.Response.Write(string.Format(@"{{""StatusUpdateID"": ""{0}""}}", statCom.StatusUpdateID));
                    }
                    else if (!string.IsNullOrEmpty(
                        context.Request.QueryString[SiteEnums.QueryStringNames.all_comments.ToString()]))
                    {
                        mu = MembershipWrapper.GetUser();

                        if (mu == null) return;

                        var preFilter = new StatusComments();

                        preFilter.GetAllStatusCommentsForUpdate(statusUpdateID);

                        var statComs = new StatusComments();
                        statComs.AddRange(
                            preFilter.Where(
                                su1 =>
                                    !BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID)));

                        statComs.IncludeStartAndEndTags = true;

                        var sb = new StringBuilder(100);

                        sb.Append(statComs.ToUnorderdList);

                        context.Response.Write(string.Format(@"{{""StatusComs"": ""{0}""}}",
                            HttpUtility.HtmlEncode(sb.ToString())));
                    }
                    else if (!string.IsNullOrEmpty(
                        context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()]))
                    {
                        int pcount =
                            Convert.ToInt32(
                                context.Request.QueryString[
                                    SiteEnums.QueryStringNames.comment_page.ToString()]);

                        var statups = new StatusUpdates();

                        pcount = pcount + 10;

                        var preFilter = new StatusUpdates();

                        preFilter.GetStatusUpdatesPageWise(pcount, 1);

                        mu = MembershipWrapper.GetUser();

                        statups.AddRange(
                            preFilter.Where(
                                su1 =>
                                    mu != null &&
                                    !BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID)));

                        statups.IncludeStartAndEndTags = false;

                        context.Response.Write(string.Format(@"{{""StatusUpdates"": ""{0}""}}",
                            HttpUtility.HtmlEncode(statups.ToUnorderdList)));
                    }

                    #endregion

                    break;
                case SiteEnums.QueryStringNames.begin_playlist:

                    #region begin_playlist

                    context.Response.Write(
                        PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[
                            SiteEnums.QueryStringNames.playlist.ToString()])));

                    #endregion

                    break;
                case SiteEnums.QueryStringNames.menu:

                    #region menu

                    mu = MembershipWrapper.GetUser();

                    int userCountChat = 0;
                    int userMessages = 0;
                    int unconfirmedUsers = 0;
                    int notifications = 0;

                    if (mu != null)
                    {
                        // log off users who are offline

                        var uasOffline = new UserAccounts();
                        uasOffline.GetWhoIsOffline(true);

                        foreach (UserAccount uaoff1 in uasOffline)
                        {
                            var cru = new ChatRoomUser();
                            cru.GetChatRoomUserByUserAccountID(uaoff1.UserAccountID);

                            if (cru.ChatRoomUserID > 0)
                            {
                                cru.DeleteChatRoomUser();
                            }

                            var offlineUser = new UserAccount(uaoff1.UserAccountID);
                            offlineUser.RemoveCache();
                        }

                        userCountChat = ChatRoomUsers.GetChattingUserCount();

                        userMessages = DirectMessages.GetDirectMessagesToUserCount(mu);
                        unconfirmedUsers =
                            UserConnections.GetCountUnconfirmedConnections(Convert.ToInt32(mu.ProviderUserKey));
                    }

                    // get users online
                    int onlineUsers = UserAccounts.GetOnlineUserCount();

                    if (mu != null)
                    {
                        notifications =
                            StatusUpdateNotifications.GetStatusUpdateNotificationCountForUser(
                                Convert.ToInt32(mu.ProviderUserKey));
                    }

                    string timedMessge = string.Format(
                        @"{{""UserCountChat"": ""{0}"",
               ""UserMessages"": ""{1}"",
               ""OnlineUsers"": ""{2}"",
               ""Notifications"": ""{3}"",
               ""UnconfirmedUsers"": ""{4}""}}", userCountChat, userMessages, onlineUsers, notifications,
                        unconfirmedUsers);

                    context.Response.Write(timedMessge);

                    #endregion

                    break;
                case SiteEnums.QueryStringNames.random:

                    #region random

                    if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(Video.GetRandomJSON(
                            context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else
                    {
                        context.Response.Write(Video.GetRandomJSON());
                    }

                    #endregion

                    break;
                case SiteEnums.QueryStringNames.video_playlist:

                    #region video_playlist

                    if (!string.IsNullOrEmpty(
                        context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetNextVideo(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]),
                                context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetFirstVideo(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])));
                    }
                    else
                    {
                        context.Response.Write(
                            PlaylistVideo.CurrentVideoInPlaylist(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])
                                ));
                    }

                    #endregion

                    break;
                case SiteEnums.QueryStringNames.video:

                    #region video

                    var vid = new Video("YT", context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]);

                    VideoLog.AddVideoLog(vid.VideoID, context.Request.UserHostAddress);

                    context.Response.Write(
                        Video.GetVideoJSON(context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]));

                    #endregion

                    break;

                case SiteEnums.QueryStringNames.playlist:

                    #region playlist

                    if (!string.IsNullOrEmpty(
                        context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetNextVideo(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]),
                                context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else if (
                        !string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetFirstVideo(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])));
                    }
                    else
                    {
                        context.Response.Write(
                            PlaylistVideo.CurrentVideoInPlaylist(
                                Convert.ToInt32(
                                    context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])
                                ));
                    }

                    #endregion

                    break;
            }
        }
Ejemplo n.º 24
0
        private void VersaVaultLoad(object sender, EventArgs e)
        {
            try
            {
                CheckForIllegalCrossThreadCalls = false;
                _service = new S3Service
                               {
                                   AccessKeyID = Utilities.AwsAccessKey,
                                   SecretAccessKey = Utilities.AwsSecretKey,
                                   UseSubdomains = true
                               };

                _amazons3 = AWSClientFactory.CreateAmazonS3Client(Utilities.AwsAccessKey, Utilities.AwsSecretKey, new AmazonS3Config { CommunicationProtocol = Protocol.HTTP });

                _service.AddObjectProgress += ServiceAddObjectProgress;
                _service.GetObjectProgress += ServiceGetObjectProgress;

                _downloadObjects = new List<string>();

                if (!Directory.Exists(Utilities.Path))
                    Directory.CreateDirectory(Utilities.Path);

                if (!Directory.Exists(Utilities.AppPath))
                    Directory.CreateDirectory(Utilities.AppPath);

                if (!Directory.Exists(Utilities.SharedFolderPath))
                    Directory.CreateDirectory(Utilities.SharedFolderPath);

                TxtUsername.Text = Utilities.MyConfig.Username;
                TxtPassword.Text = Utilities.MyConfig.Password;

                if (!string.IsNullOrEmpty(TxtUsername.Text) || !string.IsNullOrEmpty(TxtPassword.Text.Trim()))
                {
                    if (!GetBucketId())
                    {
                        if (string.IsNullOrEmpty(Utilities.MyConfig.BucketKey))
                            StopSync();
                        else
                            StartSync();
                    }
                }
                else
                    ShowForm();
            }
            catch (Exception)
            {
                return;
            }
        }
Ejemplo n.º 25
0
        public ActionResult Delete(int photoItemID)
        {
            mu = Membership.GetUser();

            pitm = new PhotoItem(photoItemID);

            if (pitm.CreatedByUserID == Convert.ToInt32(mu.ProviderUserKey))
            {
                S3Service s3 = new S3Service();

                s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
                s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

                pitm.Delete();

                if (!string.IsNullOrEmpty(pitm.FilePathStandard))
                {
                    // delete the existing photos
                    try
                    {
                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName,  pitm.FilePathStandard))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard);
                        }

                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName,  pitm.FilePathRaw))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw);
                        }

                        if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName,  pitm.FilePathThumb))
                        {
                            s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb);
                        }

                    }
                    catch
                    {
                        // whatever
                    }
                }
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 26
0
 static S3Service GetService()
 {
     S3Service service = new S3Service()
     {
         AccessKeyID = Program.Config.AccessKey,
         SecretAccessKey = Program.Config.SecretKey,
         Host = Program.Config.Region,
     };
     service.BeforeAuthorize += service_BeforeAuthorize;
     return service;
 }
Ejemplo n.º 27
0
        public void ProcessRequest(HttpContext context)
        {
            //        context.Response.ContentType = "text/plain";

               //    context.Response.CacheControl = "no-cache";

               // context.Response.AddHeader("Pragma", "no-cache");

               // //context.Response.AddHeader("Pragma", "no-store");

               // //context.Response.AddHeader("cache-control", "no-cache");

               //context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

               // context.Response.Cache.SetNoServerCaching();

            if (string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()])) return;

            SiteEnums.QueryStringNames ptyc = (SiteEnums.QueryStringNames)Enum.Parse(typeof(SiteEnums.QueryStringNames),
                context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()]);

              //  Dictionary<string, Subgurim.Chat.Usuario> usrrs = null;
            StringBuilder sb = null;
            MembershipUser mu = null;

            switch (ptyc)
            {
                case SiteEnums.QueryStringNames.status_update:
                    #region status_update

                    string key = context.Request.QueryString[SiteEnums.QueryStringNames.status_update_id.ToString()];

                    if (string.IsNullOrEmpty(key))
                    {
                        key = context.Request.QueryString[SiteEnums.QueryStringNames.most_applauded_status_update_id.ToString()];
                    }

                    int statusUpdateID = Convert.ToInt32(key);

                    StatusUpdate statup = null;

                    if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]))
                    {
                        mu = Membership.GetUser();

                        Acknowledgement ack = new Acknowledgement();

                        ack.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                        ack.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                        ack.AcknowledgementType = Convert.ToChar(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]);
                        ack.StatusUpdateID = statusUpdateID;

                        statup = new StatusUpdate(statusUpdateID);

                        if (!Acknowledgement.IsUserAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)))
                        {
                            ack.Create();

                            StatusUpdateNotification sun = new StatusUpdateNotification();

                            if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                            {
                                //  sun.GetStatusUpdateNotificationForUserStatus(Convert.ToInt32(mu.ProviderUserKey), statusUpdateID, SiteEnums.ResponseType.A);
                                sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.A);
                            }
                            else if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.B.ToString()))
                            {
                                //sun.GetStatusUpdateNotificationForUserStatus(Convert.ToInt32(mu.ProviderUserKey), statusUpdateID, SiteEnums.ResponseType.B);
                                sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.B);
                            }

                            if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID)
                            {
                                sun.UserAccountID = statup.UserAccountID;

                                SiteEnums.ResponseType rspType = SiteEnums.ResponseType.U;

                                if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                                {
                                    rspType = SiteEnums.ResponseType.A;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }
                                else
                                {
                                    rspType = SiteEnums.ResponseType.B;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }

                                sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.IsRead = false;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.IsRead = false;
                                    sun.Update();
                                }

                                SendNotificationEmail(statup.UserAccountID, rspType, sun.StatusUpdateID);
                            }

                            context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statup.StatusAcknowledgements) + @"""}");
                        }
                        else
                        {
                            // reverse

                            ack.GetAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey));

                            ack.Delete();

                            // TODO: DELETE NOTIFICATION

                            context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statup.StatusAcknowledgements) + @"""}");
                        }
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]))
                    {
                        mu = Membership.GetUser();

                        StatusCommentAcknowledgement ack = new StatusCommentAcknowledgement();

                        ack.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                        ack.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                        ack.AcknowledgementType = Convert.ToChar(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]);
                        ack.StatusCommentID = statusUpdateID; // this is really the commentID (or should be)

                        StatusComment statcomup = new StatusComment(statusUpdateID);

                        statup = new StatusUpdate(statcomup.StatusUpdateID);

                        if (!StatusCommentAcknowledgement.IsUserCommentAcknowledgement(statcomup.StatusCommentID, Convert.ToInt32(mu.ProviderUserKey)))
                        {
                            ack.Create();

                            StatusUpdateNotification sun = new StatusUpdateNotification();

                            if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                            {
                                sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID, statcomup.StatusUpdateID, SiteEnums.ResponseType.A);
                            }
                            else
                            {
                                sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID, statcomup.StatusUpdateID, SiteEnums.ResponseType.B);
                            }

                            if (Convert.ToInt32(mu.ProviderUserKey) != statcomup.UserAccountID)
                            {
                                sun.UserAccountID = statcomup.UserAccountID;

                                SiteEnums.ResponseType rspType = SiteEnums.ResponseType.U;

                                if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString()))
                                {
                                    rspType = SiteEnums.ResponseType.A;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }
                                else
                                {
                                    rspType = SiteEnums.ResponseType.B;
                                    sun.ResponseType = Convert.ToChar(rspType.ToString());
                                }

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.IsRead = false;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.IsRead = false;
                                    sun.Update();
                                }

                                SendNotificationEmail(statup.UserAccountID, rspType, sun.StatusUpdateID);
                            }

                            context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statcomup.StatusCommentAcknowledgementsOptions) + @"""}");
                        }
                        else
                        {
                            // reverse

                            ack.GetCommentAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey));

                            ack.Delete();
                            // TODO: DELETE NOTIFICATION

                            context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statcomup.StatusCommentAcknowledgementsOptions) + @"""}");
                        }
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) &&
                        !string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()])
                        )
                    {
                        mu = Membership.GetUser();

                        if (mu == null) return;

                        StatusComment statCom = new StatusComment();
                        statCom.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                        statCom.Message = HttpUtility.HtmlEncode(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]);
                        statCom.StatusUpdateID = statusUpdateID;
                        statCom.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);

                        //statCom.GetStatusCommentMessage(); // ? ignore this duplicate now

                        // TODO: CHECK IF THERE IS A RECENT MESSAGE THAT IS THE SAME
                        if (statCom.StatusCommentID == 0)
                        {
                            //BUG: THERE IS AN EVENT HANDLER THAT HAS QUEUED UP TOO MANY
                            StatusUpdate suLast = new StatusUpdate();
                            suLast.GetMostRecentUserStatus(Convert.ToInt32(mu.ProviderUserKey));

                            if (suLast.Message.Trim() != statCom.Message.Trim() || (suLast.Message.Trim() == statCom.Message.Trim() && suLast.StatusUpdateID != statCom.StatusUpdateID))
                            {
                                statCom.Create();
                            }

                            statup = new StatusUpdate(statusUpdateID);

                            // create a status update notification for the post maker and all commenters
                            StatusUpdateNotification sun = null;

                            if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID)
                            {
                                sun = new StatusUpdateNotification();

                                sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C);

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.ResponseType = Convert.ToChar(SiteEnums.ResponseType.C.ToString());
                                    sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.IsRead = false;
                                    sun.StatusUpdateID = statup.StatusUpdateID;
                                    sun.UserAccountID = statup.UserAccountID;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.IsRead = false;
                                    sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                                    sun.Update();
                                }

                                SendNotificationEmail(statup.UserAccountID, SiteEnums.ResponseType.C, sun.StatusUpdateID);
                            }

                            StatusComments statComs = new StatusComments();

                            statComs.GetAllStatusCommentsForUpdate(statusUpdateID);

                            foreach (StatusComment sc1 in statComs)
                            {
                                sun = new StatusUpdateNotification();

                                sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C);

                                if (Convert.ToInt32(mu.ProviderUserKey) == sc1.UserAccountID ||
                                    Convert.ToInt32(mu.ProviderUserKey) == statup.UserAccountID) continue;

                                if (sun.StatusUpdateNotificationID == 0)
                                {
                                    sun.IsRead = false;
                                    sun.StatusUpdateID = statusUpdateID;
                                    sun.UserAccountID = sc1.UserAccountID;
                                    sun.Create();
                                }
                                else
                                {
                                    sun.IsRead = false;
                                    sun.Update();
                                }
                            }
                            context.Response.Write(@"{""StatusAcks"": """ +  @"""}");
                        }
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) &&
                         context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "P"
                        )
                    {
                        // delete post
                        statup = new StatusUpdate(statusUpdateID);

                        StatusUpdateNotifications.DeleteNotificationsForStatusUpdate(statup.StatusUpdateID);
                        Acknowledgements.DeleteStatusAcknowledgements(statup.StatusUpdateID);

                        StatusComments statComs = new StatusComments();
                        statComs.GetAllStatusCommentsForUpdate(statup.StatusUpdateID);

                        foreach (StatusComment sc1 in statComs)
                        {
                            StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(sc1.StatusCommentID);
                        }
                        StatusComments.DeleteStatusComments(statup.StatusUpdateID);

                        statup.Delete();

                        if (statup.PhotoItemID != null)
                        {
                            PhotoItem pitm = new PhotoItem(Convert.ToInt32(statup.PhotoItemID));

                            S3Service s3 = new S3Service();

                            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
                            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard);
                            }

                            if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb))
                            {
                                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb);
                            }

                            pitm.Delete();
                        }
                        context.Response.Write(@"{""StatusAcks"": """ + @"""}");
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) &&
                             context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "C"
                            )
                    {
                        // delete comment

                        StatusComment statCom = new StatusComment(
                            Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.status_com_id.ToString()]));

                        StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(statCom.StatusCommentID);

                        statCom.Delete();

                        context.Response.Write(@"{""StatusUpdateID"": """ + statCom.StatusUpdateID.ToString() + @"""}");
                    }
                    else if (!string.IsNullOrEmpty(
                        context.Request.QueryString[SiteEnums.QueryStringNames.all_comments.ToString()]))
                    {
                        mu = Membership.GetUser();

                        if (mu == null) return;

                        StatusComments preFilter = new StatusComments();

                        preFilter.GetAllStatusCommentsForUpdate(statusUpdateID);

                        StatusComments statComs = new StatusComments();

                        foreach (BootBaronLib.AppSpec.DasKlub.BOL.StatusComment su1 in preFilter)
                        {
                            if (!BootBaronLib.AppSpec.DasKlub.BOL.BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID))
                            {
                                statComs.Add(su1);
                            }
                        }

                        statComs.IncludeStartAndEndTags = true;

                        sb = new StringBuilder(100);

                        sb.Append(statComs.ToUnorderdList);

                        context.Response.Write(@"{""StatusComs"": """ + HttpUtility.HtmlEncode(sb.ToString()) + @"""}");
                    }
                    else if (!string.IsNullOrEmpty(
                            context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()]))
                    {
                        int pcount = Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()]);

                        StatusUpdates statups = new StatusUpdates();

                        pcount = pcount + 10;

                        StatusUpdates preFilter = new StatusUpdates();

                        preFilter.GetStatusUpdatesPageWise(pcount, 1);

                        StatusUpdates sus = new StatusUpdates();

                        mu = Membership.GetUser();

                        foreach (BootBaronLib.AppSpec.DasKlub.BOL.StatusUpdate su1
                            in preFilter)
                        {
                            if (!BootBaronLib.AppSpec.DasKlub.BOL.BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID))
                            {
                                statups.Add(su1);
                            }
                        }

                        statups.IncludeStartAndEndTags = false;

                        context.Response.Write(@"{""StatusUpdates"": """ + HttpUtility.HtmlEncode(statups.ToUnorderdList) + @"""}");
                    }

                    #endregion
                    break;
                case SiteEnums.QueryStringNames.begin_playlist:
                    #region begin_playlist
                    context.Response.Write(
                       PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[
                       SiteEnums.QueryStringNames.playlist.ToString()])));
                    #endregion
                    break;
                case SiteEnums.QueryStringNames.menu:
                    #region menu

                    mu = Membership.GetUser();

                    // menu updates

                    // get count in video room
                    int userCountChat = 0;

                    // get new mail
                    int userMessages = 0;

                    // get new users
                    int unconfirmedUsers = 0;

                    // status notifications
                    int notifications = 0;

                    if (mu != null)
                    {
                        // log off users who are offline

                        UserAccounts uasOffline = new UserAccounts();
                        uasOffline.GetWhoIsOffline(true);

                        UserAccount offlineUser = null;

                        foreach (UserAccount uaoff1 in uasOffline)
                        {
                            ChatRoomUser cru = new ChatRoomUser();
                            cru.GetChatRoomUserByUserAccountID(uaoff1.UserAccountID);

                            if (cru.ChatRoomUserID > 0)
                            {
                                cru.DeleteChatRoomUser();
                            }

                            offlineUser = new UserAccount(uaoff1.UserAccountID);
                            offlineUser.RemoveCache();
                        }

                        userCountChat = ChatRoomUsers.GetChattingUserCount();

                        userMessages = BootBaronLib.AppSpec.DasKlub.BOL.DirectMessages.GetDirectMessagesToUserCount(mu);
                        unconfirmedUsers = BootBaronLib.AppSpec.DasKlub.BOL.UserConnections.GetCountUnconfirmedConnections(Convert.ToInt32(mu.ProviderUserKey));
                    }

                    // get users online
                    int onlineUsers = UserAccounts.GetOnlineUserCount();

                    if (mu != null)
                    {
                        notifications = StatusUpdateNotifications.GetStatusUpdateNotificationCountForUser(Convert.ToInt32(mu.ProviderUserKey));
                    }

                    string timedMessge = string.Format(
            @"{{""UserCountChat"": ""{0}"",
               ""UserMessages"": ""{1}"",
               ""OnlineUsers"": ""{2}"",
               ""Notifications"": ""{3}"",
               ""UnconfirmedUsers"": ""{4}""}}",userCountChat,userMessages,onlineUsers,notifications,unconfirmedUsers);

                    context.Response.Write(timedMessge);

                    #endregion
                    break;
                case SiteEnums.QueryStringNames.random:
                    #region random
                    if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(Video.GetRandomJSON(
                            context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else
                    {
                        context.Response.Write(Video.GetRandomJSON());
                    }

                    #endregion
                    break;
                case SiteEnums.QueryStringNames.video_playlist:
                    #region video_playlist
                    if (!string.IsNullOrEmpty(
               context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetNextVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]),
                            context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()]))
                    {
                        context.Response.Write(
                          PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])));
                    }
                    else
                    {
                        context.Response.Write(
                            PlaylistVideo.CurrentVideoInPlaylist(
                            Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])
                            ));
                    }
                    #endregion
                    break;
                case SiteEnums.QueryStringNames.video:
                    #region video
                    Video vid = new Video("YT", context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]);

                    VideoLog.AddVideoLog(vid.VideoID, context.Request.UserHostAddress);

                    context.Response.Write(Video.GetVideoJSON(context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]));
                    #endregion
                    break;
                case SiteEnums.QueryStringNames.begindate:
                    #region begindate

                    //string[] dates = HttpUtility.UrlDecode(
                    //    context.Request.QueryString[SiteEnums.QueryStringNames.begindate.ToString()]
                    //    ).Split('G');

                    DateTime dtBegin = Convert.ToDateTime(context.Request.QueryString[SiteEnums.QueryStringNames.begindate.ToString()]);

                    dtBegin = new DateTime(dtBegin.Year, dtBegin.Month, 1);

                    DateTime dtEnd = dtBegin.AddMonths(1).AddDays(-1);
                    Events tds = new Events();

                    tds.GetEventsForLocation(
                          dtBegin, dtEnd,
                          context.Request.QueryString[SiteEnums.QueryStringNames.country_iso.ToString()],
                          context.Request.QueryString[SiteEnums.QueryStringNames.region.ToString()],
                          context.Request.QueryString[SiteEnums.QueryStringNames.city.ToString()]);

                    CalendarItems citms = GetCitms(tds, dtBegin, dtEnd, true);

                    //[ 100, 500, 300, 200, 400 ]
                    sb = new StringBuilder();

                    sb.Append("[");

                    int processed = 1;

                    foreach (CalendarItem ci1 in citms)
                    {
                        if (processed == citms.Count)
                        {
                            sb.Append(ci1.StartDate.Day);
                        }
                        else
                        {
                            sb.Append(ci1.StartDate.Day);
                            sb.Append(", ");
                        }

                        processed++;
                    }

                    sb.Append("]");

                    context.Response.Write(sb.ToString());
                    #endregion
                    break;
                case SiteEnums.QueryStringNames.playlist:
                    #region playlist

                    if (!string.IsNullOrEmpty(
                    context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]))
                    {
                        context.Response.Write(
                            PlaylistVideo.GetNextVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]),
                            context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()]));
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()]))
                    {
                        context.Response.Write(
                          PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])));
                    }
                    else
                    {
                        context.Response.Write(
                            PlaylistVideo.CurrentVideoInPlaylist(
                            Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()])
                            ));
                    }
                    #endregion
                    break;
                default:
                    // ?
                    break;

            }
        }
 public AmazonS3StorageSource(IAmazonStorageSettings settings)
 {
     _settings = settings;
     _service = new S3Service { AccessKeyID = _settings.AccessKey, SecretAccessKey = _settings.SecretAccessKey, UseSubdomains = true };
 }
Ejemplo n.º 29
0
        public ActionResult Home(string message, HttpPostedFileBase file)
        {
            if (string.IsNullOrWhiteSpace(message) && file == null)
            {
                return RedirectToAction("Home");
            }

            if (message != null) message = message.Trim();

            if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));

            if (_ua.UserAccountID ==  18136)
            {
                // check if over posting user can take a hint to stop
                var lastUpdate = new StatusUpdate();
                lastUpdate.GetMostRecentUserStatus(_ua.UserAccountID);

                if (lastUpdate.CreateDate > DateTime.UtcNow.AddHours(-24))
                {
                    TempData["user_error"] =
                        "Please STOP posting so much, you are only allowed to post once ever 24 hours! Thank you for keeping the wall clean.";

                    return RedirectToAction("Home");
                }
            }

            ViewBag.CurrentUser = _ua.ToUnorderdListItem;

            var su = new StatusUpdate();

            su.GetMostRecentUserStatus(_ua.UserAccountID);

            DateTime startTime = DateTime.UtcNow;

            TimeSpan span = startTime.Subtract(su.CreateDate);

            // TODO: this is not working properly, preventing posts
            if (su.Message == message && file == null)
            {
                // double post
                return RedirectToAction("Home");
            }
            su = new StatusUpdate();

            if (file != null && Utilities.IsImageFile(file.FileName))
            {
                var b = new Bitmap(file.InputStream);

                const CannedAcl acl = CannedAcl.PublicRead;

                var s3 = new S3Service
                {
                    AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                    SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
                };

                var pitem = new PhotoItem {CreatedByUserID = _ua.UserAccountID, Title = message};

                Image fullPhoto = b;

                string fileNameFull = Utilities.CreateUniqueContentFilename(file);

                Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameFull,
                    file.ContentType,
                    acl);

                pitem.FilePathRaw = fileNameFull;

                // resized
                Image photoResized = b;

                string fileNameResize = Utilities.CreateUniqueContentFilename(file);

                photoResized = ImageResize.FixedSize(photoResized, 500, 375, Color.Black);

                maker = photoResized.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameResize,
                    file.ContentType,
                    acl);

                pitem.FilePathStandard = fileNameResize;

                // thumb
                Image thumbPhoto = b;

                thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center);

                string fileNameThumb = Utilities.CreateUniqueContentFilename(file);

                maker = thumbPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameThumb,
                    file.ContentType,
                    acl);

                pitem.FilePathThumb = fileNameThumb;

                pitem.Create();

                su.PhotoItemID = pitem.PhotoItemID;
            }

            su.UserAccountID = _ua.UserAccountID;
            su.Message = message;
            su.CreatedByUserID = _ua.UserAccountID;
            su.IsMobile = Request.Browser.IsMobileDevice;
            su.Create();

            if (Request.Browser.IsMobileDevice)
            {
                return new RedirectResult(Url.Action("Home") + "#most_recent");
            }
            return RedirectToAction("Home");
        }
Ejemplo n.º 30
0
 public DeleteBucketRequest(S3Service service, string bucketName)
     : base(service, "DELETE", bucketName, null, null)
 {
 }
Ejemplo n.º 31
0
        public ActionResult EditArticle(
            FormCollection fc,
            int? contentId,
            HttpPostedFileBase imageFile,
            HttpPostedFileBase videoFile)
        {
            var isExisting = contentId != null && contentId > 0;
            var model = new PreviewContentModel();
            TryUpdateModel(model);

            if (!HasImage(imageFile, model, contentId) ||
                !ModelState.IsValid ||
                !HasValidTitle(model, contentId) ||
                !IsContentCorrectLength(model) ||
                !IsMetaDescriptionLengthCorrect(model))
            {
                return View("CreateArticle", model);
            }

            Content content;

            if (isExisting)
            {
                content = new Content(Convert.ToInt32(contentId))
                {
                    UpdatedByUserID = Convert.ToInt32(_mu.ProviderUserKey)
                };
            }
            else
            {
                content = new Content
                {
                    CurrentStatus = Convert.ToChar(SiteEnums.ContentStatus.N.ToString()),
                    CreatedByUserID = Convert.ToInt32(this._mu.ProviderUserKey),
                    ReleaseDate = DateTime.UtcNow,
                    ContentKey = FromString.UrlKey(model.PreviewTitle),
                };
            }

            content.PreviewTitle = model.PreviewTitle.Trim();
            content.DetailPreview = model.DetailPreview.Trim();
            content.PreviewLanguage = model.PreviewLanguage.Trim();
            content.PreviewMetaDescription = model.PreviewMetaDescription.Trim();
            content.PreviewMetaKeywords = model.PreviewMetaKeywords.Trim();

            if (imageFile != null && imageFile.InputStream != null)
            {
                // set images
                const CannedAcl acl = CannedAcl.PublicRead;

                var s3 = new S3Service
                {
                    AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                    SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
                };

                var bitmap = new Bitmap(imageFile.InputStream);
                var fileNameFull = Utilities.CreateUniqueContentFilename(imageFile);
                var imgPhoto = ImageResize.FixedSize(bitmap, 600, 400, Color.Black);
                var maker = imgPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameFull,
                    imageFile.ContentType,
                    acl);

                if (!string.IsNullOrWhiteSpace(model.PreviewContentPhotoUrl))
                {
                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoUrl))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoUrl);
                    }
                }

                content.PreviewContentPhotoURL = fileNameFull;

                var fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile);
                var imgPhotoThumb = ImageResize.FixedSize(bitmap, 350, 250, Color.Black);

                maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameThumb,
                    imageFile.ContentType,
                    acl);

                if (!string.IsNullOrWhiteSpace(model.PreviewContentPhotoThumbUrl))
                {
                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoThumbUrl))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoThumbUrl);
                    }
                }

                content.PreviewContentPhotoThumbURL = fileNameThumb;
            }

            content.Set();

            return RedirectToAction("Preview", new {key= content.ContentKey });
        }
Ejemplo n.º 32
0
 public CopyObjectRequest(S3Service service, string bucketName, string sourceObjectKey,
                          string destObjectKey)
     : this(service, bucketName, sourceObjectKey, bucketName, destObjectKey)
 {
 }
Ejemplo n.º 33
0
 public static bool CheckVersion(bool forceCheck)
 {
     // first check the last updated date
     _notification = new Notification();
     _notification.SetMessage("Checking for updates");
     try
     {
         if (forceCheck)
         {
             _notification.Show();
             _notification.ShowForm(10);
         }
         if (forceCheck)
         {
             var amazons3 = AWSClientFactory.CreateAmazonS3Client(Utilities.AwsAccessKey, Utilities.AwsSecretKey, new AmazonS3Config { CommunicationProtocol = Protocol.HTTP });
             var listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool_32Bit.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (!string.IsNullOrEmpty(Utilities.MyConfig.InstallerVersionId) && Utilities.MyConfig.InstallerVersionId != s3ObjectVersion.VersionId)
                     {
                         while (Process.GetProcessesByName("VersaVaultSyncTool_32Bit").Length != 0)
                         {
                             Thread.Sleep(1000);
                             Application.DoEvents();
                         }
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe")))
                             File.Delete(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")))
                         {
                             File.Move(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"),
                                       Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         }
                         var service = new S3Service { AccessKeyID = Utilities.AwsAccessKey, SecretAccessKey = Utilities.AwsSecretKey };
                         _notification.SetMessage("Started downloading update.");
                         service.GetObjectProgress += ServiceGetObjectProgress;
                         service.GetObject(Utilities.AppRootBucketName, s3ObjectVersion.Key, Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"));
                         _notification.SetMessage("Updating VersaVault");
                         Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         var startInfo = new ProcessStartInfo(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")) { Verb = "runas" };
                         Process.Start(startInfo);
                         Application.Exit();
                         return false;
                     }
                     Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                     Utilities.MyConfig.Save();
                     break;
                 }
             }
             listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (s3ObjectVersion.VersionId != null && s3ObjectVersion.VersionId != "null")
                     {
                         if (!string.IsNullOrEmpty(Utilities.MyConfig.VersionId) && Utilities.MyConfig.VersionId != s3ObjectVersion.VersionId)
                         {
                             _notification.Dispose();
                             Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                             Utilities.MyConfig.Save();
                             var startInfo = new ProcessStartInfo(Path.Combine(Application.StartupPath, "VersaVaultUpdater.exe"), s3ObjectVersion.VersionId + " " + "update") { Verb = "runas" };
                             Process.Start(startInfo);
                             Application.Exit();
                             return false;
                         }
                         Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         return true;
                     }
                     // enable bucker versioning
                     var setBucketVersioning = new SetBucketVersioningRequest { BucketName = Utilities.AppRootBucketName, VersioningConfig = new S3BucketVersioningConfig { Status = "Enabled" } };
                     amazons3.SetBucketVersioning(setBucketVersioning);
                     break;
                 }
             }
             return true;
         }
     }
     catch (Exception)
     {
     }
     finally
     {
         try
         {
             _notification.Controls["LblStatus"].Text = @"VersaVault is upto date.";
             _notification.HideForm(10);
             _notification.Close();
             _notification.Dispose();
         }
         catch (Exception)
         {
         }
     }
     return true;
 }
Ejemplo n.º 34
0
 public GetAllBucketsRequest(S3Service service)
     : base(service, "GET", null, null, null)
 {
 }
Ejemplo n.º 35
0
 public GetObjectRequest(S3Service service, string bucketName, string key, bool metadataOnly)
     : base(service, metadataOnly ? "HEAD" : "GET", bucketName, key, null)
 {
 }
Ejemplo n.º 36
0
        private static string AddPhotoToBucket(
            HttpPostedFileBase file, 
            CannedAcl acl, 
            S3Service s3, 
            Bitmap photoBitmap, 
            bool resize, 
            int width = 1, 
            int height = 1)
        {
            string profilePhotoFileName = Utilities.CreateUniqueContentFilename(file);
            Image rawPhoto = photoBitmap;

            if (resize)
            {
                Image image = ImageResize.FixedSize(imgPhoto: rawPhoto, width: width, height: height, bgColor: Color.Black);
                Stream profilePhotoStream = image.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    profilePhotoStream,
                    profilePhotoStream.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    profilePhotoFileName,
                    file.ContentType,
                    acl);
            }
            else
            {
                Stream image = rawPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    image,
                    image.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    profilePhotoFileName,
                    file.ContentType,
                    acl);
            }

            return profilePhotoFileName;
        }
Ejemplo n.º 37
0
        public ActionResult Home(string message, HttpPostedFileBase file)
        {
            if (string.IsNullOrWhiteSpace(message) && file == null)
            {
                return RedirectToAction("Home");
            }

            message = message.Trim();

            mu = Membership.GetUser();

            ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));
            //StatusUpdates sus = null;

            ViewBag.CurrentUser = ua.ToUnorderdListItem;

            StatusUpdate su = new StatusUpdate();

            su.GetMostRecentUserStatus(ua.UserAccountID);

            DateTime startTime = Utilities.GetDataBaseTime();

            TimeSpan span = startTime.Subtract(su.CreateDate);

            //su = new StatusUpdate();
            // TODO: this is not working properly, preventing posts
            if (su.Message == message && file == null)
            {
                // double post
                return RedirectToAction("Home");
            }
            else
            {
                su = new StatusUpdate();
            }

            if (file != null && Utilities.IsImageFile(file.FileName))
            {
                Bitmap b = new Bitmap(file.InputStream);

                var acl = CannedAcl.PublicRead;

                S3Service s3 = new S3Service();

                s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
                s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

                PhotoItem pitem = new PhotoItem();

                pitem.CreatedByUserID = ua.UserAccountID;
                pitem.Title = message;

                // full
                System.Drawing.Image fullPhoto = (System.Drawing.Image)b;

                string fileNameFull = Utilities.CreateUniqueContentFilename(file);

                Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameFull,
                    file.ContentType,
                    acl);

                pitem.FilePathRaw = fileNameFull;

                // resized
                System.Drawing.Image photoResized = (System.Drawing.Image)b;

                string fileNameResize = Utilities.CreateUniqueContentFilename(file);

                photoResized = ImageResize.FixedSize(photoResized, 500, 375, System.Drawing.Color.Black);

                maker = photoResized.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameResize,
                    file.ContentType,
                    acl);

                pitem.FilePathStandard = fileNameResize;

                // thumb
                System.Drawing.Image thumbPhoto = (System.Drawing.Image)b;

                thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center);

                string fileNameThumb = Utilities.CreateUniqueContentFilename(file);

                maker = thumbPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    maker,
                    maker.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    fileNameThumb,
                    file.ContentType,
                    acl);

                pitem.FilePathThumb = fileNameThumb;

                pitem.Create();

                su.PhotoItemID = pitem.PhotoItemID;
            }

            su.UserAccountID = ua.UserAccountID;
            su.Message = message;
            su.CreatedByUserID = ua.UserAccountID;
            su.IsMobile = Request.Browser.IsMobileDevice;
            su.Create();

            if (Request.Browser.IsMobileDevice)
            {
                // this will bring them to the post
                return new RedirectResult(Url.Action("Home") + "#most_recent");
            }
            else
            {
                // the menu prevents brining to post correctly
                return RedirectToAction("Home");
            }
        }
Ejemplo n.º 38
0
        private static void DeletePhotos(S3Service s3, string rawPhotoToDelete, string mainPhotoToDelete, string thumbPhotoToDelete)
        {
            // delete the existing photos
            try
            {
                if (!string.IsNullOrWhiteSpace(mainPhotoToDelete) &&  s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete);
                }

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete);
                }

                if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, rawPhotoToDelete))
                {
                    s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, rawPhotoToDelete);
                }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
                // whatever
            }
        }
Ejemplo n.º 39
0
        public ActionResult DeleteVideo(int? id)
        {
            var model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content(Convert.ToInt32(id));

            S3Service s3 = new S3Service();

            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

            if (!string.IsNullOrWhiteSpace(model.ContentVideoURL) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL))
            {
                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL);

                model.ContentVideoURL = string.Empty;
                model.Set();
            }

            if (!string.IsNullOrWhiteSpace(model.ContentVideoURL2) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2))
            {
                s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2);

                model.ContentVideoURL2 = string.Empty;
                model.Set();
            }

            return RedirectToAction("EditArticle", new { @id = model.ContentID });
        }
Ejemplo n.º 40
0
        private UserPhoto ProcessMainPhotoItem(
            HttpPostedFileBase file, 
            UserPhoto up1, 
            int currentUserId, 
            CannedAcl acl, 
            S3Service s3, 
            string photoOne, 
            string photoTwo, 
            string photoThree, 
            string photoEdited,
            Bitmap photoBitmap)
        {
            string rawPhotoFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, false);
            string profilePhotoFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, true, 300,  300);

            if (string.IsNullOrEmpty(_uad.ProfileThumbPicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                _uad.ProfilePicURL = profilePhotoFileName;
                _uad.RawProfilePicUrl = rawPhotoFileName;
            }
            else
            {
                if (up1 == null)
                {
                    up1 = new UserPhoto();
                }

                if (_mu != null) up1.UserAccountID = currentUserId;

                up1.RawPicUrl = rawPhotoFileName;
                up1.PicURL = profilePhotoFileName;

                if ((_ups.Count > 0 && photoEdited == photoTwo) || (_ups.Count == 0))
                {
                    up1.RankOrder = 1;
                }
                else if ((_ups.Count > 1 && photoEdited == photoThree) || _ups.Count == 1)
                {
                    up1.RankOrder = 2;
                }

                if (_ups.Count == 1 && _ups[0].RankOrder == 2)
                {
                    _ups[0].RankOrder = 1;
                    _ups[0].Update();
                }
            }

            return up1;
        }
Ejemplo n.º 41
0
        public ActionResult EditPhoto(HttpPostedFileBase file)
        {
            mu = Membership.GetUser();
            UserPhoto up1 = null;
            int swapID = 0;

            var acl = CannedAcl.PublicRead;

            S3Service s3 = new S3Service();

            s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey;
            s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey;

            if (Request.Form["new_default"] != null &&
                int.TryParse(Request.Form["new_default"], out swapID))
            {
                // swap the default with the new default
                uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

                string currentDefaultMain = uad.ProfilePicURL;
                string currentDefaultMainThumb = uad.ProfileThumbPicURL;

                up1 = new UserPhoto(swapID);

                uad.ProfilePicURL = up1.PicURL;
                uad.ProfileThumbPicURL = up1.ThumbPicURL;
                uad.LastPhotoUpdate = DateTime.UtcNow;
                uad.Update();

                up1.PicURL = currentDefaultMain;
                up1.ThumbPicURL = currentDefaultMainThumb;
                up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Update();

                LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

                return View(uad);
            }

            string photoOne = "photo_edit_1";
            string photoTwo = "photo_edit_2";
            string photoThree = "photo_edit_3";

            LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

            uad = new UserAccountDetail();
            uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

            if (file == null)
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.NoFile);
                return View(uad);
            }

            string photoEdited = Request.Form["photo_edit"];
            string mainPhotoToDelete = string.Empty;
            string thumbPhotoToDelete = string.Empty;

            ups = new UserPhotos();
            ups.GetUserPhotos(uad.UserAccountID);

            if (string.IsNullOrEmpty(uad.ProfilePicURL) ||
                ups.Count == 2 && photoEdited == photoOne)
            {
                mainPhotoToDelete = uad.ProfilePicURL;
                thumbPhotoToDelete = uad.ProfileThumbPicURL;
            }
            else
            {
                if (ups.Count > 1 && photoEdited == photoTwo)
                {
                    up1 = new UserPhoto(ups[0].UserPhotoID);
                    up1.RankOrder = 1;
                    mainPhotoToDelete = up1.PicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
                else if (ups.Count > 1 && photoEdited == photoThree)
                {
                    up1 = new UserPhoto(ups[1].UserPhotoID);
                    up1.RankOrder = 2;
                    mainPhotoToDelete = ups[1].FullProfilePicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }

            }

            if (!string.IsNullOrEmpty(mainPhotoToDelete))
            {
                // delete the existing photos
                try
                {

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete);
                    }

                    if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete))
                    {
                        s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete);
                    }
                }
                catch
                {
                    // whatever
                }
            }

            Bitmap b = new Bitmap(file.InputStream);

            // full
            System.Drawing.Image fullPhoto = (System.Drawing.Image)b;

            fullPhoto = ImageResize.FixedSize(fullPhoto, 300, 300, System.Drawing.Color.Black);

            string fileNameFull = Utilities.CreateUniqueContentFilename(file);

            Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

            s3.AddObject(
                maker,
                maker.Length,
                AmazonCloudConfigs.AmazonBucketName,
                fileNameFull,
                file.ContentType,
                acl);

            if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) ||
                ups.Count == 2 && photoEdited == photoOne)
            {
                uad.ProfilePicURL = fileNameFull;
            }
            else
            {
                if (up1 == null)
                {
                    up1 = new UserPhoto();
                }

                up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                up1.PicURL = fileNameFull;

                if ((ups.Count > 0 && photoEdited == photoTwo) || (ups.Count == 0))
                {
                    up1.RankOrder = 1;
                }
                else if ((ups.Count > 1 && photoEdited == photoThree) || ups.Count == 1)
                {
                    up1.RankOrder = 2;
                }

                if (ups.Count == 1 && ups[0].RankOrder == 2)
                {
                    ups[0].RankOrder = 1;
                    ups[0].Update();
                }
            }

            fullPhoto = (System.Drawing.Image)b;

            fullPhoto = ImageResize.FixedSize(fullPhoto, 75, 75, System.Drawing.Color.Black);

            fileNameFull = Utilities.CreateUniqueContentFilename(file);

            maker = fullPhoto.ToAStream(ImageFormat.Jpeg);

            s3.AddObject(
                maker,
                maker.Length,
                AmazonCloudConfigs.AmazonBucketName,
                fileNameFull,
                file.ContentType,
                acl);

            //// thumb

            if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) ||
                ups.Count == 2 && photoEdited == photoOne)
            {
                uad.ProfileThumbPicURL = fileNameFull;
                uad.LastPhotoUpdate = DateTime.UtcNow;
                uad.Set();
            }
            else
            {
                up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey);
                up1.ThumbPicURL = fileNameFull;

                if (
                    (ups.Count == 0 && photoEdited == photoTwo) ||
                    (ups.Count > 0 && photoEdited == photoTwo)
                    )
                {
                    up1.RankOrder = 1;
                }
                else if
                    (
                    (ups.Count == 0 && photoEdited == photoThree) ||
                    (ups.Count > 1 && photoEdited == photoThree)
                    )
                {
                    up1.RankOrder = 2;
                }
            }

            b.Dispose();

            if (up1 != null && up1.UserPhotoID == 0)
            {
                up1.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Create();
            }
            else if (up1 != null && up1.UserPhotoID > 0)
            {
                up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey);
                up1.Update();
            }

            LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey));

            return View(uad);
        }
Ejemplo n.º 42
0
        public ActionResult EditPhoto(HttpPostedFileBase file)
        {
            UserPhoto up1 = null;
            var currentUserId = Convert.ToInt32(_mu.ProviderUserKey);
            int swapID;
            const CannedAcl acl = CannedAcl.PublicRead;

            var s3 = new S3Service
            {
                AccessKeyID = AmazonCloudConfigs.AmazonAccessKey,
                SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey
            };

            if (Request.Form["new_default"] != null &&
                int.TryParse(Request.Form["new_default"], out swapID))
            {
                // swap the default with the new default
                up1 = SwapOutDefaultPhoto(currentUserId, swapID);

                return View(_uad);
            }

            const string photoOne = "photo_edit_1";
            const string photoTwo = "photo_edit_2";
            const string photoThree = "photo_edit_3";

            if (_mu != null) LoadCurrentImagesViewBag(currentUserId);

            _uad = new UserAccountDetail();

            if (_mu != null) _uad.GetUserAccountDeailForUser(currentUserId);

            if (file == null)
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError(string.Empty, Messages.NoFile);
                return View(_uad);
            }

            string photoEdited = Request.Form["photo_edit"];
            string rawPhotoToDelete = string.Empty;
            string mainPhotoToDelete = string.Empty;
            string thumbPhotoToDelete = string.Empty;

            _ups = new UserPhotos();
            _ups.GetUserPhotos(_uad.UserAccountID);

            if (string.IsNullOrEmpty(_uad.ProfilePicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                rawPhotoToDelete = _uad.RawProfilePicUrl;
                mainPhotoToDelete = _uad.ProfilePicURL;
                thumbPhotoToDelete = _uad.ProfileThumbPicURL;
            }
            else
            {
                if (_ups.Count > 1 && photoEdited == photoTwo)
                {
                    up1 = new UserPhoto(_ups[0].UserPhotoID) { RankOrder = 1 };

                    rawPhotoToDelete = up1.RawPicUrl;
                    mainPhotoToDelete = up1.PicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
                else if (_ups.Count > 1 && photoEdited == photoThree)
                {
                    up1 = new UserPhoto(_ups[1].UserPhotoID) { RankOrder = 2 };

                    rawPhotoToDelete = up1.RawPicUrl;
                    mainPhotoToDelete = up1.FullProfilePicURL;
                    thumbPhotoToDelete = up1.ThumbPicURL;
                }
            }

            if (!string.IsNullOrEmpty(mainPhotoToDelete))
            {
                DeletePhotos(s3, rawPhotoToDelete, mainPhotoToDelete, thumbPhotoToDelete);
            }

            var photoBitmap = new Bitmap(file.InputStream);

            // 300x 300 and raw
            up1 = ProcessMainPhotoItem(file, up1, currentUserId, acl, s3, photoOne, photoTwo, photoThree, photoEdited, photoBitmap);

            // 75 x 75 (thumbnail)
            var thumbFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, true, 75, 75);

            if (string.IsNullOrEmpty(_uad.ProfileThumbPicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                _uad.ProfileThumbPicURL = thumbFileName;
                _uad.LastPhotoUpdate = DateTime.UtcNow;
                _uad.Set();
            }
            else
            {
                if (up1 != null)
                {
                    if (_mu != null) up1.UserAccountID = currentUserId;
                    up1.ThumbPicURL = thumbFileName;

                    if (
                        (_ups.Count == 0 && photoEdited == photoTwo) ||
                        (_ups.Count > 0 && photoEdited == photoTwo)
                        )
                    {
                        up1.RankOrder = 1;
                    }
                    else if
                        (
                        (_ups.Count == 0 && photoEdited == photoThree) ||
                        (_ups.Count > 1 && photoEdited == photoThree)
                        )
                    {
                        up1.RankOrder = 2;
                    }
                }
            }

            photoBitmap.Dispose();

            if (up1 != null && up1.UserPhotoID == 0)
            {
                if (_mu != null) up1.CreatedByUserID = currentUserId;
                up1.Create();
            }
            else if (up1 != null && up1.UserPhotoID > 0)
            {
                up1.UpdatedByUserID = currentUserId;
                up1.Update();
            }

            LoadCurrentImagesViewBag(currentUserId);

            return View(_uad);
        }
Ejemplo n.º 43
0
        public Program()
        {
            var usingTrustedConnection = string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(Password);

            var sourceConnection = usingTrustedConnection
                ? new ServerConnection(ServerName) { LoginSecure = true }
                : new ServerConnection(ServerName, Username, Password);

            var sqlServer = new Server(sourceConnection);

            if(sqlServer != null){

                var backup = new Backup();
                var dbc = sqlServer.Databases;

                if (dbc.Contains(DatabaseName))
                {
                    backup.Action = BackupActionType.Database;

                    backup.Database = DatabaseName;

                    var dateFilename = DateTime.UtcNow.ToString("dd-MMM-yyyy");
                    var tempFilename = String.Format("{0}-{1}.bak", DatabaseName, dateFilename);
                    var tempBackupPath = String.Format("{0}{1}", TempFilePath, tempFilename);

                    //remove old backups from this local temp location
                    foreach (var file in Directory.GetFiles(TempFilePath))
                    {
                        if (file != tempBackupPath)
                        {
                            Console.WriteLine("Removing previous temp backup " + file);
                            File.Delete(file);
                        }
                    }

                    try
                    {
                        var backupDevice = new BackupDeviceItem(tempBackupPath, DeviceType.File);
                        backup.Devices.Add(backupDevice);
                        backup.Checksum = true;
                        backup.ContinueAfterError = false;
                        backup.LogTruncation = BackupTruncateLogType.Truncate;

                        //if file exists then do an incremental, otherwise do a full
                        if (File.Exists(tempBackupPath))
                        {
                            backup.Incremental = true;
                        }
                        else
                        {
                            backup.Incremental = false;
                        }

                        // Perform backup.
                        backup.SqlBackup(sqlServer);

                        //now move the backup to S3 - overwriting anything that is there with the same name
                        var s3 = new S3Service
                                     {
                                         AccessKeyID = AccessKeyID,
                                         SecretAccessKey = SecretAccessKey
                                     };

                        var bucket = Bucket;
                        s3.AddObject(tempBackupPath, bucket, tempFilename);

                        var metadataOnly = true;

                        foreach(var listEntry in s3.ListObjects(Bucket,""))
                        {
                            var request = new GetObjectRequest(s3, Bucket, listEntry.Name, metadataOnly);

                            using (var response = request.GetResponse())
                            {
                                if (response.LastModified < DateTime.UtcNow.AddDays(DaysToKeepS3BackupFor * -1))
                                {
                                    Console.WriteLine("Going to delete old archive " + listEntry.Name);
                                    s3.DeleteObject(Bucket,listEntry.Name);
                                }
                            }
                        }
                        Console.Out.WriteLine("Backup to S3 is complete");
                        System.Threading.Thread.Sleep(10000);
                    }
                    catch(Exception ee)
                    {
                        Console.Out.WriteLine("Exception occurred - do not continue.  Wait until next run to try again "+ee.ToString());
                        System.Threading.Thread.Sleep(10000);
                    }
                }
            }
        }
Ejemplo n.º 44
0
        public S3Service Connect()
        {
            /*AmazonS3Config config = CreateConfig ();
            AmazonS3Client connection = (AmazonS3Client)Amazon.AWSClientFactory.CreateAmazonS3Client (, , config);
            return connection;*/

            var s3 = new S3Service
            {
                Host = GlobalSettings.StorageHost,
                AccessKeyID = Credential.PublicKey,
                SecretAccessKey = Credential.SecretKey,
                CustomPort = int.Parse(GlobalSettings.StoragePort),
                UseSsl = true
            };
            return s3;
        }