Ejemplo n.º 1
0
        private static async Task <ActorEntity> InsertOrMergeEntityAsync(CloudTable table, ActorEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Entity cannot be null!");
            }
            try
            {
                // Create the InsertOrReplace table operation
                TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

                // Execute the operation.
                TableResult result = await table.ExecuteAsync(insertOrMergeOperation);

                ActorEntity insertedActor = result.Result as ActorEntity;

                // Get the request units consumed by the current operation. RequestCharge of a TableResult is only applied to Azure CosmoS DB
                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge);
                }

                return(insertedActor);
            }
            catch (StorageException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Represents the method to Persist the Actor
        /// </summary>
        /// <param name="actorInstance">Represents the param Actor instance</param>
        /// <returns></returns>
        public async Task PersistActor(ActorBase actorInstance)
        {
            this.logger?.LogTrace("Persisting actor: {0}", actorInstance.Id);

            var serializedEntity = SerializeActor(actorInstance);

            ActorEntity actorEntity = new ActorEntity(this.actorSystemId, actorInstance.Id.IdAsString);

            actorEntity.SerializedActor = serializedEntity;

            await InsertOrMergeEntityAsync(this.table, new ActorEntity(this.actorSystemId, actorInstance.Id.IdAsString) { SerializedActor = serializedEntity });

            this.logger?.LogTrace("Persisting actor: {0}", actorInstance.Id);
        }
Ejemplo n.º 3
0
        private async Task <ActorBase> GetPersistedActorAsync(string actorId)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <ActorEntity>(this.actorSystemId, actorId);
            TableResult    result            = await this.table.ExecuteAsync(retrieveOperation);

            ActorEntity customer = result.Result as ActorEntity;

            if (customer == null)
            {
                return(null);
            }
            else
            {
                return(DeserializeActor <ActorBase>(customer.SerializedActor));
            }
        }