private void GetUserAdmin() { menuStrip1.Invoke(new Action(() => menuStrip1.Enabled = false)); buttonSignIn.Invoke(new Action(() => buttonSignIn.Enabled = false)); textBoxLogin.Invoke(new Action(() => textBoxLogin.Enabled = false)); textBoxPassword.Invoke(new Action(() => textBoxPassword.Enabled = false)); IEnumerable <DALServerDB.Infrastructure.User> user1 = repUs.FindAll(p => p.Login == textBoxLogin.Text && p.IsAdmin == true); if (user1 != null) { User = user1.FirstOrDefault(x => DALServerDB.Models.Crypter.GetCrypt(x.Password) == textBoxPassword.Text); } if (User == null) { MessageBox.Show(Environment.NewLine + "user not found!!!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); menuStrip1.Invoke(new Action(() => menuStrip1.Enabled = true)); buttonSignIn.Invoke(new Action(() => buttonSignIn.Enabled = true)); textBoxLogin.Invoke(new Action(() => textBoxLogin.Enabled = true)); textBoxPassword.Invoke(new Action(() => textBoxPassword.Enabled = true)); return; } if (User.IsAdmin) { this.Invoke(new Action(() => { FormMain form = new FormMain(User, Connection); form.Owner = this; this.Hide(); form.ShowDialog(); })); } }
/// <summary> /// Set button enabled or disabled from within a thread /// </summary> /// <param name="button">Button</param> /// <param name="enabled">Enabled or not</param> public static void setButtonEnabledFromThread(Button button, bool enabled) { button.Invoke((MethodInvoker)delegate { button.Enabled = enabled; }); }
/// <summary> /// 锁定控件 /// </summary> private void LockControl(bool lockControl) { butDecompressuin.Invoke(new Action(() => { butDecompressuin.Enabled = !lockControl; })); }
public static void ToggleButtonState(System.Windows.Forms.Button ButtonControl, bool ControlEnabled, string ButtonText, bool ButtonFontBold) { FontStyle newfontstyle; if (ButtonControl.InvokeRequired) { ToggleButtonStateCallback d = ToggleButtonState; ButtonControl.Invoke(d, new object[] { ButtonControl, ControlEnabled, ButtonText, ButtonFontBold }); } else { if (ButtonFontBold) { newfontstyle = FontStyle.Bold; } else { newfontstyle = FontStyle.Regular; } System.Drawing.Font newfont = new System.Drawing.Font(ButtonControl.Font, newfontstyle); ButtonControl.Font = newfont; ButtonControl.Text = ButtonText; SetButtonEnabledStatus(ButtonControl, ControlEnabled); } }
/// <summary> /// Set button text from within a thread /// </summary> /// <param name="button">Button</param> /// <param name="text">Button text</param> public static void setButtonTextFromThread(Button button, string text) { button.Invoke((MethodInvoker)delegate { button.Text = text; }); }
public void BwExportWorker_WorkCompleted(object sender, RunWorkerCompletedEventArgs e) { listViewTransactionsList.Invoke(new MethodInvoker(delegate { listViewTransactionsList.Visible = true; })); progressBarExport.Invoke(new MethodInvoker(delegate { progressBarExport.Value = 0; } )); Activate(); if (e.Result != null) { if (e.Result.Equals("success")) { btnExport.Invoke(new MethodInvoker(delegate { btnExport.Enabled = true; })); bool hasAdditionalTable = _idTable != null; btnSelectAll.Invoke(new MethodInvoker(delegate { btnSelectAll.Enabled = !hasAdditionalTable; })); btnDeselectAll.Invoke(new MethodInvoker(delegate { btnDeselectAll.Enabled = !hasAdditionalTable; })); if (hasAdditionalTable) { SelectAll(); } } } else { MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ExportBookingsForm, "NotFound.Text")); } }
/// <summary> /// CardRemovedEventHandler /// </summary> private void iCard_OnCardRemoved(object sender, string reader) { if (this.InvokeRequired) { btnConnect.Invoke(new EnableButtonDelegate(EnableButton), new object[] { btnConnect, false }); btnDisconnect.Invoke(new EnableButtonDelegate(EnableButton), new object[] { btnDisconnect, false }); btnTransmit.Invoke(new EnableButtonDelegate(EnableButton), new object[] { btnTransmit, false }); txtboxATR.Invoke(new SetTextBoxTextDelegate(SetText), new object[] { txtboxATR, string.Empty }); } else { btnConnect.Enabled = false; btnDisconnect.Enabled = false; btnTransmit.Enabled = false; txtboxATR.Text = string.Empty; } }
private void SetButtonEnable(System.Windows.Forms.Button button, bool enable) { if (button.InvokeRequired) { button.Invoke(new MethodInvoker(() => { SetButtonEnable(button, enable); })); } button.Enabled = enable; }
/// <summary> /// 锁定控件 /// </summary> private void LockControl(bool lockControl) { butCompress.Invoke(new Action(() => { butCompress.Enabled = !lockControl; butAnalyze.Enabled = !lockControl; cbFindCompressGroupQty.Enabled = !lockControl; cbCompressThreadQty.Enabled = !lockControl; })); }
public void SparTaskHookRemoveButton(object sender, EventArgs e, System.Windows.Forms.Button button) { if (button.InvokeRequired) { button.Invoke(new Action(() => this.SparTaskBar.Controls.Remove(button))); } else { this.SparTaskBar.Controls.Remove(button); } }
public static void SetLabelText(System.Windows.Forms.Button Label, dynamic Text) { if (Label.InvokeRequired) { Label.Invoke(new SetbuttonTextInvoker(SetLabelText), Label, Text); } else { Label.Text = Convert.ToString(Text); } }
public static void SetButtonEnabledStatus(System.Windows.Forms.Button ButtonControl, bool ControlEnabled) { if (ButtonControl.InvokeRequired) { SetButtonEnabledStatusCallback d = SetButtonEnabledStatus; ButtonControl.Invoke(d, new object[] { ButtonControl, ControlEnabled }); } else { ButtonControl.Enabled = ControlEnabled; } }
public static void EnableDisableButton(Button button, bool enabled) { if (button.InvokeRequired) { EnableDisableButtonDelegate button2 = new EnableDisableButtonDelegate(EnableDisableButton); button.Invoke(button2, new object[] { button, enabled }); } else { button.Enabled = enabled; } }
public static void SetButtonForeColor(Button btn, Color color) { if (btn.InvokeRequired) { SetButtonForeColorCallback D = new SetButtonForeColorCallback(SetButtonForeColor); try { btn.Invoke(D, new object[] { btn, color }); } catch { } } else { btn.ForeColor = color; } }
public void setButtonEnabled(Button button, Boolean enabled, String text) { if (button.InvokeRequired) { try { button.Invoke(new SetButtonEnabledDelegate(setButtonEnabled), new Object[] { button, enabled, text }); } catch { } } else { button.Enabled = enabled; button.Text = text; } }
public static void SetText(Button button, string text) { MethodInvoker miSetText = delegate { button.Text = text; }; if (button.InvokeRequired) { button.Invoke(miSetText); } else { miSetText(); } }
/// <summary>Callback method - copy a buffer of recorded audio data</summary> /// <param name="data">Pointer to the raw data</param> /// <param name="size">Size of the data</param> private void WaveDataArrived(IntPtr data, int size) { byte[] recBuffer = new byte[size]; System.Runtime.InteropServices.Marshal.Copy(data, recBuffer, 0, size); recordedData.Write(recBuffer, 0, recBuffer.Length); countSamplesRecorded += size / BytesPerSample; MethodInvoker invoker = new MethodInvoker(SetSamplesRecordedLabelText); lblSamplesRecorded.Invoke(invoker); if (countSamplesRecorded >= countSamplesRequired) { //enough samples arrived - allow the user to stop recording invoker = new MethodInvoker(SetStopButtonEnabled); btnStartStop.Invoke(invoker); } }
public void SetButtonEnabled(Button btn, bool enable) { if (!this.Disposing) { if (btn.InvokeRequired) { SetButtonEnabledMethod call = delegate(Button btnd, bool enabled) { btnd.Enabled = enabled; }; btn.Invoke(call, new object[] { btn, enable }); } else { btn.Enabled = enable; } } }
private void DownloadFile(System.Windows.Forms.Button button, string fileName) { try { var parameters = new Dictionary <string, string>(); parameters.Add("groupBy", GroupBy.ToString()); parameters.Add("fileType", ((button == btnExportExcel) ? "xls" : "csv")); var byteArray = Helper.DownloadAsync($"{ WEBAPI_URL }/operations/export", parameters); File.WriteAllBytes(fileName, byteArray); MessageBox.Show("Download realizado com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } finally { button.Invoke(new System.Action(() => button.Text = $"Download {((button == btnExportExcel) ? "Excel" : "CSV")}")); btnExportExcel.Invoke(new System.Action(() => btnExportExcel.Enabled = true)); btnExportCSV.Invoke(new System.Action(() => btnExportCSV.Enabled = true)); } }
void SetUpdateButtonState(bool active) { try { if (btnCheckForUpdate.InvokeRequired) { btnCheckForUpdate.Invoke( new MethodInvoker(() => { btnCheckForUpdate.Enabled = active; })); } else { btnCheckForUpdate.Enabled = active; } } catch (Exception ex) { Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, ex.Message, true); } }
private void setEnableButton(Button button, bool enabled) { if (button.InvokeRequired) { B2Delegate deleg = new B2Delegate(setEnableButton); button.Invoke(deleg, new object[] { button, enabled }); } else { button.Enabled = enabled; } }
/// <summary> /// Thread safe version to enable or disable a button. /// </summary> /// <param name="button">The <see cref="Button"/> control to be enabled or disabled.</param> /// <param name="enable">True, if the button should be enabled, otherwise false.</param> public static void EnableDisableButton(Button button, bool enable) { if (button.InvokeRequired) { button.Invoke(new EnableDisableButtonInvoker(EnableDisableButton), button, enable); } button.Enabled = enable; }
private void setStringButton(Button button, string text) { if (button.InvokeRequired) { B1Delegate deleg = new B1Delegate(setStringButton); button.Invoke(deleg, new object[] { button, text }); } else { button.Text = text; } }
private void Disable(Button button) { if (button.InvokeRequired) button.Invoke(new DisableDelegate(Disable), button); else button.PerformClick(); }
public static void UpdateButton(Button button, string text) { // If the current thread is not the UI thread, InvokeRequired will be true if (button.InvokeRequired) { // If so, call Invoke, passing it a lambda expression which calls // UpdateText with the same label and text, but on the UI thread instead. button.Invoke((Action)(() => UpdateButton(button, text))); return; } // If we're running on the UI thread, we'll get here, and can safely update // the button's text. button.Text = text; }
protected void Run() { ushort rport = Convert.ToUInt16(port.Text); ushort lport = Convert.ToUInt16(textBoxlPort.Text); ushort ipfixrport = Convert.ToUInt16(numericTextBoxIpfixPort.Text); ushort ipfixlport = Convert.ToUInt16(numericTextBoxIpfixLocalPort.Text); ushort sflowLport = Convert.ToUInt16(numericTextBoxSflowlport.Text); ushort sflowRport = Convert.ToUInt16(numericTextSFlowrport.Text); int n = chklstFlowVersion.CheckedItems.Count; flowsimulator.FlowGenerator[] flows = new flowsimulator.FlowGenerator[n]; UDPSender server = null; UDPSender ipfixSender = null; UDPSender sflowSender = null; try { for (int i = 0; i < n; ++i) { uint systime = (uint)Environment.TickCount; FlowVersionList version = (FlowVersionList)chklstFlowVersion.CheckedIndices[i]; uint id = (uint)i; flows[i] = null; switch (version) { case FlowVersionList.V1: flows[i] = new netflow.V1Netflow(1, systime, id, 0); break; case FlowVersionList.V5: flows[i] = new netflow.V5Netflow(5, systime, id, 0); break; case FlowVersionList.V7: flows[i] = new netflow.V7Netflow(7, systime, id, 0); break; case FlowVersionList.V8: flows[i] = new netflow.V8Netflow(8, systime, id, 0); ((netflow.V8Netflow)flows[i]).Aggregation = (netflow.V8Aggregation)v8aggregation; //(netflow.V8Aggregation)lstboxV8Aggregation.SelectedIndex + 1; break; case FlowVersionList.V9: flows[i] = new netflow.V9Netflow(9, systime, id, 0); ((netflow.V9Netflow)flows[i]).Templates = v9Templates; break; case FlowVersionList.IPFIX: flows[i] = new netflow.Ipfix(10, systime, id, 0); if (ipfixSender == null) { ipfixSender = new UDPSender(ipfixlport , ipfixrport , collectorIP.Text); } flows[i].UdpServer = ipfixSender; ((netflow.Ipfix)flows[i]).Templates = ipfixTemplates; break; case FlowVersionList.SFLOW: flows[i] = new flowsimulator.SFlow(systime, sFlowVersions); if (sflowSender == null) { sflowSender = new UDPSender(sflowLport, sflowRport, collectorIP.Text); } flows[i].UdpServer = sflowSender; break; } if (flows[i].UdpServer == null) { if (server == null) { server = new UDPSender(lport, rport, collectorIP.Text); } flows[i].UdpServer = server; } flows[i].Options = options; flows[i].StatusLine = textBoxStatus; } } catch (Exception e) { StartStopClickDelegate btnClick = new StartStopClickDelegate(btnStartStop_Click); MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (server != null) { server.close(); } if (ipfixSender != null) { ipfixSender.close(); } if (sflowSender != null) { sflowSender.close(); } if (btnStartStop.InvokeRequired) { btnStartStop.Invoke(btnClick, new object[] { this, null }); } else { btnStartStop_Click(this, null); } return; } // let the game begin! while (!stopSimulation) { for (int i = 0; i < n; ++i) { flows[i].sendPacket(); Thread.Sleep(1000 / packetsRate); } } if (server != null) { server.close(); } if (ipfixSender != null) { ipfixSender.close(); } if (sflowSender != null) { sflowSender.close(); } }
/// <summary> /// 路由器刷 /// </summary> private void StartShuaLYQ(List <string> list, int roundI, int keyI, int max, string account, string pwd, string ip) { int count = 1; // 等待“停止”信号,如果没有收到信号则执行 roundI = roundI * 1000; keyI = keyI * 1000; if (list.Count > 0 && max > 0) { for (int q = 1; q <= max; q++) { if (canStop) { break; } foreach (var item in list) { // 等待“停止”信号,如果没有收到信号则执行 if (canStop) { break; } string url = strUrl + "wd=" + System.Web.HttpUtility.HtmlEncode(item); System.Object nullObject = 0; string strTemp = String.Empty; System.Object nullObjStr = strTemp; axWebBrowser1.Invoke(new Action(() => axWebBrowser1.Navigate(url, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr))); this.dataGridView1.Rows.Add(count, item, "成功", q, "路由换IP"); Utils.WriteLog("第" + q + "次,关键字:" + item + ",正在使用路由换IP访问"); count++; Thread.Sleep(keyI); } string result = Utils.Disconnect(ip, account, pwd); if (!result.Contains("success")) { MessageBox.Show(result); canStop = true; button2.Invoke(new EventHandler(delegate { button2.Text = "开始刷"; })); toolStripStatusLabel1.Text = ""; button1.Invoke(new EventHandler(delegate { button1.Enabled = true; })); button3.Invoke(new EventHandler(delegate { button3.Enabled = true; })); return; } Thread.Sleep(roundI); } button2.Invoke(new EventHandler(delegate { button2.Text = "开始刷"; })); toolStripStatusLabel1.Text = ""; button1.Invoke(new EventHandler(delegate { button1.Enabled = true; })); button3.Invoke(new EventHandler(delegate { button3.Enabled = true; })); } else { MessageBox.Show("请输入词条并设置最大次数!"); canStop = true; button2.Text = "开始刷"; toolStripStatusLabel1.Text = ""; button1.Invoke(new EventHandler(delegate { button1.Enabled = true; })); button3.Invoke(new EventHandler(delegate { button3.Enabled = true; })); } // 此时已经收到停止信号,可以在此释放资源并 // 初始化变量 canStop = false; }
private void ChangeButton(Button button,string text) { if (button.InvokeRequired) { ChangeButtonDelegate del = new ChangeButtonDelegate(ChangeButton); button.Invoke(del, button,text); } else { button.Text = text; } }
private void EnableButton(Button b, bool f) { if (b.InvokeRequired) b.Invoke(new Action(() => b.Enabled = f)); else b.Enabled = f; }
// Populate mods panels public void PopulateMods() { List<string> modTypes = new List<string>() { "cars", "tracks", "skins", "misc" }; foreach (string type in modTypes) { List<Mod> modList = new List<Mod>(); int mods = 0; if (type == "cars") { modList = modCarList; } else if (type == "tracks") { modList = modTrackList; } else if (type == "skins") { modList = modSkinList; } else if (type == "misc") { modList = modMiscList; } foreach (Mod mod in modList) { Panel modPanel = new Panel(); modPanel.Size = new Size(860, 61); modPanel.Location = new Point(0, 1 + (modPanel.Height - 1) * mods); modPanel.BorderStyle = BorderStyle.FixedSingle; if (type == "cars") { carsTabPage.Invoke((MethodInvoker)delegate { carsTabPage.Controls.Add(modPanel); }); modPanel.MouseHover += delegate { carsTabPage.Focus(); }; } else if (type == "tracks") { tracksTabPage.Invoke((MethodInvoker)delegate { tracksTabPage.Controls.Add(modPanel); }); modPanel.MouseHover += delegate { tracksTabPage.Focus(); }; } else if (type == "skins") { skinsTabPage.Invoke((MethodInvoker)delegate { skinsTabPage.Controls.Add(modPanel); }); modPanel.MouseHover += delegate { skinsTabPage.Focus(); }; } else if (type == "misc") { skinsTabPage.Invoke((MethodInvoker)delegate { miscTabPage.Controls.Add(modPanel); }); modPanel.MouseHover += delegate { miscTabPage.Focus(); }; } Label modNameLabel = new Label(); modNameLabel.Text = mod.name.ToUpper(); modNameLabel.ForeColor = Color.Black; modNameLabel.Location = new Point(0, 0); modNameLabel.Padding = new Padding(4, 10, 0, 0); modNameLabel.AutoSize = true; modNameLabel.Dock = DockStyle.Left; modNameLabel.Font = new Font("Arimo", 12, FontStyle.Bold); modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modNameLabel); }); Label modVersionLabel = new Label(); modVersionLabel.Text = mod.version; modVersionLabel.ForeColor = Color.FromArgb(64, 64, 64); modVersionLabel.Location = new Point(modNameLabel.Width, 0); modVersionLabel.Padding = new Padding(4, 10, 0, 0); modVersionLabel.AutoSize = true; modVersionLabel.Font = new Font("Arimo", 12, FontStyle.Regular); modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modVersionLabel); }); Label modAuthorLabel = new Label(); modAuthorLabel.Text = mod.author; modAuthorLabel.ForeColor = Color.FromArgb(64, 64, 64); modAuthorLabel.Location = new Point(5, modPanel.Height - 20); modAuthorLabel.AutoSize = true; modAuthorLabel.Font = new Font("DejaVu Sans Condensed", 8, FontStyle.Regular); modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modAuthorLabel); }); Label modDateLabel = new Label(); modDateLabel.Text = mod.date; modDateLabel.ForeColor = Color.FromArgb(64, 64, 64); modDateLabel.Location = new Point(20 + modAuthorLabel.Width, modPanel.Height - 20); modDateLabel.AutoSize = true; modDateLabel.Font = new Font("DejaVu Sans Condensed", 8, FontStyle.Regular); modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modDateLabel); }); Button modDownloadButton = new Button(); modDownloadButton.Size = new Size(100, 61); modDownloadButton.ForeColor = Color.Black; modDownloadButton.BackColor = Color.WhiteSmoke; modDownloadButton.UseVisualStyleBackColor = true; modDownloadButton.FlatStyle = FlatStyle.Flat; //modDownloadButton.Dock = DockStyle.Right; modDownloadButton.Location = new Point(759, -1); modDownloadButton.Text = mod.size + " MB"; modDownloadButton.Font = new Font("DejaVu Sans Condensed", 10, FontStyle.Regular); modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modDownloadButton); }); ProgressBar modProgressBar = new ProgressBar(); modProgressBar.Size = new Size(modDownloadButton.Width - 12, 8); modProgressBar.Location = new Point(6, modDownloadButton.Height - modProgressBar.Height - 6); modProgressBar.Visible = false; modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.Controls.Add(modProgressBar); }); if (!File.Exists(Application.StartupPath + "\\Packages\\" + mod.fileName)) { modDownloadButton.Click += delegate { Task.Run(() => DownloadFile(true, modDownloadButton, modProgressBar, mod, type)); }; } else if (type == "cars" || type == "tracks") { if (ModIsInstalled(mod)) { modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.Text = "Uninstall"; }); //modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.UseVisualStyleBackColor = false; }); modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.BackColor = Color.Salmon; }); modDownloadButton.Click += delegate { Task.Run(() => UninstallMod(modDownloadButton, modProgressBar, mod, type)); }; } else { modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.Text = "Install"; }); //modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.UseVisualStyleBackColor = false; }); modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.BackColor = Color.LightGreen; }); modDownloadButton.Click += delegate { modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.Text = "Queued"; }); modProgressBar.Invoke((MethodInvoker)delegate { modProgressBar.Visible = true; }); Task.Run(() => Extract(modDownloadButton, modProgressBar, mod, type)); }; } } else { modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.Text = "Open"; }); modDownloadButton.Invoke((MethodInvoker)delegate { modDownloadButton.UseVisualStyleBackColor = false; }); modDownloadButton.Click += delegate { Process.Start(Application.StartupPath + "\\Packages\\" + mod.fileName); }; } mods++; } } }
private void setButtonEnable(Button button, bool enable) { if (button.InvokeRequired) button.Invoke(new Action(() => button.Enabled = enable)); else button.Enabled = enable; }
void DownloadFile(bool newFile, Button button, ProgressBar progressBar, Mod mod, string type) { QMod qmod = new QMod(); qmod.button = button; qmod.progressBar = progressBar; qmod.mod = mod; qmod.type = type; button.Invoke((MethodInvoker)delegate { button.Text = "Queued"; }); progressBar.Invoke((MethodInvoker)delegate { progressBar.Visible = true; }); if (newFile) downloadQueue.Add(qmod); if (downloadQueue.Count > 0 && !dwc.IsBusy) { lock (this) { downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.Enabled = false; }); float sizef = float.Parse(downloadQueue[0].mod.size.Replace("<", ""), CultureInfo.InvariantCulture.NumberFormat); downloadQueue[0].progressBar.Invoke((MethodInvoker)delegate { downloadQueue[0].progressBar.Visible = true; }); try { using (dwc = new WebClient()) { Uri url = new Uri(downloadQueue[0].mod.downloadLink); dwc.DownloadProgressChanged += (s, e) => { downloadQueue[0].progressBar.Invoke((MethodInvoker)delegate { downloadQueue[0].progressBar.Value = e.ProgressPercentage; }); downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.Text = string.Format("{0:0.0}", sizef - sizef * e.ProgressPercentage / 100, 1).ToString().Replace(',', '.') + " MB"; }); }; Stream myStream = dwc.OpenRead(downloadQueue[0].mod.downloadLink); string header_contentDisposition = dwc.ResponseHeaders["content-disposition"]; string fileName = new ContentDisposition(header_contentDisposition).FileName; dwc.DownloadFileCompleted += (s, e) => { downloadQueue[0].progressBar.Invoke((MethodInvoker)delegate { downloadQueue[0].progressBar.Visible = false; }); downloadQueue[0].progressBar.Invoke((MethodInvoker)delegate { downloadQueue[0].progressBar.Value = 0; }); if (e.Cancelled == true) { MessageBox.Show("Download has been cancelled."); downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.Enabled = true; }); } else if (type == "cars" || type == "tracks") { Task.Run(() => Extract(downloadQueue[0].button, downloadQueue[0].progressBar, downloadQueue[0].mod, downloadQueue[0].type)); } else { downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.Text = "Open"; }); downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.UseVisualStyleBackColor = false; }); downloadQueue[0].button.Invoke((MethodInvoker)delegate { downloadQueue[0].button.Enabled = true; }); Process.Start(Application.StartupPath + "\\Packages\\" + fileName); RemoveClickEvent(button); downloadQueue[0].button.Click += delegate { Process.Start(Application.StartupPath + "\\Packages\\" + fileName); }; } Thread.Sleep(100); downloadQueue.RemoveAt(0); if (downloadQueue.Count > 0) DownloadFile(false, downloadQueue[0].button, downloadQueue[0].progressBar, downloadQueue[0].mod, downloadQueue[0].type); }; Directory.CreateDirectory(Application.StartupPath + "\\Packages"); dwc.DownloadFileAsync(url, Application.StartupPath + "\\Packages\\" + fileName); myStream.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } }
private void UninstallMod(Button button, ProgressBar progressBar, Mod mod, string type) { lock(this) { progressBar.Invoke((MethodInvoker)delegate { progressBar.Visible = true; }); button.Invoke((MethodInvoker)delegate { button.Text = "Uninstalling..."; }); button.Invoke((MethodInvoker)delegate { button.Enabled = false; }); XDocument doc = XDocument.Load(modInstallInfoFileFullPath); XElement mods = doc.Element("installLog").Element("modsLog"); XElement files = doc.Element("installLog").Element("filesLog"); string modKey = ""; var nodes = doc.Root.Element("modsLog").Elements().ToList(); foreach (XElement xel in nodes) { if (xel.Value == mod.fileName) { modKey = xel.Attribute("modKey").Value; xel.Remove(); break; } } nodes = doc.Root.Element("filesLog").Elements().ToList(); int fileCount = 0; foreach (XElement xel in nodes) { if (xel.Attribute("modKey").Value == modKey) { fileCount++; } } int fileCurrent = 0; foreach (XElement xel in nodes) { if (xel.Attribute("modKey").Value == modKey) { if (File.Exists(xel.Value)) File.Delete(xel.Value); if (DirectoryIsEmpty(xel.Value)) Directory.Delete(xel.Value.Substring(0, xel.Value.LastIndexOf("\\"))); xel.Remove(); fileCurrent++; progressBar.Invoke((MethodInvoker)delegate { progressBar.Value = 100 * fileCurrent / fileCount; }); } } doc.Save(modInstallInfoFileFullPath); progressBar.Invoke((MethodInvoker)delegate { progressBar.Visible = false; }); progressBar.Invoke((MethodInvoker)delegate { progressBar.Value = 0; }); button.Invoke((MethodInvoker)delegate { button.Text = "Install"; }); button.Invoke((MethodInvoker)delegate { button.Enabled = true; }); RemoveClickEvent(button); button.Click += delegate { button.Invoke((MethodInvoker)delegate { button.Text = "Queued"; }); progressBar.Invoke((MethodInvoker)delegate { progressBar.Visible = true; }); Task.Run(() => Extract(button, progressBar, mod, type)); }; } }
private void updateButton(Button button, bool isVisible, bool enable) { if (button.InvokeRequired) { button.Invoke(new MethodInvoker(() => updateButton(button, isVisible, enable))); return; } button.Visible = isVisible; button.Enabled = enable; }
public void ipCapt(BackgroundWorker bc, CheckBox ck, string ip,Button But) { try { transfer PacketData = new transfer(); Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); IPEndPoint ipend = new IPEndPoint(IPAddress.Parse(ip), 0); sock.Bind(ipend); sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true); byte[] syorcval = new byte[4] { 1, 0, 0, 0 }; byte[] dataLength = new byte[4] { 1, 1, 1, 1 }; sock.IOControl(IOControlCode.ReceiveAll, syorcval, dataLength); byte[] data = new byte[65000]; sock.Receive(data); MemoryStream buffer = new MemoryStream(data); BinaryReader read = new BinaryReader(buffer); byte c = 0; byte s = read.ReadByte(); c = s; c <<= 4; c >>= 4; s >>= 4; PacketData.version = s.ToString(); PacketData.headerLength = c.ToString(); byte DcspEscn = read.ReadByte(); PacketData.DSCP = ((DcspEscn >> 2) << 2).ToString(); PacketData.ESCN = (DcspEscn << 6).ToString(); ushort length = (ushort)IPAddress.NetworkToHostOrder(read.ReadInt16()); PacketData.totalLength = length.ToString(); PacketData.Identification = ((ushort)IPAddress.NetworkToHostOrder(read.ReadInt16())).ToString(); ushort flag = (ushort)IPAddress.NetworkToHostOrder(read.ReadInt16()); int df = flag >> 13; //int mf = flagoff & (1 << 2) ; if (df == 2) PacketData.fragmentation = "NO"; else if (df == 8) PacketData.fragmentation = "YES"; else PacketData.fragmentation = "0-Reserved"; int off = flag << 3; off >>= 3; PacketData.offset = off.ToString(); PacketData.TTL = read.ReadByte().ToString(); string prot = read.ReadByte().ToString(); if (prot == "6") PacketData.protocol = "TCP"; else if (prot == "17") PacketData.protocol = "UDP"; else PacketData.protocol = "other"; int checksumIp = IPAddress.NetworkToHostOrder(read.ReadInt16()); string checksumIps = BitConverter.ToString(BitConverter.GetBytes(checksumIp)); checksumIps = checksumIps.Replace("-", ""); PacketData.checksum = checksumIps; IPAddress a = new IPAddress((uint)read.ReadInt32()); IPAddress d = new IPAddress((uint)read.ReadInt32()); if (ck.Checked) { try { PacketData.SourceDns = Dns.GetHostEntry(a.ToString()).HostName; } catch { PacketData.SourceDns = a.ToString(); } try { PacketData.DestDns = Dns.GetHostEntry(d.ToString()).HostName; } catch { PacketData.DestDns = d.ToString(); } } PacketData.source = a.ToString(); PacketData.destination = d.ToString(); PacketData.srcPort = (((ushort)IPAddress.NetworkToHostOrder(read.ReadInt16())).ToString()); PacketData.destPort = (((ushort)IPAddress.NetworkToHostOrder(read.ReadInt16())).ToString()); if (PacketData.protocol == "TCP") { PacketData.seqNumber = (((uint)IPAddress.NetworkToHostOrder(read.ReadInt32())).ToString()); PacketData.ackNumber = (((uint)IPAddress.NetworkToHostOrder(read.ReadInt32())).ToString()); //ushort offflag = (ushort)IPAddress.NetworkToHostOrder(read.ReadInt16()); byte offtcp = read.ReadByte(); PacketData.tcpOffData = (offtcp >> 4).ToString(); byte flagtcp = read.ReadByte(); PacketData.ns = ((offtcp & (1 << 7)) != 0).ToString(); PacketData.cwr = ((flagtcp & (1 << 0)) != 0).ToString(); PacketData.ece = ((flagtcp & (1 << 1)) != 0).ToString(); PacketData.urg = ((flagtcp & (1 << 2)) != 0).ToString(); PacketData.ack = ((flagtcp & (1 << 3)) != 0).ToString(); PacketData.psh = ((flagtcp & (1 << 4)) != 0).ToString(); PacketData.rst = ((flagtcp & (1 << 5)) != 0).ToString(); PacketData.syn = ((flagtcp & (1 << 6)) != 0).ToString(); PacketData.fin = ((flagtcp & (1 << 7)) != 0).ToString(); PacketData.WindowSize = ((ushort)IPAddress.NetworkToHostOrder(read.ReadInt16())).ToString(); int checksumTcp = IPAddress.NetworkToHostOrder(read.ReadInt16()); string checksumTcpString = BitConverter.ToString(BitConverter.GetBytes(checksumTcp)); checksumTcpString = checksumTcpString.Replace("-", ""); PacketData.TcpChecksum = checksumTcpString; if (PacketData.urg == "true") PacketData.urg = ((uint)IPAddress.NetworkToHostOrder(read.ReadInt32())).ToString(); read.ReadBytes(2); } else if (PacketData.protocol == "UDP") { PacketData.udpLength = ((ushort)IPAddress.NetworkToHostOrder(read.ReadInt16())).ToString(); int checksumUdp = IPAddress.NetworkToHostOrder(read.ReadInt16()); string checksumUdps = BitConverter.ToString(BitConverter.GetBytes(checksumUdp)); checksumUdps = checksumUdps.Replace("-", ""); PacketData.udpChecksum = checksumUdps; } byte[] datas = new byte[10024]; if (PacketData.protocol == "UDP") { datas = read.ReadBytes(length - 28); datas.Reverse(); } else if (PacketData.protocol == "TCP") { datas = read.ReadBytes(length - 40); datas.Reverse(); } PacketData.data = Encoding.ASCII.GetString(datas); bc.ReportProgress(0, PacketData); Thread.Sleep(60); } catch { MessageBox.Show("Error \r\nTry another interface"); bc.CancelAsync(); But.Invoke((MethodInvoker)(() => But.Text ="Start")); return; } }
private void MainForm_Load(object sender, EventArgs e) { var controlConfig = Entrance.Parameter.GetControlConfigFunc?.Invoke(); if (controlConfig == null || controlConfig.Length == 0) return; currentToolStripItemCollection = cmsMain.Items; foreach (var keyValuePair in controlConfig) { var key = keyValuePair.Key; var value = keyValuePair.Value; if (value == null) { handleGroup(key); } else { Control control = null; if (value is string) { control = new Label() { Text = (string)value }; } else if (value is Action) { var action = (Action)value; var btn = new Button() { Text = key }; btn.Click += (sender2, e2) => { disableForm(); action(); enableForm(); }; control = btn; addNotifyIconButton(btn); } else if (value is Button) { Button sourceButton = (Button)value; var btn = new Button() { Text = key }; btn.Click += (sender2, e2) => { disableForm(); sourceButton.PerformClick(); enableForm(); }; sourceButton.EnabledChanged += (sender2, e2) => { if (btn.InvokeRequired) btn.Invoke(new Action(() => btn.Enabled = sourceButton.Enabled)); else btn.Enabled = sourceButton.Enabled; }; btn.Enabled = sourceButton.Enabled; control = btn; addNotifyIconButton(btn); } else if (value is Control) { flpTools.Controls.Add(new Label() { Text = key, Width = 56 }); control = (Control)value; } flpTools.Controls.Add(control); } } this.CenterToScreen(); }
private static void safeSetText(Button b, string s) { if (b.InvokeRequired) { b.Invoke(new Action(() => b.Text = s)); } else { b.Text = s; } }
private void SetLabel(Button control) { if (control.InvokeRequired) { setLabelDelegate del = new setLabelDelegate(SetLabel); control.Invoke(del, control); } else { SetLabel lbl = new SetLabel(control.Text); lbl.ShowDialog(); if (lbl.DialogResult == DialogResult.OK) { control.Text = lbl.Label; } //control.Text = } }
public void setButton(Button myButton, bool enable) { if (myButton.InvokeRequired) myButton.Invoke(new delButtonInvoker(setButton), myButton, enable); else myButton.Enabled = enable; }
private void enablebutton(Button button) { if (button.InvokeRequired) { button.Invoke((Action)(() => enablebutton(button))); return; } button.Enabled = true; }