Exemple #1
0
        public virtual void Deserialize(GenericReader reader)
        {
            int version = reader.GetVersion();

            switch (version)
            {
            case 0:
            {
                _Info = reader.ReadTypeCreate <ScheduleInfo>(reader) ?? new ScheduleInfo();

                _Enabled         = reader.ReadBool();
                _Name            = reader.ReadString();
                _DefaultPriority = reader.ReadFlag <TimerPriority>();

                if (reader.ReadBool())
                {
                    _LastGlobalTick = reader.ReadDateTime();
                }

                if (reader.ReadBool())
                {
                    _NextGlobalTick = reader.ReadDateTime();
                }

                Delay    = reader.ReadTimeSpan();
                Interval = reader.ReadTimeSpan();
            }
            break;
            }

            Start();
        }
Exemple #2
0
 public static Schedule CreateSchedule(
     string name,
     bool enabled              = true,
     bool register             = true,
     ScheduleInfo info         = null,
     Action <Schedule> handler = null)
 {
     return(CreateSchedule <Schedule>(name, enabled, register, info, handler));
 }
Exemple #3
0
        public virtual void Deserialize(GenericReader reader)
        {
            var version = reader.GetVersion();

            if (version > 2)
            {
                UID = new CryptoHashCode(reader);
            }
            else
            {
                UID = new CryptoHashCode(CryptoHashType.MD5, TimeStamp.Now + "+" + Utility.RandomDouble());
            }

            switch (version)
            {
            case 3:
            case 2:
            case 1:
            case 0:
            {
                if (version < 2)
                {
                    _Info = reader.ReadTypeCreate <ScheduleInfo>(reader) ?? new ScheduleInfo();
                }
                else
                {
                    _Info = reader.ReadBlock(r => r.ReadTypeCreate <ScheduleInfo>(r)) ?? new ScheduleInfo();
                }

                _Enabled         = reader.ReadBool();
                _Name            = reader.ReadString();
                _DefaultPriority = reader.ReadFlag <TimerPriority>();

                if (reader.ReadBool())
                {
                    _LastGlobalTick = reader.ReadDateTime();
                }

                if (reader.ReadBool())
                {
                    _NextGlobalTick = reader.ReadDateTime();
                }

                Delay    = reader.ReadTimeSpan();
                Interval = reader.ReadTimeSpan();
            }
            break;
            }

            InvalidateNextTick();

            if (version > 0)
            {
                Running = reader.ReadBool();
            }
        }
Exemple #4
0
        public static TSchedule CreateSchedule <TSchedule>(
            string name, bool enabled = true, bool register = true, ScheduleInfo info = null, Action <Schedule> handler = null)
            where TSchedule : Schedule
        {
            var st = VitaNexCore.TryCatchGet(() => typeof(TSchedule).CreateInstance <TSchedule>(name, enabled, info, handler));

            if (st != null && register)
            {
                st.Register();
            }

            return(st);
        }
Exemple #5
0
        public Schedule(string name, bool enabled, ScheduleInfo info, Action <Schedule> onTick = null)
            : base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
        {
            _Enabled = enabled;
            _Name    = name;
            _Info    = info;

            UpdateTicks(DateTime.UtcNow);

            if (onTick != null)
            {
                OnGlobalTick += onTick;
            }

            Start();
        }
Exemple #6
0
        public virtual void Deserialize(GenericReader reader)
        {
            var version = reader.GetVersion();

            switch (version)
            {
            case 2:
            case 1:
            case 0:
            {
                if (version < 2)
                {
                    _Info = reader.ReadTypeCreate <ScheduleInfo>(reader) ?? new ScheduleInfo();
                }
                else
                {
                    reader.ReadBlock(r => _Info = r.ReadTypeCreate <ScheduleInfo>(r) ?? new ScheduleInfo());
                }

                _Enabled         = reader.ReadBool();
                _Name            = reader.ReadString();
                _DefaultPriority = reader.ReadFlag <TimerPriority>();

                if (reader.ReadBool())
                {
                    _LastGlobalTick = reader.ReadDateTime();
                }

                if (reader.ReadBool())
                {
                    _NextGlobalTick = reader.ReadDateTime();
                }

                Delay    = reader.ReadTimeSpan();
                Interval = reader.ReadTimeSpan();
            }
            break;
            }

            if (version > 0)
            {
                Running = reader.ReadBool();
            }
        }
Exemple #7
0
        public Schedule(string name, bool enabled, ScheduleInfo info, params Action <Schedule>[] onTick)
            : base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
        {
            _Enabled = enabled;
            _Name    = name ?? String.Empty;
            _Info    = info ?? new ScheduleInfo();

            UpdateTicks(DateTime.UtcNow);

            if (onTick != null)
            {
                foreach (var a in onTick)
                {
                    OnGlobalTick += a;
                }
            }

            Start();
        }
Exemple #8
0
        public Schedule(string name, bool enabled, ScheduleInfo info, params Action <Schedule>[] onTick)
            : base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
        {
            UID = new CryptoHashCode(CryptoHashType.MD5, TimeStamp.Now + "+" + Utility.RandomDouble());

            _Enabled = enabled;
            _Name    = name ?? String.Empty;
            _Info    = info ?? new ScheduleInfo();

            Instances.Add(this);

            UpdateTicks(Now);

            if (onTick != null)
            {
                foreach (var a in onTick)
                {
                    OnGlobalTick += a;
                }
            }

            Start();
        }
Exemple #9
0
		public virtual void Deserialize(GenericReader reader)
		{
			var version = reader.GetVersion();

			switch (version)
			{
				case 2:
				case 1:
				case 0:
				{
					if (version < 2)
					{
						_Info = reader.ReadTypeCreate<ScheduleInfo>(reader) ?? new ScheduleInfo();
					}
					else
					{
						reader.ReadBlock(r => _Info = r.ReadTypeCreate<ScheduleInfo>(r) ?? new ScheduleInfo());
					}

					_Enabled = reader.ReadBool();
					_Name = reader.ReadString();
					_DefaultPriority = reader.ReadFlag<TimerPriority>();

					if (reader.ReadBool())
					{
						_LastGlobalTick = reader.ReadDateTime();
					}

					if (reader.ReadBool())
					{
						_NextGlobalTick = reader.ReadDateTime();
					}

					Delay = reader.ReadTimeSpan();
					Interval = reader.ReadTimeSpan();
				}
					break;
			}

			if (version > 0)
			{
				Running = reader.ReadBool();
			}
		}
Exemple #10
0
		public Schedule(string name, bool enabled, ScheduleInfo info, params Action<Schedule>[] onTick)
			: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
		{
			_Enabled = enabled;
			_Name = name ?? String.Empty;
			_Info = info ?? new ScheduleInfo();

			UpdateTicks(DateTime.UtcNow);

			if (onTick != null)
			{
				foreach (var a in onTick)
				{
					OnGlobalTick += a;
				}
			}

			Start();
		}
Exemple #11
0
		public virtual void Deserialize(GenericReader reader)
		{
			int version = reader.GetVersion();

			switch (version)
			{
				case 1:
				case 0:
					{
						_Info = reader.ReadTypeCreate<ScheduleInfo>(reader) ?? new ScheduleInfo(reader);

						_Enabled = reader.ReadBool();
						_Name = reader.ReadString();
						_DefaultPriority = reader.ReadFlag<TimerPriority>();

						if (reader.ReadBool())
						{
							_LastGlobalTick = reader.ReadDateTime();
						}

						if (reader.ReadBool())
						{
							_NextGlobalTick = reader.ReadDateTime();
						}

						Delay = reader.ReadTimeSpan();
						Interval = reader.ReadTimeSpan();
					}
					break;
			}

			if (version < 1)
			{
				return;
			}

			if (reader.ReadBool() && _Enabled)
			{
				Running = true;
			}
		}
Exemple #12
0
		public Schedule(string name, bool enabled, ScheduleInfo info, Action<Schedule> onTick = null)
			: base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
		{
			_Enabled = enabled;
			_Name = name;
			_Info = info;

			UpdateTicks(DateTime.UtcNow);

			if (onTick != null)
			{
				OnGlobalTick += onTick;
			}

			Start();
		}