public TrayIconApplicationContext([Dependency("ToolTip")]INotificationService notificationService,
            IBuildConfigurationService buildConfigurationService, IAppConfig appConfig)
        {
            _notificationService = notificationService;
            _buildConfigurationService = buildConfigurationService;
            _appConfig = appConfig;

            TrayIcon = new NotifyIcon()
            {
                Icon = Resources.TfsIcon,
                Visible = true,
                Text = "TFS Build Notifications",

                ContextMenu = new ContextMenu(new MenuItem[]
                {
                    new MenuItem("Open Dashboard", OpenDashboard),
                    new MenuItem("Exit", Exit)
                })
            };

            TrayIcon.MouseClick += OnMouseClick;

            if (_buildConfigurationService.HasAnyMonitoredBuilds())
            {
                _notificationService.ShowGenericNotification("TFS Build Notifications", "Build notifications enabled.",
                    () => Process.Start($"http://localhost:{_appConfig.WebsitePort}"));
            }
            else
            {
                _notificationService.ShowGenericNotification("TFS Build Notifications",
                    "No build notifications configured. Click here to get started.",
                    () => Process.Start($"http://localhost:{_appConfig.WebsitePort}"));
            }
        }
Example #2
0
        public ConnectionModule(IBuildConfigurationService buildConfigurationService)
        {
            _buildConfigurationService = buildConfigurationService;

            #region /addconnection

            Get["/addconnection"] = _ =>
            {
                return(View["Views/AddConnection.cshtml", new AddEditConnectionViewModel
                            {
                                NewConfiguration = !_buildConfigurationService.HasConfiguration()
                            }]);
            };

            Post["/addconnection"] = _ =>
            {
                var model            = this.Bind <AddEditConnectionViewModel>();
                var validationResult = this.Validate(model);

                if (!validationResult.IsValid)
                {
                    model.Errors.AddRange(validationResult.Errors.SelectMany(e => e.Value).Select(y => y.ErrorMessage));

                    return(View["Views/AddConnection.cshtml", model]);
                }

                try
                {
                    _buildConfigurationService.AddConnection(model.TfsServerUrl, model.TfsServerLocation, model.UserName,
                                                             model.Password, model.PersonalAccessToken);
                }
                catch (ServiceValidationException s)
                {
                    model.Errors.AddRange(s.ServiceErrors);

                    return(View["Views/AddConnection.cshtml", model]);
                }

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /editconnection

            Get["/editconnection/{id}"] = x =>
            {
                var connection = _buildConfigurationService.GetBuildConfig().Connections.FirstOrDefault(c => c.Id.ToString() == x.id);

                if (connection != null)
                {
                    var viewModel = new AddEditConnectionViewModel
                    {
                        NewConfiguration  = false,
                        UserName          = connection.UserName,
                        TfsServerUrl      = connection.TfsServerUrl,
                        TfsServerLocation = connection.TfsServerDeployment.ToString()
                    };

                    return(View["Views/EditConnection.cshtml", viewModel]);
                }

                return(Response.AsRedirect("/"));
            };

            Post["/editconnection/{id}"] = x =>
            {
                var model            = this.Bind <AddEditConnectionViewModel>();
                var validationResult = this.Validate(model);

                if (!validationResult.IsValid)
                {
                    model.Errors.AddRange(validationResult.Errors.SelectMany(e => e.Value).Select(y => y.ErrorMessage));

                    return(View["Views/EditConnection.cshtml", model]);
                }

                try
                {
                    _buildConfigurationService.EditConnection(x.id, model.TfsServerUrl, model.TfsServerLocation,
                                                              model.UserName, model.Password, model.PersonalAccessToken);
                }
                catch (ServiceValidationException s)
                {
                    model.Errors.AddRange(s.ServiceErrors);

                    return(View["Views/EditConnection.cshtml", model]);
                }

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /deleteconnection

            Post["/deleteconnection"] = _ =>
            {
                _buildConfigurationService.DeleteConnection((string)Request.Form["ConnectionId"]);

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /addproject

            Get["/addproject/{id}"] = x =>
            {
                string id = x.id;

                try
                {
                    Connection connection;
                    var        projects = _buildConfigurationService.GetProjects(id, out connection);

                    var model = new AddProjectViewModel
                    {
                        Connection        = connection,
                        ProjectSelections = projects.Select(p => new ProjectSelectionModel
                        {
                            Id       = p.Id, Name = p.Name,
                            Disabled = _buildConfigurationService.ProjectExistsInConfig(connection.Id, p.Id)
                        }).ToList()
                    };

                    return(View["Views/AddProject.cshtml", model]);
                }
                catch (InvalidOperationException)
                {
                    return(new NotFoundResponse());
                }
            };

            Post["/addproject"] = x =>
            {
                var connectionId = (string)Request.Form["ConnectionId"];
                var selections   = this.Bind <List <ProjectSelectionModel> >();

                _buildConfigurationService.AddProjects(connectionId,
                                                       selections.Where(s => s.Selected).Select(s => new Project {
                    Id = s.Id, Name = s.Name
                }).ToList());

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /deleteproject

            Post["/deleteproject"] = _ =>
            {
                _buildConfigurationService.DeleteProject((string)Request.Form["ConnectionId"], (string)Request.Form["ProjectId"]);

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /addbuilds

            Get["/addbuilds"] = x =>
            {
                var connectionId = (string)Request.Query["connectionId"];
                var projectId    = (string)Request.Query["projectId"];

                if (string.IsNullOrEmpty(connectionId) || string.IsNullOrEmpty(projectId))
                {
                    return(new NotFoundResponse());
                }

                try
                {
                    Connection connection;
                    Project    project;
                    var        buildDefinitions = _buildConfigurationService.GetBuildDefinitions(connectionId, projectId,
                                                                                                 out connection, out project);

                    var model = new AddBuildsViewModel
                    {
                        Connection      = connection,
                        Project         = project,
                        BuildSelections = buildDefinitions.Select(b => new BuildSelectionModel
                        {
                            Id       = b.Id,
                            Name     = b.Name,
                            Disabled = _buildConfigurationService.BuildExistsInConfig(connection.Id, project.Id, b.Id)
                        }).ToList(),
                    };

                    return(View["Views/AddBuilds.cshtml", model]);
                }
                catch (InvalidOperationException)
                {
                    return(new NotFoundResponse());
                }
            };

            Post["/addbuilds"] = x =>
            {
                var connectionId = (string)Request.Form["ConnectionId"];
                var projectId    = (string)Request.Form["ProjectId"];

                var selections = this.Bind <List <BuildSelectionModel> >();

                _buildConfigurationService.AddBuildDefinitions(connectionId, projectId,
                                                               selections.Where(s => s.Selected).Select(s => new BuildDefinition {
                    Id = s.Id, Name = s.Name
                }).ToList());

                return(Response.AsRedirect("/"));
            };

            #endregion

            #region /deletebuild

            Post["/deletebuild"] = _ =>
            {
                _buildConfigurationService.DeleteBuild((string)Request.Form["LocalDefId"]);

                return(Response.AsRedirect("/"));
            };

            #endregion
        }
Example #3
0
 public DashboardHub()
 {
     // ToDo: DI
     _buildConfigurationService = new BuildConfigurationService(new TfsApiClient(LoggingErrorHandler.LogService),
                                                                new RegistryHelper());
 }
 public PollingService(IBuildConfigurationService buildConfigurationService)
 {
     _buildConfigurationService = buildConfigurationService;
 }
        public HomeModule(IBuildConfigurationService buildConfigurationService)
        {
            _buildConfigurationService = buildConfigurationService;

            Get["/"] = _ =>
            {
                if (!_buildConfigurationService.HasConfiguration())
                {
                    return(Response.AsRedirect("/addconnection"));
                }

                var buildConfig = _buildConfigurationService.GetBuildConfig();
                var viewModel   = new HomeViewModel();

                foreach (var connection in buildConfig.Connections)
                {
                    var dashboardConnection = new DashboardConnection {
                        Connection = connection
                    };

                    if (!connection.Broken)
                    {
                        foreach (var project in connection.Projects)
                        {
                            var dashboardProject = new DashboardProject {
                                Project = project
                            };

                            foreach (var buildDef in project.BuildDefinitions)
                            {
                                dashboardProject.BuildDefinitions.Add(new DashboardBuildDefinition
                                {
                                    Name    = buildDef.Name,
                                    Url     = buildDef.Url,
                                    LocalId = buildDef.LocalId,

                                    Builds = _buildConfigurationService.GetBuilds(connection, project.Name,
                                                                                  buildDef.Id).ToList()
                                });
                            }

                            dashboardConnection.Projects.Add(dashboardProject);
                        }
                    }

                    viewModel.Connections.Add(dashboardConnection);
                }

                return(View["Views/Index.cshtml", viewModel]);
            };

            Get["/buildsummary"] = x =>
            {
                var buildConfig = _buildConfigurationService.GetBuildConfig();

                var connectionId = (string)Request.Query["connectionId"];
                var projectId    = (string)Request.Query["projectId"];
                var localBuildId = (string)Request.Query["localBuildId"];

                var connection = buildConfig.Connections
                                 .FirstOrDefault(c => c.Id.ToString() == connectionId);

                var project = connection?.Projects.FirstOrDefault(p => p.Id.ToString() == projectId);

                var buildDef = project?.BuildDefinitions
                               .FirstOrDefault(b => b.LocalId.ToString() == localBuildId);

                if (buildDef != null)
                {
                    var model = new SingleBuildDefinitionViewModel
                    {
                        Connection = connection,
                        Project    = project,

                        BuildDefinition = new DashboardBuildDefinition
                        {
                            Name    = buildDef.Name,
                            Url     = buildDef.Url,
                            LocalId = buildDef.LocalId,

                            Builds = _buildConfigurationService.GetBuilds(connection, project.Name,
                                                                          buildDef.Id).ToList()
                        }
                    };

                    return(View["Views/Shared/_BuildSummary.cshtml", model]);
                }
                else
                {
                    return(null);
                }
            };
        }