Ejemplo n.º 1
0
        public void SaveTrue1()
        {
            var path = "SaveTrue1.json";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var runRegisterMoq = new Mock <IRunRegister>();

            runRegisterMoq.Setup(x => x.RegistKey(true));

            var target = new PreferencesRepository(path)
            {
                JsonSerializer = jsonSerializer,
                RunRegister    = runRegisterMoq.Object
            };

            target.New();

            var preferences = new Preferences(":", new GlobalShortcut(ModifierKeys.Alt, Key.S), AppTheme.GenerateDarkTheme().ThemeName, true);

            target.Save(preferences);

            Assert.True(File.Exists(path));
            var actual = target.All();

            Assert.Equal(1, actual.Version);
            Assert.Equal(":", actual.Delimiter);
            Assert.NotStrictEqual(new GlobalShortcut(ModifierKeys.Alt, Key.S), actual.ShowHideShortcut);
            Assert.Equal("Dark.Steel", actual.ThemeName);
            Assert.True(actual.AutoLaunch);
        }
Ejemplo n.º 2
0
 public BackupHostedService(ILogger <HostedService> logger,
                            IServiceScopeFactory factory)
     : base(logger, factory)
 {
     context              = GetService <IPlatformContext>();
     configuration        = GetService <IConfiguration>();
     preferenceRepository = new PreferencesRepository(context.CreateDbContext());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PreferencesService"/> class.
        /// </summary>
        /// <param name="unitOfWork">The unit of work.</param>
        public PreferencesService(UnitOfWork unitOfWork)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException(UnitOfWorkConst);
            }

            this.unitOfWork = unitOfWork;
            this.preferencesRepository = new PreferencesRepository(this.unitOfWork);
        }
Ejemplo n.º 4
0
        public void SaveTheme(string themeName)
        {
            var currentPreferences = GetPreferences();
            var preferences        = new Preferences(
                currentPreferences.Delimiter,
                currentPreferences.ShowHideShortcut,
                themeName,
                currentPreferences.AutoLaunch);

            PreferencesRepository.Save(preferences);
        }
Ejemplo n.º 5
0
        public void SavePreferences(
            string delimiter,
            ModifierKeys showHideModifierKeys, Key showHideKey,
            string themeName,
            bool autoLaunch)
        {
            var showHideGlobalShortcut = new GlobalShortcut(showHideModifierKeys, showHideKey);
            var preferences            = new Preferences(delimiter, showHideGlobalShortcut, themeName, autoLaunch);

            PreferencesRepository.Save(preferences);
        }
Ejemplo n.º 6
0
        public Preferences GetPreferences()
        {
            if (!PreferencesRepository.Exists())
            {
                PreferencesRepository.New();
            }

            var preferences = PreferencesRepository.All();

            return(preferences);
        }
Ejemplo n.º 7
0
        public void ExistsTrue2()
        {
            var path = "ExistsTrue2.json";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var target = new PreferencesRepository(path)
            {
                JsonSerializer = jsonSerializer
            };
            var actual = target.Exists();

            Assert.False(actual);
        }
Ejemplo n.º 8
0
        public void ExistsTrue1()
        {
            var path = "ExistsTrue1.json";

            if (!File.Exists(path))
            {
                File.Create(path);
            }

            var target = new PreferencesRepository(path)
            {
                JsonSerializer = jsonSerializer
            };
            var actual = target.Exists();

            Assert.True(actual);
        }
Ejemplo n.º 9
0
        public async override void Process()
        {
            var userService = GetService <IUserService>();
            var users       = userService.GetUsers();

            var context = GetService <IPlatformContext>();
            var preferenceRepository = new PreferencesRepository(context.CreateDbContext());

            foreach (var user in users)
            {
                var preference = preferenceRepository.FirstOrDefault(x => x.UserId.Equals(user.Id) && x.Key.Equals("EnableWeeklyEmails"));
                if (preference == null)
                {
                    continue;
                }

                var weeklyEmails = bool.Parse(preference.Value);

                if (!weeklyEmails)
                {
                    continue;
                }

                logger.LogInformation($"Sending backup to user: {user.Email} at {DateTime.Now}");

                var userdata = userService.DownloadUserData(user.Id);

                var bytes = userdata.GetBuffer();

                await emailService.Send("*****@*****.**",
                                        new List <string> {
                    user.Email
                },
                                        "Home Management Weekly back up",
                                        "Here's your weekly backup",
                                        "<strong>Here's your weekly backup</strong>",
                                        "userdata.zip",
                                        Convert.ToBase64String(bytes));
            }
        }
Ejemplo n.º 10
0
        public void NewTrue1()
        {
            var path = "NewTrue1.json";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var target = new PreferencesRepository(path)
            {
                JsonSerializer = jsonSerializer
            };

            target.New();

            Assert.True(File.Exists(path));

            var actual = target.All();

            Assert.Equal(1, actual.Version);
            Assert.Equal(",", actual.Delimiter);
            Assert.NotStrictEqual(new GlobalShortcut(ModifierKeys.Control | ModifierKeys.Shift, Key.Space), actual.ShowHideShortcut);
        }