Exemple #1
0
        private async Task <int> IterateEntriesAsync(FluentCommand command,
                                                     Func <string, IDictionary <string, object>, Task> funcAsync, CancellationToken cancellationToken)
        {
            var collectionName = command.QualifiedEntityCollectionName;
            var commandText    = await command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var result  = 0;
            var client  = new ODataClient(_settings);
            var entries = await client.FindEntriesAsync(commandText, cancellationToken).ConfigureAwait(false);

            if (entries != null)
            {
                var entryList = entries.ToList();
                foreach (var entry in entryList)
                {
                    await funcAsync(collectionName, entry).ConfigureAwait(false);

                    if (cancellationToken.IsCancellationRequested)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                    }
                    ++result;
                }
            }
            return(result);
        }
Exemple #2
0
        private async Task <IEnumerable <IDictionary <string, object> > > IterateEntriesAsync(
            FluentCommand command, bool resultRequired,
            Func <string, IDictionary <string, object>, IDictionary <string, object>, bool, Task <IDictionary <string, object> > > funcAsync, CancellationToken cancellationToken)
        {
            var collectionName = command.QualifiedEntityCollectionName;
            var entryData      = command.CommandData;
            var commandText    = await command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            IEnumerable <IDictionary <string, object> > result = null;
            var client  = new ODataClient(_settings);
            var entries = await client.FindEntriesAsync(commandText, cancellationToken).ConfigureAwait(false);

            if (entries != null)
            {
                var entryList  = entries.ToList();
                var resultList = new List <IDictionary <string, object> >();
                foreach (var entry in entryList)
                {
                    resultList.Add(await funcAsync(collectionName, entry, entryData, resultRequired).ConfigureAwait(false));
                    if (cancellationToken.IsCancellationRequested)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                    }
                }
                result = resultList;
            }

            return(result);
        }
Exemple #3
0
        private async Task <string> FormatEntryKeyAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            var entryIdent = command.HasKey
                ? await command.GetCommandTextAsync(cancellationToken)
                             .ConfigureAwait(false) : await(new FluentCommand(command).Key(command.FilterAsKey).GetCommandTextAsync(cancellationToken)).ConfigureAwait(false);

            return(entryIdent);
        }
        private async Task <string> FormatEntryKeyAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            var entryIdent = command.HasKey
                ? await command.GetCommandTextAsync(cancellationToken)
                : await(new FluentCommand(command).Key(command.FilterAsKey).GetCommandTextAsync(cancellationToken));

            return(RemoveTypeSpecification(entryIdent));
        }
Exemple #5
0
        public async Task <ODataRequest> GetRequestAsync(bool scalarResult, CancellationToken cancellationToken)
        {
            await _session.ResolveAdapterAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var commandText = _commandText == null
                ? await _command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false)
                : _commandText;

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            return(await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                   .CreateGetRequestAsync(commandText, scalarResult).ConfigureAwait(false));
        }
Exemple #6
0
        private async Task <IDictionary <string, object> > GetUpdatedResult(FluentCommand command, CancellationToken cancellationToken)
        {
            var entryKey  = command.HasKey ? command.KeyValues : command.FilterAsKey;
            var entryData = command.CommandData;

            var updatedKey = entryKey.Where(x => !entryData.ContainsKey(x.Key)).ToIDictionary();

            foreach (var item in entryData.Where(x => entryKey.ContainsKey(x.Key)))
            {
                updatedKey.Add(item);
            }
            var updatedCommand = new FluentCommand(command).Key(updatedKey);

            return(await FindEntryAsync(await updatedCommand.GetCommandTextAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false));
        }
Exemple #7
0
        private async Task <IEnumerable <IDictionary <string, object> > > ExecuteFunctionAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            var commandText = await command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var request = await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                          .CreateFunctionRequestAsync(commandText, command.FunctionName).ConfigureAwait(false);

            return(await ExecuteRequestWithResultAsync(request, cancellationToken,
                                                       x => x.AsEntries(_session.Settings.IncludeAnnotationsInResults),
                                                       () => new IDictionary <string, object>[] { }).ConfigureAwait(false));
        }
        private async Task <IEnumerable <IDictionary <string, object> > > ExecuteActionAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            var commandText = await command.GetCommandTextAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var request = await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                          .CreateActionRequestAsync(commandText, command.ActionName, command.CommandData, true);

            return(await ExecuteRequestWithResultAsync(request, cancellationToken,
                                                       x => x.AsEntries(),
                                                       () => new[] { (IDictionary <string, object>)null }));
        }
Exemple #9
0
        private async Task <IEnumerable <IDictionary <string, object> > > ExecuteActionAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            var commandText = await command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var entityTypeName = command.EntityCollection != null
                ? _session.Metadata.GetQualifiedTypeName(command.EntityCollection.Name)
                : null;

            var request = await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                          .CreateActionRequestAsync(commandText, command.ActionName, entityTypeName, command.CommandData, true).ConfigureAwait(false);

            return(await ExecuteRequestWithResultAsync(request, cancellationToken,
                                                       x => x.AsEntries(_session.Settings.IncludeAnnotationsInResults),
                                                       () => new IDictionary <string, object>[] { }).ConfigureAwait(false));
        }
Exemple #10
0
        private async Task <IDictionary <string, object> > ExecuteInsertEntryAsync(FluentCommand command, bool resultRequired, CancellationToken cancellationToken)
        {
            var entryData   = command.CommandData;
            var commandText = await command.GetCommandTextAsync(cancellationToken).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var request = await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                          .CreateInsertRequestAsync(command.QualifiedEntityCollectionName, commandText, entryData, resultRequired).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var result = await ExecuteRequestWithResultAsync(request, cancellationToken,
                                                             x => x.AsEntry(_session.Settings.IncludeAnnotationsInResults), () => null, () => request.EntryData).ConfigureAwait(false);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var keyNames = _session.Metadata.GetDeclaredKeyPropertyNames(commandText);

            if (result == null && resultRequired && Utils.AllMatch(keyNames, entryData.Keys, _session.Pluralizer))
            {
                result = await this.GetEntryAsync(commandText, entryData, cancellationToken).ConfigureAwait(false);

                if (cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }
            }

            return(result);
        }
Exemple #11
0
        private async Task <IDictionary <string, object> > ExecuteInsertEntryAsync(FluentCommand command, bool resultRequired, CancellationToken cancellationToken)
        {
            var entryData   = command.CommandData;
            var commandText = await command.GetCommandTextAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var request = await _session.Adapter.GetRequestWriter(_lazyBatchWriter)
                          .CreateInsertRequestAsync(commandText, entryData, resultRequired);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var result = await ExecuteRequestWithResultAsync(request, cancellationToken,
                                                             x => x.AsEntry(_session.Settings.IncludeAnnotationsInResults), () => null, () => request.EntryData);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            if (result == null && resultRequired &&
                _session.Metadata.GetDeclaredKeyPropertyNames(commandText).All(entryData.ContainsKey))
            {
                result = await this.GetEntryAsync(commandText, entryData, cancellationToken);

                if (cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }
            }

            return(result);
        }
Exemple #12
0
        internal async Task <IDictionary <string, object> > FindEntryAsync(FluentCommand command, CancellationToken cancellationToken)
        {
            if (IsBatchResponse)
            {
                return(_batchResponse.AsEntry());
            }

            await _session.ResolveAdapterAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var commandText = await command.GetCommandTextAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            return(await FindEntryAsync(commandText, cancellationToken));
        }
Exemple #13
0
        internal async Task <IEnumerable <IDictionary <string, object> > > FindEntriesAsync(FluentCommand command, ODataFeedAnnotations annotations, CancellationToken cancellationToken)
        {
            if (IsBatchResponse)
            {
                annotations.CopyFrom(_batchResponse.Annotations);
                return(_batchResponse.AsEntries());
            }

            await _session.ResolveAdapterAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var commandText = await command.GetCommandTextAsync(cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            return(await FindEntriesAsync(commandText, annotations, cancellationToken));
        }