Ejemplo n.º 1
0
        private void TruncateEquipmentType(Commit commit, VisionSuiteDB db,
                                           JToken @event, JArray payload, string equipmentType, string pieceOfEquipmentCode)
        {
            _logger.WriteLine($"Truncating '{equipmentType}' for equipment '{pieceOfEquipmentCode}'");

            @event.Body()["Type"] = equipmentType.Substring(0, MaxLength);

            var newPayload = payload
                             .ToString()
                             .AsBytes()
                             .Compress();

            Expression <Func <Commit, bool> > updatePredicate = c => c.CheckpointNumber == commit.CheckpointNumber;

            if (_options.WhatIf)
            {
                _updateCount += db.Commits
                                .Count(updatePredicate);
            }
            else
            {
                _updateCount += db.Commits
                                .Where(updatePredicate)
                                .Set(c => c.Payload, newPayload)
                                .Update();
            }
        }
Ejemplo n.º 2
0
 private static List <Commit> GetCommitsToCheck(Options options)
 {
     using (var db = new VisionSuiteDB(options))
     {
         var commits =
             db.Commits
             .OrderBy(c => c.CheckpointNumber)
             .ToList();
         return(commits);
     }
 }
Ejemplo n.º 3
0
        private void HandleCommit(Commit commit, VisionSuiteDB db)
        {
            var payload = commit.Payload
                          .Decompress()
                          .AsString()
                          .AsJArray();

            foreach (var @event in payload)
            {
                HandleEvent(commit, db, @event, payload);
            }
        }
Ejemplo n.º 4
0
        private void HandleEvent(Commit commit, VisionSuiteDB db, JToken @event, JArray payload)
        {
            var eventType = @event.EventType();

            if (eventType.IndexOf("SpecifyPieceOfEquipmentTypeEvent", StringComparison.InvariantCulture) != -1)
            {
                var pieceOfEquipmentCode = @event.Body()["PieceOfEquipmentCode"].ToString();
                var equipmentType        = @event.Body()["Type"].ToString();

                if (equipmentType.Length > MaxLength)
                {
                    TruncateEquipmentType(commit, db, @event, payload, equipmentType, pieceOfEquipmentCode);
                }
            }
        }
Ejemplo n.º 5
0
        public void Execute()
        {
            using (var db = new VisionSuiteDB(_options))
            {
                _logger.WriteLine($"Truncating Type properties on SpecifyPieceOfEquipmentTypeEvent that are longer then {MaxLength} characters");

                var commits = GetCommitsToCheck(_options);
                foreach (var commit in commits)
                {
                    _logger.PrintProgress();

                    HandleCommit(commit, db);
                }

                if (_options.WhatIf)
                {
                    _logger.WriteLine($"Would have updated {_updateCount} commits.");
                }
                else
                {
                    _logger.WriteLine($"Updated {_updateCount} commits.");
                }
            }
        }