Exemplo n.º 1
0
        public SyncroBasePresta()
            : base()
        {
            var logondata = LoginData();

            _url    = logondata.WebServiceUrl;
            _url   += "api/";
            _autKey = logondata.AuthKey;
            var config = ConfigurationManager.OpenExeConfiguration(
                Assembly.GetExecutingAssembly().Location);

            CheckModeDebug(config);
            if (config.AppSettings.Settings["Test"].Value == "1")
            {
                _url    = config.AppSettings.Settings["UrlPrestaShop"].Value;
                _autKey = config.AppSettings.Settings["AutKey"].Value;

                //StrumentiMusicali.Core.Manager.ManagerLog.Logger.Info("TEST _url ");
                //StrumentiMusicali.Core.Manager.ManagerLog.Logger.Info(_url);
            }

            _imageFactory          = new ImageFactory(_url, _autKey, "");
            _StockAvailableFactory = new StockAvailableFactory(_url, _autKey, "");
            _productFactory        = new ProductFactory(_url, _autKey, "");
            _categoriesFact        = new CategoryFactory(_url, _autKey, "");
            _taxRuleGroupFact      = new TaxRuleGroupFactory(_url, _autKey, "");
        }
Exemplo n.º 2
0
        private bool disposedValue = false; // Per rilevare chiamate ridondanti

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: eliminare lo stato gestito (oggetti gestiti).
                }
                _categoriesFact        = null;
                _StockAvailableFactory = null;
                _imageFactory          = null;
                _productFactory        = null;

                // TODO: liberare risorse non gestite (oggetti non gestiti) ed eseguire sotto l'override di un finalizzatore.
                // TODO: impostare campi di grandi dimensioni su Null.

                disposedValue = true;
            }
        }
        public async Task InitFactories(string url, string account)
        {
            string       baseUrl  = url;
            const string password = "";

            ProductFactory         = new ProductFactory(baseUrl, account, password);
            CategoryFactory        = new CategoryFactory(baseUrl, account, password);
            StockFactory           = new StockAvailableFactory(baseUrl, account, password);
            FeatureValuesFactory   = new ProductFeatureValueFactory(baseUrl, account, password);
            ImageFactory           = new ImageFactory(baseUrl, account, password);
            ProductSupplierFactory = new ProductSupplierFactory(baseUrl, account, password);

            ManufacturerFactory = new ManufacturerFactory(baseUrl, account, password);

            SpecialPriceFactory = new SpecificPriceFactory(baseUrl, account, password);

            var featuresFactory = new ProductFeatureFactory(baseUrl, account, password);
            var features        = await featuresFactory.GetAll();

            //SizeFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Размер", StringComparison.OrdinalIgnoreCase));
            //ColorFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Цвет", StringComparison.OrdinalIgnoreCase));

            BatteryFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Батарейки", StringComparison.OrdinalIgnoreCase));
            if (BatteryFeature == null)
            {
                BatteryFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Батарейки")
                    }
                };
                BatteryFeature = await featuresFactory.Add(BatteryFeature);
            }

            MaterialFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Материал", StringComparison.OrdinalIgnoreCase));
            if (MaterialFeature == null)
            {
                MaterialFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Материал")
                    }
                };
                MaterialFeature = await featuresFactory.Add(MaterialFeature);
            }

            CountryFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Страна", StringComparison.OrdinalIgnoreCase));
            if (CountryFeature == null)
            {
                CountryFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Страна")
                    }
                };
                CountryFeature = await featuresFactory.Add(CountryFeature);
            }

            PackingFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Упаковка", StringComparison.OrdinalIgnoreCase));
            if (PackingFeature == null)
            {
                PackingFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Упаковка")
                    }
                };
                PackingFeature = await featuresFactory.Add(PackingFeature);
            }

            LengthFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Длина", StringComparison.OrdinalIgnoreCase));
            if (LengthFeature == null)
            {
                LengthFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Длина")
                    }
                };
                LengthFeature = await featuresFactory.Add(LengthFeature);
            }

            DiameterFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Диаметр", StringComparison.OrdinalIgnoreCase));
            if (DiameterFeature == null)
            {
                DiameterFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Диаметр")
                    }
                };
                DiameterFeature = await featuresFactory.Add(DiameterFeature);
            }

            var optionsFactory = new ProductOptionFactory(baseUrl, account, password);
            var options        = await optionsFactory.GetAll();

            SizeOption = options.FirstOrDefault(f => f.name.First().Value.Equals("size", StringComparison.OrdinalIgnoreCase));
            if (SizeOption == null)
            {
                Log.Error("Size option not found, add size option!");
                throw new Exception("Size option not found");
            }

            ColorOption = options.FirstOrDefault(f => f.name.First().Value.Equals("color", StringComparison.OrdinalIgnoreCase));
            if (ColorOption == null)
            {
                Log.Error("Color option not found, add size option!");
                throw new Exception("Color option not found");
            }

            OptionsValueFactory = new ProductOptionValueFactory(baseUrl, account, password);

            CombinationFactory = new CombinationFactory(baseUrl, account, password);

            SupplierFactory = new SupplierFactory(baseUrl, account, password);
            Suppliers       = await SupplierFactory.GetAll();

            if (!Suppliers.Any())
            {
                throw new Exception("Suppliers not found, add them manualy");
            }
        }