예제 #1
0
        public static void CreateInterval(System.Timers.ElapsedEventHandler Action, int time)
        {
            var timer = new System.Timers.Timer(time);

            timer.Elapsed += Action;
            timer.Start();
        }
예제 #2
0
 private void SetupTimer(ref Timer timer, int intervalTime, System.Timers.ElapsedEventHandler e)
 {
     timer           = new System.Timers.Timer();
     timer.Interval  = intervalTime;
     timer.Elapsed  += e;
     timer.AutoReset = true;
     timer.Enabled   = true;
 }
예제 #3
0
        public static void CreateTimer(System.Timers.ElapsedEventHandler Action, int time)
        {
            var timer = new System.Timers.Timer(time);

            timer.AutoReset = false;
            timer.Elapsed  += Action;
            timer.Start();
        }
예제 #4
0
파일: Clock.cs 프로젝트: Japend/LuxAura
    public void AddTimerForMontecarlo(System.Timers.ElapsedEventHandler receiver)
    {
        Timer mTimer = new Timer(GlobalData.MONTECARLO_TIMER_MILISECONDS);

        mTimer.Elapsed  += receiver;
        mTimer.AutoReset = false;
        mTimer.Enabled   = true;
    }
예제 #5
0
        public void Start(double interval)
        {
            int val;
            c = 1;
            this.progressBar1.Value = this.progressBar1.Maximum;
            this.progressBar1.ForeColor = SystemColors.Highlight;
            int RColor = this.progressBar1.ForeColor.R;
            int GColor = System.Math.Min(255, this.progressBar1.ForeColor.G + 1);
            int BColor = this.progressBar1.ForeColor.B;
            t.Interval = 200;
            t.AutoReset = true;
            
            Func<Color, float, Color> getProgressColor = (curColor, curValuePart) =>
            {
                int R;
                int G;
                int B;

                R = (int)(255-curValuePart*(255-RColor));
                G = (int)(120 - curValuePart * (120 - GColor));
                B = (int)((0.7 + 0.3 * curValuePart) * BColor);

                R = System.Math.Max(System.Math.Min(R, 255), 0);
                G = System.Math.Max(System.Math.Min(G, 255), 0);
                B = System.Math.Max(System.Math.Min(B, 255), 0);
                return Color.FromArgb(R, G, B);
            };

            onTimer = delegate
            {
                if (this.progressBar1.Value > 0)
                {
                    val = this.progressBar1.Maximum - (int)(this.progressBar1.Maximum * (++c) * t.Interval / interval);
                    if (val < 0) val = 0;
                    if (this.progressBar1.InvokeRequired)
                    {
                        this.progressBar1.Invoke(new Action<int>(i => this.progressBar1.Value = i), val);
                        this.progressBar1.Invoke(new Action<Color, float>((foreColor, valuePart) =>
                           this.progressBar1.ForeColor =
                           getProgressColor(foreColor, valuePart)), this.progressBar1.ForeColor, ((float)val / this.progressBar1.Maximum));
                    }
                    else
                    {
                        this.progressBar1.Value = val;
                        this.progressBar1.ForeColor = getProgressColor(this.progressBar1.ForeColor, (float)val / this.progressBar1.Maximum);
                    }
                }
                else
                    this.Stop();
            };
            t.Elapsed += onTimer;
            t.Start();
        }
예제 #6
0
        protected override void OnStart(string[] args)
        {
            _timer = new Timer(10 * 60 * 1000); // every 10 minutes

            var handler = new System.Timers.ElapsedEventHandler(timer_Elapsed);

            _timer.Elapsed += handler;

            handler.Invoke(this, null);

            _timer.Start();
        }
예제 #7
0
        /// <summary>
        /// public void DownloadFile(string url, string destination, AsyncCompletedEventHandler onComplete,
        /// string report, bool async, bool kurjun)
        /// Performing file download according to download list
        /// </summary>
        /// <param name="url">URL to download from</param>
        /// <param name="destination">destination path\file</param>
        /// <param name="onComplete">What will be executed on complete</param>
        /// <param name="report">String to be written to installation form </param>
        /// <param name="async">If async download</param>
        /// <param name="kurjun">If download from kurjun</param>
        public void DownloadFile(string url, string destination, AsyncCompletedEventHandler onComplete, string report, bool async, bool kurjun)
        {
            var md5 = "";

            if (kurjun)
            {
                var filename = Path.GetFileName(destination);
                var info     = request_kurjun_fileInfo(url, RestFileinfoURL, filename);
                if (info == null)
                {
                    Program.ShowError($"File does not exist {filename}", "File error");
                    Program.form1.Visible = false;
                }
                url = url + RestFileURL + info.id;
                md5 = info.id.Replace("raw.", "");

                if (!Program.form1.PrerequisiteFilesInfo.ContainsKey(destination))
                {
                    Program.form1.PrerequisiteFilesInfo.Add(destination, info);
                }
                logger.Info("Getting file {0} from kurjun, md5sum:{1}", destination, md5);
            }

            ///////////////////////////////////////////////////////////////////////////////
            /////////////This part will be modified (removed) when 3 env deployed//////////
            ///////////////////////////////////////////////////////////////////////////////
            var shouldWeDownload = true;//will download in any case now

            if (destination.Contains("tray-dev"))
            {
                destination = destination.Remove(destination.IndexOf('-'), 4);
            }

            if (destination.Contains("_dev"))
            {
                destination = destination.Remove(destination.IndexOf('_'), 4);
            }

            if (destination.Contains("-test") && !destination.Contains("repomd5"))
            {
                destination = destination.Remove(destination.IndexOf('-'), 5);
            }
            ///////////////////////////////////////////////////////////////////////////////
            ///////////////////////////////////////////////////////////////////////////////
            ///////////////////////////////////////////////////////////////////////////////

            var fileInfo = new FileInfo(destination);

            if (fileInfo.Exists)
            {
                var calculatedMd5 = Calc_md5(destination, false);
                if (calculatedMd5 != md5)
                {
                    shouldWeDownload = true;
                }
                else
                {
                    shouldWeDownload = false;
                }
            }

            if (shouldWeDownload)
            {
                var dirInfo = new DirectoryInfo(path: Path.GetDirectoryName(destination));
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                    logger.Info("Directory created: {0}", destination);
                }

                StageReporter("", report);
                var webClient = new WebClient();

                if (onComplete != null)
                {
                    webClient.DownloadFileCompleted += onComplete;
                }

                //Add ProgressChanges event handler
                webClient.DownloadProgressChanged += ProgressChanged;

                //Add Elapsed event handler
                dwldTimerHandler = ((sender, args)
                                    =>
                {
                    dwldTimer.Elapsed -= dwldTimerHandler;
                    webClient.CancelAsync();
                    dwldTimer.Enabled = false;
                    dwldTimer.Dispose();
                    Program.ShowError("Can not download files. Please, check Your Internet connection and try later",
                                      "Repository Error");
                    Program.form1.Visible = false;
                });
                dwldTimer.Elapsed  += dwldTimerHandler;
                dwldTimer.Interval  = 300000;
                dwldTimer.AutoReset = false;
                dwldTimer.Enabled   = true;
                try
                {
                    if (async)
                    {
                        webClient.DownloadFileAsync(new Uri(url), destination);
                    }
                    else
                    {
                        webClient.DownloadFile(new Uri(url), destination);
                    }
                }
                catch (Exception ex)
                {
                    dwldTimer.Enabled = false;

                    logger.Error(ex.Message, destination);
                    Program.ShowError("Subutai repository is not available. Check Internet connection.",
                                      "Repository Error");
                }
            }
            else
            {
                dwldTimer.Enabled = false;
                onComplete?.Invoke(null, null);
            }
        }