public AppHarborCliClient(string accessToken) { var authInfo = new AuthInfo(accessToken); try { _api = new AppHarborClient(authInfo); } catch (ArgumentNullException) { throw new CommandException("You're not logged in. Log in with \"appharbor login\""); } }
public AppHarborForm() { InitializeComponent(); notifyIcon.ContextMenuStrip = contextMenuStrip; tabControl.TabPages.Remove(previousBuildsTabPage); //http://stackoverflow.com/questions/2154154/datagridview-how-to-set-column-width DataGridViewTextBoxColumn subTitleColumn = new DataGridViewTextBoxColumn(); subTitleColumn.HeaderText = "Subtitle"; subTitleColumn.MinimumWidth = 50; subTitleColumn.FillWeight = 65; subTitleColumn.DataPropertyName = "Date"; DataGridViewTextBoxColumn summaryColumn = new DataGridViewTextBoxColumn(); summaryColumn.HeaderText = "Summary"; summaryColumn.MinimumWidth = 50; summaryColumn.FillWeight = 200; summaryColumn.DataPropertyName = "Value"; dataGridViewErrors.Columns.AddRange(new DataGridViewTextBoxColumn[] { subTitleColumn, summaryColumn }); //Make the timer fire straight-away, the 1st time timer = new Timer {Enabled = true, Interval = 500}; //timer.Tick += (sender, e) => timer.Elapsed += (sender, e) => { timer.Stop(); try { if (String.IsNullOrWhiteSpace(Settings.Default.AccessToken)) { UpdateAuthorisationDetails(); } var authInfo = new AuthInfo(Settings.Default.AccessToken, Settings.Default.TokenType); var client = new AppHarborClient(authInfo); var applications = client.GetApplications(); if (applications == null || applications.Count() == 0) return; var application = applications.First(); var builds = client.GetBuilds(application.Slug); var errors = client.GetErrors(application.Slug); if (errors != null && errors.Count() > 0) { var errorInfo = errors.Take(10).Select(x => new { //2012-07-03T00:36:44.292Z Date = ParseDate(x.Date).ToString(), Value = x.Exception.Message }).ToList(); if (_formHasBeenShown) { dataGridViewErrors.Invoke((Action)delegate { dataGridViewErrors.DataSource = errorInfo; dataGridViewErrors.Show(); }); } } //var tests = client.GetTests(application.Slug, build.Id); var latestBuild = builds.OrderByDescending(x => x.Created) //.Skip(1) .FirstOrDefault(); if (latestBuild == null) return; var currentBuildStatus = GetBuildStatus(latestBuild.Status); SetNotifyIcon(currentBuildStatus); if (currentBuildStatus != _lastBuildStatus) { string msg = GetBuildStatusMsg(currentBuildStatus, _lastBuildStatus); if (String.IsNullOrEmpty(msg) == false) notifyIcon.ShowBalloonTip(1000, "Build Status", msg, ToolTipIcon.Warning); } if (_formHasBeenShown) { UpdateBuildUI(application, latestBuild, currentBuildStatus); } else { //Store the info, so when the form is popped up, we can populate it?? } if (currentBuildStatus == BuildStatus.Succeeded || currentBuildStatus == BuildStatus.Failed) { //We only really care about failed/succeeded changes _lastBuildStatus = currentBuildStatus; } } catch (System.Exception ex) { notifyIcon.ShowBalloonTip(1000, "AppHarbor Lookout - Error", ex.Message + "\n" + ex.StackTrace, ToolTipIcon.Error); } finally { #if DEBUG timer.Interval = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; #else timer.Interval = (int)TimeSpan.FromMinutes(1).TotalMilliseconds; #endif timer.Start(); } }; buildUrlLinkLabel.LinkClicked += ProcessLinkClick; logUrlLinkLabel.LinkClicked += ProcessLinkClick; applicationUrlLinkLabel.LinkClicked += ProcessLinkClick; mainScreenToolStripMenuItem.Click += (sender, e) => ToggleMainScreen(); reAuthoriseToolStripMenuItem.Click += (sender, e) => UpdateAuthorisationDetails(); exitToolStripMenuItem.Click += (sender, e) => { _allowClose = true; Close(); //If the form hasn't been shown, Close() on it's own doesn't kill the process, use Exit also Environment.Exit(1); }; notifyIcon.ShowBalloonTip(1000, "AppHarbor Lookout", "Monitoring your builds", ToolTipIcon.Info); notifyIcon.Click += (sender, e) => { var mouseEvent = e as MouseEventArgs; if (mouseEvent != null && mouseEvent.Button == MouseButtons.Left) ToggleMainScreen(); }; closeLinkLabel.Click += (sender, e) => HideMainScreen(); }
public ApiService(string token) { _AccessToken = token; _Api = new AppHarborClient(new AuthInfo(_AccessToken, "Bearer")); }