示例#1
0
        public void PastWork()
        {
            Run(() =>
            {
                var provider = new MyPlatformEnlightenmentProvider();
                PlatformEnlightenmentProvider.Current = provider;

                var cal = provider._cal;
                var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
                var due = now - TimeSpan.FromMinutes(1);

                var s = new MyScheduler();
                s.SetTime(now);

                var done = false;
                s.Schedule(due, () => { done = true; });

                Assert.AreEqual(1, s._queue.Count);

                var next = s._queue.Deq();
                Assert.IsTrue(s.Now + next.DueTime == now);

                s.SetTime(due);
                next.Invoke();

                Assert.IsTrue(done);
            });
        }
示例#2
0
        public void OnCompleted_3()
        {
            var           scheduler    = new MyScheduler();
            TaskScheduler ranScheduler = null;

            SynchronizationContext.SetSynchronizationContext(null);

            var t = Task.Factory.StartNew(() =>
            {
                var manualResetEvents = new ManualResetEvent[1];
                using (manualResetEvents[0] = new ManualResetEvent(false))
                {
                    _a.OnCompleted
                    (
                        () =>
                    {
                        ranScheduler = TaskScheduler.Current;
                        manualResetEvents[0].Set();
                    }
                    );

                    manualResetEvents[0].WaitOne(1000);
                }
            }, CancellationToken.None, TaskCreationOptions.None, scheduler);

            Assert.IsTrue(t.Wait(1000), "#1");
            Assert.AreEqual(scheduler, ranScheduler, "#2");
        }
示例#3
0
        private static void ImmediateWork_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var due = now;

            var s = new MyScheduler();

            s.SetTime(now);

            var done = false;

            s.Schedule(due, () => { done = true; });

            Assert.Equal(1, s._queue.Count);

            var next = s._queue.Deq();

            Assert.True(s.Now + next.DueTime == due);

            s.SetTime(due);
            next.Invoke();

            Assert.True(done);
        }
示例#4
0
        private static void ShortTermWork_Dispose_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var rel = TimeSpan.FromSeconds(1) /* rel <= SHORTTERM */;
            var due = now + rel;

            var s = new MyScheduler();

            s.SetTime(now);

            var done = false;
            var d    = s.Schedule(due, () => { done = true; });

            Assert.Equal(1, s._queue.Count);

            var next = s._queue.Deq();

            Assert.True(s.Now + next.DueTime == due);

            d.Dispose();

            s.SetTime(due);
            next.Invoke();

            Assert.False(done);
        }
示例#5
0
        static async Task Main(string[] args)
        {
            int counter = 0;

            MyScheduler.IntervalInHours(17, 50, 1,
                                        () =>
            {
                DateTime localDate = DateTime.Now;
                Console.WriteLine("------------------------");
                Console.WriteLine("Starting in: ");
                Console.WriteLine(localDate);
                counter++;
                Console.WriteLine("Index: " + counter);
                Console.WriteLine("------------------------");
                //Weather --> TLV
                fetchWeatherDataAsync("32.005532", "34.885411");
                Console.WriteLine("------------------------");
                //Weather --> MAD
                fetchWeatherDataAsync("40.529342", "-3.648067");
                Console.WriteLine("------------------------");
            });
            MyScheduler.IntervalInHours(16, 50, 24,
                                        () =>
            {
                //Flights -->Gets all flights from TLV -> MAD
                Console.WriteLine("------------------------");
                _ = fetchFlightDataAsync();
            });
            Console.ReadLine();
        }
示例#6
0
        public void Scheduler_ScheduleNonRecursive()
        {
            var ms  = new MyScheduler();
            var res = false;

            Scheduler.Schedule(ms, a => { res = true; });
            Assert.IsTrue(res);
        }
示例#7
0
        public void Test_Start3Threads()
        {
            MyScheduler scheduler = new MyScheduler();

            scheduler.Start3Threads();

            Assert.IsTrue(true);
        }
示例#8
0
 // Start is called before the first frame update
 void Start()
 {
     Schedule = new MyScheduler <List <Task>, Job>();
     //	new List<List<Task>>();
     //for (int i = 0; i < Enum.GetNames(typeof(Job)).Length; i++)
     //{
     //          Schedule.Add(new List<Task>());
     //      }
 }
示例#9
0
        private static void ClockChanged_Backward2_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var scm = (ClockChanged)provider.GetService <INotifySystemClockChanged>();

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var rel = TimeSpan.FromSeconds(1);
            var due = now + rel;
            var err = TimeSpan.FromMinutes(-1);

            var s = new MyScheduler();

            s.SetTime(now);

            var n = 0;

            s.Schedule(due, () => { n++; });

            Assert.Equal(0, cal._queue.Count);
            Assert.Equal(1, s._queue.Count);
            var wrk = s._queue[0];

            Assert.True(wrk.DueTime == rel);

            s.SetTime(due + err);
            scm.OnSystemClockChanged();

            Assert.Equal(1, cal._queue.Count);

            var tmr = cal._queue.Deq();

            Assert.True(tmr.Interval > rel);
            Assert.True(tmr.Interval < -err);

            s.SetTime(s.Now + tmr.Interval);
            tmr.Value._action(tmr.Value._state);

            Assert.Equal(0, n);

            Assert.Equal(0, cal._queue.Count);
            Assert.Equal(1, s._queue.Count);

            s.SetTime(due);
            s._queue.Deq().Invoke();

            Assert.Equal(1, n);

            wrk.Invoke();       // Bad schedulers may not grant cancellation immediately.
            Assert.Equal(1, n); // Invoke shouldn't cause double execution of the work.
        }
示例#10
0
        public void DisableOptimizations_UnknownService()
        {
            var s = new MyScheduler();

            Assert.IsFalse(s is IServiceProvider);

            var d = s.DisableOptimizations();

            Assert.IsTrue(d is IServiceProvider);
            Assert.IsNull(((IServiceProvider)d).GetService(typeof(bool)));
        }
示例#11
0
        public void Scheduler_ScheduleRecursive()
        {
            var ms = new MyScheduler();
            var i  = 0;

            Scheduler.Schedule(ms, a => { if (++i < 10)
                                          {
                                              a();
                                          }
                               });
            Assert.AreEqual(10, i);
        }
示例#12
0
        public ActionResult Home()
        {
            if (System.Web.HttpContext.Current.Session["User"] == null)
            {
                return(Redirect(Url.Content("/Login/Login")));
            }

            UserLogin lu = new UserLogin();

            lu = (UserLogin)System.Web.HttpContext.Current.Session["User"];
            MyScheduler.SetTimer(lu.ID);
            return(View());
        }
示例#13
0
        public void Test_Start3ThreadsAsync()
        {
            MyScheduler scheduler = new MyScheduler();
            var         task      = scheduler.Start3ThreadsAsync();

            Assert.IsNotNull(task);

            // takes max delay (about 1 min)
            task.Wait();
            Assert.AreEqual(1, task.Result);

            Assert.IsTrue(true);
        }
示例#14
0
        public void Scheduler_ScheduleWithTimeNonRecursive()
        {
            var now = DateTimeOffset.Now;
            var ms  = new MyScheduler(now)
            {
                Check = (a, t) => { Assert.IsTrue(t == TimeSpan.Zero); }
            };
            var res = false;

            Scheduler.Schedule(ms, a => { res = true; }, now);
            Assert.IsTrue(res);
            Assert.IsTrue(ms.WaitCycles == 0);
        }
示例#15
0
        public void Scheduler_ArgumentChecks()
        {
            var ms = new MyScheduler();

            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(default(IScheduler), a => { }));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(ms, default(Action <Action>)));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(default(IScheduler), () => { }, DateTimeOffset.Now));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(ms, default(Action), DateTimeOffset.Now));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(default(IScheduler), a => { }, DateTimeOffset.Now));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(ms, default(Action <Action <DateTimeOffset> >), DateTimeOffset.Now));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(default(IScheduler), a => { }, TimeSpan.Zero));
            AssertThrows <ArgumentNullException>(() => Scheduler.Schedule(ms, default(Action <Action <TimeSpan> >), TimeSpan.Zero));
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Scheduler using Quartz.Net (See codes in MyScheduler Class & the relevant Jobs)
            MyScheduler sch = new MyScheduler();

            sch.Start();
        }
示例#17
0
    public static void Main()
    {
        MyScheduler m = new MyScheduler(5);
        Task        t = new Task(() => {
            while (true)
            {
                Console.WriteLine("iam alive");
            }
        });

        t.Start();
        Thread.Sleep(1000);
        Console.ReadLine();
    }
示例#18
0
        private static void LongTermWork2_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var rel = TimeSpan.FromDays(1) /* rel > SHORTTERM and rel * MAXERRORRATIO > SHORTTERM */;
            var due = now + rel;

            var s = new MyScheduler();

            s.SetTime(now);

            var done = false;

            s.Schedule(due, () => { done = true; });

            Assert.Equal(1, cal._queue.Count);

            var wrk1 = cal._queue.Deq();

            Assert.True(wrk1.Interval < rel);

            s.SetTime(s.Now + wrk1.Interval);
            wrk1.Value._action(wrk1.Value._state);

            // Begin of second long term scheduling
            Assert.Equal(1, cal._queue.Count);

            var wrk2 = cal._queue.Deq();

            Assert.True(wrk2.Interval < rel);

            s.SetTime(s.Now + wrk2.Interval);
            wrk2.Value._action(wrk2.Value._state);
            // End of second long term scheduling

            Assert.Equal(1, s._queue.Count);

            var next = s._queue.Deq();

            Assert.True(s.Now + next.DueTime == due);

            s.SetTime(due);
            next.Invoke();

            Assert.True(done);
        }
示例#19
0
        private static void ClockChanged_Backward1_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var scm = (ClockChanged)provider.GetService <INotifySystemClockChanged>();

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var rel = TimeSpan.FromMinutes(1);
            var due = now + rel;
            var err = TimeSpan.FromMinutes(-2);

            var s = new MyScheduler();

            s.SetTime(now);

            var done = false;

            s.Schedule(due, () => { done = true; });

            Assert.Equal(1, cal._queue.Count);
            Assert.True(cal._queue[0].Interval < rel);

            Assert.Equal(0, s._queue.Count);

            s.SetTime(due + err);
            scm.OnSystemClockChanged();

            Assert.Equal(1, cal._queue.Count);

            var tmr = cal._queue.Deq();

            Assert.True(tmr.Interval > rel);
            Assert.True(tmr.Interval < -err);

            s.SetTime(s.Now + tmr.Interval);
            tmr.Value._action(tmr.Value._state);

            Assert.False(done);

            Assert.Equal(0, cal._queue.Count);
            Assert.Equal(1, s._queue.Count);

            s.SetTime(due);
            s._queue.Deq().Invoke();

            Assert.True(done);
        }
示例#20
0
        static void Main(string[] args)
        {
            BotClient = new TelegramBotClient("bot_key_here");
            ChatId    = "chat_id_here";

            // For Interval in Seconds
            // This Scheduler will start at 11:10 and call after every 15 Seconds
            // IntervalInSeconds(start_hour, start_minute, seconds)
            // Eg.: MyScheduler.IntervalInSeconds(11, 10, 15,
            MyScheduler.IntervalInMinutes(DateTime.Now.Hour, DateTime.Now.Minute, 10,
                                          () => {
                Console.WriteLine($"====== Running scheduled job at: {DateTime.Now.ToString("HH:mm:ss")} ======");
                AsyncContext.Run(CallPuppeteer);
            });

            Console.ReadKey();
        }
示例#21
0
        public void Scheduler_ScheduleWithTimeRecursive()
        {
            var now = DateTimeOffset.Now;
            var i   = 0;
            var ms  = new MyScheduler(now)
            {
                Check = (a, t) => { Assert.IsTrue(t == TimeSpan.Zero); }
            };

            Scheduler.Schedule(ms, a => { if (++i < 10)
                                          {
                                              a(now);
                                          }
                               }, now);
            Assert.IsTrue(ms.WaitCycles == 0);
            Assert.AreEqual(10, i);
        }
示例#22
0
        public void Scheduler_ScheduleWithTimeSpanRecursive()
        {
            var now = DateTimeOffset.Now;
            var ms  = new MyScheduler(now)
            {
                Check = (a, t) => { Assert.IsTrue(t < TimeSpan.FromTicks(10)); }
            };
            var i = 0;

            Scheduler.Schedule(ms, a => { if (++i < 10)
                                          {
                                              a(TimeSpan.FromTicks(i));
                                          }
                               }, TimeSpan.Zero);
            Assert.IsTrue(ms.WaitCycles == Enumerable.Range(1, 9).Sum());
            Assert.AreEqual(10, i);
        }
示例#23
0
        public BotClientService(IOptions <AppConfiguration> config)
        {
            this.config = config;

            try
            {
                BotClient = new TelegramBotClient(config.Value.TelegramBotClientKey);
                ChatIds   = config.Value.ChatIds.Split(";").ToList();

                // For Interval in Seconds
                // This Scheduler will start at 11:10 and call after every 15 Seconds
                // IntervalInSeconds(start_hour, start_minute, seconds)
                // Eg.: MyScheduler.IntervalInSeconds(11, 10, 15,
                MyScheduler.IntervalInMinutes(DateTime.Now.Hour, DateTime.Now.Minute, 10,
                                              () =>
                {
                    try
                    {
                        Console.WriteLine($"====== Running scheduled job at: {DateTime.Now.ToString("HH:mm:ss")} ======");
                        AsyncContext.Run(CallPuppeteer);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });

                MyScheduler.IntervalInSeconds(DateTime.Now.Hour, DateTime.Now.Minute, 60,
                                              () =>
                {
                    try
                    {
                        Console.WriteLine($"I'm alive!");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#24
0
 void Start()
 {
     //Todo Fix Scheduler
     Scheduler = GameObject.Find("Scheduler");
     Schedule  = new MyScheduler <List <int>, Job>();
     for (int i = 0; i < Schedule.length; i++)
     {
         foreach (var sc in Enum.GetValues(typeof(Job)).Cast <Job>().ToList())
         {
             //Schedule[sc][0] = 3;
         }
     }
     //Todo remove AStar debug
     //World world = WorldController.Instance.World;
     //Vector2 dest = new Vector2(UnityEngine.Random.Range(0,world.Width), UnityEngine.Random.Range(0, world.Height));
     ////Debug.Log("Calculate Path from " + GetPosition() + " to " + dest + ".");
     //AStar.CalculatePath(GetPosition(), dest, world, this);
 }
示例#25
0
        public async Task <IActionResult> Create([Bind("Id,intervalType,TimeStart,Interval,Device,PIN,Variable")] Schedule schedule)
        {
            if (ModelState.IsValid)
            {
                Console.WriteLine("Scheduled!");
                _context.Add(schedule);
                await _context.SaveChangesAsync();

                MyScheduler.Reset();
                this.Device = schedule.Device;
                this.PIN    = schedule.PIN;
                MyScheduler.Interval(schedule.TimeStart.Hours, schedule.TimeStart.Minutes, schedule.intervalType, schedule.Interval, true, DoSchedule);
                //Console.WriteLine($"{schedule.intervalType}\n{schedule.TimeStart}\n{schedule.Interval}\n{schedule.Device}\n{schedule.PIN}");

                return(View());
            }
            return(View(schedule));
        }
示例#26
0
        public void DeleteTargetApps()
        {
            StreamReader maReader = new StreamReader(Request.InputStream);
            string       strOBJ   = maReader.ReadToEnd();
            dynamic      dData    = (dynamic)JsonConvert.DeserializeObject(strOBJ);

            try
            {
                int       ID      = Convert.ToInt32(dData.ID.Value);
                string    Records = WebApiServiceClass.DeleteTargetAppsByID(ID);
                UserLogin lu      = new UserLogin();
                lu = (UserLogin)System.Web.HttpContext.Current.Session["User"];
                MyScheduler.SetTimer(lu.ID);
            }
            catch (Exception ex)
            {
            }
        }
示例#27
0
        private static void ClockChanged_FalsePositive_Callback()
        {
            var provider = new MyPlatformEnlightenmentProvider();

            PlatformEnlightenmentProvider.Current = provider;

            var scm = (ClockChanged)provider.GetService <INotifySystemClockChanged>();

            var cal = provider._cal;
            var now = new DateTimeOffset(2012, 4, 25, 12, 0, 0, TimeSpan.Zero);
            var rel = TimeSpan.FromMinutes(1);
            var due = now + rel;

            var s = new MyScheduler();

            s.SetTime(now);

            var done = false;

            s.Schedule(due, () => { done = true; });

            Assert.Equal(1, cal._queue.Count);

            s.SetTime(now);
            scm.OnSystemClockChanged();

            var work = cal._queue.Deq();

            Assert.True(work.Interval < rel);

            s.SetTime(s.Now + work.Interval);
            work.Value._action(work.Value._state);

            Assert.Equal(1, s._queue.Count);

            var next = s._queue.Deq();

            Assert.True(s.Now + next.DueTime == due);

            s.SetTime(due);
            next.Invoke();

            Assert.True(done);
        }
示例#28
0
        public void SaveTargetApps()
        {
            StreamReader maReader = new StreamReader(Request.InputStream);
            string       strOBJ   = maReader.ReadToEnd();
            dynamic      dData    = (dynamic)JsonConvert.DeserializeObject(strOBJ);

            try
            {
                int ID = Convert.ToInt32(dData.JsonForm.ID);

                TargetApps u = new TargetApps();
                u.ID           = ID;
                u.Name         = dData.JsonForm.Name.ToString();
                u.IntervalType = dData.JsonForm.IntervalType.ToString();
                u.TargetUrl    = dData.JsonForm.TargetUrl.ToString();
                u.TimeInterval = Convert.ToInt32(dData.JsonForm.TimeInterval);
                u.UserLoginID  = ((UserLogin)System.Web.HttpContext.Current.Session["User"]).ID;

                Uri  uriResult;
                bool result = Uri.TryCreate(u.TargetUrl, UriKind.Absolute, out uriResult) &&
                              (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

                if (!result)
                {
                    return;
                }

                if (ID == 0)
                {
                    WebApiServiceClass.NewTargetApps(u);
                }
                else
                {
                    WebApiServiceClass.UpdateTargetApps(u);
                }
                UserLogin lu = new UserLogin();
                lu = (UserLogin)System.Web.HttpContext.Current.Session["User"];

                MyScheduler.SetTimer(lu.ID);
            }
            catch (Exception ex)
            {
            }
        }
示例#29
0
        public void OnCompleted_3()
        {
            var           scheduler     = new MyScheduler();
            TaskScheduler ran_scheduler = null;

            var t = Task.Factory.StartNew(() => {
                var mre = new ManualResetEvent(false);

                a.OnCompleted(() => {
                    ran_scheduler = TaskScheduler.Current;
                    mre.Set();
                });

                mre.WaitOne(1000);
            }, CancellationToken.None, TaskCreationOptions.None, scheduler);

            Assert.IsTrue(t.Wait(1000), "#1");
            Assert.AreEqual(scheduler, ran_scheduler, "#2");
        }
示例#30
0
        public void ObserveOn_Scheduler_OnNextThrows()
        {
            var e = new ManualResetEvent(false);

            var scheduler = new MyScheduler(e);

            Observable.Range(0, 10, Scheduler.Default).ObserveOn(scheduler).Subscribe(
                x =>
            {
                if (x == 5)
                {
                    throw new Exception();
                }
            }
                );

            e.WaitOne();
            Assert.NotNull(scheduler._exception);
        }
示例#31
0
		public void OnCompleted_3 ()
		{
			var scheduler = new MyScheduler ();
			TaskScheduler ran_scheduler = null;

			var t = Task.Factory.StartNew (() => {
				var mre = new ManualResetEvent (false);

				a.OnCompleted (() => {
					ran_scheduler = TaskScheduler.Current;
					mre.Set ();
				});

				mre.WaitOne (1000);

			}, CancellationToken.None, TaskCreationOptions.None, scheduler);

			Assert.IsTrue (t.Wait (1000), "#1");
			Assert.AreEqual (scheduler, ran_scheduler, "#2");
		}