private ServiceBusResponse weatherRequest(WeatherServiceRequest weatherRequest)
        {
            switch (weatherRequest.requestType)
            {
            case (WeatherRequest.GetWeather):
                return(getWeather((GetWeatherRequest)weatherRequest));

            default:
                return(new ServiceBusResponse(false, "No results could be found pertaining to your search"));
            }
        }
示例#2
0
        private ServiceBusResponse WeatherService(WeatherServiceRequest request)
        {
            switch (request.requestType)
            {
            case (WeatherRequest.getWeather):
                return(getWeather((GetWeatherRequest)request));

            default:
                return(new ServiceBusResponse(false, "Error: Invalid Request. Request received was:" + request.requestType.ToString()));
            }
        }
        private ServiceBusResponse getWeatherCondition(WeatherServiceRequest request)
        {
            if (authenticated == false)
            {
                return(new WeatherResponse(false, "Error: You must be logged in to use the echo reverse functionality."));
            }

            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Weather");
            return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult());
        }
示例#4
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)
        {
            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;

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



            String[] responseToArray = infoResponse.response.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            String[] locations       = new String[responseToArray.Length - 3];

            Array.Copy(responseToArray, 3, locations, 0, responseToArray.Length - 3);
            CompanyInstance value = new CompanyInstance(responseToArray[0], responseToArray[1], responseToArray[2], locations);

            ViewBag.CompanyInfo = value;
            ViewBag.username    = Globals.getUser();
            ViewBag.time        = DateTime.Now.ToString();


            //Harjee format the string into an array or something, then display it nicely on the view
            string reviews = GetReview(value.companyName);

            if (!reviews.Contains(":]"))
            {
                JObject json = JObject.Parse(reviews);

                JProperty allReviews = json.Property("reviews");

                string   totalReviews       = allReviews.Value.ToString();
                string[] unformattedResults = totalReviews.Split(',');

                for (int i = 4; i < unformattedResults.Length; i += 5)
                {
                    int position = unformattedResults[i].IndexOf('}');

                    if (position < 0)
                    {
                        position = unformattedResults[i].IndexOf(']');
                    }

                    if (position >= 0)
                    {
                        unformattedResults[i] = unformattedResults[i].Substring(0, position);
                    }
                }
                if (unformattedResults.Length > 2)
                {
                    for (int i = 0; i < unformattedResults.Length; i += 5)
                    {
                        int      reviewNumber = (i / 5) + 1;
                        string[] temp         = unformattedResults[i + 1].Split(':');
                        ViewBag.reviews += "Review #" + reviewNumber + ": ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 2].Split(':');
                        ViewBag.reviews += "Stars: ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 3].Split(':');
                        ViewBag.reviews += "Timestamp: ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 4].Split(':');
                        ViewBag.reviews += "Username: "******" <br/> <br/> ";
                    }

                    ViewBag.reviews += " <br/> ";
                }
            }

            else
            {
                ViewBag.reviews = " No reviews found <br/> ";
            }

            //Call Weather Service

            WeatherServiceRequest  info     = new WeatherServiceRequest(value.locations[0]);
            WeatherServiceResponse response = (WeatherServiceResponse)connection.getWeather(info);

            ViewBag.weatherText         = response.returnData.weatherText;
            ViewBag.temperature         = response.returnData.temperature;
            ViewBag.realFeelTemperature = response.returnData.realFeelTemperature;
            if (response.returnData.weatherIcon < 10)
            {
                ViewBag.weatherIcon = "https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/0" + response.returnData.weatherIcon + "-s.png";
            }
            else
            {
                ViewBag.weatherIcon = "https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/" + response.returnData.weatherIcon + "-s.png";
            }


            return(View("DisplayCompany"));
        }
 /// <summary>
 /// Listens for the client to secifify which task is being requested from the company listing service
 /// </summary>
 /// <param name="request">Includes which task is being requested and any additional information required for the task to be executed</param>
 /// <returns>A response message</returns>
 private ServiceBusResponse weatherServiceRequest(WeatherServiceRequest request)
 {
     return(getWeatherCondition(request));
 }
示例#6
0
 public ServiceBusResponse getWeather(WeatherServiceRequest request)
 {
     send(request);
     return(readUntilEOF());
 }