コード例 #1
0
        //Performs web API call process to retrieve random quote and author
        //Comination Check class direct here to initialize
        //Uses Newtonsoft Json to deserialize
        public static async Task GetQuote()
        {
            string urlRanQuote = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";

            WebApiRequest.InitializeClient();

            using (HttpResponseMessage message = await WebApiRequest.client.GetAsync(urlRanQuote))
            {
                if (message.IsSuccessStatusCode)
                {
                    string response = await WebApiRequest.client.GetStringAsync(urlRanQuote);

                    var charRemove = new string[] { "?", "(", ")" };
                    foreach (var item in charRemove)
                    {
                        response = response.Replace(item, string.Empty);
                    }

                    QuoteModel quoteItems = JsonConvert.DeserializeObject <QuoteModel>(response);

                    Result_Success.quoteReveal  = quoteItems.quoteText;
                    Result_Success.authorReveal = quoteItems.quoteAuthor;
                }
                else
                {
                    throw new Exception(message.ReasonPhrase);
                }
            }
        }
コード例 #2
0
            /*!
             * \brief   Loads climate data per http request from the ATB/runlevel3 web service.
             *          The dataObjId has to be provided in advance with the contructor to use this method.
             *
             * \param   start       The start Date/Time of requested data.
             * \param   end         The end Date/Time of requested data.
             *
             * \return  The number of datasets in this climate, a number of 0 means that there was an exception and no data read.
             */

            public async Task <int> loadClimateByIdFromATBWebService(DateTime start, DateTime end)
            {
                if (String.IsNullOrEmpty(_dataObjId))
                {
                    return(0);
                }

                var baseData = await WebApiRequest.LoadBaseDataByIdFromATBWebService(_dataObjId);

                if (baseData["location"] != null)
                {
                    _location.lon = (double)baseData["location"][0];
                    _location.lat = (double)baseData["location"][1];
                    if (baseData["altitude"] != null)
                    {
                        _location.alt = (double)baseData["altitude"];
                    }
                }
                if (_start == null || _start > start || _end == null || _end < end)
                {
                    return(loadCsv(await WebApiRequest.LoadClimateByIdFromATBWebService(_dataObjId, start, end, this._step)));
                }
                else
                {
                    return(climateData.Count);
                }
            }
コード例 #3
0
        public ActionResult Services(FormCollection collection)
        {
            var bookingViewModel = TempData["Booking"] as BookingViewModel;

            if (bookingViewModel != null)
            {
                var hireGroupRequest = new WebApiRequest
                {
                    StartDateTime  = bookingViewModel.StartDt,
                    EndDateTime    = bookingViewModel.EndDt,
                    OutLocationId  = bookingViewModel.OperationWorkPlaceId,
                    DomainKey      = 1,
                    TarrifTypeCode = bookingViewModel.TariffTypeCode
                };
                var additionalServicesRequstResponse = new AdditionalServicesRequstResponse
                {
                    WebApiAdditionalDriverRates =
                        webApiService.GetAdditionalDriverRates(hireGroupRequest).WebApiAdditionalDriverRates,
                    WebApiAvailableInsurancesRates =
                        webApiService.GetAvailableInsurancesRates(hireGroupRequest).ApiAvailableInsurances,
                    WebApiAvailableChuffersRates =
                        webApiService.GetAvailableChauffersRates(hireGroupRequest).ApiAvailableChuffersRates
                };
                ViewBag.BookingVM = TempData["Booking"] as BookingViewModel;
                return(View(additionalServicesRequstResponse));
            }
            return(View());
        }
コード例 #4
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(WebApiRequest <SaasafrasCoreTableRebuildRequest> input, ILambdaContext context)
        {
            context.Logger.LogLine($"Entered function...");
            using (var _mysql = new MySqlQueryHandler(context))
            {
                context.Logger.LogLine($"Rebuilding core tables for {input.bodyJson.appId}, {input.bodyJson.version}");

                await _mysql.RebuildCoreTables(input.bodyJson.solutionId, input.bodyJson.version);
            }
        }
コード例 #5
0
            /*!
             * \brief   Loads climate station altitude per http request from the ATB/runlevel3 web service.
             *
             * \param   location    The location to get altitude for.
             *
             * \return  The altitude at this location.
             */

            public async Task <double> loadAltitudeFromATBWebService(Location location)
            {
                if (_location.alt.HasValue)
                {
                    return((double)_location.alt);
                }

                _location     = location;
                _location.alt = await WebApiRequest.LoadAltitudeFromATBWebService(location);

                return((double)_location.alt);
            }
コード例 #6
0
            /*!
             * \brief   Loads climate data per http request from the ATB/runlevel3 web service.
             *
             * \param   location    The location to get nearest station data from.
             * \param   tag         The tag to prefer climate data with this tag, can be null to use default tag.
             * \param   start       The start Date/Time of requested data.
             * \param   end         The end Date/Time of requested data.
             *
             * \return  The number of datasets in this climate, a number of 0 means that there was an exception and no data read.
             */

            public async Task <int> loadClimateByLocationTagFromATBWebService(Location location, String tag, DateTime start, DateTime end)
            {
                _location = location;
                if (_start == null || _start > start || _end == null || _end < end)
                {
                    return(loadCsv(await WebApiRequest.LoadClimateByLocationTagFromATBWebService(_location, tag, start, end, this._step)));
                }
                else
                {
                    return(climateData.Count);
                }
            }
コード例 #7
0
            private static async Task <int> InitializeInstance(String tag = null)
            {
                climateIds.Clear();
                climateInstances.Clear();
                CsvReader csvReader = new CsvReader(await WebApiRequest.LoadClimateIdsFromATBWebService(tag));

                while (!csvReader.EndOfStream())
                {
                    IDictionary <String, String> fields;
                    fields = csvReader.readLine();

                    if (String.IsNullOrEmpty(fields["name"]) || String.IsNullOrEmpty(fields["_id"]))
                    {
                        continue;
                    }
                    climateIds.Add(fields["name"], fields["_id"]);
                }
                return(climateIds.Count);
            }
コード例 #8
0
        public HttpRequestMessage Create(WebApiRequest requestCommand)
        {
            switch (requestCommand)
            {
            case SportsRequest msg:
                return(HandleMessage(msg));

            case TournamentsRequest msg:
                return(HandleMessage(msg));

            case TranslationsRequest msg:
                return(HandleMessage(msg));

            case TranslationRequest msg:
                return(HandleMessage(msg));

            default:
                throw new ArgumentOutOfRangeException(nameof(requestCommand));
            }
        }
コード例 #9
0
        //Performs web API call to retrieve random number combination
        public static async Task GetRanComb()
        {
            string urlRanNum = "https://www.random.org/integers/?num=4&min=0&max=7&col=1&base=10&format=plain&rnd=new";

            WebApiRequest.InitializeClient();

            using (HttpResponseMessage message = await WebApiRequest.client.GetAsync(urlRanNum))
            {
                if (message.IsSuccessStatusCode)
                {
                    string response = await message.Content.ReadAsStringAsync();

                    //-------flag - uncomment to reveal for debugging-------//
                    //MessageBox.Show(response);

                    NumModel.NumberModel.apiRanNum = response;
                }
                else
                {
                    throw new Exception(message.ReasonPhrase);
                }
            }
        }
コード例 #10
0
        private async Task <GetAdditionalDriverRatesResults> GetAdditioanalDriverRatesAsync(WebApiRequest request)
        {
            string orderContents = Newtonsoft.Json.JsonConvert.SerializeObject(request);
            HttpResponseMessage responseMessage = await PostHttpRequestAsync(orderContents, new Uri(GetAdditionalDriverChargeUri)).ConfigureAwait(false);

            if (responseMessage.IsSuccessStatusCode)
            {
                string stringContents = await responseMessage.Content.ReadAsStringAsync();

                IEnumerable <WebApiAdditionalDriverRates> resultForAdditionalDriverListRequest = CreateResultForAdditionalDriverListRequest(stringContents);
                return(new GetAdditionalDriverRatesResults
                {
                    WebApiAdditionalDriverRates = resultForAdditionalDriverListRequest
                });
            }
            string errorString = await responseMessage.Content.ReadAsStringAsync();

            return(new GetAdditionalDriverRatesResults
            {
                Error = errorString
            });
        }
コード例 #11
0
 /// <summary>
 /// Get Additional Driver Rates
 /// </summary>
 public GetAdditionalDriverRatesResults GetAdditionalDriverRates(WebApiRequest webApiRequest)
 {
     return(GetAdditioanalDriverRatesAsync(webApiRequest).Result);
 }
コード例 #12
0
        private async Task <GetAvailableChauffersRatesResults> GetChauffersRatesAsync(WebApiRequest request)
        {
            string orderContents = Newtonsoft.Json.JsonConvert.SerializeObject(request);
            HttpResponseMessage responseMessage = await PostHttpRequestAsync(orderContents, new Uri(GetAvailableChauffersRatesUri)).ConfigureAwait(false);

            if (responseMessage.IsSuccessStatusCode)
            {
                string stringContents = await responseMessage.Content.ReadAsStringAsync();

                return(new GetAvailableChauffersRatesResults
                {
                    ApiAvailableChuffersRates = CreateResultForChauffersListRequest(stringContents)
                                                //for service rate ,decide to see result of web service
                });
            }
            else
            {
                string errorString = await responseMessage.Content.ReadAsStringAsync();

                return(new GetAvailableChauffersRatesResults
                {
                    Error = errorString
                });
            }
        }
コード例 #13
0
 /// <summary>
 /// Get Available Chauffers with chrage rates
 /// </summary>
 public GetAvailableChauffersRatesResults GetAvailableChauffersRates(WebApiRequest webApiRequest)
 {
     return(GetChauffersRatesAsync(webApiRequest).Result);
 }
コード例 #14
0
        private async Task <GetAvailableInsurancesRatesResults> GetInsurancesRatesAsync(WebApiRequest request)
        {
            string requestContents = Newtonsoft.Json.JsonConvert.SerializeObject(request);
            HttpResponseMessage responseMessage = await PostHttpRequestAsync(requestContents, new Uri(GetAvailableInsurancesRateUri)).ConfigureAwait(false);

            if (responseMessage.IsSuccessStatusCode)
            {
                string stringContents = await responseMessage.Content.ReadAsStringAsync();

                IEnumerable <WebApiAvailableInsurancesRates> webApiAvailableInsurancesRateses = CreateResultForInsurancesListRequest(stringContents);
                return(new GetAvailableInsurancesRatesResults
                {
                    ApiAvailableInsurances = webApiAvailableInsurancesRateses
                });
            }
            {
                string errorString = await responseMessage.Content.ReadAsStringAsync();

                return(new GetAvailableInsurancesRatesResults
                {
                    Error = errorString
                });
            }
        }
コード例 #15
0
 /// <summary>
 /// Get Available Insurances Rates
 /// </summary>
 public GetAvailableInsurancesRatesResults GetAvailableInsurancesRates(WebApiRequest webApiRequest)
 {
     return(GetInsurancesRatesAsync(webApiRequest).Result);
 }