Exemplo n.º 1
0
        public void Import(string path)
        {
            using (var fileReader = FileReaderService.Read(path))
            {
                var line = fileReader.ReadLine();
                while (line != null)
                {
                    line = line.Trim(' ', '\t', '\r', '\n');
                    if (line.StartsWith("#"))
                    {
                        if (line.Contains(":"))
                        {
                            var    indexOfSeperater = line.IndexOf(":");
                            var    key     = line.Substring(0, indexOfSeperater).Trim(' ', '\t', '\r', '\n');
                            var    value   = line.Substring(indexOfSeperater + 1, line.Length - indexOfSeperater - 1).Trim(' ', '\t', '\r', '\n');
                            string profile = null;
                            HelperService.ExtractProfile(key, ref key, ref profile);
                            key = key.TrimStart('#').Trim(' ', '\t', '\r', '\n');

                            var configuration = GetOrCreateConfiguration(profile);
                            var changed       = false;
                            if (key == "launcher")
                            {
                                configuration.WebAppLauncher = value;
                                changed = true;
                            }
                            if (key == "argumentsPattern")
                            {
                                configuration.WebAppArgumentPattern = value;
                                changed = true;
                            }
                            if (changed)
                            {
                                WebAppConfigurationRepository.SaveConfiguration(configuration);
                            }
                        }
                    }
                    else
                    {
                        var elements = line.Split(' ');
                        var url      = elements[0];
                        var keywords = string.Join(" ", elements.Skip(1).Where(e => e.Length > 0).ToArray());
                        keywords = keywords.TrimStart('(', ' ', '\t', '\r', '\n').TrimEnd(')', ' ', '\t', '\r', '\n');
                        string profile = null;
                        if (HelperService.ExtractProfile(keywords, ref keywords, ref profile))
                        {
                            keywords = keywords.TrimStart('(', ' ', '\t', '\r', '\n').TrimEnd(')', ' ', '\t', '\r', '\n');
                        }

                        if (!string.IsNullOrEmpty(url))
                        {
                            AddWebAppItem(url, keywords, profile);
                        }
                    }
                    line = fileReader.ReadLine();
                }
            }
        }
Exemplo n.º 2
0
        public void StartUrl(string url, string profile)
        {
            var configuration = WebAppConfigurationRepository.GetConfiguration(profile);

            if (configuration != null)
            {
                var launcher         = configuration.WebAppLauncher;
                var argumentsPattern = configuration.WebAppArgumentPattern;

                var arguments = string.Format(argumentsPattern, url);
                SystemService.StartCommandLine(launcher, arguments);
            }
        }
Exemplo n.º 3
0
        public void UpdateLauncher(string launcher, string argumentPattern, string profile)
        {
            var configuration = WebAppConfigurationRepository.GetConfiguration(profile);

            if (configuration == null)
            {
                configuration = new WebAppConfiguration()
                {
                    Profile = profile,
                };
            }
            configuration.WebAppLauncher        = launcher;
            configuration.WebAppArgumentPattern = argumentPattern;

            WebAppConfigurationRepository.SaveConfiguration(configuration);
        }
Exemplo n.º 4
0
        public WebAppConfiguration GetOrCreateConfiguration(string profile)
        {
            var configuration = WebAppConfigurationRepository.GetConfiguration(profile);

            if (configuration == null)
            {
                configuration = new WebAppConfiguration()
                {
                    Profile               = profile,
                    WebAppLauncher        = "chrome.exe",
                    WebAppArgumentPattern = "--app=\"{0}\" --profile-directory=\"Default\""
                };
                WebAppConfigurationRepository.SaveConfiguration(configuration);
            }
            return(WebAppConfigurationRepository.GetConfiguration(profile));
        }
Exemplo n.º 5
0
        public void Init()
        {
            DataAccessService.Init();
            WebAppItemRepository.Init();
            WebAppConfigurationRepository.Init();

            var configurations = WebAppConfigurationRepository.GetConfigurations();

            if (configurations == null)
            {
                var configuration = new WebAppConfiguration()
                {
                    Profile               = "default",
                    WebAppLauncher        = "chrome.exe",
                    WebAppArgumentPattern = "--app=\"{0}\" --profile-directory=\"Default\""
                };
                WebAppConfigurationRepository.SaveConfiguration(configuration);
            }
        }
Exemplo n.º 6
0
 public Dictionary <string, WebAppConfiguration> GetConfigurations() =>
 WebAppConfigurationRepository
 .GetConfigurations()
 .GroupBy((WebAppConfiguration webAppConfiguration) => webAppConfiguration.Profile)
 .ToDictionary(g => g.Key, g => g.ToList().First());
Exemplo n.º 7
0
 public IEnumerable <string> GetProfiles() =>
 WebAppConfigurationRepository
 .GetConfigurations()
 .Select((configuration) => configuration.Profile);
Exemplo n.º 8
0
 public WebAppConfiguration GetConfiguration(string profile) => WebAppConfigurationRepository.GetConfiguration(profile);