Example #1
0
        public FileService(EmojiContext context, EventService events, EmojiPadConfiguration config)
        {
            _context = context;
            _event   = events;
            _config  = config;
            context.Database.Migrate();

            if (!Directory.Exists(_config.EmojiFolderPath))
            {
                Directory.CreateDirectory(_config.EmojiFolderPath);
            }

            Task.Run(() =>
            {
                while (Program.Running)
                {
                    Thread.Sleep(1000);
                    try
                    {
                        if (SyncEmojiCache())
                        {
                            _event.SetBusy();
                            context.SaveChanges();
                            Thread.Sleep(1000);
                            _event.InvokeRefreshEmojis();
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            });
        }
Example #2
0
 public WindowService(EmojiPadConfiguration config)
 {
     _config = config;
 }
Example #3
0
 public SearchService(EmojiPadConfiguration configuration, EmojiContext context, EventService events)
 {
     _configuration = configuration;
     _context       = context;
     _event         = events;
 }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var def = EmojiPadConfiguration.CreateDefault();
            var cfg = EmojiPadConfiguration.Load();

            if (!Directory.Exists(cfg.EmojiFolderPath))
            {
                Directory.CreateDirectory(cfg.EmojiFolderPath);
            }
            if (!Directory.Exists(cfg.EmojiDatabasePath))
            {
                Directory.CreateDirectory(cfg.EmojiDatabasePath);
            }

            if (cfg.FrequentEmojiCount > 1000)
            {
                cfg.FrequentEmojiCount = 1000;
            }

            if (cfg.EmojiPasteSize > 10000)
            {
                cfg.EmojiPasteSize = 10000;
            }

            bool validAccelerator = true;
            var  modifiers        = new Regex("(Command|Cmd|Control|Ctrl|CommandOrControl|CmdOrCtrl|Alt|Option|AltGr|Shift|Super)");
            var  keycodes         = new Regex("([0-9A-Z)!@#$%^&*(:+<_>?~{|}\";=,-./`[\\]']|F1*[1-9]|F10|F2[0-4]|Plus|Space|Tab|Backspace|Delete|Insert|Return|Enter|Up|Down|Left|Right|Home|End|PageUp|PageDown|Escape|Esc|VolumeUp|VolumeDown|VolumeMute|MediaNextTrack|MediaPreviousTrack|MediaStop|MediaPlayPause|PrintScreen)");
            var  spl      = cfg.Keybind.Split("+");
            bool keyfound = false;

            for (int i = 0; i < spl.Length; i++)
            {
                string val   = spl[i];
                bool   iskey = keycodes.IsMatch(val);
                bool   ismod = modifiers.IsMatch(val);
                if (iskey && !ismod)
                {
                    if (keyfound)
                    {
                        validAccelerator = false;
                        break;
                    }
                    keyfound = true;
                }

                if (i == spl.Length - 1 && !keyfound)
                {
                    validAccelerator = false;
                    break;
                }
                if (!ismod && !iskey)
                {
                    validAccelerator = false;
                    break;
                }
            }

            if (!validAccelerator || !keyfound)
            {
                cfg.Keybind = def.Keybind;
            }

            cfg.Save();
            services.AddSingleton(cfg);
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddScoped <ClipboardService>();
            services.AddSingleton <WindowService>();
            services.AddSingleton <SearchService>();
            services.AddSingleton <FileService>();
            services.AddSingleton <EmojiContext>();
            services.AddSingleton <StatusService>();
            services.AddSingleton <EventService>();
            services.AddMBServices(
                toastServiceConfiguration: new MBToastServiceConfiguration()
            {
                InfoDefaultHeading    = "Info",
                SuccessDefaultHeading = "Success",
                WarningDefaultHeading = "Warning",
                ErrorDefaultHeading   = "Error",
                Timeout          = 5000,
                MaxToastsShowing = 5
            },

                animatedNavigationManagerServiceConfiguration: new MBAnimatedNavigationManagerServiceConfiguration()
            {
                ApplyAnimation = true,
                AnimationTime  = 300
            }
                );
            services.AddMatBlazor();
        }
Example #5
0
 public EmojiLoaderService(EmojiContext context, EmojiPadConfiguration config)
 {
     _context = context;
     _config  = config;
 }
Example #6
0
 public ClipboardService(IJSRuntime js, EmojiPadConfiguration configuration)
 {
     _jsRuntime = js;
     _config    = configuration;
 }