Example #1
0
        /// <summary>
        /// Create and run a capture session
        /// </summary>
        /// <returns></returns>
        private async Task RunCapture()
        {
            var captureSession = new CaptureSession(session.SettingsManager, Preferences);

            captureSession.AddAllSolutions();
            await captureSession.Run();

            hasCompletedCapture = true;
            if (session.User != null)
            {
                await session.Service.Save(Preferences);
            }
            CompleteIfAllDone();
        }
        public async Task Signin(User user, Preferences?preferences = null)
        {
            if (User == null)
            {
                // If we are going from no user to a logged in user, capture the computer's current settings as the
                // default preferences that will be applied back when the user logs out.
                //
                // If we are going from one user to another user, we don't want to do anything because the computer's
                // current settings are the first user's rather than whatever the computer was before that user logged in
                if (Preferences is Preferences defaultPreferences)
                {
                    if (defaultPreferences.Id == "__default__")
                    {
                        var capture = new CaptureSession(SettingsManager, defaultPreferences);
                        capture.AddAllSolutions();
                        await capture.Run();

                        await Storage.Save(defaultPreferences);
                    }
                    else
                    {
                        logger.LogError("User is null, but Preferences.Id != '__default__'; not capturing default settings on signin");
                    }
                }
            }
            User = user;
            if (preferences == null)
            {
                Preferences = null;
                preferences = await Service.FetchPreferences(user);
            }
            Preferences = preferences;
            await Storage.Save(user);

            if (Preferences != null)
            {
                await Storage.Save(Preferences);
            }
            UserChanged?.Invoke(this, new EventArgs());
        }
Example #3
0
        public async void TestRun(string[] failList, string[] crashList)
        {
            getCount  = 0;
            setCount  = 0;
            callCount = 0;
            CaptureSessionTests.failList  = failList;
            CaptureSessionTests.crashList = crashList;
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddSingleton <IServiceProvider>(provider => provider);
            services.AddSingleton <SettingsManager>();
            services.AddSingleton <IRegistry, MockRegistry>();
            services.AddSingleton <IIniFileFactory, MockIniFileFactory>();
            services.AddSingleton <ISystemParametersInfo, MockSystemParametersInfo>();
            services.AddSingleton <ISystemSettingFactory, MockSystemSettingFactory>();
            var serviceProvider = services.BuildServiceProvider();

            var settings = serviceProvider.GetRequiredService <SettingsManager>();

            settings.Add(new Solution
            {
                Id       = "org.raisingthefloor.test",
                Settings = new Setting[]
                {
                    new Setting
                    {
                        Name               = "Registry Alpha",
                        Kind               = Setting.ValueKind.Boolean,
                        Default            = true,
                        HandlerDescription = new RegistrySettingHandlerDescription("Registry Alpha", "thevalue", RegistryValueKind.DWord)
                    },
                    new Setting
                    {
                        Name               = "Registry Beta",
                        Kind               = Setting.ValueKind.Integer,
                        Default            = 52L,
                        HandlerDescription = new RegistrySettingHandlerDescription("Registry Beta", "thevalue", RegistryValueKind.DWord)
                    },
                    new Setting
                    {
                        Name                 = "Registry Gamma",
                        Kind                 = Setting.ValueKind.String,
                        Default              = "default",
                        HandlerDescription   = new RegistrySettingHandlerDescription("Registry Gamma", "thevalue", RegistryValueKind.String),
                        FinalizerDescription = new SystemParametersInfoSettingFinalizerDescription(SystemParametersInfo.Action.SetCursors)
                    },
                    new Setting
                    {
                        Name               = "Ini Alpha",
                        Kind               = Setting.ValueKind.Boolean,
                        Default            = true,
                        HandlerDescription = new IniSettingHandlerDescription("thefile", "thesection", "Ini Alpha")
                    },
                    new Setting
                    {
                        Name               = "Ini Beta",
                        Kind               = Setting.ValueKind.Integer,
                        Default            = 52L,
                        HandlerDescription = new IniSettingHandlerDescription("thefile", "thesection", "Ini Beta")
                    },
                    new Setting
                    {
                        Name                 = "Ini Gamma",
                        Kind                 = Setting.ValueKind.String,
                        Default              = "default",
                        HandlerDescription   = new IniSettingHandlerDescription("thefile", "thesection", "Ini Gamma"),
                        FinalizerDescription = new SystemParametersInfoSettingFinalizerDescription(SystemParametersInfo.Action.SetCursors)
                    },
                    new Setting
                    {
                        Name               = "System Alpha",
                        Kind               = Setting.ValueKind.String,
                        Default            = true,
                        HandlerDescription = new SystemSettingHandlerDescription("System Alpha", SystemValueKind.String)
                    },
                    new Setting
                    {
                        Name               = "System Beta",
                        Kind               = Setting.ValueKind.String,
                        Default            = 52L,
                        HandlerDescription = new SystemSettingHandlerDescription("System Beta", SystemValueKind.String)
                    },
                    new Setting
                    {
                        Name                 = "System Gamma",
                        Kind                 = Setting.ValueKind.String,
                        Default              = "default",
                        HandlerDescription   = new SystemSettingHandlerDescription("System Gamma", SystemValueKind.String),
                        FinalizerDescription = new SystemParametersInfoSettingFinalizerDescription(SystemParametersInfo.Action.SetCursors)
                    }
                }
            });

            var rega  = new Preferences.Key("org.raisingthefloor.test", "Registry Alpha");
            var regb  = new Preferences.Key("org.raisingthefloor.test", "Registry Beta");
            var regc  = new Preferences.Key("org.raisingthefloor.test", "Registry Gamma");
            var inia  = new Preferences.Key("org.raisingthefloor.test", "Ini Alpha");
            var inib  = new Preferences.Key("org.raisingthefloor.test", "Ini Beta");
            var inic  = new Preferences.Key("org.raisingthefloor.test", "Ini Gamma");
            var sysa  = new Preferences.Key("org.raisingthefloor.test", "System Alpha");
            var sysb  = new Preferences.Key("org.raisingthefloor.test", "System Beta");
            var sysc  = new Preferences.Key("org.raisingthefloor.test", "System Gamma");
            var prefs = new Preferences();

            prefs.Set(rega, "incorrect");
            prefs.Set(regb, "incorrect");
            prefs.Set(regc, "incorrect");
            prefs.Set(inia, false);
            prefs.Set(inib, 0L);
            prefs.Set(inic, "incorrect");
            prefs.Set(sysa, "incorrect");
            prefs.Set(sysb, "incorrect");
            prefs.Set(sysc, "incorrect");
            var session = new CaptureSession(settings, prefs);

            session.AddAllSolutions();
            session.CaptureDefaultValues = true;
            await session.Run();

            var dict = session.Preferences.Default !["org.raisingthefloor.test"].Values;