예제 #1
0
        private void LoadStaticFromApis()
        {
            var response   = PostJson("https://my.taylormadegolf.com/myFittingExp/api/authentication?j_username=tmagitadmin&j_password=AtuS3VhLw2&remember-me=true&submit=Login", new { });
            var csrfToken  = response.Cookies["CSRF-TOKEN"].Value;
            var jSessionId = response.Cookies["JSESSIONID"].Value;

            // flex
            var ironFlex   = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Profile_Current_Shaft_Flex", response.Cookies);
            var flexString = GetDataString(ironFlex);


            var flexIronObjects = JsonConvert.DeserializeAnonymousType(flexString, loogUpObject);

            var ironCategoryId    = _staticTableHelper.GetCategoryId("Iron");
            var driverCategoryId  = _staticTableHelper.GetCategoryId("Driver");
            var fairwayCategoryId = _staticTableHelper.GetCategoryId("Fairway");
            var rescueCategoryId  = _staticTableHelper.GetCategoryId("Rescue");
            var wedgeCategoryId   = _staticTableHelper.GetCategoryId("Wedge");

            foreach (var item in flexIronObjects)
            {
                var i = new ClubShaftFlex();
                i.Value     = item.lookupValue;
                i.SortOrder = item.sortOrder;

                _repository.SaveQueue(i);
            }

            //drive loft
            var driverLoft       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Industry_Driver_Loft", response.Cookies);
            var driverLoftString = GetDataString(driverLoft);

            var driverLoftObjects = JsonConvert.DeserializeAnonymousType(driverLoftString, loogUpObject);

            foreach (var item in driverLoftObjects)
            {
                var i = new ClubLoft();
                i.Value          = item.lookupValue;
                i.SortOrder      = item.sortOrder;
                i.ClubCategoryId = driverCategoryId;
                _repository.SaveQueue(i);
            }

            //fw loft
            var fwLoft       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Industry_FW_Loft", response.Cookies);
            var fwLoftString = GetDataString(fwLoft);

            var fwObjects = JsonConvert.DeserializeAnonymousType(fwLoftString, loogUpObject);

            foreach (var item in fwObjects)
            {
                var i = new ClubLoft();
                i.Value          = item.lookupValue;
                i.SortOrder      = item.sortOrder;
                i.ClubCategoryId = fairwayCategoryId;
                _repository.SaveQueue(i);
            }

            //fw loft
            var RescueLoft       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Industry_Rescue_Loft", response.Cookies);
            var RescueLoftString = GetDataString(RescueLoft);

            var RescueObjects = JsonConvert.DeserializeAnonymousType(RescueLoftString, loogUpObject);

            foreach (var item in RescueObjects)
            {
                var i = new ClubLoft();
                i.Value          = item.lookupValue;
                i.SortOrder      = item.sortOrder;
                i.ClubCategoryId = rescueCategoryId;
                _repository.SaveQueue(i);
            }

            //iron loft
            var ironLoft       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Industry_Iron_Loft", response.Cookies);
            var ironLoftString = GetDataString(ironLoft);

            var ironObjects = JsonConvert.DeserializeAnonymousType(ironLoftString, loogUpObject);

            foreach (var item in ironObjects)
            {
                var i = new ClubLoft();
                i.Value          = item.lookupValue;
                i.SortOrder      = item.sortOrder;
                i.ClubCategoryId = ironCategoryId;
                _repository.SaveQueue(i);
            }
            //iron loft
            var ironLoft12       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/WITB_Wedge_Loft", response.Cookies);
            var ironLoftString12 = GetDataString(ironLoft12);

            var ironObjects12 = JsonConvert.DeserializeAnonymousType(ironLoftString12, loogUpObject);

            foreach (var item in ironObjects12)
            {
                var i = new ClubLoft();
                i.Value          = item.lookupValue;
                i.SortOrder      = item.sortOrder;
                i.ClubCategoryId = wedgeCategoryId;
                _repository.SaveQueue(i);
            }

            //Club shaflength
            var shaflength       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Profile_Current_Iron_Length", response.Cookies);
            var shaflengthString = GetDataString(shaflength);

            var shaflengthO = JsonConvert.DeserializeAnonymousType(shaflengthString, loogUpObject);

            foreach (var item in shaflengthO)
            {
                var i = new ClubShaftLength();
                i.Value     = item.lookupValue;
                i.SortOrder = item.sortOrder;
                _repository.SaveQueue(i);
            }

            //clubLie
            var clubLie       = GetJson("https://my.taylormadegolf.com/myFittingExp/api/lookups_by_type/Profile_Current_Iron_Lie", response.Cookies);
            var clubLieString = GetDataString(clubLie);

            var clubLieStringo = JsonConvert.DeserializeAnonymousType(clubLieString, loogUpObject);

            foreach (var item in clubLieStringo)
            {
                var i = new ClubLie();
                i.Value     = item.lookupValue;
                i.SortOrder = item.sortOrder;
                _repository.SaveQueue(i);
            }

            LoadClubCategoryTypes(response.Cookies, ironCategoryId, "WITB_Iron_Head_Loft");
            LoadClubCategoryTypes(response.Cookies, fairwayCategoryId, "WITB_FW_Head_Loft");
            LoadClubCategoryTypes(response.Cookies, rescueCategoryId, "WITB_Rescue_Head_Loft");
            LoadClubCategoryTypes(response.Cookies, wedgeCategoryId, "WITB_Wedge_Head_Loft");

            LoadClubLoftAdjustment(response.Cookies);

            var putterCategoryId = _staticTableHelper.GetCategoryId("Putter");

            LoadClubBrands(response.Cookies, 1, driverCategoryId);
            LoadClubBrands(response.Cookies, 2, ironCategoryId);
            LoadClubBrands(response.Cookies, 3, fairwayCategoryId);
            LoadClubBrands(response.Cookies, 4, rescueCategoryId);
            LoadClubBrands(response.Cookies, 5, putterCategoryId);
            LoadClubBrands(response.Cookies, 6, wedgeCategoryId);

            _repository.Save();
        }
예제 #2
0
        public void Migrate()
        {
            try
            {
                var consumersFromSugar     = _sugarDataContext.Query <WWhatsInTheBag>().OrderByDescending(x => x.DateModified).ToList();
                var whatsInTheBagSugar     = _sugarDataContext.Query <WWhatsInTheBagCstm>().ToList();
                var whatsInToConsumerSugar = _sugarDataContext.Query <WWhatsInTheBagCConsumersC>();
                var countFromSugar         = consumersFromSugar.Count;

                var loopCount = countFromSugar / _splitCount;

                if (loopCount > 0)
                {
                    loopCount = countFromSugar;
                }

                _logger.LogInformation("#################Starting Migration of Whats in the bag");
                _logger.LogInformation($"Found {countFromSugar} to migrate");

                for (var x = 0; x < loopCount; x++)
                {
                    var skip = x * _splitCount;
                    if (skip > countFromSugar)
                    {
                        break;
                    }
                    _logger.LogInformation($"Starting segment starting at {skip}");

                    _repository.ReloadContext();
                    _repository.GetDatabase().ChangeTracker.AutoDetectChangesEnabled = false;
                    var sugarItems = consumersFromSugar.Skip(x * _splitCount).Take(_splitCount).ToList();

                    foreach (var sItem in sugarItems)
                    {
                        var bagItem        = whatsInTheBagSugar.FirstOrDefault(y => y.IdC == sItem.Id);
                        var itemToConsumer = whatsInToConsumerSugar.FirstOrDefault(y => y.WWhatsInTheBagCConsumerswWhatsInTheBagIdb == sItem.Id);
                        var consumerOld    = _sugarDataContext.Query <CConsumers>().FirstOrDefault(y => y.Id == itemToConsumer.WWhatsInTheBagCConsumerscConsumersIda);

                        if (consumerOld == null)
                        {
                            continue;
                        }

                        var consumer = _repository.Query <ConsumerData.Models.Consumer>()
                                       .Include(y => y.GolferProfile)
                                       .FirstOrDefault(y => y.PrimaryEmail.ToLower() == consumerOld.Email.ToLower());
                        if (consumer == null)
                        {
                            continue;
                        }
                        if (consumer.GolferProfile == null)
                        {
                            consumer.GolferProfile = new ConsumerData.Models.GolferProfile
                            {
                                Created    = DateTime.UtcNow,
                                ConsumerId = consumer.Id.Value
                            };
                            _repository.SaveQueue(consumer);
                        }

                        var cdmItem = new ConsumerData.Models.WhatsInTheBag
                        {
                            ClubShaftFlexId      = _staticTableHelper.GetFlexId(bagItem.FlexC),
                            ClubLoftId           = _staticTableHelper.GetLoftId(bagItem.LoftC),
                            FaceLieAdjustmentId  = _staticTableHelper.GetLieId(bagItem.FaceLieAdjustmentC),
                            FaceLoftAdjustmentId = _staticTableHelper.GetLoftId(bagItem.FaceLoftAdjustmentC),
                            Created            = DateTime.UtcNow,
                            ClubCategoryId     = _staticTableHelper.GetCategoryId(sItem.Category),
                            BrandId            = _staticTableHelper.GetBrandId(sItem.Vendor),
                            ClubCategoryTypeId = _staticTableHelper.GetClubCategoryTypeId(bagItem.HeadLoftC),
                            ModelId            = _staticTableHelper.GetModelId(sItem.Model),
                            PlanToPurchase     = !string.IsNullOrWhiteSpace(sItem.PlanningToPurchase),
                            ClubShaftLengthId  = _staticTableHelper.GetChaftLengthId(bagItem.ShaftLengthC),
                            Sku             = bagItem.SkuC,
                            GolferProfileId = consumer.GolferProfile.Id
                        };

                        try
                        {
                            _repository.SaveQueue(cdmItem);
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e.Message);
                        }
                    }

                    _logger.LogInformation($"Saving Whats in the bag " + DateTime.UtcNow.ToLongDateString());
                    try
                    {
                        _repository.Save();
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e.Message);
                    }
                    _logger.LogInformation($"Saving Whats in the bag" + DateTime.UtcNow.ToLongDateString());
                }
            }
            catch (Exception e)
            {
                _logger.LogError("Migrate [WhatsInTheBag] failed", e);
            }
        }