예제 #1
0
        public static ServiceResult UpdateCityWeatherData(ICityWeatherClient cityWeatherClient,
                                                          SPWeb web, string docUrl, SPItemEventDataCollection cityItemProps)
        {
            var result = new ServiceResult();

            try
            {
                var itemName = (string)cityItemProps["Title"];

                var position = new Position()
                {
                    Lat = Decimal.Parse((string)cityItemProps[CityItemFields.Latitude]),
                    Lon = Decimal.Parse((string)cityItemProps[CityItemFields.Longitude]),
                };

                var csvContent = cityWeatherClient.GetCityWeatherCSV(position);

                //check doc hash
                if (string.IsNullOrEmpty(docUrl) ||
                    csvContent.GetHashCodeSafe() != GetCityItemWeatherContent(web, docUrl).GetHashCodeSafe())
                {
                    cityItemProps[CityItemFields.DocumentRef] = SaveCityDocument(web, itemName, csvContent);
                }

                result.Result = true;
            }
            catch (Exception e)
            {
                result.Message = e.GetAggregatedExceptionMessage();
            }

            return(result);
        }
예제 #2
0
 public CityItemEventReceivers()
 {
     _cityWeatherClient = new CityWeatherClient(
         new DataRequest(AppProperties.RetryCount, AppProperties.RetrtInterval),
         AppProperties.CityWeatherServiceUrl);
 }