private DateTime GetNextExecutionDateTime(TimerDefinition timerDefinition)
        {
            switch (timerDefinition.Type)
            {
            case TimerType.Date:
                var date1 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                return(date1.Date);

            case TimerType.DateAndTime:
                var date2 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                return(date2);

            case TimerType.Interval:
                var interval = Int32.Parse(timerDefinition.Value);
                return(_runtime.RuntimeDateTimeNow.AddMilliseconds(interval));

            case TimerType.Time:
                var now   = _runtime.RuntimeDateTimeNow;
                var date3 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                date3 = now.Date + date3.TimeOfDay;
                if (date3.TimeOfDay < now.TimeOfDay)
                {
                    date3 = date3.AddDays(1);
                }
                return(date3);
            }

            return(_runtime.RuntimeDateTimeNow);
        }
 private void Tick(object state)
 {
     if (0 >= timerCallbacks.Count) return;
     callbackLock.EnterUpgradeableReadLock();
     try
     {
         var entries = timerCallbacks.First();
         callbackLock.EnterWriteLock();
         try
         {
             var vals = new TimerDefinition[entries.Value.Count];
             entries.Value.CopyTo(vals);
             foreach (var entry in vals)
             {
                 entry.Callback.Invoke();
                 AddDefinition(entry,
                     Timeout.Infinite == entry.Interval
                     ? Timeout.InfiniteTimeSpan
                     : TimeSpan.FromMilliseconds(entry.Interval));
             }
             timerCallbacks.Remove(entries.Key);
             ResetMain();
         }
         finally
         {
             callbackLock.ExitWriteLock();
         }
     }
     finally
     {
         callbackLock.ExitUpgradeableReadLock();
     }
 }
Exemple #3
0
        private DateTime GetNextExecutionDateTime(TimerDefinition timerDefinition)
        {
            switch (timerDefinition.Type)
            {
            case TimerType.Date:
                var date1 = DateTime.ParseExact(timerDefinition.Value,
                                                _runtime.SchemeParsingCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture);
                return(date1.Date);

            case TimerType.DateAndTime:
                var date2 = DateTime.ParseExact(timerDefinition.Value,
                                                (string.Format("{0} {1}", _runtime.SchemeParsingCulture.DateTimeFormat.ShortDatePattern,
                                                               _runtime.SchemeParsingCulture.DateTimeFormat.LongTimePattern)), CultureInfo.InvariantCulture);
                return(date2);

            case TimerType.Interval:
                var interval = Int32.Parse(timerDefinition.Value);
                return(_runtime.RuntimeDateTimeNow.AddMilliseconds(interval));

            case TimerType.Time:
                var now   = _runtime.RuntimeDateTimeNow;
                var date3 = DateTime.ParseExact(timerDefinition.Value, _runtime.SchemeParsingCulture.DateTimeFormat.LongTimePattern, CultureInfo.InvariantCulture);
                if (date3 < now)
                {
                    date3 = date3.AddDays(1);
                }
                return(date3);
            }

            return(_runtime.RuntimeDateTimeNow);
        }
Exemple #4
0
        private DateTime?GetNextExecutionDateTime(TimerDefinition timerDefinition, ProcessInstance processInstance = null)
        {
            var timerValueParameterName = GetTimerValueParameterName(timerDefinition);

            if (timerDefinition.Value.Equals(ImmediateTimerValue) || timerDefinition.Value.Equals(InfinityTimerValue))
            {
                if (processInstance == null)
                {
                    return(null);
                }

                if (!processInstance.IsParameterExisting(timerValueParameterName))
                {
                    return(null);
                }

                return(processInstance.GetParameter <DateTime?>(timerValueParameterName));
            }

            if (processInstance != null && processInstance.IsParameterExisting(timerValueParameterName))
            {
                var value = processInstance.GetParameter <DateTime?>(timerValueParameterName);
                if (value != null)
                {
                    return(value);
                }
            }

            switch (timerDefinition.Type)
            {
            case TimerType.Date:
                var date1 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                return(date1.Date);

            case TimerType.DateAndTime:
                var date2 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                return(date2);

            case TimerType.Interval:
                var interval = GetInterval(timerDefinition.Value);
                if (interval <= 0)
                {
                    return(null);
                }
                return(_runtime.RuntimeDateTimeNow.AddMilliseconds(interval));

            case TimerType.Time:
                var now   = _runtime.RuntimeDateTimeNow;
                var date3 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture);
                date3 = now.Date + date3.TimeOfDay;
                if (date3.TimeOfDay < now.TimeOfDay)
                {
                    date3 = date3.AddDays(1);
                }
                return(date3);
            }

            return(_runtime.RuntimeDateTimeNow);
        }
        private void AddDefinition(TimerDefinition definition, TimeSpan dueIn)
        {
            var dueAt = dueIn == Timeout.InfiniteTimeSpan ? DateTime.MaxValue : DateTime.Now + dueIn;

            if (!timerCallbacks.TryGetValue(dueAt, out var existing))
            {
                existing = new List <TimerDefinition>();
                timerCallbacks.Add(dueAt, existing);
            }
            existing.Add(definition);
        }
Exemple #6
0
        public void UpdateTimer(Guid processId, TimerDefinition timerDefinition)
        {
            if (timerDefinition.Type != TimerType.ByProcessInstance)
            {
                throw new NotSupportedException();
            }
            var intervalSeconds      = (int)Math.Floor(timerDefinition.IntervalTimeInMilliseconds / (double)1000);
            var intervalMilliseconds = timerDefinition.IntervalTimeInMilliseconds - intervalSeconds * 1000;
            var interval             = new TimeSpan(0, 0, 0, intervalSeconds, intervalMilliseconds);

            SetTimer(processId, interval, timerDefinition.Name);
        }
Exemple #7
0
        private TimerDefinition MakeDefinition(Action callback, int timeout, int interval, int id, out TimeSpan dueIn)
        {
            var definition = new TimerDefinition
            {
                Id       = id,
                Callback = callback,
                Interval = interval
            };

            dueIn = timeout == Timeout.Infinite
                ? (interval == Timeout.Infinite ? TimeSpan.MaxValue : TimeSpan.FromMilliseconds(interval))
                : TimeSpan.FromMilliseconds(timeout);
            return(definition);
        }
Exemple #8
0
        public override IEnumerable <TimerDefinition> ParseTimers(XElement schemeMedium)
        {
            if (schemeMedium == null)
            {
                throw new ArgumentNullException("schemeMedium");
            }

            var timersElement = schemeMedium.SingleOrDefault("Timers");

            if (timersElement == null)
            {
                throw new ArgumentNullException("");
            }

            return(timersElement.Elements().ToList().Select(element => TimerDefinition.Create(GetName(element), GetType(element), GetDelay(element), GetInterval(element))).ToList());
        }
        public CustomTimersManagerEditForm([NotNull] IWurmApi wurmApi, [NotNull] TimerDefinition definition,
                                           [NotNull] TimerDefinitions timerDefinitions)
        {
            if (wurmApi == null)
            {
                throw new ArgumentNullException("wurmApi");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            if (timerDefinitions == null)
            {
                throw new ArgumentNullException("timerDefinitions");
            }
            this.wurmApi          = wurmApi;
            this.timerDefinitions = timerDefinitions;
            this.definition       = definition;

            InitializeComponent();

            foreach (var type in wurmApi.LogDefinitions.AllLogTypes)
            {
                comboBoxLogType.Items.Add(type);
            }
            comboBoxLogType.SelectedItem = LogType.Event;

            CustomTimerDefinition options = definition.CustomTimerConfig ?? new CustomTimerDefinition();

            textBoxTimerName.Text = definition.Name;
            if (options.TriggerConditions != null)
            {
                textBoxCond.Text = options.TriggerConditions[0].RegexPattern;
                if (!options.IsRegex)
                {
                    textBoxCond.Text = Regex.Unescape(textBoxCond.Text);
                }
                else
                {
                    checkBoxAsRegex.Checked = true;
                }
                comboBoxLogType.SelectedItem = options.TriggerConditions[0].LogType;
            }
            timeInputUControl2.Value    = options.Duration;
            checkBoxUptimeReset.Checked = options.ResetOnUptime;
        }
Exemple #10
0
 private void Tick(object state)
 {
     if (0 >= timerCallbacks.Count)
     {
         return;
     }
     callbackLock.EnterUpgradeableReadLock();
     try
     {
         var entries = timerCallbacks.First();
         callbackLock.EnterWriteLock();
         try
         {
             var vals = new TimerDefinition[entries.Value.Count];
             entries.Value.CopyTo(vals);
             foreach (var entry in vals)
             {
                 entry.Callback.Invoke();
                 AddDefinition(entry,
                               Timeout.Infinite == entry.Interval
                     ? Timeout.InfiniteTimeSpan
                     : TimeSpan.FromMilliseconds(entry.Interval));
             }
             timerCallbacks.Remove(entries.Key);
             ResetMain();
         }
         finally
         {
             callbackLock.ExitWriteLock();
         }
     }
     finally
     {
         callbackLock.ExitUpgradeableReadLock();
     }
 }
        public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
        {
            base.Initialize(parentGroup, player, definition);
            View.SetCooldown(pathCooldown);

            skillEntryParser = new SkillEntryParser(WurmApi);

            MoreOptionsAvailable = true;

            PerformAsyncInits();
        }
Exemple #12
0
 private string GetTimerValueParameterName(TimerDefinition timerDefinition)
 {
     return(GetTimerValueParameterName(timerDefinition.Name));
 }
Exemple #13
0
 public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
 {
     base.Initialize(parentGroup, player, definition);
     View.ShowSkill = true;
     VerifyMoneyAmountAgainstCd();
     UpdateMoneyCounter();
     InitCompleted = true;
 }
Exemple #14
0
        public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
        {
            base.Initialize(parentGroup, player, definition);
            View.SetCooldown(PrayCooldown);
            MoreOptionsAvailable = true;

            skillEntryParser = new SkillEntryParser(WurmApi);

            favorNotify = new FavorTimerNotify(this, Character, ServerGroupId, Logger, SoundManager, TrayPopups, skillEntryParser);

            View.UpdateSkill(FaithLevel);
            View.ShowSkill = ShowFaithSkillOnTimer;

            PerformAsyncInits();
        }
Exemple #15
0
        public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
        {
            base.Initialize(parentGroup, player, definition);
            View.SetCooldown(SermonPreacherCooldown);

            PerformAsyncInits();
        }
 private TimerDefinition MakeDefinition(Action callback, int timeout, int interval, int id, out TimeSpan dueIn)
 {
     var definition = new TimerDefinition
     {
         Id = id,
         Callback = callback,
         Interval = interval
     };
     dueIn = timeout == Timeout.Infinite
         ? (interval == Timeout.Infinite ? TimeSpan.MaxValue : TimeSpan.FromMilliseconds(interval))
         : TimeSpan.FromMilliseconds(timeout);
     return definition;
 }
 private void AddDefinition(TimerDefinition definition, TimeSpan dueIn)
 {
     List<TimerDefinition> existing;
     var dueAt = dueIn == Timeout.InfiniteTimeSpan ? DateTime.MaxValue : DateTime.Now + dueIn;
     if (!timerCallbacks.TryGetValue(dueAt, out existing))
     {
         existing = new List<TimerDefinition>();
         timerCallbacks.Add(dueAt, existing);
     }
     existing.Add(definition);
 }
        public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
        {
            base.Initialize(parentGroup, player, definition);
            View.SetCooldown(AlignmentCooldown);
            MoreOptionsAvailable = true;

            PerformAsyncInits();
        }
Exemple #19
0
        public override void Initialize(PlayerTimersGroup parentGroup, string player, TimerDefinition definition)
        {
            base.Initialize(parentGroup, player, definition);

            View.SetCooldown(ShortMeditCooldown);

            skillEntryParser = new SkillEntryParser(WurmApi);

            sleepNotify         = new SleepBonusNotify(Logger, SoundManager, TrayPopups, Character, "Can turn off sleep bonus now");
            sleepNotify.Enabled = SleepBonusReminder;

            View.UpdateSkill(MeditationSkill);
            View.ShowSkill      = ShowMeditSkill;
            View.ShowMeditCount = ShowMeditCount;

            MoreOptionsAvailable = true;
            PerformAsyncInits();
        }