Esempio n. 1
0
        public void GetProductByIdTest_2_times_with_timer()
        {
            var service = ObjectFactoryBase.Resolve <IProductService>();
            var timer   = new Stopwatch();

            timer.Start();
            service.GetProductById(ProductIdExisting);
            timer.Stop();
            Trace.WriteLine(timer.ElapsedMilliseconds);

            timer.Reset();
            timer.Start();
            service.GetProductById(ProductIdExisting);
            timer.Stop();

            Trace.WriteLine("Elapsed ms: " + timer.ElapsedMilliseconds);
            timer.Reset();

            Startup.Container.RegisterInstance <ICacheProvider>(new CacheProvider());
            Startup.Container.RegisterSingleton <VersionedCacheProviderBase>();

            ObjectFactoryConfigurator.DefaultContainer = Startup.Container;
            service = ObjectFactoryBase.Resolve <IProductService>();

            timer.Start();
            service.GetProductById(ProductIdExisting);
            timer.Stop();
            Trace.WriteLine("Elapsed ms: " + timer.ElapsedMilliseconds);
        }
Esempio n. 2
0
        public void Temp()
        {
            var productService = ObjectFactoryBase.Resolve <IProductService>();
            var article        = productService.GetProductById(2166354);

            XamlConfigurationParser.Save(article);
        }
Esempio n. 3
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            ILogger logger = null;

            if (Log)
            {
                logger = ObjectFactoryBase.Resolve <ILogger>();
            }

            if (Log)
            {
                logger.Debug(string.Format("Binding for path = {0}", Path));
            }

            var ipvt = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));

            var targetObject = ipvt.TargetObject as DependencyObject;

            string name = ResolveName(ipvt);

            if (name != null && targetObject != null)
            {
                var be = CreateExpression();

                // зарегистрируем биндинг
                var dp = targetObject.GetDependencyProperty(name);

                if (dp != null)
                {
                    if (Log)
                    {
                        logger.Debug(string.Format("Register binding with path {0} for dp {1}.{2} {3}", Path, dp.OwnerType, dp.PropertyType, dp));
                    }

                    targetObject.RegisterBinding(dp, be);
                }
                else
                {
                    if (Log)
                    {
                        logger.Debug(string.Format("DP is not found for path {0} obj {1} prop {2}", Path, ipvt.TargetObject, ipvt.TargetProperty));
                    }
                }
            }
            else if (ipvt.TargetObject is BindingExtension && name != null)
            {
                var be = CreateExpression();

                return(be);
            }
            else
            {
                if (Log)
                {
                    logger.Debug(string.Format("Something is failed {0} {1}", ipvt.TargetObject, ipvt.TargetProperty));
                }
            }

            return(null);
        }
Esempio n. 4
0
        public void Test_Binding_To_Model_With_Converter()
        {
            Run(() =>
            {
                QPModelBindingValueProvider.ThrowOnErrors = true;
                var control = ValidationHelper.GetXaml <GroupGridView>("QA.Core.Models.Tests.Xaml.EntityEditor_GridView_Converter.xaml");
                var service = ObjectFactoryBase.Resolve <IProductService>();
                var model   = service.GetProductById(2360);

                control.DataContext = model;

                Assert.AreEqual("true", control.Title);

                foreach (var child in control.GetChildren())
                {
                    var item = child;
                    if (item != null)
                    {
                        var bindedValue = ((Label)item.Columns[0].CellTemplate).Title;
                        Assert.IsNotNull(bindedValue);
                        Assert.IsTrue(bindedValue == "published" || bindedValue == "notpublished");
                    }
                }
            });
        }
Esempio n. 5
0
        public void Test_That_Fake_Service_Works()
        {
            var service = ObjectFactoryBase.Resolve <IProductService>();
            var product = service.GetProductById(2360);

            Assert.IsNotNull(product);
        }
Esempio n. 6
0
        public void Test_Binding_To_Model()
        {
            Run(() =>
            {
                QPModelBindingValueProvider.ThrowOnErrors = true;
                var control = ValidationHelper.GetXaml <QPControlTest>("QA.Core.Models.Tests.Xaml.Test002.xaml");
                var service = ObjectFactoryBase.Resolve <IProductService>();
                var model   = service.GetProductById(2360);

                control.DataContext = model;
                var t       = control.Title;
                var n       = control.Name;
                var c       = control.Caption;
                var intProp = control.ContentId;

                var t1 = ((QPControlTest)control.Content).Title;
                var n1 = ((QPControlTest)control.Content).Name;
                var c1 = ((QPControlTest)control.Content).Caption;

                Assert.IsTrue(intProp != 0);

                Assert.IsNotNull(t);
                Assert.IsNotNull(n);
                Assert.IsNotNull(c);

                Assert.IsNotNull(t1);
                Assert.IsNotNull(n1);
                Assert.IsNotNull(c1);
            });
        }
        public void NotifyProductsChanged(Dictionary <int, int[]> affectedProductIdsByContentId)
        {
            var settingService = ObjectFactoryBase.Resolve <ISettingsService>();

            int productContentId = int.Parse(settingService.GetSetting(SettingsTitles.PRODUCTS_CONTENT_ID));

            if (!affectedProductIdsByContentId.ContainsKey(productContentId))
            {
                return;
            }

            var taskService = ObjectFactoryBase.Resolve <ITaskService>();

            const int userId = 1;

            string taskData =
                ActionData.Serialize(new ActionData
            {
                ActionContext =
                    new ActionContext {
                    ContentItemIds = affectedProductIdsByContentId[productContentId], ContentId = productContentId, Parameters = new Dictionary <string, string>()
                }
            });

            var taskKey = typeof(ProductRelevanceAction).Name;

            taskService.AddTask(taskKey, taskData, userId, "Админ", "Обновление статусов на витрине");
        }
Esempio n. 8
0
        public void Issue_failed_loading()
        {
            var service       = ObjectFactoryBase.Resolve <IProductService>();
            var faliedProduct = service.GetProductById(675494);

            Assert.IsNotNull(faliedProduct);
        }
Esempio n. 9
0
        private static string GetUrl(PlainArticleField field)
        {
            if (field == null) return null;
            var value = field.Value;

            if (value == null) return null;

            if
            (field.FieldId.HasValue &&
                !string.IsNullOrEmpty(field.Value)
                && (field.PlainFieldType == PlainFieldType.File
                    || field.PlainFieldType == PlainFieldType.DynamicImage
                    || field.PlainFieldType == PlainFieldType.Image)
            )
            {
                string baseUri = ObjectFactoryBase.Resolve<IDBConnector>().GetUrlForFileAttribute(field.FieldId.Value);
                return $"{baseUri}/{field.Value}";
            }
            else if (field.PlainFieldType == PlainFieldType.String || field.PlainFieldType == PlainFieldType.StringEnum)
            {
                return field.Value;
            }
            else
            {
                return null;
            }
        }
Esempio n. 10
0
        // ReSharper disable once InconsistentNaming
        public ActionResult GetXmlFromConsumer(int content_item_id, bool live = false)
        {
            var consumerMonitoringServiceFunc = ObjectFactoryBase.Resolve <Func <bool, IConsumerMonitoringService> >();

            var xml = consumerMonitoringServiceFunc(live).GetProduct(content_item_id);

            return(View("GetXml", (object)xml));
        }
Esempio n. 11
0
        public void Test_get_parents()
        {
            var service = ObjectFactoryBase.Resolve <IRegionService>();
            var result  = service.GetParentsIds(1945);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count);
        }
Esempio n. 12
0
        private static IModelObject GetModel()
        {
            QPModelBindingValueProvider.ThrowOnErrors = true;
            var          service = ObjectFactoryBase.Resolve <IProductService>();
            IModelObject model   = service.GetProductById(2360);

            return(model);
        }
Esempio n. 13
0
        public Article DeserializeProductXml(XDocument productXml, Models.Configuration.Content definition)
        {
            var rootProductElement = productXml.Root?.Elements().First().Elements().First();

            var productDeserializer = ObjectFactoryBase.Resolve <IProductDeserializer>();

            return(productDeserializer.Deserialize(new XmlProductDataSource(rootProductElement), definition));
        }
Esempio n. 14
0
        /// <summary>
        /// Преобразовать статью из формата редактора продуктов в DPC-Article
        /// </summary>
        public Article DeserializeProduct(JObject rootArticleDictionary, Content definition)
        {
            var productDeserializer = ObjectFactoryBase.Resolve <IProductDeserializer>();

            var productDataSource = new EditorJsonProductDataSource(rootArticleDictionary);

            return(productDeserializer.Deserialize(productDataSource, definition));
        }
Esempio n. 15
0
        public void GetProductByIdTest()
        {
            var service = ObjectFactoryBase.Resolve <IProductService>();
            var product = service.GetProductById(698473);

            Assert.IsNotNull(product);
            Assert.AreEqual(287, product.ContentId);
            Assert.AreEqual(MproductIdExisting, product.Id);
        }
Esempio n. 16
0
        public void GetSimpleProductXmlByIdTest()
        {
            var service    = ObjectFactoryBase.Resolve <IProductService>();
            var xmlservice = ObjectFactoryBase.Resolve <IXmlProductService>();
            var content    = service.GetSimpleProductsByIds(new[] { ProductIdExisting })[0];
            var xml        = xmlservice.GetProductXml(content, ArticleFilter.DefaultFilter);

            Assert.IsTrue(xml.Contains("<Type>"));
        }
Esempio n. 17
0
        public void TextJsonDeserialization()
        {
            var jsonProductService = ObjectFactoryBase.Resolve <IJsonProductService>();
            var defStr             = File.ReadAllText("TestData\\ProductDefinition.xaml");
            var json          = File.ReadAllText("TestData\\ProductJson.js");
            var resultArticle = jsonProductService.DeserializeProduct(json, (Content)XamlConfigurationParser.CreateFrom(defStr));
            var resultXaml    = XamlConfigurationParser.Save(resultArticle);
            var referenceXaml = File.ReadAllText("TestData\\ReferenceDto.xaml");

            Assert.AreEqual(resultXaml, referenceXaml);
        }
Esempio n. 18
0
        public Article DeserializeProduct(JObject rootArticleDictionary, Content definition)
        {
            var product = rootArticleDictionary.SelectToken("product");
            if (product != null)
            {
                rootArticleDictionary = (JObject)product;
            }

            var productDeserializer = ObjectFactoryBase.Resolve<IProductDeserializer>();

            return productDeserializer.Deserialize(new JsonProductDataSource(rootArticleDictionary), definition);
        }
Esempio n. 19
0
        /// <exception cref="MessageResultException"/>
        public void PublishProduct(int productId, Dictionary <string, string> actionParameters)
        {
            var userProvider = ObjectFactoryBase.Resolve <IUserProvider>();

            UserId   = userProvider.GetUserId();
            UserName = userProvider.GetUserName();

            using (var transaction = CreateTransaction())
            {
                ProcessProduct(productId, actionParameters ?? new Dictionary <string, string>());
                transaction.Commit();
            }
        }
Esempio n. 20
0
        public void Profile_LoadStructureCache()
        {
            var connectinStringObject = ConfigurationManager.ConnectionStrings["qp_database"];
            var connectionString      = connectinStringObject.ConnectionString;

            Do(connectionString);

            var timer = new Stopwatch();

            timer.Start();
            Do(connectionString);
            timer.Stop();
            ObjectFactoryBase.Resolve <ILogger>().Info("Cold Elapsed ms: " + timer.ElapsedMilliseconds);
        }
Esempio n. 21
0
        public static void ClassInitialize()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            _service = ObjectFactoryBase.Resolve <IArticleDependencyService>();
            stopWatch.Stop();
            Debug.WriteLine($"IArticleDependencyService отрезолвен за {stopWatch.Elapsed.TotalSeconds} сек");

            stopWatch.Reset();
            stopWatch.Start();
            ((ArticleDependencyService)_service).InitCache(false);
            stopWatch.Stop();
            Debug.WriteLine($"ArticleDependencyService инициализировал кеш {stopWatch.Elapsed.TotalSeconds} сек");
        }
Esempio n. 22
0
        public void GetProductsByIdsTest()
        {
            var timer   = new Stopwatch();
            var service = ObjectFactoryBase.Resolve <IProductService>();

            timer.Start();
            service.GetProductsByIds(ProductsContentId, new[] { ProductIdExisting, ProductIdExistingService, 3136 });
            timer.Stop();
            ObjectFactoryBase.Resolve <ILogger>().Info("Cold Elapsed ms: " + timer.ElapsedMilliseconds);
            timer.Reset();
            timer.Start();
            service.GetProductsByIds(ProductsContentId, new[] { ProductIdExisting, ProductIdExistingService, 3136 });
            timer.Stop();
            ObjectFactoryBase.Resolve <ILogger>().Info("Hot Elapsed ms: " + timer.ElapsedMilliseconds);
        }
Esempio n. 23
0
        // ReSharper disable once InconsistentNaming
        public ActionResult GetXml(int content_item_id, bool live = false)
        {
            var product = _productService.GetProductById(content_item_id, live);

            if (product == null)
            {
                ViewBag.Message = ProductCardStrings.ProductNotFound;
                return(View("GetXml"));
            }

            var filter = live ? ArticleFilter.LiveFilter : ArticleFilter.DefaultFilter;

            var xml = ObjectFactoryBase.Resolve <IXmlProductService>().GetProductXml(product, filter);

            return(View("GetXml", (object)xml));
        }
Esempio n. 24
0
        public void TestXmlDeserialization()
        {
            var xmlProductService = ObjectFactoryBase.Resolve <IXmlProductService>();
            var xDoc          = XDocument.Load("TestData\\Product.xml");
            var defStr        = File.ReadAllText("TestData\\ProductDefinition.xaml");
            var resultArticle = xmlProductService.DeserializeProductXml(xDoc, (Content)XamlConfigurationParser.CreateFrom(defStr));
            var st            = new Stopwatch();

            st.Start();
            xmlProductService.DeserializeProductXml(xDoc, (Content)XamlConfigurationParser.CreateFrom(defStr));
            st.Stop();

            Debug.WriteLine(st.Elapsed);
            XamlConfigurationParser.Save(resultArticle);
            File.ReadAllText("TestData\\ReferenceDto.xaml");
        }
Esempio n. 25
0
        public void RegionTagTest()
        {
            ObjectFactoryBase.Resolve <IContentDefinitionService>();
            ObjectFactoryBase.Resolve <IRegionService>();
            ObjectFactoryBase.Resolve <VersionedCacheProviderBase>();
            ObjectFactoryBase.Resolve <ICacheItemWatcher>();
            ObjectFactoryBase.Resolve <ISettingsService>();
            ObjectFactoryBase.Resolve <IUserProvider>();
            ObjectFactoryBase.Resolve <RegionTagService>();

            var serviceLoader = ObjectFactoryBase.Resolve <IProductService>();
            var xmlservice    = ObjectFactoryBase.Resolve <IXmlProductService>();
            var product       = serviceLoader.GetProductsByIds(288, new[] { /*PRODUCT_ID_CACHE_TEST,*/ 854754 });

            xmlservice.GetSingleXmlForProducts(product, ArticleFilter.DefaultFilter);
        }
Esempio n. 26
0
        private static void ProcessProduct(int id)
        {
            var service    = ObjectFactoryBase.Resolve <IProductService>();
            var xmlservice = ObjectFactoryBase.Resolve <IXmlProductService>();
            var content    = service.GetProductById(id);
            var text       = ConfigurationSerializer.GetXml(content);

            using (var file = File.CreateText(id + ".xaml"))
            {
                file.Write(text);
            }

            using (var file = File.CreateText(id + ".xml"))
            {
                file.Write(xmlservice.GetProductXml(content, ArticleFilter.DefaultFilter));
            }
        }
Esempio n. 27
0
 public string GetFileUrl(PlainArticleField field)
 {
     if (field != null &&
         field.FieldId.HasValue &&
         !string.IsNullOrEmpty(field.Value) &&
         (field.PlainFieldType == PlainFieldType.File ||
          field.PlainFieldType == PlainFieldType.DynamicImage ||
          field.PlainFieldType == PlainFieldType.Image))
     {
         string baseUri = ObjectFactoryBase.Resolve <IDBConnector>().GetUrlForFileAttribute(field.FieldId.Value);
         return($"{baseUri}/{field.Value}");
     }
     else
     {
         return("javascript:void();");
     }
 }
Esempio n. 28
0
        internal void RegisterBinding(DependencyProperty dp, BindingExression bindingExpression)
        {
            // получим dependencyproperty
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            if (dp.Log)
            {
                var logger = ObjectFactoryBase.Resolve <ILogger>();
                logger.Debug(string.Format("for {0} {1}.{2} {3} list: {4}", dp, dp.OwnerType, dp.PropertyType, bindingExpression.Expression, _bindings.GetHashCode()));
            }

            _bindings[dp] = bindingExpression;

            // удаляем текущее значение, если оно было
            _valueTable[dp] = new ValueEntry(DependencyProperty.UnsetValue);
        }
Esempio n. 29
0
        public ActionResult Publish(SendProductModel model)
        {
            var action = ObjectFactoryBase.Resolve <PublishAction>();

            if (model != null && ModelState.IsValid)
            {
                var idsList = model.ArticleIds.SplitString(' ', ',', ';', '\n', '\r').Distinct().ToArray();
                if (idsList.Length > 200)
                {
                    ModelState.AddModelError("", ProductCardStrings.TooMuchProducts);
                    return(View("Send", model));
                }

                int[] ids;
                try
                {
                    ids = idsList.Select(int.Parse).ToArray();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ProductCardStrings.NotNumberValues + ". " + ex.Message);
                    return(View("Send", model));
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        var context = new ActionContext {
                            ContentId = 288, ContentItemIds = ids
                        };
                        action.Process(context);
                        model.Message = ProductCardStrings.PublishedAndSendSuccess;
                    }
                    catch (ActionException ex)
                    {
                        model.Message = ex.Message;
                    }
                }
            }

            return(View("Send", model));
        }
Esempio n. 30
0
        public void PublishAllProducts()
        {
            var service = ObjectFactoryBase.Resolve <IProductService>();

            ObjectFactoryBase.Resolve <IXmlProductService>();

            var nService = ObjectFactoryBase.Resolve <IQPNotificationService>();
            var ids      = new List <int>();

            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["qp_database"].ConnectionString))
            {
                con.Open();
                using (var cmd = new SqlCommand(@"select content_item_id from content_288 p inner join item_link L on L.item_id =p.content_item_id  and link_id=p.Regions where archive=0 and l.linked_item_id=1762", con))
                {
                    using (var rd = cmd.ExecuteReader())
                    {
                        while (rd.Read())
                        {
                            ids.Add((int)rd.GetDecimal(0));
                        }

                        rd.Close();
                    }
                }
            }

            var tasks = new List <Task>();

            foreach (var id in ids)
            {
                var content = service.GetProductById(id);
                ConfigurationSerializer.GetXml(content);
                var result = nService.SendProductsAsync(new[] { content }, true, "Admin", 1, false, false);
                tasks.Add(result);
            }

            var newT = Task.WhenAll(tasks);

            newT.Wait();
        }