Exemplo n.º 1
0
 /// <summary>
 /// 设置进度条的值。
 /// </summary>
 /// <param name="PB">进度条。</param>
 /// <param name="Val">值。</param>
 public static void SetProgress(ToolStripProgressBar PB, double Val)
 {
     if (PB != null)
     {
         PB.Value = ((int)Val > 100) ? 100 : (((int)Val < 0) ? 0 : (int)Val);
         PB.Invalidate();
     }
 }
Exemplo n.º 2
0
 public static bool AddProgressBar(ToolStripProgressBar progressbar)
 {
     if (!progress.Contains(progressbar))
     {
         progress.Add(progressbar);
         progressbar.Value = percent;
         progressbar.Invalidate();
     }
     return(true);
 }
        // note that AsyncScan is Scan implemented through a backgroundWorker so as not to hang the program
        // can we add a progress bar here??? try it...
        public int AsyncScan(ref ToolStripProgressBar progressBar, ref ToolStripStatusLabel statusLabelPercentCompleted,
                             ref BackgroundWorker bw, ref PNA analyzer, ref DataDisplay dataDisplay)
        {
            int i = 0, i_xy = 0, i_z = 0;

            progressBar.Minimum   = 0;
            progressBar.Maximum   = this.probePoints.Count * this.probeZPoints.Count;
            progressBar.Visible   = true;
            progressBar.ForeColor = Color.DarkRed; // try to change the progressbar colour
            for (i_xy = 0; i_xy < this.probePoints.Count; i_xy++)
            {
                for (i_z = 0; i_z < this.probeZPoints.Count; i_z++)
                {
                    i = i_xy * this.probeZPoints.Count + i_z;
                    progressBar.Value = i;
                    progressBar.Invalidate();
                    statusLabelPercentCompleted.Text = String.Format("{0}%", (progressBar.Value * 100) / progressBar.Maximum);
                    if (bw.CancellationPending)
                    {
                        progressBar.Visible = false;
                        statusLabelPercentCompleted.Text = "";
                        return(0);
                    }
                    dataDisplay.SetActivePoint(i_xy);
                    PointF point  = this.probePoints[i_xy];
                    float  zpoint = this.probeZPoints[i_z];
                    Translator.Move((decimal)point.X, (decimal)point.Y, (decimal)zpoint);
                    DataPoint dbpt = new DataPoint(analyzer.Points);
                    // Let the probe settle
                    Thread.Sleep(200);
                    dbpt.Data      = analyzer.Measure();
                    dbpt.Location  = this.probePoints[i_xy];
                    dbpt.LocationZ = this.probeZPoints[i_z];
                    dbpt.Index     = i;
                    dataPoints.Add(dbpt);
                }
            }
            dataDisplay.SetActivePoint(-1);
            progressBar.Visible = false;
            statusLabelPercentCompleted.Text = "";
            return(1);
        }
Exemplo n.º 4
0
 private void progress()
 {
     pb.PerformStep();
     pb.Invalidate();
 }
Exemplo n.º 5
0
 public void SetProgress(int n)
 {
     progress.Value = n;
     progress.Invalidate();
 }
Exemplo n.º 6
0
        public static string[] Translate(string[] text, string sourceLanguageCode, string destLanguageCode, ToolStripProgressBar tspb, ToolStripLabel tsl)
        {
            List <List <string> > textChunks = new List <List <string> >();
            List <string>         currChunk  = new List <string>();
            int currChunkLength = 0;

            foreach (string str in text)
            {
                if (currChunkLength + str.Length > CHAR_LIMIT)
                {
                    textChunks.Add(currChunk);
                    currChunk = new List <string>();
                }
                currChunk.Add(str);
                currChunkLength += str.Length;
            }
            if (currChunk.Count > 0)
            {
                textChunks.Add(currChunk);
            }
            List <string> result = new List <string>();
            int           cpt    = 0;
            int           max    = textChunks.Sum((x) => x.Count);
            Stopwatch     sw     = new Stopwatch();

            sw.Start();
            foreach (List <string> chunk in textChunks)
            {
                tspb.Value = (cpt / max) * 100;
                tsl.Text   = $"Translated {cpt}/{max}";
                tspb.Invalidate();
                tsl.Invalidate();
                string chunkText = Uri.EscapeDataString(chunk.Aggregate((left, right) => left += DELIMITER.ToString() + right));
                Console.WriteLine(GetTranslationURL(sourceLanguageCode, destLanguageCode, chunkText));
                if (CurrentRequestCount >= REQUEST_LIMIT - 1)
                {
                    int timeToSleep = Convert.ToInt32((REQUEST_LIMIT_RESET - (sw.ElapsedMilliseconds / 1000)) * 1000);
                    MessageBox.Show($"Request limit reached, sleeping for {timeToSleep / 1000} seconds");
                    Thread.Sleep(timeToSleep + 1000);
                    CurrentRequestCount = 0;
                    sw.Restart();
                }
                WebRequest  rq = WebRequest.Create(GetTranslationURL(sourceLanguageCode, destLanguageCode, chunkText));
                WebResponse wr = rq.GetResponse();
                CurrentRequestCount++;
                string tmpTxt = wr.GetResponseStream().ReadToEnd();

                /**
                 * Sample return :
                 * [[["Hello","hola",null,null,1]],null,"es",null,null,null,0.91015625,null,[["es"],null,[0.91015625],["es"]]]
                 *     ^^^^^ What we need
                 */
                IEnumerable <char> tmp            = tmpTxt.Split(',')[0].Skip(4);
                string             resultTxt      = new string(tmp.Take(tmp.Count() - 1).ToArray());
                string[]           splitDelimiter = new[] { "" };
                foreach (char c in DELIMITER)
                {
                    splitDelimiter[0] += c;
                }
                result.AddRange(resultTxt.Split(splitDelimiter, StringSplitOptions.None));
                cpt += chunk.Count;
            }
            return(result.ToArray());
        }