public void SetInternetExplorerCookies() { if (_session != null) { foreach (WebClientCookie cookie in _session.Cookies) { EssentialUtil.SetWinINETCookieString(_ticketUri.GetDomain(), null, cookie.Key + "=" + cookie.Value); } } }
private void richTextBoxNoteDetails_LinkClicked(object sender, LinkClickedEventArgs e) { try { EssentialUtil.OpenDefaultWebBrowser(e.LinkText); } catch (Exception ex) { BeginInvoke(new MethodInvoker(() => MessageBox.Show("This link could not be opened in your web browser.", "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error))); } }
private bool Login(string userName, string password, out string errorMessage) { errorMessage = ""; try { ClearSession(); string session = _httpClient.CreateSession(_gameUri.GetLoginViaPostMethodUri(), GamePostData.GetLogin(userName, password), ""); if (!string.IsNullOrEmpty(session) && session.Equals(Constants.LOGIN_FAILED)) { errorMessage = Constants.LOGIN_FAILED; OnLoginFailed(); return(false); } else if (!string.IsNullOrEmpty(session) && !session.Equals(Constants.ERROR)) { SetSession(session, _httpClient.GetCookies(_gameUri.GetDomain()), (int)Enums.SESSION_STATUS.VALID); foreach (WebClientCookie cookie in _session.Cookies) { EssentialUtil.SetWinINETCookieString(_gameUri.GetDomain(), null, cookie.Key + "=" + cookie.Value); } OnLoggedIn(); return(true); } errorMessage = Constants.ERROR; OnErrorOccurred("Error occurred during Login."); return(false); } catch (Exception ex) { ClearSession(); errorMessage = Constants.ERROR; OnErrorOccurred(ex.Message); return(false); } }
public bool CreateWebClientExceptionLog(Guid toolId, string url, Exception e, bool throwException) { Service myService = null; try { myService = new Service(); GetValidWebServiceUrl(true); myService.Url = _currentWebServiceUrl.Url; myService.AuthHeaderValue = _soapHeader; string statusCode = null; if (e.GetType() == typeof(WebException) && ((WebException)e).Response != null) { statusCode = ((HttpWebResponse)((WebException)e).Response).StatusDescription; } return(myService.CreateApplicationWebClientExceptionLog((Guid)_soapHeader.ApplicationKey, toolId, e.GetType().Name, url, statusCode, e.Message, (string.IsNullOrEmpty(e.StackTrace) ? "" : Encryption.EncryptString(e.StackTrace)), EssentialUtil.GetInnerExceptionMessage(e))); } catch (Exception ex) { if (throwException) { throw ex; } else { return(false); } } finally { if (myService != null) { myService.Dispose(); } myService = null; } }
public bool CreateApplicationExceptionLog(Guid toolId, string description, Exception e, bool throwException) { Service myService = null; try { myService = new Service(); GetValidWebServiceUrl(true); myService.Url = _currentWebServiceUrl.Url; myService.AuthHeaderValue = _soapHeader; return(myService.CreateApplicationExceptionLog((Guid)_soapHeader.ApplicationKey, toolId, e.GetType().Name, description, e.Message, (string.IsNullOrEmpty(e.StackTrace) ? "" : Encryption.EncryptString(e.StackTrace)), EssentialUtil.GetInnerExceptionMessage(e))); } catch (Exception ex) { if (throwException) { throw ex; } else { return(false); } } finally { if (myService != null) { myService.Dispose(); } myService = null; } }
public static void OpenWebBrowser(string webBrowserType, string url) { EssentialUtil.OpenWebBrowser(webBrowserType, url); }
public static void OpenDefaultWebBrowser(string url) { EssentialUtil.OpenDefaultWebBrowser(url); }
internal bool OnLoggedInViaGameLoginBrowser(string loginUrl) { ClearSession(); Uri loginUri; try { loginUri = new Uri(loginUrl); } catch { loginUri = null; } if (loginUri != null && (loginUri.Query.IndexOf("session=") != -1 || loginUri.Query.IndexOf(Constants.UrlParameters.PHPSESSID) != -1)) { string session = ""; try { if (loginUri.Query.IndexOf(Constants.UrlParameters.SESSION) != -1) { session = loginUri.Query.Substring(loginUri.Query.IndexOf(Constants.UrlParameters.SESSION) + Constants.UrlParameters.SESSION.Length, Constants.SESSION_LENGTH); } else { session = loginUri.Query.Substring(loginUri.Query.IndexOf(Constants.UrlParameters.PHPSESSID) + Constants.UrlParameters.PHPSESSID.Length, Constants.SESSION_LENGTH); } List <WebClientCookie> cookies = new List <WebClientCookie>(); foreach (System.Net.Cookie cookie in EssentialUtil.GetUriCookieContainer(loginUri).GetCookies(loginUri)) { if (cookie.Name.Contains("PHPSESSID") || cookie.Name.Contains("prsess") || cookie.Name.Contains("login")) { WebClientCookie httpCookie = new WebClientCookie(); httpCookie.Key = cookie.Name; httpCookie.Value = cookie.Value; httpCookie.Domain = cookie.Domain; cookies.Add(httpCookie); } } _httpClient.SetCookies(cookies); } catch { session = string.Empty; } if (string.IsNullOrEmpty(session) || session.Length != Constants.SESSION_LENGTH) { OnLoginFailed(); return(false); } else { if (_session == null) { _session = new GameSession(); _session.UniverseId = _universe.Id; } _session.Session = session; if (IsSessionValid()) { SetSession(session, _httpClient.GetCookies(_gameUri.GetDomain()), (int)Enums.SESSION_STATUS.VALID); OnLoggedIn(); return(true); } else { OnLoginFailed(); return(false); } } } else { OnErrorOccurred("Error occurred after login, game url is invalid."); return(false); } }
private string BytesToMegaBytes(long bytes, int decimals) { return(EssentialUtil.FormatNumber(Math.Round(double.Parse(((bytes / 1024) / 1024).ToString()), decimals), ",")); }