Beispiel #1
0
        public async Task<ActionResult> Populate(string SearchString, string Protocol) {
            //get data from omdbapi.com
            var httpHelper = new HttpServices();
            var movies = httpHelper.GetMoviesInfo(SearchString, Protocol);
            Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Retrieved " + movies.Count + " movies");
            if (movies != null){
                //add movies to SQL database
                await dataProvider.AddRangeAsync(movies);
                Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Movie entries saved");

                //send msg to queue
                Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> Start sending 'create' messages");
                cloudServiceProvider.SendMessages("Create", movies);
                Trace.TraceInformation(TraceInfo.ShortTime + "WER >>> End sending 'create' messages");

                //return view with data
                return View("Index", await dataProvider.ToListAsync());
            } else {
                return View();
            }
        }
Beispiel #2
0
        //PROCESS A MESSAGE
        private void ProcessQueueMessage(BrokeredMessage msg)
        {
            //CHECK: recognize the app id? fail- abandon this message
            if (!isMessageFromWebApp(msg)) { return; }

            //PROCESS: base on action value
            //Delete all records in database
            string act = msg.Properties["Action"].ToString();
            if (act == "DeleteAll")
            {
                azureServiceProvider.DeleteAllBlobs();
                msg.Complete();
                return;
            }
            //Delete a record
            else if (act == "Delete") {
                string imageUrl = msg.Properties["ImageUrl"].ToString();
                string thumbUrl = msg.Properties["ThumbURL"].ToString();
                azureServiceProvider.DeleteMovieImageBlobs(imageUrl, thumbUrl);
                msg.Complete();
                return;
            }

            //GET MESSAGE CONTENT (Create)
            string imdbId = msg.Properties["imdbId"].ToString();
            string remoteFileUrl = msg.Properties["Poster"].ToString();
            var movieId = int.Parse(msg.Properties["MovieId"].ToString());

            //CHECK: no image URL?
            if (remoteFileUrl == "" | remoteFileUrl == null){
                msg.Complete();
                return;
            }

            //CHECK: SQL record for the movieId exist?
            if (dataProvider.Count(movieId) < 1) {
                msg.Complete();
                return;
            }

            //CHECK - if no imdbId found, , fail- delete this message
            int imdbCount = dataProvider.Count(imdbId);
            if (imdbCount < 1){
                msg.Complete();
                return;
            }

            //CHECK - if there is more than one imdbId found (ie duplicate movies info), delete duplicate records
            else if (imdbCount > 1){
                //remove duplicate item
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Duplicate movies detected");
                dataProvider.RemoveDuplicate(movieId);
                msg.Complete();
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Duplicate message was deleted.");
                return;
            } else if (imdbCount == 1) {

                //DOWNLOAD IMAGE FILE
                //HttpSevice provides service of download, save, convert image to stream
                HttpServices httpHelper = new HttpServices();

                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Downloads poster from remote web site");
                var mStream = httpHelper.GetImageStream(remoteFileUrl);

                //DEFINE BLOB NAME
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Creating thumbnail");
                Uri blobUri = new Uri(remoteFileUrl);
                string blobName = blobUri.Segments[blobUri.Segments.Length - 1];
                var urls = azureServiceProvider.SaveImagesToContainer(mStream, blobName);
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Saved poster & thumbnail to Azure");

                //UPDATE THE URL IN SQL DB
                dataProvider.UpdateImageURL(urls, imdbId);
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Updated urls for poster & thumbnail.");

                msg.Complete();
                Trace.TraceInformation(TraceInfo.ShortTime + "WKR >>> Message process completed");

                mStream.Dispose();
                mStream = null;
            }
        }