private void restoreRRSData(BackupObj item) { this.lblStatusMsg.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "Restoring data...."; })); this.cmdResult.restore = false; this.cmd.restore(item.filename); DateTime now5 = DateTime.Now; this.btnConnectDevice.Invoke(new MethodInvoker(delegate { this.maxwait = (int)this.numMaxWait.Value; })); while (!this.cmdResult.restore) { Thread.Sleep(500); if ((DateTime.Now - now5).TotalSeconds > (double)this.maxwait) { throw new Exception("restore rrs timeout"); } this.cmd.checkrestore(); } }
public void saverrsthread(ListViewItem currentSeletectItem) { BackupObj currentbk = this.listbackup.FirstOrDefault((BackupObj x) => x.filename == currentSeletectItem.SubItems[7].Text); this.listViewRRS.Invoke(new MethodInvoker(delegate { currentSeletectItem.BackColor = Color.Yellow; })); string filename = ""; base.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "Saving RRS..."; currentbk.timemod = DateTime.Now; int num = currentbk.runtime; currentbk.runtime = num + 1; filename = currentbk.filename.Replace(".zip", ""); this.cmd.backupAppAndSystem(string.Join(";", currentbk.appList.ToArray()), currentbk.filename.Replace(".zip", ""), this.textBoxCommentRRS.Text + "[]" + currentbk.country, currentbk.timemod.ToString("MM/dd/yyyy HH:mm:ss"), currentbk.runtime.ToString()); })); this.cmdResult.backup = false; DateTime now = DateTime.Now; this.btnConnectDevice.Invoke(new MethodInvoker(delegate { this.maxwait = (int)this.numMaxWait.Value; })); while (!this.cmdResult.backup) { Thread.Sleep(500); bool flag = (DateTime.Now - now).TotalSeconds > (double)this.maxwait; if (flag) { this.lblStatusMsg.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "Request timeout..."; MessageBox.Show("Save RRS error! Please stop to prevent RRS lost"); })); return; } this.cmd.checkbackup(filename); } this.lblStatusMsg.Invoke(new MethodInvoker(delegate { currentSeletectItem.SubItems[5].Text = this.textBoxCommentRRS.Text; currentSeletectItem.SubItems[2].Text = currentbk.timemod.ToString("MM/dd/yyyy HH:mm:ss"); currentSeletectItem.SubItems[3].Text = currentbk.runtime.ToString(); this.lblStatusMsg.Text = "Saved RRS"; this.btnSaveRRS.Enabled = true; this.textBoxCommentRRS.Enabled = true; this.btnSaveRRS.Text = "Save"; currentSeletectItem.BackColor = Color.Lime; })); }
ListViewItem getRRSListViewItemFromBackupObj(BackupObj item) { ListViewItem currentlistview = null; base.Invoke(new MethodInvoker(delegate { foreach (object obj in this.listViewRRS.Items) { ListViewItem listViewItem = (ListViewItem)obj; if (listViewItem.SubItems[7].Text == item.filename) { currentlistview = listViewItem; break; } } })); return(currentlistview); }
public void restorethread() { int selectedindex = 0; BackupObj currentbk = new BackupObj(); this.listViewRRS.Invoke(new MethodInvoker(delegate { selectedindex = this.listViewRRS.Items.IndexOf(this.listViewRRS.SelectedItems[0]); currentbk = this.listbackup.FirstOrDefault((BackupObj x) => x.filename == this.listViewRRS.Items[selectedindex].SubItems[7].Text); this.listViewRRS.SelectedItems[0].BackColor = Color.Yellow; })); this.wipeAppData(currentbk.appList.ToList()); this.cmdResult.restore = false; this.cmd.restore(currentbk.filename); DateTime now2 = DateTime.Now; this.btnConnectDevice.Invoke(new MethodInvoker(delegate { this.maxwait = (int)this.numMaxWait.Value; })); while (!this.cmdResult.restore) { Thread.Sleep(500); bool flag2 = (DateTime.Now - now2).TotalSeconds > (double)this.maxwait; if (flag2) { return; } this.cmd.checkrestore(); } this.listViewRRS.Invoke(new MethodInvoker(delegate { this.listViewRRS.Items[selectedindex].BackColor = Color.Lime; this.lblStatusMsg.Text = "App restored"; this.btnRestoreRRS.Enabled = true; })); }
private void openAppAndrunRRSS(BackupObj item) { ListViewItem currentlistview = getRRSListViewItemFromBackupObj(item); this.lblStatusMsg.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "Opening application...."; })); foreach (string appID in item.appList) { this.cmdResult.openApp = 0; this.cmd.openApp(appID); while (this.cmdResult.openApp != 0) { Thread.Sleep(1000); if ((DateTime.Now - DateTime.Now).TotalSeconds > (double)this.maxTimeOpenApp) { throw new Exception("open application timeout"); } } int waittime = 20; this.rsswaitnum.Invoke(new MethodInvoker(delegate { waittime = (int)this.rsswaitnum.Value; })); for (int i = 0; i < waittime; i++) { Thread.Sleep(1000); this.lblStatusMsg.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "Application will be closed in " + (waittime - i - 1).ToString() + " seconds"; })); } string scriptText = ""; string key = ""; this.lblStatusMsg.Invoke(new MethodInvoker(delegate { if (this.useScriptWhenRRS.Checked) { ScriptEntity scriptEntity = this.listScriptRRS.FirstOrDefault((ScriptEntity x) => x.scriptAppID == appID); if (scriptEntity != null & scriptEntity.scriptDictionary.Keys.Count > 0) { Random random3 = new Random(); int index = random3.Next(0, scriptEntity.scriptDictionary.Keys.Count); if (scriptEntity.scriptKey == "Random") { scriptText = scriptEntity.scriptDictionary.ElementAt(index).Value; key = scriptEntity.scriptDictionary.ElementAt(index).Key; } else { scriptText = scriptEntity.scriptDictionary[scriptEntity.scriptKey]; key = scriptEntity.scriptKey; } } this.lblStatusMsg.Text = "Running script " + key; } })); if (scriptText != "") { this.excuteScript(scriptText); } } base.Invoke(new MethodInvoker(delegate { this.listViewRRS.SelectedIndices.Clear(); currentlistview.Selected = true; })); this.cmd.closeApp("all"); Thread.Sleep(3000); this.saverrsthread(currentlistview); base.Invoke(new MethodInvoker(delegate { currentlistview.BackColor = Color.Lime; currentlistview.Checked = false; this.listViewRRS.Refresh(); this.savecheckedssh(); })); }
public void autoRRS() { try { bool useSSHServer = false; bool randomRRS = false; resetStyleListViewRRS(); base.Invoke(new MethodInvoker(delegate { this.tempproxytool = this.proxytool.Text; this.tempproxycountry = this.comboProxyGeo.Text; useSSHServer = this.cbRRSUsingSSHServer.Checked; randomRRS = this.cbRandomRRS.Checked; })); Random rnd = new Random(); IOrderedEnumerable <BackupObj> orderedEnumerable = from item in this.listbackup orderby rnd.Next() select item; IEnumerator <BackupObj> enumerator = null; if (randomRRS) { enumerator = orderedEnumerable.GetEnumerator(); } else { enumerator = this.listbackup.GetEnumerator(); } START_RRS: while (enumerator.MoveNext()) { try { BackupObj item = enumerator.Current; ListViewItem currentlistview = getRRSListViewItemFromBackupObj(item); bool ckenable = false; base.Invoke(new MethodInvoker(delegate { ckenable = currentlistview.Checked; })); if (ckenable && currentlistview != null) { base.Invoke(new MethodInvoker(delegate { currentlistview.BackColor = Color.Yellow; this.listViewRRS.Refresh(); })); bool checkApp = false; do { checkApp = true; refreshAppListAndWait(); foreach (string bundleId in item.appList) { if (!isAppInstalled(bundleId)) { base.Invoke(new MethodInvoker(delegate { MessageBox.Show("App not installed: " + bundleId); })); Thread.Sleep(3000); checkApp = false; } } }while (!checkApp); if (item.country != "" & useSSHServer) //rrs use SSH Server { sshServer_ChangeCountry(item.country); } this.cmd.closeApp("all"); this.fakeIP(); this.wipeAppData(item.appList); Thread.Sleep(5000); this.restoreRRSData(item); Thread.Sleep(5000); this.openAppAndrunRRSS(item); } } catch (Exception ex) { this.LogMessage(ex.ToString(), Color.Black); Thread.Sleep(5000); continue; } } if (this.cbRRSLoop.Checked) { enumerator.Reset(); base.Invoke(new MethodInvoker(delegate { foreach (ListViewItem listviewItem in this.listViewRRS.Items) { listviewItem.Checked = true; listviewItem.BackColor = Color.Empty; } })); goto START_RRS; } } catch (ThreadAbortException ex) { } catch (Exception ex) { //AutoClosingMessageBox.Show(ex.ToString(), "", 3000); base.Invoke(new MethodInvoker(delegate { disconnect(); return; })); } FINISH_LABEL: this.lblStatusMsg.Invoke(new MethodInvoker(delegate { this.lblStatusMsg.Text = "RRS done."; this.btnStartRRS.Text = "START"; this.btnStartRRS.Refresh(); this.enableRRSGui(); this.enableAll(); this.btnStartLead.Enabled = true; this.proxytool.Text = this.tempproxytool; this.comboProxyGeo.Text = this.tempproxycountry; if (this.cbRRSThenLead.Checked) { this.btnStart_Click(null, null); } })); }
private void onGetListBackUpResult(string rawBackupResult) { this.listViewRRS.Items.Clear(); this.listbackup.Clear(); this.Contact.SelectedTab = this.Contact.TabPages[2]; this._sshssh = true; string path = AppDomain.CurrentDomain.BaseDirectory + this.DeviceInfo.SerialNumber + "\\checkssh.dat"; List <string> checkSSHLines = new List <string>(); if (File.Exists(path)) { checkSSHLines = File.ReadAllLines(path).ToList <string>(); } string[] arrayRRS = rawBackupResult.Split(new string[] { "|" }, StringSplitOptions.None); foreach (string singleRRS in arrayRRS) { string[] componentRRS = singleRRS.Split(new string[] { "=" }, StringSplitOptions.None); if (componentRRS.Count <string>() > 1) { BackupObj bkup = new BackupObj(); bkup.filename = componentRRS[0]; string[] nameComponent = componentRRS[0].Split(new string[] { "_" }, StringSplitOptions.None); bkup.timecreate = new DateTime( Convert.ToInt32(nameComponent[0]), //year Convert.ToInt32(nameComponent[1]), //month Convert.ToInt32(nameComponent[2]), //day Convert.ToInt32(nameComponent[3]), //hour Convert.ToInt32(nameComponent[4]), //minute Convert.ToInt32(nameComponent[5])); //second string[] appsComponent = componentRRS[1].Split(new string[] { ";" }, StringSplitOptions.None); List <string> applistRRS = new List <string>(); foreach (string appBundleId in appsComponent) { if (appBundleId != "") { applistRRS.Add(appBundleId); } } bkup.appList = applistRRS; bkup.comment = ""; if (componentRRS.Count <string>() > 4) { string[] commentComponent = componentRRS[2].Split(new string[] { "[]" }, StringSplitOptions.None); bkup.country = ""; try { bkup.comment = commentComponent[0]; bkup.country = commentComponent[1]; } catch (Exception) { } if (componentRRS[3] == "") { bkup.timemod = bkup.timecreate; } else { try { bkup.timemod = DateTime.Parse( componentRRS[3].Replace("CH", "PM").Replace("SA", "AM"), new CultureInfo("en-US", false) ); } catch (Exception e) { base.Invoke(new MethodInvoker(delegate { MessageBox.Show("Error on RRS file: " + bkup.filename + " please delete this RRS file and try again", "Get RRS error", MessageBoxButtons.OK, MessageBoxIcon.Error); })); return; } } if (componentRRS[4] == "") { bkup.runtime = 0; } else { bkup.runtime = Convert.ToInt32(componentRRS[4]); } } ListViewItem listViewItem = new ListViewItem(new string[] { "", bkup.timecreate.ToString("MM/dd/yyyy HH:mm:ss"), bkup.timemod.ToString("MM/dd/yyyy HH:mm:ss"), bkup.runtime.ToString(), componentRRS[1], bkup.comment, bkup.country, bkup.filename }); if (checkSSHLines.FirstOrDefault((string x) => x == bkup.filename) != null) { listViewItem.Checked = true; } this.listViewRRS.Items.Add(listViewItem); this.listbackup.Add(bkup); this.labelTotalRRS.Text = "Total RRS:" + (Convert.ToInt32(this.labelTotalRRS.Text.Replace("Total RRS:", "")) + 1).ToString(); } } this.listViewRRS.Refresh(); this._sshssh = false; }