Exemplo n.º 1
0
 public void Handle(JenkinsBuild item)
 {
     _processStarter.Start(item.Url);
 }
Exemplo n.º 2
0
 private void ExecuteInfo(object o)
 {
     _processStarter.Start(Urls.ArchitectWebsiteUrl);
     FinishInteraction();
 }
Exemplo n.º 3
0
        public void Handle(GitHubIssue item)
        {
            var url = $"https://github.com/{item.Owner}/{item.Repository}/issues/{item.IssueNumber}";

            _processStarter.Start(url);
        }
Exemplo n.º 4
0
 public void Handle(JenkinsJob_v1 item)
 {
     _processStarter.Start(item.URL);
 }
Exemplo n.º 5
0
        public void Run(string[] args)
        {
            if (args == null || args.Length < 2)
            {
                return;
            }

            var target = args[1];

            if (string.IsNullOrEmpty(target))
            {
                _dialogService.Warn("Empty target argument");
                return;
            }

            if (_config == null)
            {
                try {
                    _config = _configProvider.GetConfig();
                } catch (Exception ex) {
                    _dialogService.Error("Failed reading config:\n" + ex);
                    return;
                }
            }

            if (_config?.Mappings == null || !_config.Mappings.Any())
            {
                _dialogService.Info("No mappings in config");
                return;
            }

            List <Mapping> matchedMappings;

            try {
                matchedMappings =
                    _config.Mappings
                    .Where(m =>
                           m.Filters != null &&
                           m.Filters
                           .Select(f => _filterFactory.GetFilter(f.Key, f.Value))
                           .Where(f => f != null)
                           .All(f => f.Accepts(target))
                           )
                    .OrderBy(m => m.Priority).ThenBy(m => m.Name)
                    .Take(10)
                    .ToList();

                if (!matchedMappings.Any())
                {
                    matchedMappings =
                        _config.Mappings
                        .Where(m => m.Filters == null)
                        .OrderBy(m => m.Priority).ThenBy(m => m.Name)
                        .Take(10)
                        .ToList();
                }
            }
            catch (Exception ex) {
                _dialogService.Error(ex.ToString());
                return;
            }

            if (!matchedMappings.Any())
            {
                return;
            }

            var stringExpander = new VarsStringExpander(_config.Vars);

            bool StartMapping(Mapping mapping)
            {
                if (mapping != null)
                {
                    var command = stringExpander.Expand(mapping.Command);
                    try {
                        _processStarter.Start(
                            command,
                            mapping.Admin,
                            Path.GetDirectoryName(target),
                            stringExpander.Expand(mapping.Args),
                            args
                            );
                        return(true);
                    }
                    catch (Exception ex) {
                        _dialogService.Error($"Error starting '{command}':\n" + ex);
                    }
                }
                return(false);
            }

            if (matchedMappings.Count == 1)
            {
                var mapping = matchedMappings.First();
                StartMapping(mapping);
                return;
            }

            MainWindow mainWindow = null;

            mainWindow = new MainWindow {
                AllowsTransparency = _config.Opacity < 1.0,
                Opacity            = _config.Opacity,
                DataContext        = new MainViewModel {
                    Theme      = _config.Theme,
                    HeaderText = string.Format(_config.HeaderTemplate, target, Path.GetFileName(target)),
                    Items      = matchedMappings.Select((m, i) => new OptionViewModel {
                        Number       = i + 1,
                        Name         = m.Name,
                        IconSupplier = () => _iconProvider.GetIcon(stringExpander.Expand(m.Icon ?? m.Command)).Result,
                        Action       = () => { if (StartMapping(m))
                                               {
                                                   mainWindow.Close();
                                               }
                        }
                    }).ToList(),
                    CloseTimeout = _config.AutoCloseTimeout * 1000,
                    CloseAction  = () => mainWindow.Close()
                }
            };

            var app = new Application {
                ShutdownMode = ShutdownMode.OnMainWindowClose,
                MainWindow   = mainWindow
            };

            mainWindow.Show();
            app.Run();
        }