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); }
public void Temp() { var productService = ObjectFactoryBase.Resolve <IProductService>(); var article = productService.GetProductById(2166354); XamlConfigurationParser.Save(article); }
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); }
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"); } } }); }
public void Test_That_Fake_Service_Works() { var service = ObjectFactoryBase.Resolve <IProductService>(); var product = service.GetProductById(2360); Assert.IsNotNull(product); }
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, "Админ", "Обновление статусов на витрине"); }
public void Issue_failed_loading() { var service = ObjectFactoryBase.Resolve <IProductService>(); var faliedProduct = service.GetProductById(675494); Assert.IsNotNull(faliedProduct); }
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; } }
// 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)); }
public void Test_get_parents() { var service = ObjectFactoryBase.Resolve <IRegionService>(); var result = service.GetParentsIds(1945); Assert.IsNotNull(result); Assert.AreEqual(3, result.Count); }
private static IModelObject GetModel() { QPModelBindingValueProvider.ThrowOnErrors = true; var service = ObjectFactoryBase.Resolve <IProductService>(); IModelObject model = service.GetProductById(2360); return(model); }
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)); }
/// <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)); }
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); }
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>")); }
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); }
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); }
/// <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(); } }
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); }
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} сек"); }
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); }
// 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)); }
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"); }
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); }
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)); } }
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();"); } }
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); }
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)); }
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(); }