public OAuthPopup(IppRealmOAuthProfile ippRealmOAuthProfile)
 {
     InitializeComponent();
     _ippRealmOAuthProfile = ippRealmOAuthProfile;
     readConsumerKeysFromConfiguration();
     startOAuthHandshake();
 }
 private void manageConnection_Click(object sender, EventArgs e)
 {
     string actionTag = (manageConnection.Tag == null) ? "" : manageConnection.Tag.ToString();
     switch (actionTag)
     {
         case "Disconnect":
             callPlatform("https://appcenter.intuit.com/api/v1/Connection/Disconnect");
             _ippRealmOAuthProfile = new IppRealmOAuthProfile();
             dataGridView1.DataSource = null;
             setManageConnectionToConnect();
             if (File.Exists("ipp.xml")) { File.Delete("ipp.xml"); }
             break;
         default:
             _ippRealmOAuthProfile = new IppRealmOAuthProfile();
             OAuthPopup oauthPopup = new OAuthPopup(_ippRealmOAuthProfile);
             DialogResult dialogResult = oauthPopup.ShowDialog();
             switch (dialogResult)
             {
                 case System.Windows.Forms.DialogResult.OK:
                     saveProfileToDisk();
                     setManageConnectionToDisconnect();
                     Application.DoEvents();
                     displayCustomers();
                     break;
             }
             break;
     }
 }
 private void Main_Load(object sender, EventArgs e)
 {
     _ippRealmOAuthProfile = readProfileFromDisk();
     if (_ippRealmOAuthProfile == null) { setManageConnectionToConnect(); }
     else if (_ippRealmOAuthProfile.expirationDateTime.Subtract(DateTime.Now).TotalDays < 30)
     {
         //We are within 30 days of token expiration, so call the Reconnect API to get new access tokens
         try
         {
             callReconnectAndUpdateProfile();
             setManageConnectionToDisconnect();
             Application.DoEvents();
             displayCustomers();
         }
         catch
         {
             _ippRealmOAuthProfile = new IppRealmOAuthProfile();
             saveProfileToDisk();
             setManageConnectionToConnect();
             if (File.Exists("ipp.xml")) { File.Delete("ipp.xml"); }
         }
     }
     else
     {
         setManageConnectionToDisconnect();
         Application.DoEvents();
         displayCustomers();
     }
 }