Exemple #1
0
        //Add a new video.
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int?year = null;

            if (txtYear.Text != "")
            {
                year = Convert.ToInt32(txtYear.Text);
            }
            int edit = 0;

            if (txtPath.Text == "")
            {
                MessageBox.Show("Choose file!", "No file chosen", MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }

            Task.Run(new Action(() => {
                Dispatcher.Invoke(new Action(() =>
                {
                    stMain.Visibility = Visibility.Collapsed;

                    if (video == null)
                    {
                        int?id = _proxy.AddVideo(txtName.Text, txtDesc.Text == "" ? null : txtDesc.Text, txtPath.Text, txtSubs.Text, "WolfV.png", chCopy.IsChecked == true ? false : true, mark, user, year, DateTime.Now);
                        if (id == null)
                        {
                            MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop);
                            stMain.Visibility = Visibility.Visible;
                            return;
                        }
                        edit = Convert.ToInt32(id);

                        if (lPath.Content.ToString() != "...")
                        {
                            if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.FilesType.VideosImages))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                _proxy.RemoveItem(edit, EngServRef.ServerData.Video);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.ServerData.Video, EngServRef.PropertyData.Imgpath);
                        }
                        if (chCopy.IsChecked == true)
                        {
                            try
                            {
                                if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos))
                                {
                                    MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                    _proxy.RemoveItem(edit, EngServRef.ServerData.Video);
                                    stMain.Visibility = Visibility.Visible;
                                    return;
                                }
                                _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path);
                            }
                            catch (OutOfMemoryException)
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                _proxy = new EngServRef.EngServiceClient();
                                _proxy.RemoveItem(edit, EngServRef.ServerData.Video);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                        }
                        if (txtSubs.Text != "")
                        {
                            if (!_proxy.Upload(File.ReadAllBytes(txtSubs.Text), $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.FilesType.Subtitles))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                _proxy.RemoveItem(edit, EngServRef.ServerData.Video);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath);
                        }
                    }
                    else
                    {
                        edit = Convert.ToInt32(video);

                        string path = _proxy.GetItemProperty(Convert.ToInt32(video), EngServRef.ServerData.Video, EngServRef.PropertyData.Path);
                        if (txtPath.Text != path && chCopy.IsChecked == true)
                        {
                            if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path);
                        }
                        else if (txtPath.Text == path && txtPath.Text.Contains(":") && chCopy.IsChecked == true)
                        {
                            if (!File.Exists(txtPath.Text))
                            {
                                MessageBox.Show("This file does not exist!", "Wrong", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            if (!_proxy.Upload(File.ReadAllBytes(txtPath.Text), $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.FilesType.Videos))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtPath.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.Path);
                        }
                        else if (chCopy.IsChecked == false)
                        {
                            _proxy.EditData(edit, txtPath.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Path);
                        }
                        string subs = _proxy.GetItemProperty(Convert.ToInt32(video), EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath);
                        if (txtSubs.Text != subs)
                        {
                            if (!File.Exists(txtSubs.Text))
                            {
                                MessageBox.Show("This file does not exist!", "Wrong", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            if (!_proxy.Upload(File.ReadAllBytes(txtSubs.Text), $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.FilesType.Subtitles))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, $"{edit}{Path.GetExtension(txtSubs.Text)}", EngServRef.ServerData.Video, EngServRef.PropertyData.SubPath);
                        }
                        if (lPath.Content.ToString() != "...")
                        {
                            FormData.EditVideos.Add(edit);
                            string file = $"{edit}{Path.GetExtension(lPath.Content.ToString())}";
                            if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), file, EngServRef.FilesType.VideosImages))
                            {
                                MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop);
                                stMain.Visibility = Visibility.Visible;
                                return;
                            }
                            _proxy.EditData(edit, file, EngServRef.ServerData.Video, EngServRef.PropertyData.Imgpath);
                        }
                        _proxy.EditData(edit, chCopy.IsChecked != true ? "True" : null, EngServRef.ServerData.Video, EngServRef.PropertyData.IsAbsolute);
                        _proxy.EditData(edit, txtYear.Text == "" ? null : txtYear.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Year);
                        _proxy.RemoveFullItemData(edit, EngServRef.ServerData.VideoCategory);
                        _proxy.EditData(edit, txtName.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Name);
                        _proxy.EditData(edit, txtDesc.Text == "" ? null : txtDesc.Text, EngServRef.ServerData.Video, EngServRef.PropertyData.Description);
                    }

                    foreach (CheckBox item in lstCategory.Items)
                    {
                        if (item.IsChecked == true)
                        {
                            _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.VideoCategory);
                        }
                    }
                    Close();
                }));
            }));
        }