示例#1
0
        /// <summary>
        /// на входе строка вида
        /// CME;-W:6,7;1020
        /// Yahoo;W:1,2,3,4,5;0,15+
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static ScheduleRoutine TryParse(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            str = str.Trim(' ', (char)9);
            if (str.StartsWith("//") || str.StartsWith("--") || str.StartsWith("/*"))
            {
                return(null);
            }
            var parts = str.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length != 3)
            {
                return(null);
            }

            var title        = parts[0];
            var isExclusive  = parts[1].StartsWith("-");
            var weekDays     = isExclusive ? parts[1].Substring(3) : parts[1].Substring(2);
            var separateDays = weekDays.ToIntArrayUniform();

            var shouldExtendMinutes = parts[2].EndsWith("+");
            var strMinutes          = shouldExtendMinutes
                                 ? parts[2].Substring(0, parts[2].Length - 1)
                                 : parts[2];

            var minutesArray     = strMinutes.ToIntArrayUniform();
            var totalMinutesList = new List <int>(minutesArray);

            if (shouldExtendMinutes)
            {
                var lastInterval = minutesArray[minutesArray.Length - 1] - minutesArray[minutesArray.Length - 2];
                for (var inter = minutesArray[minutesArray.Length - 1] + lastInterval;
                     inter < 1440; inter += lastInterval)
                {
                    totalMinutesList.Add(inter);
                }
            }

            var routine = new ScheduleRoutine {
                GrabberCode = title, MinuteIntervals = totalMinutesList.ToArray()
            };

            if (isExclusive)
            {
                routine.ExclusiveWeekdays = separateDays;
            }
            else
            {
                routine.InclusiveWeekdays = separateDays;
            }

            return(routine);
        }
示例#2
0
        private Scheduler()
        {
            var setsFile = string.Format("{0}\\schedule.txt", ExecutablePath.ExecPath);

            if (!File.Exists(setsFile))
            {
                return;
            }

            using (var sr = new StreamReader(setsFile))
            {
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (timerInterval == 0)
                    {
                        var lineAsNumber = line.ToIntSafe();
                        if (lineAsNumber.HasValue)
                        {
                            timerInterval = lineAsNumber.Value;
                        }
                        continue;
                    }
                    var routine = ScheduleRoutine.TryParse(line);
                    if (routine != null)
                    {
                        routines.Add(routine);
                    }
                }
            }

            // инициализация сборщиков новостей
            grabbers.Add("CME", new CMEGrabber());
            grabbers.Add("Yahoo", new YahooGrabber());
            grabbers.Add("TradeSharp", new TradeSharpGrabber());
        }
示例#3
0
        /// <summary>
        /// на входе строка вида
        /// CME;-W:6,7;1020
        /// Yahoo;W:1,2,3,4,5;0,15+
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static ScheduleRoutine TryParse(string str)
        {
            if (string.IsNullOrEmpty(str)) return null;
            str = str.Trim(' ', (char) 9);
            if (str.StartsWith("//") || str.StartsWith("--") || str.StartsWith("/*")) return null;
            var parts = str.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 3) return null;

            var title = parts[0];
            var isExclusive = parts[1].StartsWith("-");
            var weekDays = isExclusive ? parts[1].Substring(3) : parts[1].Substring(2);
            var separateDays = weekDays.ToIntArrayUniform();

            var shouldExtendMinutes = parts[2].EndsWith("+");
            var strMinutes = shouldExtendMinutes
                                 ? parts[2].Substring(0, parts[2].Length - 1)
                                 : parts[2];

            var minutesArray = strMinutes.ToIntArrayUniform();
            var totalMinutesList = new List<int>(minutesArray);
            if (shouldExtendMinutes)
            {
                var lastInterval = minutesArray[minutesArray.Length - 1] - minutesArray[minutesArray.Length - 2];
                for (var inter = minutesArray[minutesArray.Length - 1] + lastInterval;
                    inter < 1440; inter += lastInterval)
                    totalMinutesList.Add(inter);
            }

            var routine = new ScheduleRoutine {GrabberCode = title, MinuteIntervals = totalMinutesList.ToArray()};
            if (isExclusive) routine.ExclusiveWeekdays = separateDays;
            else routine.InclusiveWeekdays = separateDays;

            return routine;
        }