Esempio n. 1
0
 private void RecordSourceSystemEntity(IProcessedArgs <TEntity> args)
 {
     if (this.loggingConfigurationProvider.MigrationConfiguration.SourceSystemEntity &&
         args.SourceSystemEntity != null &&
         !EntityTransactionOutcomesThatRecordSourceSystemEntity.Contains(args.Outcome))
     {
         SerializedEntity serializedEntity =
             this.GetSerializedSourceSystemEntity(args);
         if (serializedEntity != null)
         {
             if (args.SourceSystemEntityId != null)
             {
                 var entity =
                     new IdentityOperationSourceSystemEntity(
                         this.operationExecutive.CurrentOperation,
                         this.context.EntityType.Id,
                         this.context.SourceSystem.Id,
                         args.SourceSystemEntityId,
                         serializedEntity);
                 this.safeRepository
                 .CreateIdentityOperationSourceSystemEntity(entity);
             }
             else
             {
                 var entity = new OperationSerializedEntity(
                     this.operationExecutive.CurrentOperation,
                     serializedEntity);
                 this.safeRepository
                 .CreateOperationSourceSystemEntity(entity);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Processes the specified source system entity.
        /// </summary>
        /// <param name="entity">The entity to process.</param>
        /// <returns>The outcome of the processing of the specified entity.</returns>
        public IProcessedArgs <TEntity> Process(TEntity entity)
        {
            EntityTransactionOutcome outcome;

            this.SourceSystemEntity = entity;
            Exception exceptionThrown = null;

            try
            {
                outcome = this.Process();
            }
            catch (DestinationSystemException exception)
            {
                outcome         = EntityTransactionOutcome.ExceptionThrown;
                exceptionThrown = exception.InnerException;
            }
            return(new ProcessedArgs(
                       this.operationExecutive.CurrentOperation.TimeStamp,
                       this.operationExecutive.CurrentOperation.LogMessages,
                       exceptionThrown,
                       this.SourceSystemEntity,
                       this.SourceSystemEntityId,
                       this.DestinationSystemEntity,
                       this.Mapping?.DestinationSystemEntityId,
                       outcome,
                       SerializedEntity.Create(this.SerializedSourceSystemEntity),
                       this.ValueChanges));
        }
Esempio n. 3
0
 public IdentityOperationSourceSystemEntity(
     IOperation operation,
     Guid entityTypeId,
     Guid sourceSystemId,
     string sourceSystemEntityId,
     SerializedEntity entity)
 {
     this.Identity = new SourceSystemEntityIdentity(
         entityTypeId, sourceSystemId, sourceSystemEntityId);
     this.Operation = operation;
     this.Entity    = entity;
 }
Esempio n. 4
0
        GetSerializedSourceSystemEntity(IProcessedArgs <TEntity> args)
        {
            SerializedEntity serializedEntity;

            if (args.SerializedSourceSystemEntity != null)
            {
                serializedEntity = new SerializedEntity(
                    args.SerializedSourceSystemEntity.DataHash,
                    args.SerializedSourceSystemEntity.Data,
                    args.SerializedSourceSystemEntity.Label);
            }
            else
            {
                serializedEntity = this.SerializeEntity(args.SourceSystemEntity);
            }
            return(serializedEntity);
        }
Esempio n. 5
0
 public void SaveOrUpdate(SerializedEntity se)
 {
     if (se != null)
     {
         if (se.OID == 0)
         {
             se.CreatedAt = DateTime.Now;
             siaqodb.StoreObject(se);
         }
         else
         {
             se.Updated   = true;
             se.UpdatedAt = DateTime.Now;
             siaqodb.StoreObject(se);
         }
     }
 }
Esempio n. 6
0
        public bool DeleteObject(SerializedEntity o, OrmSchema schema)
        {
            using (var bucket = GetBucket(schema))
            {
                for (int i = 0; i < bucket.Objects.Count; i++)
                {
                    if (schema.PrimaryKeys.All(primaryKey => Equals(bucket.Objects[i][primaryKey.MappedName], o[primaryKey.MappedName])))
                    {
                        bucket.IndexedObjects.Remove(bucket.IndexedObjects.First(kv => kv.Value == bucket.Objects[i]).Key);
                        bucket.Objects.RemoveAt(i);
                        return true;
                    }
                }
            }

            return false;
        }
Esempio n. 7
0
    public void Serialize(CelestialSystem cs)
    {
        scs = new SerializedCs();
        var planets = cs.Planets;

        scs.playerIndex = planets.FindIndex(planet => planet.ControlledBy is InputPlanetController);
        scs.aiIndex     = planets.FindIndex(planet => planet.ControlledBy is AiPlanetController);

        scs.planets = new List <SerializedPlanet>();
        foreach (var planet in planets)
        {
            scs.planets.Add(new SerializedPlanet()
            {
                entity     = SerializedEntity.FromEntity(planet.SimulatedEntity),
                hp         = planet.Hp,
                startHp    = planet.StartHp,
                color      = planet.Appearance.color,
                weaponType = planet.Weapon?.Type.Name,
            });
        }

        scs.planets.Add(new SerializedPlanet()
        {
            entity    = SerializedEntity.FromEntity(cs.centralStar.SimulatedEntity),
            hp        = cs.centralStar.Hp,
            startHp   = cs.centralStar.StartHp,
            color     = cs.centralStar.Appearance.color,
            isCentral = true,
        });


        scs.projectiles = new List <SerializedProjectile>();
        foreach (var projectile in cs.Projectiles)
        {
            scs.projectiles.Add(new SerializedProjectile()
            {
                entity = SerializedEntity.FromEntity(projectile),
            });
        }

        var json = JsonUtility.ToJson(scs);

        PlayerPrefs.SetString(saveGameKey, json);
        PlayerPrefs.Save();
    }
Esempio n. 8
0
 private void RecordDestinationSystemEntity(
     EntityTransaction transaction, IProcessedArgs <TEntity> args)
 {
     if (this
         .loggingConfigurationProvider
         .MigrationConfiguration
         .DestinationSystemEntity &&
         args.DestinationSystemEntity != null)
     {
         SerializedEntity serializedDestinationSystemEntity =
             this.SerializeEntity(args.DestinationSystemEntity);
         if (serializedDestinationSystemEntity != null)
         {
             this.safeRepository
             .CreateOperationDestinationSystemEntity(
                 new OperationSerializedEntity(
                     transaction, serializedDestinationSystemEntity));
         }
     }
 }
Esempio n. 9
0
 public OperationSerializedEntity(
     IOperation operation, SerializedEntity entity)
 {
     this.Operation = operation;
     this.Entity    = entity;
 }
Esempio n. 10
0
 public void Delete(SerializedEntity se)
 {
     siaqodb.Delete(se);
 }
Esempio n. 11
0
 public void UpdateWithoutSetAsUpdated(SerializedEntity se)
 {
 }
Esempio n. 12
0
 public CompositeKey(OrmSchema schema, SerializedEntity o)
 {
     _keyValues = schema.PrimaryKeys.ToDictionary(pk => pk.MappedName, pk => o[pk.MappedName]);
 }
Esempio n. 13
0
        public ObjectWriteResult WriteObject(SerializedEntity o, bool createNew, OrmSchema schema)
        {
            var result = new ObjectWriteResult();

            using (var bucket = GetBucket(schema))
            {
                if (createNew)
                {
                    foreach (var incrementKey in schema.IncrementKeys.Where(incrementKey => o[incrementKey.MappedName].Convert<long>() == 0))
                    {
                        o[incrementKey.MappedName] = bucket.NextIncrementCounter(incrementKey.FieldName).Convert(incrementKey.FieldType);

                        result.OriginalUpdated = true;
                    }

                    var storedObject = o.AsDictionary();

                    bucket.Objects.Add(storedObject);
                    bucket.IndexedObjects[new CompositeKey(schema,o)] = storedObject;

                    result.Added = true;
                    result.Success = true;
                }
                else
                {
                    if (schema.PrimaryKeys.Length > 0)
                    {
                        for (int i = 0; i < bucket.Objects.Count; i++)
                        {
                            if (schema.PrimaryKeys.All(primaryKey => Equals(bucket.Objects[i][primaryKey.MappedName], o[primaryKey.MappedName])))
                            {
                                var compositeKey = new CompositeKey(schema, o);

                                var storedObject = o.AsDictionary();

                                bucket.Objects[i] = storedObject;
                                bucket.IndexedObjects[compositeKey] = storedObject;
                                result.Success = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        result.Success = false;
                    }
                }
            }

            return result;
        }