Beispiel #1
0
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            var key = new HotelProperty()
            {
                AppacitiveId   = workItem.ArticleId,
                PropertyId     = long.Parse(workItem.HotelId),
                SupplierFamily = workItem.SupplierFamily
            };
            var appacitiveHotelKey = _appacitive.CreateHotelKey(key);

            List <HotelTimeDetail> inDetails  = null;
            List <HotelTimeDetail> outDetails = null;

            //1. Get the checkinout details from the appacitive
            _appacitive.GetCheckInOutDetails(appacitiveHotelKey, out inDetails, out outDetails);
            if (inDetails != null || outDetails != null)
            {
                //2. Update/Add the checkinout details
                _inOutDetailsProvider.AddOrUpdate(workItem.HotelId, workItem.SupplierFamily, inDetails, outDetails);
            }
            else
            {
                _inOutDetailsProvider.Delete(workItem.HotelId, workItem.SupplierFamily);
            }
            return(null);
        }
        //private readonly IDatabaseManager _sqlDb = SqlDataProviderFactory.GetDatabaseManager();
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            //var key = new HotelProperty()
            //{
            //    AppacitiveId = workItem.ArticleId,
            //    PropertyId = long.Parse(workItem.HotelId),
            //    SupplierFamily = workItem.SupplierFamily
            //};
            //var sqlHotelKey = _sqlDb.CreateHotelKey(key);
            //var appacitiveHotelKey = _appacitive.CreateHotelKey(key);

            ////1. Get nearby hotel attractions from the appacitive for the hotelarticle id.
            //var sourceAttractions = _appacitive.GetAreaAttractions(appacitiveHotelKey);

            ////2. Get nearby hotel attractions from the client database
            //var destAttractions = _sqlDb.GetAreaAttractions(sqlHotelKey);

            ////3. compare these two lists and update the client database accordingly
            //sourceAttractions = sourceAttractions ?? new List<AreaAttraction>();
            //destAttractions = destAttractions ?? new List<AreaAttraction>();
            ////3.1 Add or Update hotel attractions
            //foreach (var sourceAttraction in sourceAttractions)
            //{
            //    var foundIndex = destAttractions.FindIndex(i => i.Equals(sourceAttraction));
            //    if (foundIndex == -1)
            //    {
            //        _sqlDb.SaveAreaAttraction(sqlHotelKey, sourceAttraction); // Add
            //    }
            //    else
            //    {
            //        if (destAttractions[foundIndex].IsUpdated(sourceAttraction))
            //        {
            //            sourceAttraction.Id = destAttractions[foundIndex].Id;
            //            _sqlDb.SaveAreaAttraction(sqlHotelKey, sourceAttraction); //Update
            //        }
            //        destAttractions.RemoveAt(foundIndex);
            //    }
            //}
            ////3.2 delete missing hotel nearby attractions
            //foreach (var destAttraction in destAttractions)
            //{
            //    _sqlDb.DeleteAreaAttraction(sqlHotelKey, destAttraction);
            //}
            return(null);
        }
        public static HotelWorkItem ToHotelWorkItem(this Article article)
        {
            if (article == null)
            {
                return(null);
            }
            var workItem = new HotelWorkItem();

            workItem.Id             = article.Id;
            workItem.UtcCreateDate  = article.UtcCreateDate;
            workItem.UtcLastUpdated = article.UtcLastUpdated;
            workItem.ArticleId      = article.Get <string>("hotel_article_id");
            workItem.HotelId        = article.Get <string>("hotel_id");
            workItem.Revision       = article.Get <long>("version");
            workItem.SupplierFamily = article.Get <string>("supplier_family");
            workItem.Schema         = article.Get <string>("content_type");
            workItem.ChangeType     = article.Get <ChangeType>("change_type");
            return(workItem);
        }
Beispiel #4
0
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            var key = new HotelProperty()
            {
                AppacitiveId   = workItem.ArticleId,
                PropertyId     = long.Parse(workItem.HotelId),
                SupplierFamily = workItem.SupplierFamily
            };
            var appacitiveHotelKey = _appacitive.CreateHotelKey(key);

            //1. Get images from the appacitive for the hotelarticle id.
            var sourceImages = _appacitive.GetImagesForHotel(appacitiveHotelKey);

            //2. Get images from the client database
            var destImages = _imageDataProvider.GetImagesForHotel(workItem.HotelId, workItem.SupplierFamily);

            //3. compare these two lists and update the client database accordingly
            sourceImages = sourceImages ?? new List <HotelImage>();
            destImages   = destImages ?? new List <HotelImage>();
            //3.1 Add new hotel images
            foreach (var sourceImage in sourceImages)
            {
                var foundIndex = destImages.FindIndex(i => i.Equals(sourceImage));
                if (foundIndex == -1)
                {
                    _imageDataProvider.SaveImage(workItem.HotelId, workItem.SupplierFamily, sourceImage);
                }
                else
                {
                    if (destImages[foundIndex].IsUpdated(sourceImage))
                    {
                        _imageDataProvider.UpdateImage(workItem.HotelId, workItem.SupplierFamily, sourceImage);
                    }
                    destImages.RemoveAt(foundIndex);
                }
            }
            //3.2 delete hotel images
            foreach (var destImage in destImages)
            {
                _imageDataProvider.DeleteImage(destImage.Id);
            }
            return(null);
        }
Beispiel #5
0
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            //1. Get the activities from the appacitive using the hotel article id.
            //2. Get the activities from the client database using the hotelid and supplierfamily
            //3. Compare two above list and detect which all activities are added/deleted/updated
            //4. Update/delete/add activities into the client database.

            IKey hotelKey = new AppacitiveDAL.HotelKey()
            {
                HotelArticleId = workItem.ArticleId, HotelId = Convert.ToInt64(workItem.HotelId), SupplierFamily = workItem.SupplierFamily
            };
            IActivityDataProvider activityDataProvider = new ActivityDataProvider();

            // Get Appacitive activities by HotelArticleId
            List <HotelActivity> sourceActivities = new AppacitiveDAL.DatabaseManager().GetHotelActivities(hotelKey);

            // Get Client DB activities by HotelArticleId
            List <HotelActivity> destinationActivities = activityDataProvider.GetHotelActivities(hotelKey);

            foreach (var sourceActivity in sourceActivities)
            {
                HotelActivity activity = destinationActivities.Find(x => x.Equals(sourceActivity));
                if (activity == null)
                {
                    // New Hotel Activity
                    activityDataProvider.InsertHotelActivity(hotelKey, sourceActivity);
                }
                else
                {
                    // Old Hotel Activity
                    if (!activity.IsUpdated(sourceActivity))
                    {
                        activityDataProvider.UpdateHotelActivity(hotelKey, sourceActivity);
                    }

                    destinationActivities.Remove(activity);
                }
            }

            destinationActivities.ForEach(x => activityDataProvider.DeleteHotelActivity(hotelKey, x));

            return(null);
        }
        public void HotelWorkItemInputShouldBuildOnDataTypeAndChangeTypeTest()
        {
            var dataType = Unique.NewString;
            var workItem = new HotelWorkItem()
            {
                Schema = dataType, ChangeType = ChangeType.Updated
            };
            var command = new Mock <IWorkItemCommand>().Object;

            try
            {
                var key = string.Format("{0}.{1}", dataType, "Updated");
                ObjectBuilder.RegisterInstance <IWorkItemCommand>(command, key);
                IWorkItemCommandFactory commandFactory = new HotelWorkItemCommandFactory();
                var cmd = commandFactory.BuildCommand(workItem);
                Assert.IsTrue(cmd == command, "Incorrect command built by the factory for the given workitem.");
            }
            finally
            {
                ObjectBuilder.Reset();
            }
        }
Beispiel #7
0
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            IKey hotelKey = new AppacitiveDAL.HotelKey()
            {
                HotelArticleId = workItem.ArticleId, HotelId = Convert.ToInt64(workItem.HotelId), SupplierFamily = workItem.SupplierFamily
            };
            IDescriptionDataProvider descriptionDataProvider = new DescriptionDataProvider();

            // Get Appacitive descriptions by HotelArticleId
            List <HotelDescription> sourceDescriptions = new AppacitiveDAL.DatabaseManager().GetHotelDescriptions(hotelKey);

            // Get Client DB descriptions by HotelArticleId
            List <HotelDescription> destinationDescriptions = descriptionDataProvider.GetHotelDescriptions(hotelKey);

            foreach (var sourceDescription in sourceDescriptions)
            {
                HotelDescription description = destinationDescriptions.Find(x => x.Equals(sourceDescription));
                if (description == null)
                {
                    // New Hotel description
                    descriptionDataProvider.InsertHotelDescription(hotelKey, sourceDescription);
                }
                else
                {
                    // Old Hotel description
                    if (!description.IsUpdated(sourceDescription))
                    {
                        descriptionDataProvider.UpdateHotelDescription(hotelKey, sourceDescription);
                    }

                    destinationDescriptions.Remove(description);
                }
            }

            destinationDescriptions.ForEach(x => descriptionDataProvider.DeleteHotelDescription(hotelKey, x));

            return(null);
        }
        protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
        {
            IKey hotelKey = new AppacitiveDAL.HotelKey()
            {
                HotelArticleId = workItem.ArticleId, HotelId = Convert.ToInt64(workItem.HotelId), SupplierFamily = workItem.SupplierFamily
            };

            ISupplierHotelDataProvider supplierHotelDataProvider = new SupplierHotelDataProvider();

            List <SupplierHotel> sourceSupplierHotels = new AppacitiveDAL.DatabaseManager().GetSupplierHotelIdsByHotelIdSupplierFamily(hotelKey);

            List <SupplierHotel> destinationSupplierHotels = supplierHotelDataProvider.GetSupplierHotels(hotelKey);

            foreach (var sourceSupplierHotel in sourceSupplierHotels)
            {
                SupplierHotel supplierHotel = destinationSupplierHotels.Find(x => x.Equals(sourceSupplierHotel));
                if (supplierHotel == null)
                {
                    // New Hotel SupplierHotel
                    supplierHotelDataProvider.InsertSupplierHotel(hotelKey, sourceSupplierHotel);
                }
                else
                {
                    // Old Hotel SupplierHotel
                    if (!supplierHotel.IsUpdated(sourceSupplierHotel))
                    {
                        supplierHotelDataProvider.UpdateSupplierHotel(hotelKey, sourceSupplierHotel);
                    }

                    destinationSupplierHotels.Remove(supplierHotel);
                }
            }

            destinationSupplierHotels.ForEach(x => supplierHotelDataProvider.DeleteSupplierHotel(hotelKey, x));

            return(null);
        }
Beispiel #9
0
 protected override Task ProcessHotelWorkItem(HotelWorkItem workItem, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }