public void AddAndRemoveStartupTest()
 {
     StartUpManager.AddApplicationToCurrentUserStartup();
     StartUpManager.IsApplicationAddedToCurrentUserStartup().Should().BeTrue();
     StartUpManager.RemoveApplicationFromCurrentUserStartup();
     StartUpManager.IsApplicationAddedToCurrentUserStartup().Should().BeFalse();
 }
 private static void HandleAutostart(UserSettings settings)
 {
     if (settings.Autostart)
     {
         StartUpManager.AddApplicationToCurrentUserStartup();
     }
     else
     {
         StartUpManager.RemoveApplicationFromCurrentUserStartup();
     }
 }
        private void ApplyAutoStart(bool enabled)
        {
            AppSettings.AutoStartEnabled = enabled;

            if (AppSettings.AutoStartEnabled)
            {
                StartUpManager.AddApplicationToCurrentUserStartup();
            }
            else
            {
                StartUpManager.RemoveApplicationFromCurrentUserStartup();
            }
        }
 private void enableToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (StartUpManager.IsUserAdministrator())
     {
         // Will Add application to All Users StartUp
         StartUpManager.AddApplicationToAllUserStartup();
     }
     else
     {
         // Will Add application to Current Users StartUp
         StartUpManager.AddApplicationToCurrentUserStartup();
     }
 }
Esempio n. 5
0
        private void Default_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(Settings.Default.LaunchAtStartup):
            {
                if (Settings.Default.LaunchAtStartup)
                {
                    StartUpManager.AddApplicationToCurrentUserStartup();
                }
                else
                {
                    StartUpManager.RemoveApplicationFromCurrentUserStartup();
                }
                break;
            }
            }

            Settings.Default.Save();
        }
Esempio n. 6
0
        public SettingsViewModel(IUserSettings userSettings, IList <ISelectableViewPart> selectableViewParts
                                 , ISpotSet spotSet, IContext context, ISerialStream serialStream)
        {
            if (selectableViewParts == null)
            {
                throw new ArgumentNullException(nameof(selectableViewParts));
            }

            this.Settings       = userSettings ?? throw new ArgumentNullException(nameof(userSettings));
            this.spotSet        = spotSet ?? throw new ArgumentNullException(nameof(spotSet));
            Context             = context ?? throw new ArgumentNullException(nameof(context));
            this.serialStream   = serialStream ?? throw new ArgumentNullException(nameof(serialStream));
            SelectableViewParts = selectableViewParts.OrderBy(p => p.Order)
                                  .ToList();
#if DEBUG
            SelectedViewPart = SelectableViewParts.Last();
#else
            SelectedViewPart = SelectableViewParts.First();
#endif

            PossibleLedCountsVertical   = Enumerable.Range(10, 190).ToList();
            PossibleLedCountsHorizontal = Enumerable.Range(10, 290).ToList();

            PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(SelectedViewPart):
                    var name = SelectedViewPart?.ViewPartName ?? "nothing";
                    break;
                }
            };

            Settings.PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(Settings.SpotsX):
                    RaisePropertyChanged(() => SpotsXMaximum);
                    RaisePropertyChanged(() => LedCount);
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.SpotsY):
                    RaisePropertyChanged(() => SpotsYMaximum);
                    RaisePropertyChanged(() => LedCount);
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.UseLinearLighting):
                    RaisePropertyChanged(() => UseNonLinearLighting);
                    break;

                case nameof(Settings.OffsetLed):
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.Autostart):
                    if (Settings.Autostart)
                    {
                        StartUpManager.AddApplicationToCurrentUserStartup();
                    }
                    else
                    {
                        StartUpManager.RemoveApplicationFromCurrentUserStartup();
                    }
                    break;

                case nameof(Settings.ComPort):
                    RaisePropertyChanged(() => TransferCanBeStarted);
                    RaisePropertyChanged(() => TransferCanNotBeStarted);
                    break;
                }
            };
        }
        public SettingsViewModel(IUserSettings userSettings, IList <ISelectableViewPart> selectableViewParts
                                 , ISpotSet spotSet, IContext context, TelemetryClient tc, ISerialStream serialStream)
        {
            WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent");

            watcher = new ManagementEventWatcher(query);
            watcher.EventArrived += (s, e) => RaisePropertyChanged(() => AvailableComPorts);
            // watcher.Query = query;
            watcher.Start();
            // watcher.WaitForNextEvent();
            if (selectableViewParts == null)
            {
                throw new ArgumentNullException(nameof(selectableViewParts));
            }

            this.Settings       = userSettings ?? throw new ArgumentNullException(nameof(userSettings));
            this.spotSet        = spotSet ?? throw new ArgumentNullException(nameof(spotSet));
            Context             = context ?? throw new ArgumentNullException(nameof(context));
            this.serialStream   = serialStream ?? throw new ArgumentNullException(nameof(serialStream));
            SelectableViewParts = selectableViewParts.OrderBy(p => p.Order)
                                  .ToList();
#if DEBUG
            SelectedViewPart = SelectableViewParts.First();
#else
            SelectedViewPart = SelectableViewParts.First();
#endif

            PossibleLedCountsVertical   = Enumerable.Range(10, 190).ToList();
            PossibleLedCountsHorizontal = Enumerable.Range(10, 290).ToList();

            PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(SelectedViewPart):
                    var name = SelectedViewPart?.ViewPartName ?? "nothing";
                    tc.TrackPageView(name);
                    break;
                }
            };

            Settings.PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(Settings.SpotsX):
                    RaisePropertyChanged(() => SpotsXMaximum);
                    RaisePropertyChanged(() => LedCount);
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.SpotsY):
                    RaisePropertyChanged(() => SpotsYMaximum);
                    RaisePropertyChanged(() => LedCount);
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.LedsPerSpot):
                    RaisePropertyChanged(() => LedCount);
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.UseLinearLighting):
                    RaisePropertyChanged(() => UseNonLinearLighting);
                    break;

                case nameof(Settings.OffsetLed):
                    RaisePropertyChanged(() => OffsetLedMaximum);
                    break;

                case nameof(Settings.Autostart):
                    if (Settings.Autostart)
                    {
                        StartUpManager.AddApplicationToCurrentUserStartup();
                    }
                    else
                    {
                        StartUpManager.RemoveApplicationFromCurrentUserStartup();
                    }
                    break;

                case nameof(Settings.ComPort):
                    RaisePropertyChanged(() => TransferCanBeStarted);
                    RaisePropertyChanged(() => TransferCanNotBeStarted);
                    break;
                }
            };
        }