Example #1
0
        public Main()
        {
            Ioc.Container.RegisterInstance(typeof(Main), this, new ContainerControlledLifetimeManager());
            this.InitializeComponent();

            this.RefreshQueueColumns();
            this.LoadCompletedColumnWidths();

            if (CommonUtilities.DebugMode)
            {
                MenuItem queueFromJsonItem = new MenuItem {
                    Header = "Queue job from JSON..."
                };
                queueFromJsonItem.Click += (sender, args) =>
                {
                    EncodeJobViewModel    jobViewModel = this.viewModel.CreateEncodeJobVM();
                    DebugEncodeJsonDialog dialog       = new DebugEncodeJsonDialog();
                    dialog.ShowDialog();

                    if (!string.IsNullOrWhiteSpace(dialog.EncodeJson))
                    {
                        try
                        {
                            JsonEncodeObject encodeObject = JsonConvert.DeserializeObject <JsonEncodeObject>(dialog.EncodeJson);

                            jobViewModel.DebugEncodeJsonOverride = dialog.EncodeJson;
                            jobViewModel.Job.OutputPath          = encodeObject.Destination.File;
                            jobViewModel.Job.SourcePath          = encodeObject.Source.Path;

                            this.processingService.Queue(jobViewModel);
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(this, "Could not parse encode JSON:" + Environment.NewLine + Environment.NewLine + exception.ToString());
                        }
                    }
                };

                this.toolsMenu.Items.Add(new Separator());
                this.toolsMenu.Items.Add(queueFromJsonItem);
            }

            this.DataContextChanged += this.OnDataContextChanged;
            TheDispatcher            = this.Dispatcher;

            this.presetGlowEffect.Opacity = 0.0;
            this.pickerGlowEffect.Opacity = 0.0;
            this.statusText.Opacity       = 0.0;

            NameScope.SetNameScope(this, new NameScope());
            this.RegisterName("PresetGlowEffect", this.presetGlowEffect);
            this.RegisterName("PickerGlowEffect", this.pickerGlowEffect);
            this.RegisterName("StatusText", this.statusText);

            var storyboard = (Storyboard)this.FindResource("statusTextStoryboard");

            storyboard.Completed += (sender, args) =>
            {
                this.statusText.Visibility = Visibility.Collapsed;
            };

            var presetGlowFadeUp = new DoubleAnimation
            {
                From     = 0.0,
                To       = 1.0,
                Duration = new Duration(TimeSpan.FromSeconds(0.1))
            };

            var presetGlowFadeDown = new DoubleAnimation
            {
                From      = 1.0,
                To        = 0.0,
                BeginTime = TimeSpan.FromSeconds(0.1),
                Duration  = new Duration(TimeSpan.FromSeconds(1.6))
            };

            this.presetGlowStoryboard = new Storyboard();
            this.presetGlowStoryboard.Children.Add(presetGlowFadeUp);
            this.presetGlowStoryboard.Children.Add(presetGlowFadeDown);

            Storyboard.SetTargetName(presetGlowFadeUp, "PresetGlowEffect");
            Storyboard.SetTargetProperty(presetGlowFadeUp, new PropertyPath("Opacity"));
            Storyboard.SetTargetName(presetGlowFadeDown, "PresetGlowEffect");
            Storyboard.SetTargetProperty(presetGlowFadeDown, new PropertyPath("Opacity"));

            var pickerGlowFadeUp = new DoubleAnimation
            {
                From     = 0.0,
                To       = 1.0,
                Duration = new Duration(TimeSpan.FromSeconds(0.1))
            };

            var pickerGlowFadeDown = new DoubleAnimation
            {
                From      = 1.0,
                To        = 0.0,
                BeginTime = TimeSpan.FromSeconds(0.1),
                Duration  = new Duration(TimeSpan.FromSeconds(1.6))
            };

            this.pickerGlowStoryboard = new Storyboard();
            this.pickerGlowStoryboard.Children.Add(pickerGlowFadeUp);
            this.pickerGlowStoryboard.Children.Add(pickerGlowFadeDown);

            Storyboard.SetTargetName(pickerGlowFadeUp, "PickerGlowEffect");
            Storyboard.SetTargetProperty(pickerGlowFadeUp, new PropertyPath("Opacity"));
            Storyboard.SetTargetName(pickerGlowFadeDown, "PickerGlowEffect");
            Storyboard.SetTargetProperty(pickerGlowFadeDown, new PropertyPath("Opacity"));

            this.Loaded += (e, o) =>
            {
                this.RestoredWindowState = this.WindowState;
            };

            this.statusService.MessageShown += (o, e) =>
            {
                this.ShowStatusMessage(e.Value);
            };
        }
Example #2
0
        public Main()
        {
            Ioc.Container.RegisterSingleton <Main>(() => this);
            this.InitializeComponent();

            this.sourceRow.Height = new GridLength(Config.SourcePaneHeightStar, GridUnitType.Star);
            this.queueRow.Height  = new GridLength(Config.QueuePaneHeightStar, GridUnitType.Star);

            this.Activated += (sender, args) =>
            {
                DispatchUtilities.BeginInvoke(async() =>
                {
                    // Need to yield here for some reason, otherwise the activation is blocked.
                    await Task.Yield();
                    this.toastNotificationService.Clear();
                });
            };

            this.notifyIcon = new NotifyIcon
            {
                Visible = false
            };
            this.notifyIcon.Click       += (sender, args) => { this.RestoreWindow(); };
            this.notifyIcon.DoubleClick += (sender, args) => { this.RestoreWindow(); };

            StreamResourceInfo streamResourceInfo = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/VidCoder_icon.ico"));

            if (streamResourceInfo != null)
            {
                Stream iconStream = streamResourceInfo.Stream;
                this.notifyIcon.Icon = new Icon(iconStream);
            }

            this.RefreshQueueColumns();
            this.LoadCompletedColumnWidths();

#if DEBUG
            var debugDropDown = new DropDownButton {
                Header = "Debug"
            };
            var queueFromJsonItem = new Fluent.MenuItem {
                Header = "Queue job from JSON..."
            };

            queueFromJsonItem.Click += (sender, args) =>
            {
                if (!this.viewModel.HasVideoSource)
                {
                    StaticResolver.Resolve <IMessageBoxService>().Show("Must open source before adding queue job from JSON");
                    return;
                }

                EncodeJobViewModel    jobViewModel = this.viewModel.CreateEncodeJobVM();
                DebugEncodeJsonDialog dialog       = new DebugEncodeJsonDialog();
                dialog.ShowDialog();

                if (!string.IsNullOrWhiteSpace(dialog.EncodeJson))
                {
                    try
                    {
                        JsonEncodeObject encodeObject = JsonConvert.DeserializeObject <JsonEncodeObject>(dialog.EncodeJson);

                        jobViewModel.DebugEncodeJsonOverride = dialog.EncodeJson;
                        jobViewModel.Job.FinalOutputPath     = encodeObject.Destination.File;
                        jobViewModel.Job.SourcePath          = encodeObject.Source.Path;

                        this.processingService.Queue(jobViewModel);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(this, "Could not parse encode JSON:" + Environment.NewLine + Environment.NewLine + exception.ToString());
                    }
                }
            };

            debugDropDown.Items.Add(queueFromJsonItem);

            var throwExceptionItem = new Fluent.MenuItem {
                Header = "Throw exception"
            };
            throwExceptionItem.Click += (sender, args) =>
            {
                throw new InvalidOperationException("Rats.");
            };

            debugDropDown.Items.Add(throwExceptionItem);

            var addLogItem = new Fluent.MenuItem {
                Header = "Add 1 log item"
            };
            addLogItem.Click += (sender, args) =>
            {
                StaticResolver.Resolve <IAppLogger>().Log("This is a log item");
            };

            debugDropDown.Items.Add(addLogItem);

            var addTenLogItems = new Fluent.MenuItem {
                Header = "Add 10 log items"
            };
            addTenLogItems.Click += (sender, args) =>
            {
                for (int i = 0; i < 10; i++)
                {
                    StaticResolver.Resolve <IAppLogger>().Log("This is a log item");
                }
            };

            debugDropDown.Items.Add(addTenLogItems);

            var doAnActionItem = new Fluent.MenuItem {
                Header = "Perform action"
            };
            doAnActionItem.Click += (sender, args) =>
            {
                var app = (App)System.Windows.Application.Current;
                app.ChangeTheme(new Uri("/Themes/Dark.xaml", UriKind.Relative));
            };

            debugDropDown.Items.Add(doAnActionItem);

            this.toolsRibbonGroupBox.Items.Add(debugDropDown);
#endif

            this.DataContextChanged += this.OnDataContextChanged;
            TheDispatcher            = this.Dispatcher;

            this.statusText.Opacity = 0.0;

            NameScope.SetNameScope(this, new NameScope());
            this.RegisterName("StatusText", this.statusText);

            var storyboard = (Storyboard)this.FindResource("StatusTextStoryboard");
            storyboard.Completed += (sender, args) =>
            {
                this.statusText.Visibility = Visibility.Collapsed;
            };

            this.presetTreeViewContainer.PresetTreeView.OnHierarchyMouseUp += (sender, args) =>
            {
                this.presetButton.IsDropDownOpen = false;
            };

            this.presetButton.DropDownOpened += (sender, args) =>
            {
                var item = UIUtilities.FindDescendant <TreeViewItem>(this.presetTreeViewContainer.PresetTreeView, viewItem =>
                {
                    return(viewItem.Header == this.viewModel.PresetsService.SelectedPreset);
                });

                if (item != null)
                {
                    UIUtilities.BringIntoView(item);
                }
            };

            this.Loaded += (e, o) =>
            {
                this.RestoredWindowState = this.WindowState;
            };

            this.statusService.MessageShown += (o, e) =>
            {
                this.ShowStatusMessage(e.Value);
            };
        }