Example #1
0
        public async Task <bool> maybeAdd(Match match)
        {
            var now = DateTime.Now;
            var b   = await Task.Run(() =>
            {
                var needToSerialize = false;
                if (!AreSameSkirmish(SkirmishTime, now))
                {
                    SkirmishTime    = now;
                    SkirmishMatch   = match;
                    needToSerialize = true;
                }
                if (!AreSameTimezone(TimezoneTime, now))
                {
                    TimezoneTime    = now;
                    TimezoneMatch   = match;
                    needToSerialize = true;
                }
                if (((now - LastUpdateTime).TotalSeconds >= 60.0 || LastUpdateTime == DateTime.MinValue) &&
                    !match.IsEqualTo(Matches.First.Value.Value))
                {
                    if (Matches.Count == 61)
                    {
                        Matches.RemoveLast();
                    }
                    Matches.AddFirst(new KeyValuePair <DateTime, Match>(now, match));
                    needToSerialize = true;
                }
                if (needToSerialize)
                {
                    Serialize();
                }
                return(needToSerialize);
            });

            return(b);
        }