Exemple #1
0
        /// <summary>
        /// Add async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="payload">Payload.</param>
        /// <param name="apiMethod">API method.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task <T> AddAsync <T>(T payload, RestApiMethod apiMethod)
        {
            Guard.Argument(payload, nameof(payload)).Equals(null);

            var baseAddress = GetBaseAddress();
            var path        = apiRestSection.GetSection(Constant.Routing).GetValue <string>(apiMethod.ToString());
            var jObject     = await client.PostAsync(payload, baseAddress, path, new CancellationToken());

            return(jObject == null ? (default) : jObject.ToObject <T>());
        /// <summary>
        /// Add async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="payload">Payload.</param>
        /// <param name="apiMethod">API method.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task <T> AddAsync <T>(T payload, RestApiMethod apiMethod)
        {
            if (payload.Equals(null))
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var baseAddress = GetBaseAddress();
            var path        = apiRestSection.GetSection(Constant.Routing).GetValue <string>(apiMethod.ToString());
            var jObject     = await client.PostAsync(payload, baseAddress, path, new CancellationToken());

            onionService.ChangeCircuit("ILoveTangram".ToSecureString());

            return(jObject == null ? (default) : jObject.ToObject <T>());
Exemple #3
0
        /// <summary>
        /// Add async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="payload">Payload.</param>
        /// <param name="apiMethod">API method.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task <T> AddAsync <T>(T payload, RestApiMethod apiMethod)
        {
            Guard.Argument(payload, nameof(payload)).Equals(null);

            JObject jObject = null;
            var     cts     = new CancellationTokenSource();

            try
            {
                var baseAddress = GetBaseAddress();
                var path        = apiRestSection.GetSection(Constant.Routing).GetValue <string>(apiMethod.ToString());

                cts.CancelAfter(60000);
                jObject = await client.PostAsync(payload, baseAddress, path, cts.Token);
            }
            catch (OperationCanceledException ex)
            {
                logger.LogWarning(ex.Message);
            }

            return(jObject == null ? (default) : jObject.ToObject <T>());
Exemple #4
0
        private async Task <TaskResult <T> > PostArticle <T>(T payload, RestApiMethod api) where T : class
        {
            var result = await Util.TriesUntilCompleted(async() => { return(await Client.AddAsync(payload, api)); }, 10, 100);

            return(result);
        }
Exemple #5
0
        private async Task <IEnumerable <TaskResult <T> > > PostParallel <T>(IEnumerable <T> payload, RestApiMethod apiMethod)
        {
            var tasks = payload.Select(async p => await Util.TriesUntilCompleted(async() => { return(await Client.AddAsync(p, apiMethod)); }, 10, 100));

            return(await Task.WhenAll(tasks));
        }