Esempio n. 1
0
        private void OnRootChanged(object sender, EventArgs e)
        {
            Root       = _manager.Root;
            ThisDevice = Root.Devices[ThisDeviceId];
            Settings   = Root.Settings;

            // precreated data
            var ds = ThisDevice.DeviceSettings;

            if (Equals(ds, null))
            {
                ds = Create <IDeviceSettings>();
                ds.DisableTopMost         = TopMostModeConverter.GetDisableTopMost(TopMostMode.Manual);
                ds.TopMostExtendedMode    = TopMostModeConverter.GetTopMostExtendedMode(TopMostMode.Manual);
                ThisDevice.DeviceSettings = ds;
            }
            _manager.GetOrCreate(() => ThisDevice.DeviceSettings, v => ThisDevice.DeviceSettings = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs, v => ThisDevice.KPIs                   = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs.Cpu, v => ThisDevice.KPIs.Cpu           = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs.CloudIn, v => ThisDevice.KPIs.CloudIn   = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs.CloudOut, v => ThisDevice.KPIs.CloudOut = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs.Encoder, v => ThisDevice.KPIs.Encoder   = v);
            _manager.GetOrCreate(() => ThisDevice.KPIs.Vpn, v => ThisDevice.KPIs.Vpn           = v);

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Root)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ThisDevice)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Settings)));
        }
        public MainSettingsModel(LocalSettingsService localSettings, CoreData coreData, StreamSettingsModel streamSettings, ConnectionService connectionService,
                                 TranscodingModel transcoding)
        {
            CoreData              = coreData;
            StreamSettings        = streamSettings;
            Transcoding           = transcoding;
            _connectionService    = connectionService;
            AutoLogon.SilentValue = localSettings.Settings.AutoLogon; // TODO: what is is not registred and not save password
            AutoLogon.OnChange    = async(o, n) => await localSettings.ChangeSettingsUnconditionally(s => s.AutoLogon = n);

            CurrentStreamingToCloudBehavior.Value = StreamingToCloudBehaviors.First(s => s.Value == default);
            CurrentEncoderType.Value     = EncoderTypes.First(s => s.Value == default);
            CurrentEncoderQuality.Value  = EncoderQualities.First(s => s.Value == default);
            CurrentTopMostMode.Value     = TopMostModes.First(s => s.Value == TopMostMode.WhenCompact);
            CurrentVpnBehavior.Value     = VpnBehaviors.First(s => s.Value == default);
            CurrentRendererType.Value    = RendererTypes.First(s => s.Value == default);
            CurrentBlenderType.Value     = BlenderTypes.First(s => s.Value == default);
            CurrentRecordingFormat.Value = RecordingFormats.First(s => s.Value == default);

            CurrentStreamingToCloudBehavior.OnChange = (o, n) => coreData.Settings.StreamingToCloud = n.Value;
            CurrentEncoderType.OnChange    = (o, n) => coreData.Settings.EncoderType = n.Value;
            CurrentEncoderQuality.OnChange = (o, n) => coreData.Settings.EncoderQuality = n.Value;
            CurrentTopMostMode.OnChange    = (o, n) =>
            {
                coreData.ThisDevice.DeviceSettings.DisableTopMost      = TopMostModeConverter.GetDisableTopMost(n.Value);
                coreData.ThisDevice.DeviceSettings.TopMostExtendedMode = TopMostModeConverter.GetTopMostExtendedMode(n.Value);
            };
            CurrentRecordingFormat.OnChange    = (o, n) => coreData.Settings.RecordingFormat = n.Value;
            CurrentVpnBehavior.OnChange        = (o, n) => coreData.ThisDevice.DeviceSettings.VpnBehavior = n.Value;
            CurrentRendererType.OnChange       = (o, n) => coreData.ThisDevice.DeviceSettings.RendererType = n.Value;
            CurrentBlenderType.OnChange        = (o, n) => coreData.ThisDevice.DeviceSettings.BlenderType = n.Value;
            HardwareAdapter.OnChange           = (o, n) => coreData.ThisDevice.DeviceSettings.RendererAdapter = n;
            PreferNalHdr.OnChange              = (o, n) => coreData.Settings.PreferNalHdr = n;
            EnableQsvNv12Optimization.OnChange = (o, n) => coreData.Settings.DisableQsvNv12Optimization = !n;

            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.StreamingToCloud, (s, c, p) => CurrentStreamingToCloudBehavior.SilentValue = StreamingToCloudBehaviors.FirstOrDefault(r => r.Value == CoreData.Settings.StreamingToCloud));
            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.EncoderType, (s, c, p) => CurrentEncoderType.SilentValue       = EncoderTypes.FirstOrDefault(r => r.Value == CoreData.Settings.EncoderType));
            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.EncoderQuality, (s, c, p) => CurrentEncoderQuality.SilentValue = EncoderQualities.FirstOrDefault(r => r.Value == CoreData.Settings.EncoderQuality));
            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.PreferNalHdr, (s, c, p) => PreferNalHdr.SilentValue            = CoreData.Settings.PreferNalHdr);
            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.DisableQsvNv12Optimization, (s, c, p) => EnableQsvNv12Optimization.SilentValue = !CoreData.Settings.DisableQsvNv12Optimization);
            CoreData.Subscriptions.SubscribeForProperties <ISettings>(s => s.RecordingFormat, (s, c, p) => CurrentRecordingFormat.SilentValue = RecordingFormats.FirstOrDefault(r => r.Value == CoreData.Settings.RecordingFormat));

            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.DisableTopMost, (s, c, p) => UpdateTopMost());
            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.TopMostExtendedMode, (s, c, p) => UpdateTopMost());
            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.VpnBehavior, (s, c, p) => CurrentVpnBehavior.SilentValue   = VpnBehaviors.FirstOrDefault(r => r.Value == CoreData.ThisDevice.DeviceSettings.VpnBehavior));
            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.RendererType, (s, c, p) => CurrentRendererType.SilentValue = RendererTypes.FirstOrDefault(r => r.Value == CoreData.ThisDevice.DeviceSettings.RendererType));
            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.BlenderType, (s, c, p) => CurrentBlenderType.SilentValue   = BlenderTypes.FirstOrDefault(r => r.Value == CoreData.ThisDevice.DeviceSettings.BlenderType));
            CoreData.Subscriptions.SubscribeForProperties <IDeviceSettings>(s => s.RendererAdapter, (s, c, p) =>
            {
                if (HardwareAdapters != null)
                {
                    HardwareAdapter.SilentValue = HardwareAdapters.Contains(CoreData.ThisDevice.DeviceSettings.RendererAdapter) ? CoreData.ThisDevice.DeviceSettings.RendererAdapter : HardwareAdapters.FirstOrDefault();
                }
            });
        }
        private void RefreshTopMost()
        {
            if (_window != null)
            {
                var mode = TopMostModeConverter.ToMode(_coreData.ThisDevice.DeviceSettings);

                bool topMost = false;
                switch (mode)
                {
                case TopMostMode.Always:
                    topMost = true;
                    break;

                case TopMostMode.WhenCompact:
                    topMost = _lastState == AppWindowState.Compact;
                    break;

                case TopMostMode.Never:
                    topMost = false;
                    break;

                case TopMostMode.Manual:
                    topMost = _topMostPinned;
                    break;
                }

                if (_lastState == AppWindowState.FullScreen || _lastState == AppWindowState.Maximized || _lastState == AppWindowState.Minimized)
                {
                    topMost = false;
                }

                if (topMost != _window.Topmost)
                {
                    _window.Topmost = topMost;
                }
            }
        }
        private CaptionButtonViewModel CreatePin()
        {
            if (TopMostModeConverter.ToMode(_coreData.ThisDevice.DeviceSettings) != TopMostMode.Manual)
            {
                return(null);
            }

            if (_topMostPinned)
            {
                return(CreateButton(CaptionButtonType.PinOff, PackIconKind.PinOff, "Disable 'Top most' mode", () =>
                {
                    _topMostPinned = false;
                    RefreshButtons(true);
                }));
            }
            else
            {
                return(CreateButton(CaptionButtonType.Pin, PackIconKind.Pin, "Enable 'Top most' mode", () =>
                {
                    _topMostPinned = true;
                    RefreshButtons(true);
                }));
            }
        }
 private void UpdateTopMost() => CurrentTopMostMode.SilentValue = TopMostModes.FirstOrDefault(s => s.Value == TopMostModeConverter.ToMode(CoreData.ThisDevice.DeviceSettings));