Пример #1
0
        /// <summary>
        ///     Cycle with checpoint scores
        /// </summary>
        /// <param name="cycleIdentifier"></param>
        /// <param name="timestampTicks"></param>
        /// <param name="scores"></param>
        public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, params KeyValuePair <int, CpScore>[] scores)
        {
            _timestampTicks = timestampTicks;
            Cycle           = cycleIdentifier;

            _scores = scores.ToDictionary(score => score.Key, val => val.Value);
        }
Пример #2
0
        /// <summary>
        ///     Cycle with checpoint scores
        /// </summary>
        /// <param name="cycleIdentifier"></param>
        /// <param name="timestampTicks"></param>
        /// <param name="scores"></param>
        public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, params KeyValuePair<int, CpScore>[] scores)
        {
            _timestampTicks = timestampTicks;
            Cycle = cycleIdentifier;

            _scores = scores.ToDictionary(score => score.Key, val=>val.Value);
        }
Пример #3
0
 protected CpStatus(CycleIdentifier cycle, int cp)
 {
     Cp = cp;
     //var localTime = new CheckPoint(cycle, cp).DateTime.ToLocalTime();
     //DateTime = localTime.ToShortDateString() + " " + localTime.ToShortTimeString();
     DateTime = new CheckPoint(cycle, cp).DateTime;
     Type     = this.GetType().ToString();
 }
Пример #4
0
 protected CpStatus(CycleIdentifier cycle, int cp)
 {
     Cp = cp;
     //var localTime = new CheckPoint(cycle, cp).DateTime.ToLocalTime();
     //DateTime = localTime.ToShortDateString() + " " + localTime.ToShortTimeString();
     DateTime = new CheckPoint(cycle, cp).DateTime;
     Type = GetType().ToString();
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     if (_timeStamps[cycle.Id] == timestampTicks)
     {
         //shouldn't need to update _cycleScores since the CycleScore is updated elsewhere. This method is for persisting somewhere
         _timeStamps[cycle.Id] = DateTimeOffset.Now.Ticks;
         return true;
     }
     return false;
 }
 public CycleScore GetScoreForCycle(CycleIdentifier cycle)
 {
     ScoreEntity scoreEntity;
     if (_cycleScoresCache.TryGetValue(cycle.Id, out scoreEntity))
     {
         return scoreEntity.CycleScore();
     }
     scoreEntity = ScoreForCycleFromStorage(cycle);
     _cycleScoresCache[cycle.Id] = scoreEntity;
     return scoreEntity.CycleScore();
 }
 public CycleScore GetScoreForCycle(CycleIdentifier cycle)
 {
     CycleScore cycleScore;
     if (!_cycleScores.TryGetValue(cycle.Id, out cycleScore))
     {
         var timestamp = DateTimeOffset.Now;
         cycleScore = new CycleScore(cycle, timestamp.Ticks);
         _timeStamps[cycle.Id] = timestamp.Ticks;
         _cycleScores[cycle.Id] = cycleScore;
     }
     return cycleScore;
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     var scoreEntity = _cycleScoresCache[cycle.Id];
     if (scoreEntity.Timestamp.Ticks != timestampTicks)//final check before we overwrite something we didn't mean to
     {
         return false;
     }
     scoreEntity.SaveScores(checkpoint,cpScore);
     //this does update scoreEntity.TimeStamp
     _cloudTable.Execute(scoreEntity.Timestamp == DateTimeOffset.MinValue ? TableOperation.Insert(scoreEntity) : TableOperation.Replace(scoreEntity));
     //should we check the _cloudTable.Execute().HttpStatusCode ??
     return true;
     //what is the new TimeStamp??
     //else it's not the right timestamp
 }
Пример #9
0
        public CheckPoint(DateTime dateTime)
        {
            var timesincezero = dateTime.Subtract(_zeroTime);
            var cps           = (timesincezero.Days * 24 + timesincezero.Hours) / 5;

            CP = cps % 35;

            //rather than say this is CP 0 of cycle 2, consider it CP 35 of cycle 1
            if (CP == 0)
            {
                CP    = 35;
                Cycle = new CycleIdentifier((cps / 35) - 1);
            }
            else
            {
                Cycle = new CycleIdentifier(cps / 35);
            }
        }
        private ScoreEntity ScoreForCycleFromStorage(CycleIdentifier cycle)
        {
            var scoreEntity = new ScoreEntity(cycle);

            var retrieveOperation = TableOperation.Retrieve<ScoreEntity>(ScoreEntity.CincinnatiArea, scoreEntity.RowKey);

            var retrievedResult = _cloudTable.Execute(retrieveOperation);

            if (retrievedResult.Result == null)
            {
                // Execute the insert operation.
                //don't insert yet
                //_cloudTable.Execute(TableOperation.Insert(scoreEntity));
                return scoreEntity;
            }
            scoreEntity = (ScoreEntity) retrievedResult.Result;
            return scoreEntity;
        }
Пример #11
0
        public CheckPoint(DateTime dateTime)
        {
            var timesincezero = dateTime.Subtract(_zeroTime);
            var cps = (timesincezero.Days*24 + timesincezero.Hours)/5;

            CP = cps%35;

            //rather than say this is CP 0 of cycle 2, consider it CP 35 of cycle 1
            if (CP == 0)
            {
                CP = 35;
                Cycle = new CycleIdentifier((cps / 35) - 1);
            }
            else
            {
                Cycle = new CycleIdentifier(cps / 35);
            }
        }
Пример #12
0
        /// <summary>
        ///     Cycle with checpoint scores
        /// </summary>
        /// <param name="cycleIdentifier"></param>
        /// <param name="timestampTicks"></param>
        /// <param name="isSnoozed"></param>
        /// <param name="currentCheckPoint"></param>
        /// <param name="scores"></param>
        public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, bool isSnoozed, CheckPoint currentCheckPoint, params KeyValuePair<int, CpScore>[] scores)
        {
            _timestampTicks = timestampTicks;
            Cycle = cycleIdentifier;
            IsSnoozed = isSnoozed;
            _scores = scores.ToDictionary(score => score.Key, val=>val.Value);

            if (Cycle.Id > currentCheckPoint.Cycle.Id)
            {
                _maxCheckPoint = 0;
            }
            else if (Cycle.Id == currentCheckPoint.Cycle.Id)
            {
                _maxCheckPoint = currentCheckPoint.CP;
            }
            else
            {
                _maxCheckPoint = 35;//past cycles
            }
        }
        public bool UpdateScore(CycleIdentifier cycle, long? timestampTicks, params KeyValuePair<int, CpScore>[] cpScores)
        {
            var scoreEntity = _cycleScoresCache[cycle.Id];
            if (timestampTicks.HasValue && scoreEntity.Timestamp.Ticks != timestampTicks.Value)//final check before we overwrite something we didn't mean to
            {
                return false;
            }
            if (cpScores==null || cpScores.Length == 0)
            {
                return false;
            }
            foreach (var keyValuePair in cpScores)
            {
                scoreEntity.SaveScores(keyValuePair.Key, keyValuePair.Value);
            }

            //this does update scoreEntity.TimeStamp
            _cloudTable.Execute(scoreEntity.Timestamp == DateTimeOffset.MinValue ? TableOperation.Insert(scoreEntity) : TableOperation.Replace(scoreEntity));
            //should we check the _cloudTable.Execute().HttpStatusCode ??
            return true;
            //what is the new TimeStamp??
            //else it's not the right timestamp
        }
Пример #14
0
 /// <summary>
 ///     create a new checkpoint
 /// </summary>
 /// <param name="cycleScore"></param>
 public ScoreEntity(CycleIdentifier cycleScore)
 {
     PartitionKey = CincinnatiArea;
     RowKey = cycleScore.Id.ToString();
     Timestamp = DateTimeOffset.MinValue;
 }
Пример #15
0
 public MissingScore(int cp, CycleIdentifier cycleIdentifier)
     : base(cycleIdentifier, cp)
 {
 }
Пример #16
0
 public FutureScore(int cp, CycleIdentifier cycleIdentifier)
     : base(cycleIdentifier, cp)
 {
 }
Пример #17
0
 public CheckPoint(CycleIdentifier cycle, int cp)
 {
     Cycle = cycle;
     CP = cp;
 }
 public bool SetSnooze(CycleIdentifier cycle, long timestampTicks, bool isSnooze)
 {
     return true;
 }
Пример #19
0
 public RecordedScore(CpScore cpScore, CycleIdentifier cycleIdentifier, int cp)
     : base(cycleIdentifier, cp)
 {
     ResistanceScore  = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     return UpdateScore(cycle, timestampTicks, new KeyValuePair<int, CpScore>(checkpoint,cpScore));
 }
Пример #21
0
 public CheckPoint(CycleIdentifier cycle, int cp)
 {
     Cycle = cycle;
     CP    = cp;
 }
Пример #22
0
 public RecordedScore(CpScore cpScore, CycleIdentifier cycleIdentifier, int cp)
     : base(cycleIdentifier, cp)
 {
     ResistanceScore = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }
Пример #23
0
 public FutureScore(int cp, CycleIdentifier cycleIdentifier)
     : base(cycleIdentifier, cp)
 {
 }
Пример #24
0
 public MissingScore(int cp, CycleIdentifier cycleIdentifier)
     : base(cycleIdentifier, cp)
 {
 }