public ActionResult Index()
        {
            var imageDalc = new ImageDalc();
            var searchDalc = new SearchDalc();

            var imgData = imageDalc.GetAll();//.Take(25);
            var searchData = searchDalc.GetAll().LastOrDefault();

            var homeViews = new List<HomeModel>();

            searchData.EventDetails.Take(25).ToList().ForEach(s =>
            {
                homeViews.Add(new HomeModel()
                {
                    EventId = s.EventId,
                    EventName = s.EventName,
                    ImageDetails = imgData.Where(d => d.EventId == s.EventId).ToList()
                });
            });

            imageDalc.disconnect();
            searchDalc.disconnect();

            return View(homeViews);
        }
Beispiel #2
0
        static void QuerySQS()
        {
            var searchDalc = new SearchDalc();
            var imageDalc = new ImageDalc();
            var colorExtract = new DominantColor();

            var sqs = AWSClientFactory.CreateAmazonSQSClient();
            var receiveMessageRequest = new ReceiveMessageRequest();
            receiveMessageRequest.QueueUrl = "https://sqs.us-west-2.amazonaws.com/xx";
            var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);

            if (receiveMessageResponse.IsSetReceiveMessageResult())
            {
                var receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                foreach (var message in receiveMessageResult.Message)
                {
                    var eventDetails = new List<EventDetail>();

                    if (message.IsSetBody())
                        eventDetails = FetchEvents(message.Body);

                    if (eventDetails != null && eventDetails.Count > 0)
                    {
                        var searchResult = searchDalc.Add(new Search() { EventDetails = eventDetails, SearchTerm = message.Body, SqsId = message.MessageId });
                        if (!string.IsNullOrEmpty(searchResult._id))
                        {
                            eventDetails.Take(25).ToList().ForEach(e =>
                            {
                                Console.WriteLine(e.EventName);
                                var imageResults = SearchEventImagesFromConnect(e.EventId);

                                Parallel.ForEach(imageResults, image =>
                                {
                                    var img = new ImageDetail()
                                    {
                                        EventId = e.EventId,
                                        ImageId = image.ImageId,
                                        Thumbnail = image.UrlThumb,
                                        DominantColor = colorExtract.GetDominantColor(image.UrlThumb).Result
                                    };
                                    imageDalc.Add(img);
                                    Console.WriteLine(img._id);
                                });
                            });
                        }
                    }

                    var messageRecieptHandle = message.ReceiptHandle;
                    var deleteRequest = new DeleteMessageRequest();
                    deleteRequest.QueueUrl = "https://sqs.us-west-2.amazonaws.com/xx";
                    deleteRequest.ReceiptHandle = messageRecieptHandle;
                    sqs.DeleteMessage(deleteRequest);
                }
            }

            searchDalc.disconnect();
            imageDalc.disconnect();
        }