private void InitIntegrationConnectors() { mwApiConn = (mwApiConn) ?? new MWA.Integration.MWApiIntegrationConnector("MWAPI"); // tbSystemMessages.Text = String.Format("MWApi:{0}", MatchLogger.MatchLogger.GetApiUrl()); mwApiConn.ApiUrl = new Uri(MatchLogger.MatchLogger.GetApiUrl()); }
private void Button_Click(object sender, RoutedEventArgs e) { if (mwApiConn == null) { mwApiConn = new MWA.Integration.MWApiIntegrationConnector("MWAPI"); } mwApiConn.IsActive = true; mwApiConn.IsConnected = false; mwApiConn.ConnectionState = ConnState.CONNECTING; mwApiConn.ApiUrl = new Uri("https://www.mwoarena.com/api/"); //mwApiConn.ApiUrl = new Uri("http://v5-dev/api/"); Settings.Default.MwaLogin = tbMwaLogin.Text; Settings.Default.MwaPassword = tbMwaPassword.Password; var client = new HttpClient(); var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("username", Settings.Default.MwaLogin), new KeyValuePair <string, string>("password", tbMwaPassword.Password), new KeyValuePair <string, string>("grant_type", "password") }); Console.WriteLine("Authenticate as user a:a to get access token"); var response = client.PostAsync(mwApiConn.ApiUrl.ToString().Replace("api/", "Token"), content).Result; if (!response.IsSuccessStatusCode) { Console.WriteLine("Authentication failed"); mwApiConn.IsActive = false; mwApiConn.IsConnected = false; mwApiConn.ConnectionState = ConnState.ERROR; } else { var result = response.Content.ReadAsAsync <JObject>().Result; var accessToken = result.Value <string>("access_token"); Console.WriteLine("Access token: {0}", accessToken); mwApiConn.AuthHeader = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); Console.WriteLine("Access same protected resource with bearer token identity."); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var profile = client.GetAsync(mwApiConn.ApiUrl + "MechWarrior") .Result.Content.ReadAsAsync <JObject>() .Result; mwApiConn.IsActive = false; btnApiConn_Click("Login", new RoutedEventArgs()); tcMWApi.SelectedItem = TabAssoc; } }
private void mwApiConn_PropertyChanged(object sender, PropertyChangedEventArgs pce) { if (sender != null) { MWA.Integration.MWApiIntegrationConnector changedWaic = (MWA.Integration.MWApiIntegrationConnector)sender; string pc = pce.PropertyName; if (pc == "IsActive") { if (changedWaic.IsActive) { animateApiMonitorActivated(); } } if (pc == "ConnectionState") { imgMWApiConn.Opacity = (!changedWaic.IsConnected) ? 1 : .4; tbSystemMessages.Text = String.Format("{0}.{2}:{1}", changedWaic.Name, changedWaic.ConnectorSource, changedWaic.ConnectionState.ToString()); // if (mwApiConn.ConnectionState == ConnState.ACTIVE || mwApiConn.ConnectionState == ConnState.CONNECTED) // MwaMainDataGrid.ItemsSource = mwApiConn.MM.Select(m=>new { Mech=m.mech,DMG=m.damage}); switch (changedWaic.ConnectionState) { case ConnState.ACTIVE: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.Yellow); imgMWApiConn.Opacity = 1; return; } case ConnState.CONNECTING: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.Turquoise); imgMWApiConn.Opacity = 1; return; } case ConnState.CONNECTED: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.Green); imgMWApiConn.Opacity = 1; return; } case ConnState.ERROR: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.Red); imgMWApiConn.Opacity = 1; return; } case ConnState.DISCONNECTED: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.DimGray); imgMWApiConn.Opacity = .4; return; } case ConnState.NOTINITIALIZED: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.DarkGray); imgMWApiConn.Opacity = .4; return; } case ConnState.INITIALIZING: { setApiMonitorState(tbMWApiStatus, System.Windows.Media.Brushes.LightYellow); imgMWApiConn.Opacity = 1; return; } } } } }
public MainWindow() { SetBrowserFeatureControl(); InitializeComponent(); // Create the interop host control. AppIcon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name); updater = new SharpUpdater(this); this.tbSystemMessages.Text = this.tbSystemMessages.Text + " [A" + this.ApplicationAssembly.GetName().Version.ToString() + "]"; string refrate = (ConfigurationManager.AppSettings["DefaultRefresh"] == null || ConfigurationManager.AppSettings["DefaultRefresh"] == "") ? refreshrate.ToString() : ConfigurationManager.AppSettings["DefaultRefresh"]; refreshrate = int.Parse(refrate); mwApiConn = new MWA.Integration.MWApiIntegrationConnector("MWApi"); buildApiConn = new WebApiIntegrationConnector(); ((INotifyPropertyChanged)mwApiConn).PropertyChanged += new PropertyChangedEventHandler(mwApiConn_PropertyChanged); lwConn = new ExeIntegrationConnector("Logwarrior.exe"); //lwConn = new LWConn("MatchCompletedPublishingTestForm.exe"); //MatchLogger.MatchCompletedPublisher.OnMatchCompleted+= HandleMatch; OverlaySettings.loadSettings(); btnLWConn.BorderBrush = System.Windows.Media.Brushes.Transparent; btnLWConn.BorderThickness = new Thickness(0, 0, 0, 0); btnLWConn.Background = System.Windows.Media.Brushes.Transparent; btnApiConn.BorderBrush = System.Windows.Media.Brushes.Transparent; btnApiConn.BorderThickness = new Thickness(0, 0, 0, 0); btnApiConn.Background = System.Windows.Media.Brushes.Transparent; if (Properties.Settings.Default.dailyCompletionList == null) { Properties.Settings.Default.dailyCompletionList = new System.Collections.Specialized.StringCollection(); } btnBuildConn_Click("", new RoutedEventArgs()); menuItem_filters_Association.IsChecked = Properties.Settings.Default.filterAssociation; menuItem_filters_ShowBuilds.IsChecked = Properties.Settings.Default.filterShowBuilds; if (Properties.Settings.Default.positionWidth > 0) { Width = Properties.Settings.Default.positionWidth; Height = Properties.Settings.Default.positionHeight; Left = Properties.Settings.Default.positionLeft; Top = Properties.Settings.Default.positionTop; } getStartupInformation(); if (tbPilotName.Text == "Pilot Name" || (string.IsNullOrEmpty(Properties.Settings.Default.UserName) || Properties.Settings.Default.UserName == "Pilot Name")) { ForcePilotNameEntry(); } else { InitIntegrationConnectors(); tcMWApi.SelectedItem = TabHome; } }