/// <summary> /// Allows external classes to close the window /// </summary> internal void FormTest_Close() { wpfTest.Dispatcher.Invoke(() => { wpfTest.Hide(); wpfTest.Close(); }); }
private bool authUser(bool refreshAccessToken = false) { bool retVal = false; try { string jsonData = File.ReadAllText(_jsonFilePath); _jObject = (JObject)JsonConvert.DeserializeObject(jsonData); if (_refresh_token != null && !_reAuthorize) { _jObject["refresh_token"] = _jObject["refresh_token"].ToString().Replace("{refresh_token}", _refresh_token); } // Assign client_Id & client_secret to JObject if (_client_id != null && _client_secret != null) { _jObject["client_Id"] = _client_id; _jObject["client_secret"] = _client_secret; } else { _client_id = (string)_jObject["client_Id"]; _client_secret = (string)_jObject["client_secret"]; } replaceMapping(ref _jObject, _jObject); //AuthWindow authWindow = new AuthWindow(this); //_window = new WPFWindow(); _window._oAuth2 = this; _window._windowTitle = _app_name.Replace("_", " "); _window._jObject = _jObject; //_window.Show(); if (refreshAccessToken) { _window.loadAuthUrl(refreshAccessToken).Wait(); _window.Close(); } else { _window.loadAuthUrl(false).Wait(-1); _window.Closed += AuthWindow_Closed; _window.Closed += (s, e) => Dispatcher.ExitAllFrames(); Dispatcher.Run(); } if (_jObject != null) { _jObject.Remove("client_Id"); _jObject.Remove("client_secret"); _jObject.Remove("redirect_uri"); _jObject.Remove("auth_code"); _jObject.Remove("authorize_url"); _jObject.Remove("authorize_query"); _jObject.Remove("reauthorize_url"); _jObject.Remove("reauthorize_query"); _jObject.Remove("access_token_url"); _jObject.Remove("access_token_query"); _jObject.Remove("refresh_token_url"); _jObject.Remove("refresh_token_query"); _jObject["reauthorize"] = false; string jString = _jObject.ToString(); jString = "\"root\":" + jString; jString = @"{" + "'?xml': {" + "'@version': '1.0'," + "'@standalone': 'no'" + "}," + jString + "}"; XmlDocument doc = JsonConvert.DeserializeXmlNode(jString); doc.Save(_xmlFilePath); //System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(doc.GetType()); //using (StringWriter textWriter = new StringWriter()) //{ // x.Serialize(textWriter, doc); // if (_xmlFilePath != string.Empty) // { // XmlDocument doc = new XmlDocument(); // doc.LoadXml(content); // doc.Save(SaveAs); // } //} retVal = true; } } catch (Exception e) { retVal = false; //writeLog(e); Console.WriteLine(e.Message); } return(retVal); }