Exemple #1
0
        private void OnDone(ScheduleCallData data, Guid?guid)
        {
            Type?type = Type.GetType(data.Type);

            if (type == null)
            {
                throw new Exception($"Invalid type {type}");
            }
            MethodInfo?method = type.GetMethod(data.Function);

            if (method == null)
            {
                throw new Exception($"Invalid method {method} in {type}");
            }
            object obj = CreateObject(type);

            if (obj == null)
            {
                throw new Exception($"Couldn't create {type} from services");
            }
            method.Invoke(obj, new object?[] { data.Data });
            if (guid != null)
            {
                Guid id = guid.Value;
                if (_database.Db.Schedules.ContainsKey(id))
                {
                    _database.Db.Schedules.Remove(id);
                    _database.WriteData();
                }
            }
        }
Exemple #2
0
        public void Add <T>(DateTime time, string func, string data)
        {
            string           typeName = typeof(T).FullName !;
            ScheduleCallData callData = new ScheduleCallData(typeName, func, data);

            Add(time, callData);
        }
Exemple #3
0
        public void Add(DateTime time, ScheduleCallData callData, bool writeData = true)
        {
            Guid     guid  = Guid.NewGuid();
            TimeSpan delay = time - DateTime.Now;

            if (delay.TotalMilliseconds < 0)
            {
                return;
            }
            Task.Delay(delay).ContinueWith(task => OnDone(callData, guid));
            _database.Db.Schedules.Add(guid, new SchedulerEntry(callData, time));
            if (writeData)
            {
                _database.WriteData();
            }
        }
Exemple #4
0
 public SchedulerEntry(ScheduleCallData callData, DateTime time)
 {
     CallData = callData;
     Time     = time;
 }