Beispiel #1
0
        private static void UpdateProgress()
        {
            ProgressBar.Invoke(new InvokeDelegate(SetProgressBarValue), (int)((double)Status.CurrentProgress * 10000 / Status.TotalProgress));

            if (Status.TotalProgress > 0)
            {
                ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), string.Format("{0}/{1}", Status.CurrentProgress, Status.TotalProgress));
                PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), string.Format("{0:0.##}%", (double)Status.CurrentProgress * 100 / Status.TotalProgress));

                TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "已用时间:" + TimeSpan.FromMilliseconds(Timer.ElapsedMilliseconds).ToString(@"hh\:mm\:ss\.fff"));

                var time = (double)Timer.ElapsedMilliseconds * (Status.TotalProgress - Status.CurrentProgress) / Status.CurrentProgress;
                if (time.HasValue())
                {
                    TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "估计剩余时间:" + TimeSpan.FromMilliseconds(time).ToString(@"hh\:mm\:ss\.fff"));
                }
                else
                {
                    TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始");
                }
            }
            else
            {
                StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), Status.CurrentStatus);
                ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), "等待开始");
                PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), "等待开始");
                TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "等待开始");
                TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始");
            }
        }
Beispiel #2
0
 public void StartUpload(UploadContract contract)
 {
     StatusLabel.Invoke(new Action(() => StatusLabel.Text = "Uploading: " + contract.Filename));
     Uploading  = true;
     FileUpload = contract;
     UploadTimer.Start();
 }
Beispiel #3
0
        private void SetPasswordButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(PasswordField.Text) &&
                !string.IsNullOrWhiteSpace(ConfirmPasswordField.Text) &&
                PasswordField.Text == ConfirmPasswordField.Text)
            {
                string strText = PasswordField.Text;
                string key     = "*****@*****.**";
                string encText = Tools.EncryptText(strText, key);

                var         root = Registry.CurrentUser;
                RegistryKey reg  = root.OpenSubKey("Software", true).CreateSubKey("hSmNz");
                reg.Close();
                RegistryKey reg1 = root.OpenSubKey("Software").OpenSubKey("hSmNz", true);
                reg1.SetValue("SNG", encText);
                reg1.SetValue("IsSNG", true);
                reg1.Close();
                RemovePasswordButton.Enabled = true;
                StatusLabel.ForeColor        = Color.Green;
                StatusLabel.Text             = "Password has been set!";
                SetPasswordButton.Enabled    = false;
                PasswordField.Text           = "";
                ConfirmPasswordField.Text    = "";
                materialLabel5.Text          = "";
                PasswordField.Enabled        = false;
                ConfirmPasswordField.Enabled = false;
                Timer t1 = new Timer(3500);
                t1.Start();
                t1.Elapsed += (o, args) =>
                {
                    StatusLabel.Invoke(new Action(() => { StatusLabel.Text = ""; }));
                    t1.Stop();
                };
            }
        }
Beispiel #4
0
 private void OberflächeDeaktivieren(bool Aktivieren)
 {
     if (Aktivieren)
     {
         CSVPfadSuchenButton.Invoke(new Action <bool>(s => { CSVPfadSuchenButton.Enabled = s; }), true);
         TestEmailAdresseTextBox.Invoke(new Action <bool>(s => { TestEmailAdresseTextBox.Enabled = s; }), true);
         if (AdressePrüfen(TestEmailAdresseTextBox.Text))
         {
             TestButton.Invoke(new Action <bool>(s => { TestButton.Enabled = s; }), true);
         }
         StartenButton.Invoke(new Action <bool>(s => { StartenButton.Enabled = s; }), true);
         StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), "Status: 0/0 versendet ETA: 0m 0s");
         Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Minimum = s; }), 0);
         if (!ReferenceEquals(AlleMails, null))
         {
             Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Maximum = s; }), AlleMails.Length);
         }
         else
         {
             Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Maximum = s; }), 1);
         }
         Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Value = s; }), 0);
     }
     else
     {
         CSVPfadSuchenButton.Invoke(new Action <bool>(s => { CSVPfadSuchenButton.Enabled = s; }), false);
         TestEmailAdresseTextBox.Invoke(new Action <bool>(s => { TestEmailAdresseTextBox.Enabled = s; }), false);
         TestButton.Invoke(new Action <bool>(s => { TestButton.Enabled = s; }), false);
         StartenButton.Invoke(new Action <bool>(s => { StartenButton.Enabled = s; }), false);
     }
 }
Beispiel #5
0
        public void UpdateStatusLabel(string status)
        {
            if (StatusLabel.InvokeRequired)
            {
                StatusLabel.Invoke(new Action <string>(UpdateStatusLabel), status);
                return;
            }

            label1.Text = status;
        }
Beispiel #6
0
 private void Form1_Shown(object sender, EventArgs e)
 {
     new Thread(delegate()
     {
         OberflächeDeaktivieren(false);
         StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), "Status: Überprüfe auf Updates");
         Program.Update();
         OberflächeDeaktivieren(true);
     }).Start();
 }
Beispiel #7
0
 private bool WarteAnimation(int Pos, int MaxPos)
 {
     for (int i = 0; i < 30; i++)
     {
         StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), string.Format("Status: {0}/{1} Keine Verbindung. Versuche erneut" + (new StringBuilder(i + 1).Insert(0, ".", i + 1).ToString()), Pos, MaxPos));
         Thread.Sleep(1000);
     }
     GC.Collect();
     return(true);
 }
Beispiel #8
0
        /// <summary>
        /// Updates the status label with the text.
        /// </summary>
        /// <param name="newText"></param>
        private void UpdateStatusLabel(string newText)
        {
            if (StatusLabel.InvokeRequired)
            {
                //invoke so that we are on the right thread to update the status
                StatusLabel.Invoke(m_statusLabelUpdate, new Object[] { newText });
                return;
            }

            StatusLabel.Text = newText;
            Application.DoEvents();
        }
Beispiel #9
0
        public void Report(FtpProgress value)
        {
            if (value.Progress < 100 && stopwatch.IsRunning && stopwatch.ElapsedMilliseconds < 250)
            {
                // only update the progress every 250ms unless setting it to 100%
                return;
            }

            var statusText = $"Downloading {FileName}\r\n{value.Progress:F0}% complete\r\n{value.TransferSpeedToString()}";

            StatusLabel.Invoke(new Action(() => StatusLabel.Text = statusText));
            stopwatch.Restart();
        }
Beispiel #10
0
        public static void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), "等待开始");
            ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), "等待开始");
            PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), "等待开始");
            TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "等待开始");
            TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始");

            ProgressBar.Invoke(new InvokeDelegate(SetProgressBarValue), 0);
            //ProgressBar.Invoke(new InvokeDelegate(SetProgressBarMaximum), 100);

            //Console.WriteLine("Worker Reset");
            WorkerInBusy.Set();
        }
Beispiel #11
0
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        private void ChageStatusText(string Text)
        {
            if (StatusLabel.InvokeRequired)
            {
                StatusLabel.Invoke(new Action(() =>
                {
                    StatusLabel.Text = Text;
                }));
            }
            else
            {
                StatusLabel.Text = Text;
            }
        }
Beispiel #12
0
 /// <summary>
 /// keeps checking the connection is stable. if the connection is lost all screens will be closed.
 /// </summary>
 private void CheckCon()
 {
     if (control.CheckConnection() == false)
     {
         foreach (Form client in Clients)
         {
             client.Close();
             StatusLabel.Invoke(new Action(() => StatusLabel.Text = "Server unavailable!"));
             button1.Invoke(new Action(() => button1.Enabled      = false));
         }
     }
     else
     {
         StatusLabel.Invoke(new Action(() => StatusLabel.Text = ""));
         button1.Invoke(new Action(() => button1.Enabled      = true));
     }
 }
Beispiel #13
0
        public static void Start(StatusWrapper status)
        {
            //if (Worker != null)
            //{
            //    Console.WriteLine("Force Cancelling Worker");
            //    Worker.CancelAsync();
            //}
            //Console.WriteLine("Wait for Worker Reset");
            WorkerInBusy.WaitOne();
            //Console.WriteLine("Worker Reset!!!");

            Status = status;
            Timer.Restart();

            //ProgressBar.Invoke(new InvokeDelegate(SetProgressBarMaximum), status.TotalProgress);
            StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), status.CurrentStatus);
            //ProgressBar.Maximum = Status.TotalProgress;
            //StatusLabel.Text = Status.CurrentStatus;
            UpdateProgress();

            Worker.RunWorkerAsync();
        }
Beispiel #14
0
        private void RemovePasswordButton_Click(object sender, EventArgs e)
        {
            var         root = Registry.CurrentUser;
            RegistryKey reg1 = root.OpenSubKey("Software").OpenSubKey("hSmNz", true);

            reg1.DeleteValue("SNG");
            reg1.SetValue("IsSNG", false);
            reg1.Close();
            SetPasswordButton.Enabled    = true;
            RemovePasswordButton.Enabled = false;
            StatusLabel.ForeColor        = Color.Green;
            StatusLabel.Text             = "Password has been removed!";
            PasswordField.Enabled        = true;
            Timer t1 = new Timer(3500);

            t1.Start();
            t1.Elapsed += (o, args) =>
            {
                StatusLabel.Invoke(new Action(() => { StatusLabel.Text = ""; }));

                t1.Stop();
            };
        }
Beispiel #15
0
        /// <summary>
        /// First checks if server is available. after check if the username and password in the field marches anything in the database on the server.
        /// lastly a check to see if it's a captain or a technician.
        /// creates a  thread with either captain or technician screen-
        /// </summary>
        private void Login()
        {
            var ServerCheck = control.CheckConnection();

            Username = textBoxUsername.Text;
            Password = textBoxPassword.Text;
            if (ServerCheck.Equals(false))
            {
                StatusLabel.Invoke(new Action(() => StatusLabel.Text = "Server unavailable! try again later."));
            }
            else
            {
                Boolean LoginCheck = control.Login(Username, Password);
                if (LoginCheck == true)
                {
                    StatusLabel.Invoke(new Action(() => StatusLabel.Text = "Success!"));
                    Boolean CaptainCheck = control.CaptainCheck();
                    if (CaptainCheck == true)
                    {
                        ThreadStart starter = new ThreadStart(BootCaptainScreen);
                        Thread      thread  = new Thread(starter);
                        thread.Start();
                    }
                    else if (CaptainCheck == false)
                    {
                        ThreadStart starter = new ThreadStart(BootWorkerScreen);
                        Thread      thread  = new Thread(starter);
                        thread.Start();
                    }
                }
                else if (LoginCheck == false)
                {
                    StatusLabel.Invoke(new Action(() => StatusLabel.Text = "Username or Password is incorrect."));
                }
            }
        }
Beispiel #16
0
        private void BGWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BgWorkerInformation BgData = (BgWorkerInformation)e.Argument;

            string[] VarLines = BgData.VarText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);


            int           NumVars         = 0;
            List <string> VarPlaceholders = new List <string>();

            //get all of the split out info into a list
            List <Array> VarList = new List <Array>();

            for (int i = 0; i < VarLines.Length; i++)
            {
                string[] VarList_Split = (VarLines[i].Trim().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries));
                if (VarList_Split.Length > 1)
                {
                    NumVars++;
                    VarList.Add(VarList_Split.ToList().GetRange(1, VarList_Split.Length - 1).ToArray());
                    VarPlaceholders.Add(VarList_Split[0]);
                }
            }


            try {
                StatusLabel.Invoke((MethodInvoker) delegate
                {
                    StatusLabel.Text = "Recursing variable combinations... This might take a while...";
                });

                //Set up our code


                List <string> RecursedVars = Recursion(0, VarList).Distinct().ToList();


                using (StreamWriter outputFile = new StreamWriter(new FileStream(BgData.FileOutputLocation, FileMode.Create, FileAccess.Write), Encoding.UTF8))
                {
                    outputFile.WriteLine("Input Variable Data:");
                    outputFile.WriteLine(BgData.VarText + "\r\n\r\n");
                    outputFile.WriteLine("Input Code Data:");
                    outputFile.WriteLine(BgData.CodeText + "\r\n\r\n");
                    outputFile.WriteLine("Code Output:\r\n");

                    int LineCount = RecursedVars.Count;
                    LineCountString = LineCount.ToString();

                    for (int i = 0; i < LineCount; i++)
                    {
                        StringBuilder OutputCode = new StringBuilder();
                        OutputCode.Append(BgData.CodeText);

                        StatusLabel.Invoke((MethodInvoker) delegate {
                            StatusLabel.Text = "Writing line " + (i + 1).ToString() + " of " + LineCountString;
                            StatusLabel.Invalidate();
                            StatusLabel.Update();
                            StatusLabel.Refresh();
                            Application.DoEvents();
                        });

                        string[] Var_Replacements = RecursedVars[i].Split(' ');
                        for (int j = 0; j < NumVars; j++)
                        {
                            OutputCode.Replace(VarPlaceholders[j], Var_Replacements[j]);
                        }

                        outputFile.WriteLine(OutputCode.ToString());
                    }
                }


                e.Result = BgData.FileOutputLocation;
            }
            catch
            {
                MessageBox.Show("An error occurred while building your code.", "Ruh-roh!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Result = null;
            }
        }
Beispiel #17
0
 public static void Display(StatusWrapper status)
 {
     StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), status.CurrentStatus);
 }
Beispiel #18
0
        private void TestButton_Click(object sender, EventArgs e)
        {
            try
            {
                new Thread(delegate()
                {
                    OberflächeDeaktivieren(false);
                    var TestEmailAnzahl = 3;
                    var Fehler          = string.Empty;
                    if (AlleMails.Length < 3)
                    {
                        TestEmailAnzahl = AlleMails.Length;
                    }
                    if (!AlleMailsÜberprüfen())
                    {
                        MessageBox.Show("Es sind bei der Überprüfung der Daten Fehler vorgekommen. Diese wurden in folgende Datei geschrieben:\n\n" + ProgrammPfad + @"\EmailAdressenFehler.txt" + "\n\nBitte beheben Sie diese Fehler zuerst. Es wurden keine Emails versandt.");
                    }
                    else
                    {
                        Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Maximum = s; }), TestEmailAnzahl);
                        {
                            Parallel.For(0, TestEmailAnzahl, new ParallelOptions {
                                MaxDegreeOfParallelism = TestEmailAnzahl
                            }, i =>
                            {
                                AlleMails[i].TextBearbeiten(this);
                            });
                            for (int i = 0; i < TestEmailAnzahl; i++)
                            {
                                Fehler = AlleMails[i].EmailSenden(SMTPServerIP, TestEmailAdresseTextBox.Text, true);
                                while (!Fehler.Equals(string.Empty) && (i != TestEmailAnzahl))
                                {
                                    switch (Fehler)
                                    {
                                    case "1":
                                        WarteAnimation(i + 1, TestEmailAnzahl);
                                        break;

                                    default:
                                        MessageBox.Show("Fehler: " + Fehler);
                                        i = TestEmailAnzahl;
                                        break;
                                    }
                                    Fehler = AlleMails[i].EmailSenden(SMTPServerIP, TestEmailAdresseTextBox.Text, true);
                                }
                                if (i != TestEmailAnzahl)
                                {
                                    StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), string.Format("Status: {0}/{1} versendet", i + 1, TestEmailAnzahl));
                                    Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Value = s; }), i + 1);
                                }
                            }
                        }
                    }
                    OberflächeDeaktivieren(true);
                    GC.Collect();
                }).Start();
            }
            catch (Exception ex)
            {
                Program.MeldeFehler(ex.Message + "\n" + ex.StackTrace);
                Environment.Exit(1);
            }
        }
Beispiel #19
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            InitProxies();
            InitModes();

            // 更新时间和状态
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        Invoke(new MethodInvoker(() =>
                        {
                            Text = "v2tap - " + DateTime.Now.ToString();
                        }));

                        StatusLabel.Invoke(new MethodInvoker(() =>
                        {
                            StatusLabel.Text = "当前状态:" + Status;
                        }));

                        Thread.Sleep(100);
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            // 更新流量信息
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        if (isStarted)
                        {
                            var channel = new Grpc.Core.Channel("127.0.0.1:1020", Grpc.Core.ChannelCredentials.Insecure);
                            var client  = new v2ray.Core.App.Stats.Command.StatsService.StatsServiceClient(channel);
                            var uplink  = client.GetStats(new v2ray.Core.App.Stats.Command.GetStatsRequest {
                                Name = "inbound>>>defaultInbound>>>traffic>>>uplink", Reset = true
                            });
                            var downlink = client.GetStats(new v2ray.Core.App.Stats.Command.GetStatsRequest {
                                Name = "inbound>>>defaultInbound>>>traffic>>>downlink", Reset = true
                            });

                            UsedBandwidth += uplink.Stat.Value;
                            UsedBandwidth += downlink.Stat.Value;
                            StatusStrip.Invoke(new MethodInvoker(() =>
                            {
                                BandwidthLabel.Text = "总流量:" + Utils.Util.ProcessBandwidth(UsedBandwidth);
                                UplinkLabel.Text    = "↑:" + Utils.Util.ProcessBandwidth(uplink.Stat.Value) + "/s";
                                DownlinkLabel.Text  = "↓:" + Utils.Util.ProcessBandwidth(downlink.Stat.Value) + "/s";
                            }));
                        }
                        else
                        {
                            StatusStrip.Invoke(new MethodInvoker(() =>
                            {
                                BandwidthLabel.Text = "总流量:0 KB";
                                UplinkLabel.Text    = "↑:0 KB/s";
                                DownlinkLabel.Text  = "↓:0 KB/s";
                            }));
                        }

                        Thread.Sleep(1000);
                    }
                    catch (Exception)
                    {
                    }
                }
            });
        }
Beispiel #20
0
 private void StartenButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (!BereitsVersendet || (BereitsVersendet && (MessageBox.Show("Sie haben die Emails schon einmal versendet. Sind Sie sich sicher, dass Sie das noch einmal tun möchten?", "Bestätigung", MessageBoxButtons.YesNo) == DialogResult.Yes)))
         {
             new Thread(delegate()
             {
                 OberflächeDeaktivieren(false);
                 AlleZeiten = new List <long>();
                 if (!AlleMailsÜberprüfen())
                 {
                     MessageBox.Show("Es sind bei der Überprüfung der Daten Fehler vorgekommen. Diese wurden in die Datei:\n\n" + ProgrammPfad + @"\EmailAdressenFehler.txt" + "\n\ngeschrieben. Bitte beheben Sie diese Fehler zuerst. Es wurden keine Emails versandt.");
                 }
                 else
                 {
                     var GefundeneFehler = new List <string>();
                     var Parallelität    = 10;
                     if (AlleMails.Length < 10)
                     {
                         Parallelität = AlleMails.Length;
                     }
                     ;
                     Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Minimum = s; }), 0);
                     Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Maximum = s; }), AlleMails.Length);
                     int ProcessedEmailCount = 0;
                     for (int i = 0; i < AlleMails.Length; i++)
                     {
                         var CurWatch = new Stopwatch();
                         CurWatch.Start();
                         AlleMails[i].TextBearbeiten(this);
                         CurWatch.Stop();
                         StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), string.Format("Status: {0}/{1} vorbereitet {2}", ProcessedEmailCount, AlleMails.Length, ETABerechnen(CurWatch.ElapsedMilliseconds / Parallelität, AlleMails.Length - 1 - ProcessedEmailCount)));
                         Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Value = s; }), ProcessedEmailCount);
                         Interlocked.Increment(ref ProcessedEmailCount);
                         if (i % 50 == 0)
                         {
                             GC.Collect();
                         }
                     }
                     AlleZeiten       = new List <long>();
                     var Watch        = new Stopwatch();
                     var Rückgabewert = string.Empty;
                     for (int i = 0; i < AlleMails.Length; i++)
                     {
                         Watch.Restart();
                         Rückgabewert = AlleMails[i].EmailSenden(SMTPServerIP, string.Empty, false);
                         while (Rückgabewert == "1")
                         {
                             Rückgabewert = AlleMails[i].EmailSenden(SMTPServerIP, string.Empty, false);
                             WarteAnimation(i + 1, AlleMails.Length);
                             Watch.Reset();
                         }
                         if (!Rückgabewert.Equals(string.Empty))
                         {
                             GefundeneFehler.Add("Zeile: " + (i + 2).ToString() + ", Spalte: Empfänger, Wert: " + AlleMails[i].Empfänger + ", Ursache: " + Rückgabewert);
                         }
                         Watch.Stop();
                         StatusLabel.Invoke(new Action <string>(s => { StatusLabel.Text = s; }), string.Format("Status: {0}/{1} versendet {2}", i + 1, AlleMails.Length, ETABerechnen(Watch.ElapsedMilliseconds, AlleMails.Length - 1 - i)));
                         Ladebalken.Invoke(new Action <int>(s => { Ladebalken.Value = s; }), i + 1);
                         if (i % 30 == 0)
                         {
                             GC.Collect();
                         }
                     }
                     if (File.Exists(ProgrammPfad + @"\EmailAdressenFehler.txt"))
                     {
                         File.Delete(ProgrammPfad + @"\EmailAdressenFehler.txt");
                     }
                     if (GefundeneFehler.Count > 0)
                     {
                         File.WriteAllLines(ProgrammPfad + @"\EmailAdressenFehler.txt", GefundeneFehler);
                         MessageBox.Show("Es sind beim Versand der Emails Fehler vorgekommen. Diese wurden in folgende Datei geschrieben:\n\n" + ProgrammPfad + @"\EmailAdressenFehler.txt" + "\n\nAlle anderen Emails wurden erfolgreich verschickt.");
                     }
                     else
                     {
                         MessageBox.Show("Vorgang ohne Fehler abgeschlossen.");
                     }
                     BereitsVersendet = true;
                 }
                 OberflächeDeaktivieren(true);
                 GC.Collect();
             }).Start();
         }
     }
     catch (Exception ex)
     {
         Program.MeldeFehler(ex.Message + "\n" + ex.StackTrace);
         Environment.Exit(1);
     }
 }
Beispiel #21
0
        Dictionary <int, List <Quest> > Quests = new Dictionary <int, List <Quest> >();//int = Zone int[] = Quests

        private void GetAllQuests()
        {
            StatusLabel.Invoke((MethodInvoker) delegate()
            {
                StatusLabel.Text = "Fetching all quests";
            });
            PrintDebugMessage("Function: Fetching All quests");
            progressBar1.Invoke((MethodInvoker) delegate()
            {
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                progressBar1.Maximum = 3;
            });

            ToggleButtons(false);
            string URL = "https://db.rising-gods.de/?zones=";

            Web        w            = new Web();
            List <int> ContinentIDS = new List <int>();

            ContinentIDS.Add(0);
            ContinentIDS.Add(1);
            ContinentIDS.Add(8);

            Dictionary <int, string[]> Zones = new Dictionary <int, string[]>();

            foreach (int z in ContinentIDS)
            {
                w.Navigate(URL + z);
                Object Read = (Object)w.GetVar("g_listviews['zones']['data']['length']");
                if (Read == null)
                {
                    return;
                }

                int ZoneLength = int.Parse(Read.ToString());
                //ReadOnlyCollection<Object> read = (ReadOnlyCollection<Object>)r;
                //int ZoneLength = int.Parse(web.GetVar("g_listviews['zones']['data']['length']").ToString());
                string DataPath = "g_listviews['zones']['data']";

                for (int i = 0; i < ZoneLength; i++)
                {
                    string Name = w.GetVar(DataPath + "['" + i + "']['name']").ToString();
                    int    ID   = int.Parse(w.GetVar(DataPath + "['" + i + "']['id']").ToString());
                    Zones.Add(ID, new string[] { Name, z.ToString() });
                }
                progressBar1.Invoke((MethodInvoker) delegate()
                {
                    progressBar1.PerformStep();
                });
            }
            progressBar1.Invoke((MethodInvoker) delegate()
            {
                progressBar1.Maximum = progressBar1.Maximum + Zones.Count;
            });
            int QuestsAdded = 0;

            foreach (KeyValuePair <int, string[]> Z in Zones)
            {
                List <Quest> Quests    = new List <Quest>();
                int          Zone      = Z.Key;
                int          Continent = int.Parse(Z.Value[1]);
                string       ZoneName  = Z.Value[0];
                URL = "https://www.burning-crusade.com/database/?quests=" + Continent + "." + Zone;
                w.Navigate(URL);
                int length = -1;
                try
                {
                    length = int.Parse(w.GetVar("g_listviews['quests']['data']['length']").ToString());
                }
                catch
                {
                    PrintDebugMessage("!Error! fetching Zone:" + Zone + " with name: " + ZoneName);
                    continue;
                }
                for (int i = 0; i < length; i++)
                {
                    int    ID       = int.Parse(w.GetVar("g_listviews['quests']['data']['" + i + "']['id']").ToString());
                    string Name     = w.GetVar("g_listviews['quests']['data']['" + i + "']['name']").ToString();
                    int    Level    = int.Parse(w.GetVar("g_listviews['quests']['data']['" + i + "']['level']").ToString());
                    int    ReqLevel = Level;
                    try
                    {
                        ReqLevel = int.Parse(w.GetVar("g_listviews['quests']['data']['" + i + "']['reqlevel']").ToString());
                    }
                    catch
                    {
                        PrintDebugMessage("!Error! Got no ReqLevel for the quest:" + ID + ":" + Name + " used questlevel instead!");
                    }
                    int Side = int.Parse(w.GetVar("g_listviews['quests']['data']['" + i + "']['side']").ToString());
                    Quests.Add(new Quest());
                    Quests[Quests.Count - 1].ID       = ID;
                    Quests[Quests.Count - 1].Name     = Name;
                    Quests[Quests.Count - 1].Level    = Level;
                    Quests[Quests.Count - 1].ReqLevel = ReqLevel;
                    Quests[Quests.Count - 1].Side     = Side;
                    QuestsAdded++;
                    StatusLabel.Invoke((MethodInvoker) delegate()
                    {
                        StatusLabel.Text = "Quests Added: " + QuestsAdded;
                    });
                }
                progressBar1.Invoke((MethodInvoker) delegate()
                {
                    progressBar1.PerformStep();
                });
                this.Quests.Add(Zone, Quests);
            }



            PrintDebugMessage("DONE: " + "Fetched " + QuestsAdded + " quests!");
            w.Quit();
            progressBar1.Invoke((MethodInvoker) delegate()
            {
                progressBar1.Value = progressBar1.Maximum;
            });
            ToggleButtons(true);
        }
Beispiel #22
0
        private void BgWorkerClean_DoWork(object sender, DoWorkEventArgs e)
        {
            DictionaryData BGWorkerData = (DictionaryData)e.Argument;

            TranslationClient client = TranslationClient.Create();


            //selects the text encoding based on user selection
            Encoding InputSelectedEncoding  = null;
            Encoding OutputSelectedEncoding = null;

            this.Invoke((MethodInvoker) delegate()
            {
                InputSelectedEncoding  = Encoding.GetEncoding(InputEncodingDropdown.SelectedItem.ToString());
                OutputSelectedEncoding = Encoding.GetEncoding(OutputEncodingDropdown.SelectedItem.ToString());
            });



            //get the list of files
            var SearchDepth = SearchOption.TopDirectoryOnly;

            if (ScanSubfolderCheckbox.Checked)
            {
                SearchDepth = SearchOption.AllDirectories;
            }
            var files = Directory.EnumerateFiles(BGWorkerData.TextFileFolder, BGWorkerData.FileExtension, SearchDepth);



            try {
                foreach (string fileName in files)
                {
                    if (e.Cancel)
                    {
                        break;
                    }



                    //set up our variables to report
                    string Filename_Clean = Path.GetFileName(fileName);

                    string SubDirStructure = Path.GetDirectoryName(fileName).Replace(BGWorkerData.TextFileFolder, "").TrimStart('\\');


                    //creates subdirs if they don't exist
                    string Output_Location = BGWorkerData.OutputFileLocation + '\\' + SubDirStructure;

                    if (!Directory.Exists(Output_Location))
                    {
                        Directory.CreateDirectory(Output_Location);
                    }

                    Output_Location = Path.Combine(Output_Location, Path.GetFileName(fileName));

                    //report what we're working on
                    FilenameLabel.Invoke((MethodInvoker) delegate
                    {
                        FilenameLabel.Text = "Processing: " + Filename_Clean;
                        FilenameLabel.Invalidate();
                        FilenameLabel.Update();
                        FilenameLabel.Refresh();
                        Application.DoEvents();
                    });



                    // __        __    _ _          ___        _               _
                    // \ \      / / __(_) |_ ___   / _ \ _   _| |_ _ __  _   _| |_
                    //  \ \ /\ / / '__| | __/ _ \ | | | | | | | __| '_ \| | | | __|
                    //   \ V  V /| |  | | ||  __/ | |_| | |_| | |_| |_) | |_| | |_
                    //    \_/\_/ |_|  |_|\__\___|  \___/ \__,_|\__| .__/ \__,_|\__|
                    //                                            |_|


                    using (StreamReader inputfile = new StreamReader(fileName, InputSelectedEncoding))
                    {
                        if (e.Cancel)
                        {
                            break;
                        }

                        string readText = inputfile.ReadToEnd();

                        string[] readText_Chunked = new string[0];

                        if (!string.IsNullOrWhiteSpace(readText))
                        {
                            readText_Chunked = SplitStringByLength(readText, BGWorkerData.MaxCharsPerRequest);
                        }

                        StringBuilder TranslatedText_Output = new StringBuilder();

                        for (int i = 0; i < readText_Chunked.Length; i++)
                        {
                            if (e.Cancel)
                            {
                                break;
                            }

                            try
                            {
                                if (e.Cancel)
                                {
                                    break;
                                }

                                StatusLabel.Invoke((MethodInvoker) delegate
                                {
                                    StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API...";
                                    StatusLabel.Invalidate();
                                    StatusLabel.Update();
                                    StatusLabel.Refresh();
                                    Application.DoEvents();
                                });

                                var response = client.TranslateText(readText_Chunked[i],
                                                                    sourceLanguage: BGWorkerData.InputLang,
                                                                    targetLanguage: BGWorkerData.OutputLang);

                                TranslatedText_Output.Append(response.TranslatedText + " ");
                            }
                            catch (Google.GoogleApiException ex)
                            {
                                if (e.Cancel)
                                {
                                    break;
                                }

                                if (ex.Error.Code == 403)
                                {
                                    if (ex.Error.Message.Contains("Daily Limit Exceeded"))
                                    {
                                        //report what we're working on
                                        StatusLabel.Invoke((MethodInvoker) delegate
                                        {
                                            StatusLabel.Text = "Status: " + ex.Error.Message;
                                            StatusLabel.Invalidate();
                                            StatusLabel.Update();
                                            StatusLabel.Refresh();
                                            Application.DoEvents();
                                        });

                                        MessageBox.Show("The Google Translate API reports that you have exceeded your daily use limit. You will need to visit the \"Quotas\" section of the Google Cloud Dashboard to increase your limits or, alternatively, wait until midnight for your quota to reset.", "Daily Limit Exceeded", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                        e.Cancel = true;
                                        break;
                                    }

                                    else
                                    {
                                        if (e.Cancel)
                                        {
                                            break;
                                        }

                                        int retry_counter = 0;
                                        while (retry_counter < BGWorkerData.MaxRetries)
                                        {
                                            retry_counter++;

                                            int      TimerCounter = 0;
                                            DateTime d            = DateTime.Now;

                                            while (TimerCounter < BGWorkerData.DurationLength + 2)
                                            {
                                                TimeSpan ts = DateTime.Now.Subtract(d);
                                                if (ts.Seconds >= 1)
                                                {
                                                    //do some work
                                                    TimerCounter += ts.Seconds;
                                                    d             = DateTime.Now;

                                                    //report what we're working on
                                                    StatusLabel.Invoke((MethodInvoker) delegate
                                                    {
                                                        StatusLabel.Text = "Status: Rate limit reached. Sleeping for " + (BGWorkerData.DurationLength - TimerCounter + 1).ToString() + "...";
                                                        StatusLabel.Invalidate();
                                                        StatusLabel.Update();
                                                        StatusLabel.Refresh();
                                                        Application.DoEvents();
                                                    });
                                                }
                                            }

                                            try
                                            {
                                                //report what we're working on
                                                StatusLabel.Invoke((MethodInvoker) delegate
                                                {
                                                    StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API... Retry #" + retry_counter.ToString();
                                                    StatusLabel.Invalidate();
                                                    StatusLabel.Update();
                                                    StatusLabel.Refresh();
                                                    Application.DoEvents();
                                                });

                                                var response = client.TranslateText(readText_Chunked[i],
                                                                                    sourceLanguage: BGWorkerData.InputLang,
                                                                                    targetLanguage: BGWorkerData.OutputLang);

                                                TranslatedText_Output.Append(response.TranslatedText + " ");

                                                retry_counter = BGWorkerData.MaxRetries;
                                            }
                                            catch
                                            {
                                            }
                                        }
                                    }
                                }

                                else if (ex.Error.Code == 429 || (ex.Error.Code >= 500 && ex.Error.Code < 600))
                                {
                                    int retry_counter = 0;
                                    while (retry_counter < BGWorkerData.MaxRetries)
                                    {
                                        retry_counter++;

                                        int      TimerCounter = 0;
                                        DateTime d            = DateTime.Now;

                                        while (TimerCounter < System.Math.Pow(retry_counter, 2))
                                        {
                                            TimeSpan ts = DateTime.Now.Subtract(d);
                                            if (ts.Seconds >= 1)
                                            {
                                                //do some work
                                                TimerCounter += ts.Seconds;
                                                d             = DateTime.Now;

                                                //report what we're working on
                                                StatusLabel.Invoke((MethodInvoker) delegate
                                                {
                                                    StatusLabel.Text = "Status: Error " + ex.Error.Code.ToString() + "; " + ex.Error.Message + " -- Retrying in " + (BGWorkerData.DurationLength - TimerCounter + 1).ToString() + "...";
                                                    StatusLabel.Invalidate();
                                                    StatusLabel.Update();
                                                    StatusLabel.Refresh();
                                                    Application.DoEvents();
                                                });
                                            }
                                        }

                                        try
                                        {
                                            //report what we're working on
                                            StatusLabel.Invoke((MethodInvoker) delegate
                                            {
                                                StatusLabel.Text = "Status: Sending request " + (i + 1).ToString() + "/" + readText_Chunked.Length.ToString() + " to API... Retry #" + retry_counter.ToString();
                                                StatusLabel.Invalidate();
                                                StatusLabel.Update();
                                                StatusLabel.Refresh();
                                                Application.DoEvents();
                                            });

                                            var response = client.TranslateText(readText_Chunked[i],
                                                                                sourceLanguage: BGWorkerData.InputLang,
                                                                                targetLanguage: BGWorkerData.OutputLang);

                                            TranslatedText_Output.Append(response.TranslatedText + " ");

                                            retry_counter = BGWorkerData.MaxRetries;
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }

                                else
                                {
                                    //report what we're working on
                                    StatusLabel.Invoke((MethodInvoker) delegate
                                    {
                                        StatusLabel.Text = "Status: " + ex.Error.Message;
                                        StatusLabel.Invalidate();
                                        StatusLabel.Update();
                                        StatusLabel.Refresh();
                                        Application.DoEvents();
                                    });
                                }
                            }
                        }



                        //open up the output file
                        using (StreamWriter outputFile = new StreamWriter(new FileStream(Output_Location, FileMode.Create), OutputSelectedEncoding))
                        {
                            outputFile.Write(TranslatedText_Output.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Transmogrifier encountered an issue somewhere while trying to translate your texts. The most common cause of this is trying to open your output file(s) while the program is still running. Did any of your input files move, or is your output file being opened/modified by another application? " +
                                "After clicking the \"OK\" Button, you will receive an error code. Please write down this error code (or take a screenshot) and contact the software's author ([email protected]) for additional help.", "Error while translating", MessageBoxButtons.OK, MessageBoxIcon.Error);

                MessageBox.Show(ex.ToString(), "Error Code", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #23
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (!File.Exists("eula.txt"))
            {
                string eula = "" +
                              "1. 软件由 Holli_Freed 制作并开源与 GitHub 上\n" +
                              "\n" +
                              "GitHub:https://github.com/hacking001/v2tap\n" +
                              "\n" +
                              "最终解释权归 Holli_Freed 所有!" +
                              "";
                MessageBox.Show(eula, "免责声明", MessageBoxButtons.OK, MessageBoxIcon.Information);

                File.WriteAllText("eula.txt", "");
            }

            v2rayUserIDTextBox.Text = Guid.NewGuid().ToString();
            v2rayTransferMethodComboBox.SelectedIndex = 2;

            using (UdpClient client = new UdpClient("114.114.114.114", 53))
            {
                IPAddress address = ((IPEndPoint)client.Client.LocalEndPoint).Address;

                int  addressCount = 0;
                int  gatewayCount = 0;
                bool addressGeted = false;

                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in adapters)
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();

                    foreach (UnicastIPAddressInformation information in properties.UnicastAddresses)
                    {
                        if (information.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            string IP = information.Address.ToString();

                            if (IP.StartsWith("10.") || IP.StartsWith("172.") || IP.StartsWith("192."))
                            {
                                if (Equals(information.Address, address))
                                {
                                    addressGeted = true;
                                }
                                else
                                {
                                    if (!addressGeted)
                                    {
                                        addressCount++;
                                    }
                                }

                                AdapterAddressComboBox.Items.Add(IP);
                            }
                        }
                    }

                    foreach (GatewayIPAddressInformation information in properties.GatewayAddresses)
                    {
                        if (information.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            string IP = information.Address.ToString();

                            if (IP.StartsWith("10.") || IP.StartsWith("172.") || IP.StartsWith("192."))
                            {
                                if (!addressGeted)
                                {
                                    gatewayCount++;
                                }

                                AdapterGatewayComboBox.Items.Add(IP);
                            }
                        }
                    }
                }
                AdapterAddressComboBox.SelectedIndex = addressCount;
                AdapterGatewayComboBox.SelectedIndex = gatewayCount;
            }

            if (Process.GetProcessesByName("tun2socks").Length == 1 && Process.GetProcessesByName("wv2ray").Length == 1)
            {
                status = "检测到 tun2socks 和 v2ray 服务已启动!";

                ControlButton.Text = "关闭";
            }
            else
            {
                Utils.SharedUtils.ExecuteCommand("TASKKILL /F /T /IM tun2socks.exe");
                Utils.SharedUtils.ExecuteCommand("TASKKILL /F /T /IM wv2ray.exe");
            }

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    try
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            Text = "v2tap - " + DateTime.Now.ToString();
                        });

                        StatusLabel.Invoke((MethodInvoker) delegate
                        {
                            StatusLabel.Text = "当前状态:" + status;
                        });
                    }
                    catch
                    {
                    }

                    Thread.Sleep(100);
                }
            });
        }