Example #1
0
        /// <summary>
        /// Get latest image for a given camera
        /// </summary>
        /// <param name="camera">Camera object</param>
        /// <returns>Status of API call <seealso cref="APIMASH.ApiResponseStatus"/>. This method will alway return success.</returns>
        public async Task <APIMASH.ApiResponseStatus> GetCameraImage(TomTomCameraViewModel camera)
        {
            BitmapImage cameraImage = null;

            // invoke the API (explicit deserializer provided because the image responses from TomTom don't include a Content-Type header
            var apiResponse = await Invoke <BitmapImage>(
                Deserializers <BitmapImage> .DeserializeImage,
                "https://api.tomtom.com/trafficcams/getfullcam/{0}.jpg?key={1}",
                camera.CameraId,
                this._apiKey);

            // if successful, grab image as deserialized response
            if (apiResponse.IsSuccessStatusCode)
            {
                cameraImage = apiResponse.DeserializedResponse;
            }

            // otherwise, use some stock image to reflect error condition
            else if (apiResponse.StatusCode == HttpStatusCode.NotFound)
            {
                cameraImage = new BitmapImage(new Uri("ms-appx:///APIMASH_APIs/Assets/camera404.png"));
            }
            else
            {
                cameraImage = new BitmapImage(new Uri("ms-appx:///APIMASH_APIs/Assets/cameraError.png"));
            }

            // populate the ViewModel with the image
            TomTomCamerasModel.PopulateViewModel(cameraImage, apiResponse.RawResponse, camera);

            // return a success status (there will always be an image returned)
            return(ApiResponseStatus.Default);
        }
Example #2
0
        /// <summary>
        /// Get latest image for a given camera
        /// </summary>
        /// <param name="camera">Camera object</param>
        /// <returns>Status of API call <seealso cref="APIMASH.ApiResponseStatus"/>. This method will alway return success.</returns>
        public async Task <APIMASH.ApiResponseStatus> GetCameraImage(TomTomCameraViewModel camera)
        {
            BitmapImage cameraImage = null;

            Byte[] imageBytes;

            // invoke the API (explicit deserializer provided because the image responses from TomTom don't include a Content-Type header
            var apiResponse = await Invoke <BitmapImage>(
                Deserializers <BitmapImage> .DeserializeImage,
                "https://api.tomtom.com/trafficcams/getfullcam/{0}.jpg?key={1}",
                camera.CameraId,
                this._apiKey);



            // if successful, grab image as deserialized response
            if (apiResponse.IsSuccessStatusCode)
            {
                cameraImage = apiResponse.DeserializedResponse;
                imageBytes  = apiResponse.RawResponse;
            }

            // otherwise, use some stock image to reflect error condition
            else
            {
                var errorImage = (apiResponse.StatusCode == HttpStatusCode.NotFound) ?
                                 "ms-appx:///APIMASH_APIs/Assets/camera404.png" :
                                 "ms-appx:///APIMASH_APIs/Assets/cameraError.png";

                cameraImage = new BitmapImage(new Uri(errorImage));
                imageBytes  = Encoding.UTF8.GetBytes(errorImage);
            }

            lock (_resultsLock)
            {
                // populate the ViewModel with the image and if image was added, determine if we're at capacity and remove oldest picture
                if (TomTomCamerasModel.PopulateViewModel(cameraImage, imageBytes, camera))
                {
                    UpdateTimeLapseQueue(camera.CameraId);
                }
            }

            // return a success status (there will always be an image returned)
            return(ApiResponseStatus.Default);
        }
Example #3
0
        /// <summary>
        /// Get latest image for a given camera
        /// </summary>
        /// <param name="camera">Camera object</param>
        /// <returns>Status of API call <seealso cref="APIMASH.ApiResponseStatus"/>. This method will alway return success.</returns>
        public async Task<APIMASH.ApiResponseStatus> GetCameraImage(TomTomCameraViewModel camera)
        {
            BitmapImage cameraImage = null;

            // invoke the API (explicit deserializer provided because the image responses from TomTom don't include a Content-Type header
            var apiResponse = await Invoke<BitmapImage>(
                Deserializers<BitmapImage>.DeserializeImage,
                "https://api.tomtom.com/trafficcams/getfullcam/{0}.jpg?key={1}",
                camera.CameraId,
                this._apiKey);

            // if successful, grab image as deserialized response
            if (apiResponse.IsSuccessStatusCode)
            {
                cameraImage = apiResponse.DeserializedResponse;
            }

            // otherwise, use some stock image to reflect error condition
            else if (apiResponse.StatusCode == HttpStatusCode.NotFound)
            {
                cameraImage = new BitmapImage(new Uri("ms-appx:///APIMASH_APIs/Assets/camera404.png"));
            }
            else
            {
                cameraImage = new BitmapImage(new Uri("ms-appx:///APIMASH_APIs/Assets/cameraError.png"));
            }

            // populate the ViewModel with the image
            TomTomCamerasModel.PopulateViewModel(cameraImage, camera);

            // return a success status (there will always be an image returned)
            return ApiResponseStatus.Default;
        }
Example #4
0
 public static void PopulateViewModel(BitmapImage camImage, TomTomCameraViewModel viewModel)
 {
     viewModel.Image = camImage;
     viewModel.LastRefresh = DateTime.UtcNow;
 }
Example #5
0
 public static void PopulateViewModel(BitmapImage camImage, Byte[] imageBytes, TomTomCameraViewModel viewModel)
 {
     viewModel.Image       = camImage;
     viewModel.ImageBytes  = imageBytes;
     viewModel.LastRefresh = DateTime.UtcNow;
 }
Example #6
0
        public static Boolean PopulateViewModel(BitmapImage camImage, Byte[] imageBytes, TomTomCameraViewModel viewModel)
        {
            // guard against current camera reference going null due to a refresh
            if (viewModel == null)
            {
                return(false);
            }

            // only add the image if there are none or it differ from last one stored for this camera
            if ((viewModel.TimeLapse.Count == 0) || (!Enumerable.SequenceEqual <Byte>(viewModel.LastImageBytes, imageBytes)))
            {
                viewModel.LastImageBytes = imageBytes;
                viewModel.TimeLapse.Add(new TimeLapseImage(camImage, DateTime.UtcNow));

                return(true);
            }
            else
            {
                return(false);
            }
        }