private string PrepareDataAndPostSession(string sessionId, bool appendData, ref NameValueCollection postParams) { //CacheProcessor.CreateDecryptedImages(sessionId); //List<string> decryptedImagePaths = new List<string>(CacheProcessor.GetDecryptedImagePaths(sessionId)); //if (decryptedImagePaths == null || decryptedImagePaths.Count <= 0) // return string.Empty; CacheProcessor.DecryptData(sessionId); List <string> loadedData = CacheProcessor.LoadData(sessionId); if ((loadedData == null || loadedData.Count <= 0) && !appendData) { CacheProcessor.DeleteSessionFolder(sessionId); return("EMPTY_FOLDER"); } CacheProcessor.CreateDecryptedImages(sessionId); List <string> decryptedImagePaths = new List <string>(CacheProcessor.GetDecryptedImagePaths(sessionId)); if (appendData) { postParams = _ServerApiProvider.AppendPostSessionParams(loadedData, CurrentContext.GetInstance().Session, CurrentContext.GetInstance().LoginData); } else { postParams = _ServerApiProvider.CreatePostSessionParams(loadedData); } string postUrl = _ServerApiProvider.CreatePostSessionUrl(); if (!WebProcessor.CheckInternetConnection()) { ErrorTimer.GetInstance().StartTimer(); return("CONNECTION_FAIL"); } return(WebProcessor.UploadFileWithParams(postUrl, _ServerApiProvider.PrepareFilesData(decryptedImagePaths, "screenshot_files[]", "image/jpeg"), postParams)); /* MOCK */ /*FAKE++; * * if (FAKE == 0) * return WebProcessor.UploadFileWithParams(postUrl, * _ServerApiProvider.PrepareFilesData(decryptedImagePaths), postParams); * else if (FAKE > 0 && FAKE < 3) * return "FAIL"; * else * return WebProcessor.UploadFileWithParams(postUrl, * _ServerApiProvider.PrepareFilesData(decryptedImagePaths), postParams);*/ /* MOCK */ }
// AHMED EDIT private void GetSavedEmailAndDetectVersion() { try { VersionController.GetInstance(); string email = string.Empty; RegistryProcessor.GetFromRegistry(CommonConst.REGISTRY_PATH, CommonConst.EMAIL_VALUE_NAME, ref email, RegistryProcessor.RegistryParts.HKEY_CURRENT_USER); if (!WebProcessor.CheckInternetConnection()) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetNetworkLine("Connection Error")); MessageBox.Show("Connection Error"); CurrentContext.GetInstance().VersionData.State = VersionState.UNKNOWN; IsInternetExists = false; return; } else { IsInternetExists = true; } if (!string.IsNullOrEmpty(email)) { CurrentContext.GetInstance().VersionData.VersionDetected = VersionController.GetInstance().GetVersionData(email); } else { CurrentContext.GetInstance().VersionData.VersionDetected = VersionController.GetInstance().GetVersionData(string.Empty); } if (CurrentContext.GetInstance().VersionData.VersionDetected) { _new_version_lb.TextAlign = ContentAlignment.MiddleCenter; DetectVersionState(); } else { CurrentContext.GetInstance().VersionData.State = VersionState.UNKNOWN; } } catch { CurrentContext.GetInstance().VersionData.State = VersionState.UNKNOWN; } }
private void _current_timer_tm_Tick(object sender, EventArgs e) { _local_time_al_lb.Text = string.Format("Local Time: {0:hh:mm tt}", DateTime.Now); _local_time_lb.Text = string.Format("Local Time: {0:hh:mm tt}", DateTime.Now); if (!IsInternetExists) { InternetConnectionCount++; if (InternetConnectionCount >= CommonConst.CHECK_CONNECTION_INTERVAL) { InternetConnectionCount = 0; if (WebProcessor.CheckInternetConnection()) { IsInternetExists = true; try { CurrentContext.GetInstance().VersionData.VersionDetected = VersionController.GetInstance().GetVersionData(string.Empty); if (CurrentContext.GetInstance().VersionData.VersionDetected) { _new_version_lb.TextAlign = ContentAlignment.MiddleCenter; DetectVersionState(); } else { CurrentContext.GetInstance().VersionData.State = VersionState.UNKNOWN; } SetVersionButton(); ConfVersionPanel(); } catch { CurrentContext.GetInstance().VersionData.State = VersionState.UNKNOWN; } } else { IsInternetExists = false; } } } }
private void OnInternalTimedEvent(object source, ElapsedEventArgs e) { _Count++; if (WebProcessor.CheckInternetConnection()) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetNetworkLine("Exp. Internet Connection OK")); _InternalTimer.Stop(); _Handler.ConnectionStateChanged(true); _IsStarted = false; _Handler.CheckConnectionEventFired(); } else { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetNetworkLine("Exp. Internet Connection Fail")); _InternalTimer.Stop(); _InternalTimer.Interval = _Count < _Times.Length ? _Times[_Count] : _Times[_Times.Length - 1]; _InternalTimer.Start(); } }
public string SendBugReport(string report, bool isCrashReport) { if (!WebProcessor.CheckInternetConnection()) { return("Internet Connection Error"); } string url = SessionController.GetInstance().ServerApiProvider.CreateBugReportUrl(); string email = "*****@*****.**"; if (CurrentContext.GetInstance().LoginData != null && !string.IsNullOrEmpty(CurrentContext.GetInstance().LoginData.Login)) { email = CurrentContext.GetInstance().LoginData.Login; } else { string regEmail = string.Empty; RegistryProcessor.GetFromRegistry(CommonConst.REGISTRY_PATH, CommonConst.EMAIL_VALUE_NAME, ref regEmail, RegistryProcessor.RegistryParts.HKEY_CURRENT_USER); if (!string.IsNullOrEmpty(regEmail)) { email = regEmail; } } string currVersion = "1.00"; if (CurrentContext.GetInstance().VersionData != null) { currVersion = CurrentContext.GetInstance().VersionData.CurrentVersion.ToString(); } string token = CommonConst.BUG_REPORT_TOKEN; string logFile = LogController.GetInstance().IsLogFileExists(); NameValueCollection postParams = new NameValueCollection(); postParams.Add("from", email); postParams.Add("body", report); postParams.Add("tracker_version", currVersion); postParams.Add("token", token); if (isCrashReport) { postParams.Add("crash_report", "1"); } List <string> logFilePath = new List <string>(); logFilePath.Add(logFile); string resp = WebProcessor.UploadFileWithParams(url, SessionController.GetInstance().ServerApiProvider. PrepareFilesData(logFilePath, "activity_log", "text/plain"), postParams); LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetNavigationLine("Server reply: " + resp)); return(resp); }
private void _login_btn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(_username_Tb.Text) || string.IsNullOrEmpty(_password_Tb.Text)) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetLoginFailedLine("Incorrect username or password")); MessageBox.Show("Login or password is empty"); } else { if (!CurrentContext.GetInstance().IsSessionDataLocked) { ThreadPool.QueueUserWorkItem(new WaitCallback((s) => { CurrentContext.GetInstance().IsSessionDataLocked = true; if (!WebProcessor.CheckInternetConnection()) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetLoginFailedLine("Network unavailable")); this.Invoke((MethodInvoker) delegate() { MessageBox.Show("Network unavailable"); }); CurrentContext.GetInstance().IsSessionDataLocked = false; return; } LoginState loginState = LoginDataController.GetInstance().Login(_username_Tb.Text, _password_Tb.Text); if (loginState == LoginState.LOGGED) { this.Invoke((MethodInvoker) delegate() { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetLoginSuccessLine()); RegistryProcessor.SetToRegistry(CommonConst.REGISTRY_PATH, CommonConst.EMAIL_VALUE_NAME, CurrentContext.GetInstance().LoginData.Login, RegistryProcessor.RegistryParts.HKEY_CURRENT_USER); // AHMED EDITS string pwd = CurrentContext.GetInstance().LoginData.Password; pwd = StringCipher.Encrypt(pwd, CommonConst.DES_KEY); if (!string.IsNullOrEmpty(pwd)) { RegistryProcessor.SetToRegistry(CommonConst.REGISTRY_PATH, CommonConst.PWD_VALUE_NAME, pwd, RegistryProcessor.RegistryParts.HKEY_CURRENT_USER); } // AHMED EDITS MainForm mainForm = new MainForm(); mainForm.Show(); mainForm.Visible = false; mainForm.Left = this.Left; mainForm.Top = this.Top; mainForm.Size = this.Size; mainForm.Visible = true; IsHide = true; _balloon_ni.Visible = false; this.Hide(); LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetNavigationLine("Main page")); LogController.GetInstance().RemoveLogHandler(this); }); } else { this.Invoke((MethodInvoker) delegate() { if (loginState == LoginState.CONNECTION_FAIL) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetLoginFailedLine("Web server did not responded")); MessageBox.Show("Connection Error"); } else if (loginState == LoginState.LOGIN_FAIL) { LogController.GetInstance().LogData(LogController. GetInstance().LogFormat.GetLoginFailedLine("Incorrect username or password")); MessageBox.Show("Login Error"); } }); } CurrentContext.GetInstance().IsSessionDataLocked = false; })); } } }