Esempio n. 1
0
        public void UpdateProcess(NodeControl updated)
        {
            Action visible = () => { PBarCanvas.Dispatcher.Invoke(() => { PBarCanvas.Visibility = System.Windows.Visibility.Visible; }); };
            Action hide    = () => { PBarCanvas.Dispatcher.Invoke(() => { PBarCanvas.Visibility = System.Windows.Visibility.Hidden; }); };

            Action <int> add = (x) => { Progress.Dispatcher.Invoke(() => { Progress.Value += Progress.Maximum / x; }); };

            Progress.Value = 0;

            Action act = () =>
            {
                List <Action> acts = null;
                visible();
                Thread.Sleep(5);
                Dispatcher.Invoke(() => { acts = updateProcess(updated); });


                foreach (var a in acts)
                {
                    a();
                    add(acts.Count);
                    Thread.Sleep(5);
                }
                hide();
            };

            Sheduler.DoIt(act);
        }
Esempio n. 2
0
        public void Sheduler_Throw_ArgumentException()
        {
            //Act
            var rs = new Sheduler();


            //Assert
            ExceptionAssert.Throws <ArgumentNullException>(() => rs.SheduleSession(null, new DateTime(), 0));
        }
Esempio n. 3
0
        public void Sheduler_IsProgramSheduled()
        {
            //Arrange
            var sheduled = new Sheduler();
            var date     = new DateTime(2016, 2, 1, 9, 0, 0);
            var session  = new List <Session>
            {
                new Session()
                {
                    Duration = 30, Title = "A1"
                },
                new Session()
                {
                    Duration = 30, Title = "A2"
                },
                new Session()
                {
                    Duration = 30, Title = "A3"
                },
                new Session()
                {
                    Duration = 30, Title = "A4"
                },
                new Session()
                {
                    Duration = 30, Title = "A5"
                },
                new Session()
                {
                    Duration = 30, Title = "A6"
                },
                new Session()
                {
                    Duration = 30, Title = "A7"
                },
                new Session()
                {
                    Duration = 30, Title = "A8"
                },
            };

            //Act

            var result = sheduled.SheduleSession(session, date, 180);

            //Assert
            Assert.IsTrue(result.FirstOrDefault().StartTime == date);


            var secondItem   = result.Skip(1).FirstOrDefault();
            var expectedTime = date.AddMinutes(secondItem.Duration);

            Assert.IsTrue(secondItem.StartTime == expectedTime);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            if (!TryParse(args))
            {
                return;
            }
            Sheduler sheduler = new Sheduler(args[0], Int32.Parse(args[1]), Int32.Parse(args[2]));
            Thread   monitor  = new Thread(sheduler.Startcycle);

            monitor.IsBackground = true;
            monitor.Start();
            Console.ReadLine();
        }
Esempio n. 5
0
        public void Sheduler_StartTimeIsSheduled()
        {
            //Arrange
            var result  = new Sheduler();
            var date    = new DateTime(2016, 2, 1, 9, 0, 0);
            var session = new List <Session>
            {
                new Session()
                {
                    Duration = 30, Title = "A1"
                },
                new Session()
                {
                    Duration = 30, Title = "A2"
                },
                new Session()
                {
                    Duration = 30, Title = "A3"
                },
                new Session()
                {
                    Duration = 30, Title = "A4"
                },
                new Session()
                {
                    Duration = 30, Title = "A5"
                },
                new Session()
                {
                    Duration = 30, Title = "A6"
                },
                new Session()
                {
                    Duration = 30, Title = "A7"
                },
                new Session()
                {
                    Duration = 30, Title = "A8"
                },
            };

            //Act

            var sheduler = result.SheduleSession(session, date, 180);

            //Assert
            Assert.IsTrue(sheduler.FirstOrDefault().StartTime == date);
        }
Esempio n. 6
0
        protected override void OnStart(string[] args)
        {
            Sheduler sheduler = new Sheduler();

            // программа создания списка задач
            var si = new ScheduleItem
            {
                Task = new TaskRebuildDatabaseIndex(
                    @"Provider = SQLOLEDB.1; Persist Security Info = False; User ID = admin; Initial Catalog = Общепит_ЖД; Data Source = PAUL-PC"),
                Regularity = new WeeklyRegularity()
            };

            ((WeeklyRegularity)(si.Regularity)).SetTime(13, 0);
            ((WeeklyRegularity)(si.Regularity)).AddWeekDay(DayOfWeek.Friday);
            sheduler.AddSchedule(si);

            sheduler.Run();
        }
Esempio n. 7
0
        private static bool CorrectTime(Sheduler sheduler)
        {
            bool cng = false;

            if (sheduler == null)
            {
                return(false);
            }
            if (!sheduler.NextRun.HasValue)
            {
                return(false);
            }
            if (sheduler.NextRun.Value <= DateTime.Now)
            {
                sheduler.UpdateShedule();
                cng = true;
            }
            return(cng);
        }
Esempio n. 8
0
        /// <summary>
        /// Инициализация бота
        /// </summary>
        public static void Main(string[] args)
        {
            /// Инициализация шедулера
            var sheduler = new Sheduler(Bot);

            Thread tr = new Thread(sheduler.Run);

            tr.Start();

            var me = Bot.GetMeAsync().Result;

            Console.Title = me.Username;

            Bot.OnMessage       += BotOnMessageReceived;
            Bot.OnMessageEdited += BotOnMessageReceived;
            Bot.OnReceiveError  += BotOnReceiveError;

            Bot.StartReceiving(Array.Empty <UpdateType>());
            Console.WriteLine($"Start listening for @{me.Username}");
            Console.ReadLine();
            Bot.StopReceiving();
        }
        public void TestSheduler()
        {
            Sheduler instance = new Sheduler();

            Event[]      events = { new Event(0, 3), new Event(0, 1), new Event(1,  2), new Event(3, 5),
                                    new Event(1,      3), new Event(1, 3), new Event(1,  3), new Event(3, 6),
                                    new Event(2,      7), new Event(2, 3), new Event(2,  7), new Event(7, 9),
                                    new Event(3,      5), new Event(2, 4), new Event(2,  3), new Event(3, 7),
                                    new Event(4,      5), new Event(6, 7), new Event(6,  9), new Event(7, 9),
                                    new Event(8,      9), new Event(4, 6), new Event(8, 10), new Event(7, 10) };
            List <Event> testValues = new List <Event> {
                new Event(0, 1), new Event(1, 2), new Event(2, 3), new Event(3, 5),
                new Event(6, 7), new Event(8, 9)
            };

            List <Event> result = instance.GetOptimalSheduler(events, 0, 10);

            for (var i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(result[i], testValues[i]);
            }
        }
Esempio n. 10
0
 protected SchedulingEntity(int id)
 {
     _id = id;
     using (ISession session = NHibernateHelper.SessionManager.GetSessionFor <WebEnvironmentFiact>().SessionFactory.OpenSession())
     {
         Sheduler sheduler       = session.Get <TSheduler>(id);
         var      isSynchronized = CorrectTime(sheduler);
         DateTime?fixedTime      = sheduler.NextRun;
         if (isSynchronized || !fixedTime.HasValue)
         {
             session.Save(sheduler);
             session.Flush();
             if (!fixedTime.HasValue)
             {
                 return;
             }
         }
         TimeSpan launch = fixedTime.Value.Subtract(DateTime.Now);
         State  = TaskExecutionType.Idle;
         _heart = new ScheduleInstance(launch);
     }
     _heart.Tripped   += InstanceTripped;
     _heart.Completed += (obj, args) => OnCompleted(this, args);
 }
Esempio n. 11
0
        //Загрузка библиотеки нодов и постройка списка
        private void LoadNodesLibrary()
        {
            Sheduler.Start();
            NodeLibrary.InitializeLibrary();

            var categories = NodeLibrary.Nodes.Select(x => x.Category).Distinct().ToList();

            foreach (var cat in categories)
            {
                var incCat = cat.Split(new char[] { '/' });

                var          tvs    = NodesPanel.Items.OfType <TreeViewItem>().Where(x => ((string)x.Header) == incCat[0]);
                var          asdq   = NodesPanel.Items.OfType <TreeViewItem>();
                TreeViewItem tvitem = tvs.Count() > 0 ? tvs.First() : null;

                if (tvitem == null)
                {
                    tvitem = new TreeViewItem()
                    {
                        Header = incCat[0], Margin = new Thickness(0, 5, 10, 5)
                    };
                    NodesPanel.Items.Add(tvitem);
                }


                var nodes = NodeLibrary.Nodes.Where(x => x.Category == incCat[0]);
                foreach (var node in nodes)
                {
                    if (tvitem.Items.OfType <Label>().Where(x => ((string)x.Content) == node.NCName).Count() != 0)
                    {
                        continue;
                    }
                    tvitem.Items.Add(new Label()
                    {
                        Content = node.NCName, Margin = new Thickness(0, 0, 10, 0)
                    });
                }

                string path   = incCat[0];
                var    preTvi = tvitem;

                for (int i = 1; i < incCat.Length; i++)
                {
                    path += "/" + incCat[i];
                    var          tvis = preTvi.Items.OfType <TreeViewItem>().Where(x => ((string)x.Header) == path);
                    TreeViewItem tvi  = tvis.Count() > 0 ? tvis.First() : null;
                    if (tvi == null)
                    {
                        tvi = new TreeViewItem()
                        {
                            Header = incCat[i], Margin = new Thickness(0, 5, 10, 5)
                        };
                        preTvi.Items.Add(tvi);
                    }

                    var catNodes = NodeLibrary.Nodes.Where(x => x.Category == path);
                    foreach (var node in catNodes)
                    {
                        if (tvi.Items.OfType <Label>().Where(x => (string)x.Content == node.NCName).Count() != 0)
                        {
                            continue;
                        }
                        tvi.Items.Add(new Label()
                        {
                            Content = node.NCName, Margin = new Thickness(0, 0, 10, 0)
                        });
                    }

                    preTvi = tvi;
                }
            }
        }
Esempio n. 12
0
        private void InstanceTripped(SchedulingEventArg arg)
        {
            lock (_heart)
            {
                Sheduler sheduler = null;
                using (
                    ISession session =
                        NHibernateHelper.SessionManager.GetSessionFor <WebEnvironmentFiact>().SessionFactory.OpenSession()
                    )
                {
                    try
                    {
                        sheduler = session.Get <TSheduler>(_id);
                        if (sheduler == null)
                        {
                            arg.Interval = -1;
                            return;
                        }
                        if (_cancelTokSource != null)
                        {
                            arg.Interval = -1;
                            return;
                        }
                        State              = TaskExecutionType.Running;
                        sheduler.LastRun   = _heart.LastRun;
                        sheduler.Iteration = _heart.CountLaunches;
                        _cancelTokSource   = new CancellationTokenSource();

                        _status = new StatusTask
                        {
                            StartRun     = DateTime.Now,
                            EndRun       = null,
                            Error        = null,
                            Sheduler     = session.Get <Sheduler>(Id),
                            TaskExecType = TaskExecType.Running
                        };

                        session.Save(_status);
                        _recId = _status.Id;
                        var  keyPair = new KeyValuePair <int, CancellationToken>(_status.Id, _cancelTokSource.Token);
                        Task task    = null;
                        try
                        {
                            task = Task.Factory.StartNew(x =>
                            {
                                var key =
                                    (KeyValuePair <int, CancellationToken>)x;
                                if (!key.Value.IsCancellationRequested)
                                {
                                    var t = new Thread(DoWork);
                                    t.Start(key.Key);
                                    while (t.IsAlive &&
                                           !key.Value.IsCancellationRequested)
                                    {
                                    }
                                    if (t.IsAlive)
                                    {
                                        t.Abort();
                                    }
                                }
                            }, keyPair, _cancelTokSource.Token);
                            if (sheduler.IsKill && sheduler.Runtime.HasValue)
                            {
                                task.Wait(new TimeSpan(0, sheduler.Runtime.Value, 0));
                                if (task.IsCompleted && _cancelTokSource != null &&
                                    !_cancelTokSource.IsCancellationRequested)
                                {
                                    State = TaskExecutionType.Succeed;
                                }
                                else if (task.Status != TaskStatus.Canceled && task.Status != TaskStatus.RanToCompletion &&
                                         task.Status != TaskStatus.Faulted)
                                {
                                    _cancelTokSource.Cancel();
                                    State = TaskExecutionType.Failure;
                                }
                                else
                                {
                                    State = TaskExecutionType.Failure;
                                }
                            }
                            else
                            {
                                task.Wait();
                                if (task.IsCompleted && _cancelTokSource != null &&
                                    !_cancelTokSource.IsCancellationRequested)
                                {
                                    State = TaskExecutionType.Succeed;
                                }
                                else
                                {
                                    State = TaskExecutionType.Failure;
                                }
                            }
                            Task.WaitAll(new[] { task });
                            if (task.Status != TaskStatus.Canceled && task.Status != TaskStatus.RanToCompletion &&
                                task.Status != TaskStatus.Faulted)
                            {
                                task.Dispose();
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (AggregateException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            State = TaskExecutionType.Failure;
                            Thread.ResetAbort();
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        finally
                        {
                            if (task != null && task.Status != TaskStatus.RanToCompletion)
                            {
                                Task.WaitAll(new[] { task });
                                if (task.Status != TaskStatus.Canceled &&
                                    task.Status != TaskStatus.Faulted)
                                {
                                    task.Dispose();
                                }
                            }
                        }
                    }
                    catch
                    {
                        State = TaskExecutionType.Failure;
                    }

                    finally
                    {
                        if (sheduler != null)
                        {
                            if (_status != null)
                            {
                                session.Refresh(_status);
                                _status = session.Get <StatusTask>(_recId);
                                if (_status.TaskExecType != TaskExecType.Failure)
                                {
                                    _status.TaskExecType =
                                        (TaskExecType)Enum.Parse(typeof(TaskExecType), ((int)State).ToString());
                                    _status.EndRun = DateTime.Now;
                                    session.Save(_status);
                                }
                            }
                            sheduler.Duration = _heart.LastDuration;
                            sheduler.UpdateShedule();

                            DateTime?next = sheduler.NextRun;
                            arg.Interval = !next.HasValue
                                               ? -1
                                               : (long)next.Value.Subtract(DateTime.Now).TotalMilliseconds;
                            if (IsRemove)
                            {
                                arg.Interval = -1;
                            }
                            sheduler.IsEnabled = next.HasValue;
                            session.Save(sheduler);
                            session.Flush();
                            _cancelTokSource = null;
                            _status          = null;
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public ActionResult Index(int?id, string type)
        {
            SchedulerModel model;

            try
            {
                if (id.HasValue)
                {
                    _shaper = Db <WebEnvironmentFiact> .NSession.Get <Sheduler>(id);
                }
                else
                {
                    switch (type)
                    {
                    case "import":
                        _shaper = new ImportSheduling();
                        break;

                    case "export":
                        _shaper = new ExportSheduling();
                        break;

                    case "eitp_hour":
                        _shaper = new EitpHourScheduling();
                        break;

                    case "eitp_daily":
                        _shaper = new EitpDailyScheduling();
                        break;

                    default:
                        _shaper = new MoreSheduling();
                        break;
                    }
                }
                model             = LoadSheduling(_shaper.Frequency);
                model.Type        = _shaper.Type;
                model.IsEnabled   = _shaper.IsEnabled;
                model.Name        = _shaper.Name;
                model.IsKill      = _shaper.IsKill;
                model.Runtime     = _shaper.Runtime;
                model.Param       = _shaper.Param;
                model.TimeGetData = _shaper.TimeGetData;
                if (_shaper.Frequency is SingleLanchFrequency)
                {
                    model.FrequencyType = 0;
                }
                else
                {
                    model.FrequencyType = 1;
                }
                model.Id = _shaper.Id;
                LoadEntity(model);
            }
            catch (Exception e)
            {
                model = new SchedulerModel();
            }

            return(View(model));
        }
Esempio n. 14
0
        public ActionResult Index(SchedulerModel model)
        {
            var session = Db <WebEnvironmentFiact> .NSession;

            if (model.Id == 0)
            {
                switch (model.Type)
                {
                case "import":
                    _shaper = new ImportSheduling();
                    break;

                case "export":
                    _shaper = new ExportSheduling();
                    break;

                default:
                    _shaper = new MoreSheduling();
                    break;
                }
            }
            else
            {
                _shaper = session.Get <Sheduler>(model.Id);
                try
                {
                    using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
                    {
                        IImportAxapta channel = factory.CreateChannel();
                        var           id      = _shaper.Id;
                        channel.RemoveShedule(id);
                    }
                    Thread.Sleep(2000);
                }catch (Exception e)
                {
                }
            }

            _shaper.IsEnabled   = model.IsEnabled;
            _shaper.IsKill      = model.IsKill;
            _shaper.Runtime     = model.Runtime;
            _shaper.Param       = model.Param;
            _shaper.TimeGetData = model.TimeGetData;
            _shaper.Name        = model.Name;
            SheduleFrequencyProperty oldFreq = _shaper.Frequency;

            session.Delete(oldFreq);
            _shaper.Frequency = ApplySheduling(model);
            _shaper.UpdateShedule();
            model           = LoadSheduling(_shaper.Frequency);
            model.IsEnabled = _shaper.IsEnabled;

            model.Name = _shaper.Name;
            if (_shaper.Frequency is SingleLanchFrequency)
            {
                model.FrequencyType = 0;
            }
            else
            {
                model.FrequencyType = 1;
            }
            model.Id          = _shaper.Id;
            model.Runtime     = _shaper.Runtime;
            model.IsKill      = _shaper.IsKill;
            model.Param       = _shaper.Param;
            model.TimeGetData = _shaper.TimeGetData;
            LoadEntity(model);
            ModelState.Clear();
            session.Save(_shaper);
            session.Flush();
            if (_shaper.IsEnabled)
            {
                try
                {
                    using (var factory = new ChannelFactory <IImportAxapta>("MyImportAxapta"))
                    {
                        IImportAxapta channel = factory.CreateChannel();
                        channel.AddShedule(_shaper.Id);
                    }
                }catch (Exception e)
                {
                }
            }
            return(View(model));
        }
Esempio n. 15
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var a = new Sheduler();

            a.Start(target.Text);
        }
Esempio n. 16
0
 public GameScreen(SpriteBatch window) : base(window)
 {
     sheduler = new Sheduler();
     game     = new GameCore(window);
 }