Beispiel #1
0
        private Instant?ParseInstant(string text)
        {
            var result = TimePattern.Parse(text);

            if (result.Success)
            {
                return(result.Value.Minus(DefaultBias));
            }

            return(null);
        }
        /// <summary>
        /// Determines if the current rule should be applied depending on the time pattern that has been applied to it.
        /// </summary>
        /// <param name="timezone">The timezone to adjust for. This will typically be the timezone set by the user that owns
        /// the dialplan. If no timezone is specified UTC will be assumed.</param>
        /// <returns>True if the rule should be applied, false otherwise.</returns>
        public bool IsTimeMatch(DateTimeOffset now, string timezone)
        {
            var localTime = now.AddMinutes(TimeZoneHelper.GetTimeZonesUTCOffsetMinutes(timezone));

            if (localTime.DayOfWeek == DayOfWeek.Monday && TimePattern.IndexOf("M", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Tuesday && TimePattern.IndexOf("Tu", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Wednesday && TimePattern.IndexOf("W", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Thursday && TimePattern.IndexOf("Th", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Friday && TimePattern.IndexOf("F", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Saturday && TimePattern.IndexOf("Sa", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }
            else if (localTime.DayOfWeek == DayOfWeek.Sunday && TimePattern.IndexOf("Su", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }

            var timesMatch = Regex.Match(TimePattern, TIMES_REGEX);

            if (timesMatch.Success)
            {
                int startHour   = Convert.ToInt32(timesMatch.Result("${startHour}"));
                int startMinute = Convert.ToInt32(timesMatch.Result("${startMinute}"));
                int endHour     = Convert.ToInt32(timesMatch.Result("${endHour}"));
                int endMinute   = Convert.ToInt32(timesMatch.Result("${endMinute}"));

                TimeSpan startTime = new TimeSpan(startHour, startMinute, 0);
                TimeSpan endTime   = new TimeSpan(endHour, endMinute, 0);

                if (localTime.TimeOfDay < startTime || localTime.TimeOfDay > endTime)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Gets a list of the days that the rule's time pattern matches.
        /// </summary>
        /// <returns>A list of matching days.</returns>
        public List <DayOfWeek> MatchedDays()
        {
            var days = new List <DayOfWeek>();

            if (TimePattern.IndexOf("M", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Monday);
            }

            if (TimePattern.IndexOf("Tu", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Tuesday);
            }

            if (TimePattern.IndexOf("W", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Wednesday);
            }

            if (TimePattern.IndexOf("Th", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Thursday);
            }

            if (TimePattern.IndexOf("F", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Friday);
            }

            if (TimePattern.IndexOf("Sa", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Saturday);
            }

            if (TimePattern.IndexOf("Su", StringComparison.OrdinalIgnoreCase) != -1)
            {
                days.Add(DayOfWeek.Sunday);
            }

            return(days);
        }
        private void BaseServer_OutPutEvent(System.Diagnostics.DataReceivedEventArgs e)
        {
            try
            {
                var log = e.Data;
                if (log != null)
                {
                    if (TimePattern.Match(log).Success)
                    {
                        if (TypePattern.Match(log).Success)
                        {
                            var result = log.Remove(0, TimePattern.Match(log).ToString().Length);
                            var type   = TypePattern.Match(log).ToString().Split('/')[1].Split(']')[0];
                            var color  = "8BC34A";
                            if (type == "INFO")
                            {
                                color = "64B5F6";
                            }
                            else if (type == "WARN")
                            {
                                color = "f44336";
                            }
                            else if (type == "ERROR")
                            {
                                color = "f44336";
                            }
                            m_Client.Send(Encoding.UTF8.GetBytes("C," + color + "|" + log.Split('[')[1].Split(']')[0] + "|" + type + "|" + result));
                            P.AddToOutput(color, TimePattern.Match(log).ToString(), result, type);
                        }
                    }
                    else
                    {
                        P.AddToOutput("fff", "", log, "");
                    }
                }

                /*
                 * if (log.Split('[')[1] != null)
                 *  if (log.Split('[')[1].Split(']')[0] != null)
                 *      if (log.Split('[')[1].Split(']')[0].Split(':') != null)
                 *          if (log.Split('[')[1].Split(']')[0].Split(':').Length == 3)
                 *          {
                 *              var result = log.Replace(log.Split(']')[0] + "]", "");
                 *              var type = result.Split('[')[1].Split(']')[0].Split('/')[1];
                 *              var thread = result.Split('[')[1].Split(']')[0].Split('/')[0];
                 *
                 *              var color = "8BC34A";
                 *              if (type == "INFO")
                 *                  color = "64B5F6";
                 *              else if (type == "WARN")
                 *                  color = "f44336";
                 *              else if (type == "ERROR")
                 *                  color = "f44336";
                 *              client.SendString("C," + color + "|" + log.Split('[')[1].Split(']')[0]+ "|" + type + "|" + result);
                 *              Task.Run(() => { P.AddToOutput(color, log.Split('[')[1].Split(']')[0], result, type); });
                 *          }
                 *          else
                 *          {
                 *              client.SendString("C," + "" + "|" + log + "|" + "" + "|" + "");
                 *              P.AddToOutput("fff", "", log, "");
                 *          }
                 */
            }
            catch { }
        }
        /// <summary>
        /// 讀取資料到畫面上
        /// </summary>
        private void ReadJob2Screen(string JobId)
        {
            try
            {
                txtJobId.Text = JobId;

                JobData job = frmScheduleJobUI.Jobs.JobDatas.AsEnumerable().Where(c => c.JobId == JobId).FirstOrDefault();
                if (job != null)
                {
                    txtJobName.Text   = job.JobName;
                    labDLLName.Text   = job.DLLName;
                    labClassName.Text = job.ClassName;
                    txtNameSpace.Text = job.NameSpace;

                    switch (job.UsePeriodType)
                    {
                    case PeriodType.BY_DAILY:
                        if (!string.IsNullOrEmpty(job.ExecuteTime) && job.ExecuteTime != "00:00")     //為時間區隔的反覆性週期工作
                        {
                            if (!TimePattern.Match(job.ExecuteTime).Success)
                            {
                                numHourHH.Focus();
                                throw new Exception("每 HH:ss 反覆執行中的 (小時:分鐘) 設定不正確。");
                            }
                            //屬於每日,且週期性的固定在 HH:ss 中反覆執行.
                            rbHHss.Enabled = true;
                            SetHHssByJobTime(job.ExecuteTime, numHourHH, numMinuteHH);
                            cbEnableTime.Checked = job.Enabled;
                        }
                        else
                        {
                            //屬於每天執行的排程
                            rbDay.Checked = true;
                            if (!TimePattern.Match(job.StartTime).Success)
                            {
                                numHourDay.Focus();
                                throw new Exception("(天) 排程中的 (小時:分鐘) 設定不正確。");
                            }
                            SetHHssByJobTime(job.StartTime, numHourDay, numMinuteDay);
                            cbPeriodDay.Checked = job.IsPeriodJob == PeriodJob.IS_PERIOD;
                            cbEnableDay.Checked = job.Enabled;
                        }
                        break;

                    case PeriodType.BY_WEEKLY:
                        rbWeek.Checked = true;
                        cbExecWeek.SelectedIndex
                            = cbExecWeek.Items.IndexOf(cbExecWeek.Items.OfType <ListItem>()
                                                       .Where(c => c.ValueMember == job.ExceuteWeek.ToString()).FirstOrDefault());

                        SetHHssByJobTime(job.StartTime, numHourWeek, numMinuteWeek);
                        cbPeriodWeek.Checked = job.IsPeriodJob == PeriodJob.IS_PERIOD;
                        cbEnableWeek.Checked = job.Enabled;
                        break;

                    case PeriodType.BY_MONTHLY:
                        rbMonth.Checked = true;
                        cbExecDay.SelectedIndex
                            = cbExecDay.Items.IndexOf(cbExecDay.Items.OfType <ListItem>()
                                                      .Where(c => c.ValueMember == job.ExecuteDay.ToString()).FirstOrDefault());

                        SetHHssByJobTime(job.StartTime, numHourMonth, numMinuteMonth);
                        cbPeriodMonth.Checked = job.IsPeriodJob == PeriodJob.IS_PERIOD;
                        cbEnableMonth.Checked = job.Enabled;
                        break;
                    }
                    txtEMailAddress.Text = job.EMailAddress;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("顯示排程工作資料時,發生錯誤!詳細訊息:{0}", ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }