public static void UploadVideo(User uploader, FileUpload videoUpload, FileUpload thumbnailUpload)
 {
     try
     {
         ParsnipData.Media.Video myVideo = new ParsnipData.Media.Video(uploader, videoUpload.PostedFile, thumbnailUpload.PostedFile);
         myVideo.Insert();
         //myVideo.Update();
         HttpContext.Current.Response.Redirect($"edit_media?id={myVideo.Id}", false);
     }
     catch (Exception ex)
     {
         var e = "Exception whilst uploading video: " + ex;
         new LogEntry(Log.Debug)
         {
             text = e
         };
         Debug.WriteLine(e);
         HttpContext.Current.Response.Redirect("photos?error=video");
     }
 }
 public static Video UploadVideo(User uploader, FileUpload videoUpload)
 {
     try
     {
         ParsnipData.Media.Video myVideo = new ParsnipData.Media.Video(uploader, videoUpload.PostedFile);
         myVideo.Insert();
         return(myVideo);
     }
     catch (Exception ex)
     {
         var e = "Exception whilst uploading video: " + ex;
         new LogEntry(Log.Debug)
         {
             Text = e
         };
         Debug.WriteLine(e);
         HttpContext.Current.Response.Redirect("photos?error=video");
     }
     return(null);
 }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //If there is an access token, get the token & it's data.
            //If there is no access token, check that the user is logged in.
            var accessToken = Request.QueryString["share"];



            if (Request.QueryString["id"] == null)
            {
                if (Request.QueryString["share"] == null)
                {
                    Response.Redirect("home");
                }
                else
                {
                    myUser       = ParsnipData.Accounts.User.LogIn();
                    myMediaShare = new MediaShare(new MediaShareId(Request.QueryString["share"].ToString()));
                    shareId      = myMediaShare.Id;
                    try
                    {
                        myMediaShare.Select();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (string.IsNullOrEmpty(myMediaShare.MediaId.ToString()))
                    {
                        new LogEntry(Log.Debug)
                        {
                            text = $"Someone tried to access share {myMediaShare.Id}. Access was denied because the person who created this link has been suspended."
                        };
                        ShareUserSuspendedError.Visible = true;
                    }
                    else
                    {
                        if (!IsPostBack)
                        {
                            myMediaShare.TimesUsed++;
                            myMediaShare.View(myUser);
                        }

                        User createdBy = ParsnipData.Accounts.User.Select(myMediaShare.UserId);

                        var myUserId = myUser == null ? default : myUser.Id;
                                       myImage        = ParsnipData.Media.Image.Select(myMediaShare.MediaId, myUserId);
                                       myVideo        = Video.Select(myMediaShare.MediaId, myUserId);
                                       myYoutubeVideo = Youtube.Select(myMediaShare.MediaId, myUserId);


                                       new LogEntry(Log.Debug)
                                       {
                                           text = string.Format("{0}'s link to {1} got another hit! Now up to {2}", createdBy.FullName, MyMedia.Title, myMediaShare.TimesUsed)
                                       };
                    }
                }
            }
            else
            {
                myUser = Account.SecurePage("view?id=" + Request.QueryString["id"], this, Data.DeviceType);

                myVideo        = Video.Select(new MediaId(Request.QueryString["id"]), myUser.Id);
                myYoutubeVideo = Youtube.Select(new MediaId(Request.QueryString["id"]), myUser.Id);

                myImage = ParsnipData.Media.Image.Select(new MediaId(Request.QueryString["id"].ToString()), myUser == null ? default : myUser.Id);


                if (MyMedia != null && MyMedia.MyMediaShare != null)
                {
                    myMediaShare = MyMedia.MyMediaShare;

                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyMedia.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                }
            }

            ShareLink.Value = Request.Url.GetLeftPart(UriPartial.Authority) + "/view?share=" +
                              myMediaShare.Id;



            //Get the image which the user is trying to access, and display it on the screen.
            if (MyMedia == null || string.IsNullOrEmpty(MyMedia.Compressed))
            {
                //ShareLinkContainer.Visible = false;
                if (ShareUserSuspendedError.Visible == false)
                {
                    UploadUserSuspendedError.Visible = true;
                }
            }
            else
            {
                ImageTitle.InnerText = MyMedia.Title;
                Page.Title           = MyMedia.Title;

                if (MyMedia.Type == "image")
                {
                    ImagePreview.Src = MyMedia.Compressed;
                }

                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:title\" content=\"{0}\" />", MyMedia.Title)));
                //This will break youtube videos which have not had their thumbnail regenerated
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:image\" content=\"{0}\" />", MyMedia.Compressed.Contains("https://lh3.googleusercontent.com") ? MyMedia.Compressed : string.Format("{0}/{1}", Request.Url.GetLeftPart(UriPartial.Authority), MyMedia.Compressed))));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"og:type\" content=\"website\" />"));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:url\" content=\"{0}\" />", Request.Url.ToString())));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:description\" content=\"{0}\" />", MyMedia.Description)));
                Page.Header.Controls.Add(new LiteralControl(string.Format("<meta property=\"og:alt\" content=\"{0}\" />", MyMedia.Alt)));
                Page.Header.Controls.Add(new LiteralControl("<meta property=\"fb:app_id\" content=\"521313871968697\" />"));

                if (Request.QueryString["share"] == null)
                {
                    MediaShare myMediaShare;


                    myMediaShare = MyMedia.MyMediaShare;
                    if (myMediaShare == null)
                    {
                        myMediaShare = new MediaShare(MyMedia.Id, myUser.Id);
                        myMediaShare.Insert();
                    }
                }
            }
        }