Exemple #1
0
        public async Task <CinemaDetails> GetCinema(string name)
        {
            CinemaDetails cinema = _cacheService.Get <CinemaDetails>(name);

            if (cinema == null)
            {
                if (_connectivity.EnsureInternetAccess())
                {
                    var uri = ResourceIdentifier.CinemasUri();
                    try
                    {
                        var responseString = await _httpService.Get(uri);

                        var cinemas = (List <CinemaDetails>)_jsonConverter.DeserializeObject(responseString, typeof(List <CinemaDetails>));
                        var query   = (from c in cinemas where (c.Name + " " + c.City).Equals(name) select c);
                        cinema = query.First();
                        _cacheService.Set(name, cinema, CacheExpiry(15.0));
                    }
                    catch
                    {
                        ShowGetFailedNotification();
                        return(new CinemaDetails());
                    }
                }
                else
                {
                    ShowConnectionNotification();
                    return(new CinemaDetails());
                }
            }

            return(cinema);
        }
Exemple #2
0
        public Response ParseToResponse(string json)
        {
            var response = _jsonConverter.DeserializeObject <Response>(json);

            response.Json = json;
            response.Type = GetType(response);
            return(response);
        }
Exemple #3
0
        /// <summary>
        /// Load a wallet using a file name.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public void Load(string fileName)
        {
            var json = _fileWrapper.Load(fileName);

            Wallet = _jsonConverter.DeserializeObject <NEP6Wallet>(json);
            _openWalletFilename = fileName;
        }
        public T Get <T>(string key, T defaultValue)
        {
            var path = GetPath(key);

            if (!File.Exists(path))
            {
                return(defaultValue);
            }

            var json = File.ReadAllText(path);

            if (string.IsNullOrEmpty(json))
            {
                return(defaultValue);
            }

            var type = typeof(T);

            if (TypeHelper.IsPrimitiveOrString(type))
            {
                return((T)Convert.ChangeType(json, type));
            }

            return(_jsonConverter.DeserializeObject <T>(json));
        }
Exemple #5
0
        public async Task <APIGatewayProxyResponse> QueryActors(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.LogLine($"Query request: {_jsonConverter.SerializeObject(request)}");

            var requestBody = _jsonConverter.DeserializeObject <ActorsSearchRequest>(request.Body);

            if (string.IsNullOrEmpty(requestBody.FirstName))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = "FirstName is mandatory"
                });
            }
            var queryRequest = BuildQueryRequest(requestBody.FirstName, requestBody.LastName);

            _logger.LogInformation("QueryActors invoked with {FirstName} and {LastName}, {@Content}",
                                   requestBody.FirstName, requestBody.LastName, requestBody);

            var response = await _dynamoDbReader.QueryAsync(queryRequest);

            context.Logger.LogLine($"Query result: {_jsonConverter.SerializeObject(response)}");

            var queryResults = BuildActorsResponse(response);

            _logger.LogInformation("QueryActors result for {FirstName} and {LastName} is {@Content}",
                                   requestBody.FirstName, requestBody.LastName, queryResults);

            return(new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body = _jsonConverter.SerializeObject(queryResults)
            });
        }
Exemple #6
0
        //private void OnDestroy()
        //{
        //    _locator.DeregisterSingleton<IGameManager>();
        //}

        private Action <string> MakeHandlerBridge <T>(Action <T> action)
        {
            return(data =>
            {
                var jdata = _jconverter.DeserializeObject <T>(data);
                action(jdata);
            });
        }
        public async Task <CustomerCreateResult> Create(CustomerCreateRequest customerCreateRequest)
        {
            var stringContent = await customerApiClient.CreateCustomerAsync(customerCreateRequest);

            var result = jsonConverter.DeserializeObject <CustomerCreateResult>(stringContent);

            return(result);
        }
        public async Task <PrizeBulkCreationResult> CreatePrizes(PrizeBulkCreationRequest prizeBulkCreationRequest)
        {
            var stringContent = await prizesApiClient.CreatePrizesBulkAsync(prizeBulkCreationRequest);

            var result = jsonConverter.DeserializeObject <PrizeBulkCreationResult>(stringContent);

            return(result);
        }
Exemple #9
0
        public IEnumerable <PackageInfo> GetPackages()
        {
            var    scriptData         = "{}";
            string responseFormServer = _applicationClient.ExecutePostRequest(_packagesListServiceUrl, scriptData);
            var    json     = _jsonConverter.CorrectJson(responseFormServer);
            var    packages = _jsonConverter.DeserializeObject <List <Dictionary <string, string> > >(json);

            return(packages.Select(CreatePackageInfo));
        }
Exemple #10
0
    public async Task <IActionResult> GetAsync([FromQuery] LyricRequest request)
    {
        var url = $"{settings.Lyrics.Endpoint}?apikey={settings.Lyrics.ApiKey}&territory=US&reqtype=default&trackid=artistname:{request.ArtistName.Replace(" ", "+")},trackname:{request.SongName.Replace(" ", "+")}&format=clean&output={settings.Lyrics.Output}";

        var result = await httpClient.GetAsync(url);

        var lyricFindResponse = jsonConverter.DeserializeObject <LyricFindResponse>(await result.Content.ReadAsStringAsync());

        return(base.Ok(lyricFindResponse));
    }
        public async Task <IActionResult> Post(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "queries")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            if (req == null)
            {
                return(new NotFoundObjectResult("Null HttpRequest"));
            }

            string requestBody = await _readerService.ReadToEndAsync(req.Body);

            if (string.IsNullOrEmpty(requestBody))
            {
                return(new BadRequestObjectResult("Could not find Start Date or End date"));
            }

            var data = _jsonConverter.DeserializeObject <VehicleQueryRequest>(requestBody);

            if (data == null)
            {
                return(new BadRequestObjectResult("VehicleQueryrequest is null after deserialization"));
            }

            try
            {
                var result = await _vehicleQueryService.GetByDate(data.StartDate, data.EndDate);

                //Send Email
                var msg = _emailService.Create(result);
                if (msg == null)
                {
                    log.LogWarning("Error creating Email");
                }
                var response = await _emailService.Send(msg);

                log.LogInformation($"Output Response: {response.Success} - {response.Message}. Number of Queries: {result.NumberOfQueries}");

                return(new OkObjectResult(result));
            }
            catch (Exception e)
            {
                log.LogInformation($"Exception occured. {e.Message}");
                throw e;
            }
        }
Exemple #12
0
        private T GetResponse <T>(HttpResponseMessage response)
        {
            if (!response.IsSuccessStatusCode || response.Content == null)
            {
                throw new Exception("Error to call: " + response.RequestMessage.RequestUri.AbsolutePath + " | Response Code: " + response.StatusCode);
            }

            string result = response.Content.ReadAsStringAsync().Result;

            if (result == null)
            {
                return(default(T));
            }

            T obj = _jsonConverter.DeserializeObject <T>(result);

            return(obj);
        }
        public T Get <T>(string key, T defaultValue)
        {
            var json = PlayerPrefs.GetString(key, null);

            if (string.IsNullOrEmpty(json))
            {
                return(defaultValue);
            }

            var type = typeof(T);

            if (TypeHelper.IsPrimitiveOrString(type))
            {
                return((T)Convert.ChangeType(json, type));
            }

            return(_jsonConverter.DeserializeObject <T>(json));
        }
Exemple #14
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var data    = await argument;
            var message = jsonConverter.DeserializeObject <RunMessage>(data.Text);

            // Testing
            var builder = new StringBuilder();

            builder.AppendLine("Merged pull request:");
            builder.AppendLine($"    {message.MergeMessage}");
            builder.AppendLine("Updated pull request:");
            builder.AppendLine($"    {message.UpdateMessage}");
            builder.AppendLine("Conflicting pull requests:");
            builder.AppendLine(string.Join(message.ConflictMessages.Max(x => $"    {x}"), Environment.NewLine));

            await context.PostAsync(builder.ToString());

            context.Wait(MessageReceivedAsync);
        }
        public async Task <BlockHeader> GetBlockHeader(UInt256 hash)
        {
            var blockHeaderRedisValue = await _redisDbJsonContext.Get(hash.BuildDataBlockKey());

            return(blockHeaderRedisValue.IsNull ? null : _jsonConverter.DeserializeObject <BlockHeader>(blockHeaderRedisValue));
        }