Ejemplo n.º 1
0
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id, string responseStatus = null)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName    = id;
            ViewBag.ResponseStatus = responseStatus;

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;

            GetWeatherInfoRequest  AccuWeatherRequest  = new GetWeatherInfoRequest(infoResponse.companyInfo.locations[0]);
            GetWeatherInfoResponse AccuWeatherResponse = connection.getAccuWeatherInfo(AccuWeatherRequest);

            ViewBag.AccuWeatherInfo = AccuWeatherResponse.data;

            return(View("DisplayCompany"));
        }
Ejemplo n.º 2
0
        public async Task <WeatherInfo> GetWeatherAsync(GetWeatherInfoRequest request)
        {
            return(await _context.WeatherCollection.Find(Builders <WeatherInfo> .Filter.And(

                                                             Builders <WeatherInfo> .Filter.Eq(v => v.ShortDate, request.ShortDate),
                                                             Builders <WeatherInfo> .Filter.Eq(v => v.City, request.City)
                                                             )).SingleAsync().ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        public async Task <WeatherInfo> GetWeatherAsync(GetWeatherInfoRequest request)
        {
            var key = ("GetWeatherAsync_" + request.ShortDate + request.City).GetHashCode();

            if (_cache.TryGetValue(key, out var result))
            {
                return(await Task.FromResult((WeatherInfo)result));
            }

            var originalResponse = await _innerRepository.GetWeatherAsync(request).ConfigureAwait(false);

            _cache.Set(key, originalResponse, TimeSpan.FromMinutes(5));

            return(originalResponse);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends the data to the weather service, and returns the response.
        /// </summary>
        /// <param name="request">The data sent by the client</param>
        /// <returns>The response from the company directory service</returns>
        private GetWeatherInfoResponse getAccuWeather(GetWeatherInfoRequest request)
        {
            if (authenticated == false)
            {
                return(new GetWeatherInfoResponse(false, "Error: You must be logged in to use the weather functionality.", null));
            }

            // This class indicates to the request function where
            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("AccuWeather");

            // The Request<> funtion itself is an asynchronous operation. However, since we do not want to continue execution until the Request
            // function runs to completion, we call the ConfigureAwait, GetAwaiter, and GetResult functions to ensure that this thread
            // will wait for the completion of Request before continueing.
            return(requestingEndpoint.Request <GetWeatherInfoResponse>(request, sendOptions).
                   ConfigureAwait(false).GetAwaiter().GetResult());
        }
Ejemplo n.º 5
0
        public async Task <WeatherInfo> GetWeather(GetWeatherInfoRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (string.IsNullOrEmpty(request.City))
            {
                throw new ArgumentException(nameof(request.City));
            }

            try
            {
                _log.Info($"Get weather for {request.City} on {request.ShortDate}");

                return(await _weatherRepository.GetWeatherAsync(request));
            }
            catch (Exception e)
            {
                _log.Error("Error when getting weather", e);
                throw;
            }
        }
 public GetWeatherInfoResponse getAccuWeatherInfo(GetWeatherInfoRequest request)
 {
     send(request);
     return((GetWeatherInfoResponse)readUntilEOF());
 }