예제 #1
0
        /// <summary>
        /// This method downloads the file of the FTP server
        /// </summary>
        /// <param name="post"></param>
        private void DownloadMedia(Post post)
        {
            if (post.MediaID == 0) return;

            _media = LogicCollection.MediaLogic.GetById(post.MediaID);

            var saveMedia = new FolderBrowserDialog();

            if (saveMedia.ShowDialog() != DialogResult.OK) return;

            var pathSelected = saveMedia.SelectedPath;

            var succeeded = false;
            if (_media.Type == MediaType.Image)
            {
                try
                {
                    pbMediaMessage.Image.Save($"{pathSelected}/{_media.Path}");
                    succeeded = true;
                }
                catch (IOException e)
                {
                    Logger.Write(e.Message);
                    succeeded = false;
                }
            }
            else
            {
                succeeded = FtpHelper.DownloadFile($"/{post.EventID}/{post.GuestID}/{_media.Path}", $"{pathSelected}/{_media.Path}");
            }

            MessageBox.Show(succeeded
                ? "Bestand is succesvol gedownload"
                : "Er is iets misgegaan met het downloaden van deze media");
        }
예제 #2
0
 public bool DeleteMedia(Media media)
 {
     if (LogicCollection.MediaLogic.Delete(media))
     {
         return true;
     }
     return false;
 }
예제 #3
0
 private void btBestandUploaden_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(Filepath))
     {
         MessageBox.Show("Geen bestand geselecteerd!");
     }
     else
     {
         UploadedFile = LogicCollection.MediaLogic.UploadMedia(Filepath, _user, _event);
             // Show errors
         if (UploadedFile != null)
         {
             MessageBox.Show("Uw bestand is succesvol upgeload", "File successfully uploaded",
                 MessageBoxButtons.OK,
                 MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
             btnUpload.Text = "Selecteer een bestand...";
             pbPreview.ImageLocation = null;
             Invalidate();
         }
         else
             MessageBox.Show("Er is iets misgegaan");
     }
 }
예제 #4
0
        private void trvCatalogue_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (trvCatalogue.SelectedNode.Parent != null)
            {
                string child = e.Node.Text;
                string mediaId = child.Substring(0, child.IndexOf("-", StringComparison.Ordinal)).Trim();

                _media = LogicCollection.MediaLogic.GetById(Convert.ToInt32(mediaId));

                picCatalogue.ImageLocation = $"{FtpHelper.ServerHardLogin}/{_event.ID}/{_media.UserID}/{_media.Path}";
                _delete.Visible = true;
            }
        }
예제 #5
0
        /// <summary>
        /// This method is use to load image from FTP server
        /// </summary>
        /// <param name="post">The post to look up the media of</param>
        private void ShowMedia(Post post)
        {
            if (post.MediaID != 0)
            {
                _media = LogicCollection.MediaLogic.GetById(post.MediaID);
                switch (_media.Type)
                {
                    case MediaType.Image:
                        var ftpPath = $"/{post.EventID}/{post.GuestID}/{_media.Path}";
                        pbMediaMessage.ImageLocation = $"{FtpHelper.ServerHardLogin}/{ftpPath}";
                        break;
                    case MediaType.Audio:
                        // Show mp3 icon
                        pbMediaMessage.Image = Properties.Resources.mp3;
                        break;
                    default:
                        // Show mp4 icon
                        pbMediaMessage.Image = Properties.Resources.mp4;
                        break;
                }
            }
            else
            {
                // Post doesn't have any attached media
                pbMediaMessage.Visible = false;
                lblDownloadMedia.Visible = false;

                tbMessage.Width = 614;

                lblLikeStatus.Location = new Point(545, lblLikeStatus.Location.Y);
                lbLike.Location = new Point(560, lbLike.Location.Y);

                lblDeletePost.Location = new Point(481, lblDeletePost.Location.Y);
                lbReport.Location = new Point(481, lbReport.Location.Y);

                lbReaction.Location = new Point(420, lbReaction.Location.Y);
            }
        }
예제 #6
0
 public Post GetByMediaId(Media media)
 {
     return _context.GetByMediaId(media);
 }
 public Post GetByMediaId(Media media)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public Media Insert(Media media)
 {
     return _context.Insert(media);
 }
예제 #9
0
 public bool Delete(Media media)
 {
     return _context.Delete(media);
 }
예제 #10
0
        public Media UploadMedia(string localFilePath, User user, Event ev)
        {
            // Set file variables
            var ftpFileName = Path.GetFileName(localFilePath);
            var ftpFileExtension = Path.GetExtension(localFilePath);
            var ftpFileNameWithoutExtension = Path.GetFileNameWithoutExtension(localFilePath);

                Media media = null;
                if (!File.Exists(FtpHelper.ServerAddress + "/" + ev.ID))
                {
                    // Creates user & event map if not exsist on FTP server
                    FtpHelper.CreateDirectory(ev.ID.ToString());
                    if (!File.Exists(FtpHelper.ServerAddress + "/" + ev.ID + "/" + user.ID))
                    {
                        FtpHelper.CreateDirectory(ev.ID + "/" + user.ID);
                    }
                }

                if (FtpHelper.UploadFile(localFilePath, ev.ID + "/" + user.ID + "/" + ftpFileName))
                {
                    // Check file extension
                    var type = LogicCollection.MediaLogic.CheckExtension(ftpFileExtension);

                    // Makes the object media
                    media = new Media(0, user.ID, ev.ID, type, ftpFileNameWithoutExtension,
                        ftpFileExtension, ftpFileName);
                    media = LogicCollection.MediaLogic.Insert(media);
                }

                return media;
        }
예제 #11
0
        /// <summary>
        /// Uploads a file to the FTP server
        /// </summary>
        private void btBestandUploaden_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_filepath))
            {
                MessageBox.Show(@"Geen bestand geselecteerd!");
            }
            else
            {
                // Set file variables
                var ftpFileName = Path.GetFileName(_filepath);
                var ftpFileExtension = Path.GetExtension(_filepath);
                var ftpFileNameWithoutExtension = Path.GetFileNameWithoutExtension(_filepath);

                if (_user != null)
                {
                    // TODO: Refactor to have less duplicate code. Move these to separate functions!

                    // REMEMBER: BELOW IS A GUEST
                    if (!File.Exists(FtpHelper.ServerAddress + "/" + _event.ID))
                    {
                        // Creates user & event map if not exsist on FTP server
                        FtpHelper.CreateDirectory(_event.ID.ToString());
                        if (!File.Exists(FtpHelper.ServerAddress + "/" + _event.ID + "/" + _user.ID))
                        {
                            FtpHelper.CreateDirectory(_event.ID + "/" + _user.ID);
                        }
                    }

                    if (!FtpHelper.UploadFile(_filepath, _event.ID + "/" + _user.ID + "/" + ftpFileName)) return;

                    // Check file extension
                    var type = CheckExtension(ftpFileExtension);

                    // Makes the object media
                    var media = new Media(0, _user.ID, _event.ID, type, ftpFileNameWithoutExtension,
                        ftpFileExtension, ftpFileName);
                    _uploadedFile = _logicMedia.Insert(media);

                    // Show errors
                    if (_uploadedFile != null)
                        MessageBox.Show("Uw bestand is succesvol upgeload", "File successfully uploaded", MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    else
                        MessageBox.Show("Er is iets misgegaan");
                }
                else
                {
                    // REMEMBER: BELOW IS A ADMIN
                    if (!File.Exists(FtpHelper.ServerAddress + "/" + _event.ID))
                    {
                        // Creates user & event map if not exsist on FTP server
                        FtpHelper.CreateDirectory(_event.ID.ToString());
                        if (!File.Exists(FtpHelper.ServerAddress + "/" + _event.ID + "/" + _admin.ID))
                        {
                            FtpHelper.CreateDirectory(_event.ID + "/" + _admin.ID);
                        }
                    }

                    if (!FtpHelper.UploadFile(_filepath, _event.ID + "/" + _admin.ID + "/" + ftpFileName)) return;

                    // Check file extension
                    var type = CheckExtension(ftpFileExtension);

                    // Makes the object media
                    var media = new Media(0, _admin.ID, _event.ID, type, ftpFileNameWithoutExtension,
                        ftpFileExtension, ftpFileName);
                    _uploadedFile = _logicMedia.Insert(media);

                    // Show errors
                    if (_uploadedFile != null)
                        MessageBox.Show("Uw bestand is succesvol geüpload", "File successfully uploaded", MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    else
                        MessageBox.Show("Er is iets misgegaan");
                }
            }
        }