Exemplo n.º 1
0
        public static IVsSqmMulti TryGetSqmService(string baseDirectory)
        {
            IVsSqmMulti          result       = null;
            Guid                 rsid         = new Guid("2508FDF0-EF80-4366-878E-C9F024B8D981");
            Guid                 riid         = new Guid("B17A7D4A-C1A3-45A2-B916-826C3ABA067E");
            QueryServiceDelegate queryService = TryGetSqmServiceDelegate(baseDirectory);

            if (queryService != null)
            {
                try
                {
                    queryService(ref rsid, ref riid, out result);
                }
                catch (Exception e)
                {
                    Debug.Assert(false, string.Format("Could not get SQM service or have SQM related errors: {0}", e.ToString()));
                    return(null);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Queries the configured services
        /// </summary>
        /// <param name="selectedTemperatureUnitId">Id of the selected temperature UOM</param>
        /// <param name="selectedWindSpeedUnitId">Id of the selected temperature UOM</param>
        /// <param name="location">The location being searched</param>
        /// <param name="queryServiceDelegate">Callback for querying a service</param>
        public async Task <QueryResults> QueryServices(int selectedTemperatureUnitId, int selectedWindSpeedUnitId, string location, QueryServiceDelegate queryServiceDelegate = null)
        {
            if (queryServiceDelegate == null)
            {
                queryServiceDelegate = new QueryServiceDelegate(QueryService);
            }

            QueryResults returnValue = new QueryResults()
            {
                ServicesOffline   = 0,
                TotalServices     = 0,
                TemperatureResult = 0,
                TemperatureUOM    = WeatherTestDb.TemperatureUom.FirstOrDefault(i => i.Id == selectedTemperatureUnitId).Title,
                WindSpeedResult   = 0,
                WindSpeedUOM      = WeatherTestDb.WindSpeedUom.FirstOrDefault(i => i.Id == selectedWindSpeedUnitId).Title
            };

            IEnumerable <WeatherService> services = WeatherTestDb.WeatherService;

            returnValue.TotalServices = services.Count();

            List <decimal> temperatures = new List <decimal>();
            List <decimal> windSpeeds   = new List <decimal>();

            foreach (WeatherService service in services)
            {
                try
                {
                    ServiceResult serviceResult = await queryServiceDelegate(service, location);

                    if (selectedTemperatureUnitId != service.TemperatureUomid)
                    {
                        TemperatureConversion conversion = WeatherTestDb.TemperatureConversion.First(i =>
                                                                                                     i.FromTemperatureUomid == service.TemperatureUomid &&
                                                                                                     i.ToTemperatureUomid == selectedTemperatureUnitId);

                        string calculation = string.Format(conversion.Formula.Replace("{value}", "{0}"), serviceResult.TemperatureResult);
                        serviceResult.TemperatureResult = EvaluateExpression(calculation);
                    }
                    temperatures.Add(serviceResult.TemperatureResult);

                    if (selectedWindSpeedUnitId != service.WindSpeedUomid)
                    {
                        WindSpeedConversion conversion = WeatherTestDb.WindSpeedConversion.First(i =>
                                                                                                 i.FromWindSpeedUomid == service.WindSpeedUomid &&
                                                                                                 i.ToWindSpeedUomid == selectedWindSpeedUnitId);

                        string calculation = string.Format(conversion.Formula.Replace("{value}", "{0}"), serviceResult.WindSpeedResult);
                        serviceResult.WindSpeedResult = EvaluateExpression(calculation);
                    }
                    windSpeeds.Add(serviceResult.WindSpeedResult);
                }
                catch (HttpRequestException)
                {
                    returnValue.ServicesOffline++;
                }
            }

            if (temperatures.Count > 0)
            {
                returnValue.TemperatureResult = temperatures.Average();
            }
            if (windSpeeds.Count > 0)
            {
                returnValue.WindSpeedResult = windSpeeds.Average();
            }

            return(returnValue);
        }