Exemplo n.º 1
0
        public async void AjustaFrasesRowKey(string partitionKey, string rowKey)
        {
            List <Frase> ListaFrases = GetFrasesGrupoJugador(partitionKey, rowKey).Result;
            string       NombreGrupo; int NoFrase = 1; int NoFrases = ListaFrases.Count;
            int          zeroCounter = Convert.ToString(NoFrases).Length - Convert.ToString(NoFrase).Length;

            for (int i = 0; i < NoFrases; i++)
            {
                for (int j = 9; j <= i; j = (j + 1) * 10 - 1)
                {
                    if (j == i)
                    {
                        zeroCounter = zeroCounter - 1;
                    }
                }
                NombreGrupo = rowKey + "." + getNZeros(zeroCounter) + NoFrase;
                TableOperation RetrieveOperation = TableOperation.Retrieve <FraseEntity>(partitionKey, ListaFrases[i].nombre_grupo);
                TableResult    RetrievedResult   = await cloudTableFR.ExecuteAsync(RetrieveOperation);

                FraseEntity    EntityToDelete  = (FraseEntity)RetrievedResult.Result;
                TableOperation DeleteOperation = TableOperation.Delete(EntityToDelete);
                await cloudTableFR.ExecuteAsync(DeleteOperation);

                FraseEntity EntityToCreate = new FraseEntity(partitionKey, NombreGrupo);
                EntityToCreate.valor_frase = ListaFrases[i].valor_frase;
                TableOperation InsertOperation = TableOperation.Insert(EntityToCreate);
                await cloudTableFR.ExecuteAsync(InsertOperation); NoFrase++;
            }
        }
Exemplo n.º 2
0
        public async Task <bool> BorrarFrase(string partitionKey, string rowKey, int no_frase)
        {
            bool response = false; int NoFraseGrupo, NoFrasesGrupo;
            int  NoDigitosAnterior = 0, NoDigitosActual = 0, diferenciaNoDigits = 0;
            TableQuery <FraseEntity> tableQuery = new TableQuery <FraseEntity>();
            TableContinuationToken   ContinuationToken = new TableContinuationToken();

            foreach (FraseEntity fraseentity in await cloudTableFR.ExecuteQuerySegmentedAsync(tableQuery, ContinuationToken))
            {
                NoFraseGrupo = GetGroupPhraseNumberByRowKey(fraseentity.RowKey);
                if (fraseentity.PartitionKey.Equals(partitionKey) && GetGroupNameByRowKey(fraseentity.RowKey).Equals(rowKey) && NoFraseGrupo == no_frase)
                {
                    TableOperation RetrieveOperation = TableOperation.Retrieve <FraseEntity>(fraseentity.PartitionKey, fraseentity.RowKey);
                    TableResult    RetrievedResult   = await cloudTableFR.ExecuteAsync(RetrieveOperation);

                    FraseEntity    EntityToDelete  = (FraseEntity)RetrievedResult.Result;
                    TableOperation DeleteOperation = TableOperation.Delete(EntityToDelete);
                    await cloudTableFR.ExecuteAsync(DeleteOperation);

                    NoFrasesGrupo      = GetGroupPhrasesNumberByRowKey(partitionKey, rowKey).Result;
                    NoDigitosAnterior  = NoFrasesGrupo.ToString().Length;
                    NoDigitosActual    = (NoFrasesGrupo - 1).ToString().Length;
                    diferenciaNoDigits = NoDigitosAnterior - NoDigitosActual;
                    if (diferenciaNoDigits == 1)
                    {
                        AjustaFrasesRowKey(partitionKey, rowKey);
                    }
                    response = true; break;
                }
            }
            return(response);
        }
Exemplo n.º 3
0
        public async Task <bool> ActualizarFrase(string partitionKey, string rowKey, int no_frase, string valor_frase)
        {
            bool response = false; int NoFraseGrupo;
            TableQuery <FraseEntity> tableQuery = new TableQuery <FraseEntity>();
            TableContinuationToken   ContinuationToken = new TableContinuationToken();

            foreach (FraseEntity fraseentity in await cloudTableFR.ExecuteQuerySegmentedAsync(tableQuery, ContinuationToken))
            {
                NoFraseGrupo = GetGroupPhraseNumberByRowKey(fraseentity.RowKey);
                if (fraseentity.PartitionKey.Equals(partitionKey) && GetGroupNameByRowKey(fraseentity.RowKey).Equals(rowKey) && NoFraseGrupo == no_frase)
                {
                    TableOperation RetrieveOperation = TableOperation.Retrieve <FraseEntity>(partitionKey, fraseentity.RowKey);
                    TableResult    RetrievedResult   = await cloudTableFR.ExecuteAsync(RetrieveOperation);

                    FraseEntity    EntityToUpdate  = (FraseEntity)RetrievedResult.Result;
                    TableOperation UpdateOperation = TableOperation.Replace(EntityToUpdate);
                    await cloudTableFR.ExecuteAsync(UpdateOperation);

                    response = true; break;
                }
            }
            return(response);
        }
Exemplo n.º 4
0
        public async Task <bool> CrearFrase(Frase frase)
        {
            bool response = false; int NoFrasesGrupo = 0, NoDigitosAnterior = 0;
            int  NoDigitosActual = 0, diferenciaNoDigits = 0;

            try {
                NoFrasesGrupo     = GetGroupPhrasesNumberByRowKey(frase.email_jugador, frase.nombre_grupo).Result;
                NoDigitosAnterior = NoFrasesGrupo.ToString().Length;
                if (NoFrasesGrupo == 0)
                {
                    NoFrasesGrupo = 1;
                }
                else
                {
                    NoFrasesGrupo = NoFrasesGrupo + 1;
                };
                FraseEntity fraseEntity = new FraseEntity(frase.email_jugador, frase.nombre_grupo + "." + NoFrasesGrupo);
                fraseEntity.valor_frase = frase.valor_frase;
                TableOperation insertOperation = TableOperation.Insert(fraseEntity);
                await cloudTableFR.ExecuteAsync(insertOperation);

                NoDigitosActual    = NoFrasesGrupo.ToString().Length;
                diferenciaNoDigits = NoDigitosActual - NoDigitosAnterior;
                if (diferenciaNoDigits == 1)
                {
                    AjustaFrasesRowKey(frase.email_jugador, frase.nombre_grupo);
                }
                response = true;
            }
            catch (Exception exception) {
                await Console.Out.WriteLineAsync(exception.Message);

                response = false;
            }
            return(response);
        }