public virtual string FetchContent(HtmlDocument doc, string key, NameValueCollection mappings) { string rowValue = string.Empty; bool textOnly = false; try { int index = mappings[key].IndexOf('_'); string toWhatField = mappings[key].Substring(0, index); IBaseField mappingItem = FieldDefinitions.FirstOrDefault(f => f.InnerItem.Fields[FromWhatField].Value == key && f.InnerItem.Fields["To What Field"].Value == toWhatField); textOnly = mappingItem.InnerItem.Fields["Strip HTML"]?.Value == "1" || ImportTextOnly; } catch (Exception ex) { Logger.Log(ex.ToString(), rowValue, LogType.GetImportDataError, key, rowValue); } var node = HtmlService.HandleNodesLookup(key, doc); if (node == null) { return(rowValue); } rowValue = textOnly ? node.InnerText : node.InnerHtml; return(rowValue); }
public string FetchContent(HtmlDocument doc, object key, NameValueCollection mappings, ImportConfig storedConfig) { string rowValue = string.Empty; bool textOnly = false; bool useXPath = false; try { int index = mappings[key.ToString()].IndexOf('_'); string toWhatField = mappings[key.ToString()].Substring(0, index); IBaseField mappingItem = FieldDefinitions.FirstOrDefault(f => f.InnerItem.Fields[HtmlScraper.Constants.FieldNames.FromWhatField].Value == key.ToString() && f.InnerItem.Fields[HtmlScraper.Constants.FieldNames.ToWhatField].Value == toWhatField); useXPath = mappingItem.InnerItem.Fields[HtmlScraper.Constants.FieldNames.UseXpath].Value == "1"; textOnly = mappingItem.InnerItem.Fields[HtmlScraper.Constants.FieldNames.ImportTextOnly].Value == "1" || storedConfig.ImportTextOnly; } catch (Exception ex) { Logger.Log(ex.ToString(), rowValue, ProcessStatus.GetImportDataError, key.ToString(), rowValue); } string htmlObj = string.Empty; bool isAttrValue = false; string attrName = string.Empty; HtmlNode node = null; htmlObj = key.ToString(); if (htmlObj.Contains("/@")) { isAttrValue = true; List <string> attrItems = htmlObj.Split('/').Where(a => a.StartsWith("@")).ToList(); attrName = attrItems.FirstOrDefault(a => !a.Contains("=")); htmlObj = htmlObj.Replace("/" + attrName, ""); attrName = attrName.Replace("@", ""); } node = useXPath ? Helper.HandleNodesLookup(htmlObj, doc, true) : Helper.HandleNodesLookup(htmlObj, doc); if (node == null) { return(rowValue); } rowValue = isAttrValue && node.Attributes[attrName] != null ? node.Attributes[attrName].Value : (textOnly ? node.InnerText : node.InnerHtml); return(rowValue); }
public virtual void Add(IBaseField item) { string itemType = string.Empty; if (this.isUniversal) { this.items.Add(item); } else if (this.itemsType == (itemType = item.GetType().Name)) { this.items.Add(item); } else { throw new Exception(string.Format("Попытка добавить в коллекцию значение типа {0}. Ожидалось значение типа {1}", itemType, this.itemsType)); } }
private IBaseField GenerateFieldMapping(Item child) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); //check for assembly if (string.IsNullOrEmpty(bm.HandlerAssembly)) { Logger.Log("BaseDataMap.GenerateFieldMapping", string.Format("the field's Handler Assembly is not defined on item {0}: {1}", child.Paths.FullPath, bm.HandlerAssembly)); return(null); } //check for class if (string.IsNullOrEmpty(bm.HandlerClass)) { Logger.Log("BaseDataMap.GenerateFieldMapping", string.Format("the field's Handler Class is not defined on item {0}: {1}", child.Paths.FullPath, bm.HandlerClass)); return(null); } //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child, Logger }); } catch (FileNotFoundException) { Logger.Log("BaseDataMap.GenerateFieldMapping", string.Format("the field's binary specified could not be found on item {0} : {1}", child.Paths.FullPath, bm.HandlerAssembly)); } if (bf != null) { return(bf); } else { Logger.Log("BaseDataMap.GenerateFieldMapping", string.Format("the field's class type could not be instantiated {0} :{1}", child.Paths.FullPath, bm.HandlerClass)); } return(null); }
public IBaseField BuildBaseField(Item fieldItem) { //create an item to get the class / assembly name from var handlerAssembly = fieldItem.Fields["Handler Assembly"].Value; var handlerClass = fieldItem.Fields["Handler Class"].Value; //check for assembly if (string.IsNullOrEmpty(handlerAssembly)) { Logger.Log("the field's Handler Assembly is not defined", fieldItem.Paths.FullPath, LogType.ImportDefinitionError, fieldItem.Name, handlerAssembly); return(null); } //check for class if (string.IsNullOrEmpty(handlerClass)) { Logger.Log("the field's Handler Class is not defined", fieldItem.Paths.FullPath, LogType.ImportDefinitionError, fieldItem.Name, handlerClass); return(null); } //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { var obj = Sitecore.Reflection.ReflectionUtil.CreateObject(handlerAssembly, handlerClass, new object[] { fieldItem, Logger }); if (obj is IBaseField) { bf = (IBaseField)obj; } } catch (FileNotFoundException) { Logger.Log("the field's binary specified could not be found", fieldItem.Paths.FullPath, LogType.ImportDefinitionError, fieldItem.Name, handlerAssembly); } return(bf); }
private void RunProcessor(IBaseField fieldMap, Item newItem) { //Check for warnings MultilistField WarningTags = fieldMap.InnerItem.Fields[DataImporter.HtmlScraper.Constants.FieldNames.WarningTriggerTags]; if (WarningTags.Count > 0) { WriteTagWarnings.Run(newItem, fieldMap.InnerItem); } //"To What Field" MultilistField processors = fieldMap.InnerItem.Fields[DataImporter.HtmlScraper.Constants.FieldNames.FieldPostProcessors]; foreach (var targetId in processors.TargetIDs) { Item processor = ToDB.GetItem(targetId); if (processor == null) { continue; } Processor.Execute(processor, newItem, fieldMap.InnerItem); } }
public BaseDataMap(Database db, string connectionString, Item importItem, string lastUpdated = "") { Overwrite = importItem.Fields["Overwrite Item"] != null && ((CheckboxField)importItem.Fields["Overwrite Item"]).Checked; SkipExistingItems = importItem.Fields["Skip Existing Items"] != null && ((CheckboxField)importItem.Fields["Skip Existing Items"]).Checked; SearchIndex = importItem.Fields["Search Index"] != null ? importItem.Fields["Search Index"].Value : ""; DeltasOnly = importItem.Fields["Deltas Only"] != null && ((CheckboxField)importItem.Fields["Deltas Only"]).Checked; LastUpdatedFieldName = importItem.Fields["Last Updated Field Name"] != null ? importItem.Fields["Last Updated Field Name"].Value : ""; LastUpdated = string.IsNullOrEmpty(lastUpdated) ? DateTime.Now.AddDays(-30) : DateTime.Parse(lastUpdated); MissingItemsQuery = importItem.Fields["Missing Items Query"] != null ? importItem.Fields["Missing Items Query"].Value : ""; HistorySnapshotQuery = importItem.Fields["History Snapshot Query"] != null ? importItem.Fields["History Snapshot Query"].Value : ""; //instantiate log log = new StringBuilder(); //setup import details SitecoreDB = db; DatabaseConnectionString = connectionString; //get query Query = importItem.Fields["Query"].Value; if (string.IsNullOrEmpty(Query)) { Log("Error", "the 'Query' field was not set"); } //get parent and store it var parentID = importItem.Fields["Import To Where"].Value; if (!string.IsNullOrEmpty(parentID)) { var parent = SitecoreDB.Items[parentID]; if (parent.IsNotNull()) { Parent = parent; } else { Log("Error", "the 'To Where' item is null"); } } else { Log("Error", "the 'To Where' field is not set"); } //get new item template var templateID = importItem.Fields["Import To What Template"].Value; if (!string.IsNullOrEmpty(templateID)) { var templateItem = SitecoreDB.Items[templateID]; if (templateItem.IsNotNull()) { if ((BranchItem)templateItem != null) { NewItemTemplate = (BranchItem)templateItem; } else { NewItemTemplate = (TemplateItem)templateItem; } } else { Log("Error", "the 'To What Template' item is null"); } } else { Log("Error", "the 'To What Template' field is not set"); } //more properties ItemNameDataField = importItem.Fields["Pull Item Name from What Fields"].Value; ItemNameMaxLength = int.Parse(importItem.Fields["Item Name Max Length"].Value); var iLang = SitecoreDB.GetItem(importItem.Fields["Import To Language"].Value); ImportToLanguage = LanguageManager.GetLanguage(iLang.Name); if (ImportToLanguage == null) { Log("Error", "The 'Import Language' field is not set"); } //foldering information FolderByDate = ((CheckboxField)importItem.Fields["Folder By Date"]).Checked; FolderByName = ((CheckboxField)importItem.Fields["Folder By Name"]).Checked; DateField = importItem.Fields["Date Field"].Value; if (FolderByName || FolderByDate) { //setup a default type to an ordinary folder var FolderItem = SitecoreDB.Templates["{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"]; //if they specify a type then use that var folderID = importItem.Fields["Folder Template"].Value; if (!string.IsNullOrEmpty(folderID)) { FolderItem = SitecoreDB.Templates[folderID]; } FolderTemplate = FolderItem; } //start handling fields var Fields = GetItemByTemplate(importItem, FieldsFolderID); if (Fields.IsNotNull()) { var c = Fields.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from var bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { bf = (IBaseField) ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Log("Error", string.Format("the field:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bf != null) { FieldDefinitions.Add(bf); } else { Log("Error", string.Format("the field: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Log("Warn", "there are no fields to import"); } } else { Log("Warn", "there is no 'Fields' folder"); } }
protected void CreateEDT(IBaseField baseField) { if (String.IsNullOrEmpty(baseField.ExtendedDataType) == false) { // There is already a EDT defined for this field return; } // The Name of the edt to create should have the prefix as per the Settings // If the Prefix already exists on the var modelSettings = Settings.FetchSettings.FindOrCreateSettings(); var edtName = baseField.Name; if (String.IsNullOrEmpty(modelSettings.Prefix) == false && edtName.StartsWith(modelSettings.Prefix, StringComparison.InvariantCultureIgnoreCase) == false) { edtName = modelSettings.Prefix + edtName; } Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdt edtToCreate = null; if (baseField is IFieldContainer) { //var currentField = baseField as IFieldContainer; edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtContainer(); } else if (baseField is IFieldDate) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtDate(); } else if (baseField is IFieldEnum) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtEnum(); } else if (baseField is IFieldGuid) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtGuid(); } else if (baseField is IFieldInt) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtInt(); } else if (baseField is IFieldReal) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtReal(); } else if (baseField is IFieldString) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtString(); } else if (baseField is IFieldTime) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtTime(); } else if (baseField is IFieldUtcDateTime) { edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtUtcDateTime(); } this.copyProperties(baseField, edtToCreate); edtToCreate.Name = edtName; if (edtToCreate != null) { // Find current model var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo(); //Create menu item in the right model var metaModelProviders = ServiceLocator.GetService <IMetaModelProviders>() as IMetaModelProviders; var metaModelService = metaModelProviders.CurrentMetaModelService; metaModelService.CreateExtendedDataType(edtToCreate, modelSaveInfo); //Update the table field with the EDT, also remove any labels from the field baseField.ExtendedDataType = edtToCreate.Name; baseField.Label = String.Empty; baseField.HelpText = String.Empty; // Add to the current active project Common.CommonUtil.AddElementToProject(edtToCreate); } }
public MobileAliasUserKeyHandler(BaseDataMap map, IBaseField fieldDefinition) : base(map, fieldDefinition) { UserKeyStorage = new MobileAliasUserKeyStorage(); }
protected BaseUserKeyHandler(BaseDataMap map, IBaseField fieldDefinition) { Map = map; FieldDefinition = fieldDefinition; }
/// <summary> /// /Handle the click event in the OnClick method. Here we will test the selected object, get the object’s model and label file, and create the label. /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { try { // Get the metamodel service IMetaModelService metaModelService = helper.MetaModelService; // Is the selected element a table? if (e.SelectedElement is ITable) { ITable table = e.SelectedElement as ITable; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = table.Name; } else if (e.SelectedElement is IBaseField) { IBaseField baseField = e.SelectedElement as IBaseField; var table = baseField.Table; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = String.Format("{0}_{1}", baseField.Table.Name, baseField.Name); } if (e.SelectedElement is IView) { IView view = e.SelectedElement as IView; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(view.Name)); labelPrefix = view.Name; } else if (e.SelectedElement is IViewBaseField) { IViewBaseField baseField = e.SelectedElement as IViewBaseField; var view = baseField.View; helper.setModelAndLabelFile(metaModelService.GetViewModelInfo(view.Name)); labelPrefix = String.Format("{0}_{1}", baseField.View.Name, baseField.Name); } else if (e.SelectedElement is IFormDesign) { IFormDesign formDesign = e.SelectedElement as IFormDesign; var form = formDesign.Form; helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(form.Name)); labelPrefix = formDesign.Form.Name; } else if (e.SelectedElement is IFormControl) { IFormControl formControl = e.SelectedElement as IFormControl; IRootElement rootElement = formControl.RootElement as IRootElement; if (rootElement is IFormExtension) { helper.setModelAndLabelFile(metaModelService.GetFormExtensionModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); labelPrefix = labelPrefix.Replace(".","_"); } else { helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); } } else if (e.SelectedElement is ISecurityPrivilege) { ISecurityPrivilege securityObject = e.SelectedElement as ISecurityPrivilege; helper.setModelAndLabelFile(metaModelService.GetSecurityPrivilegeModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.PrivilegeTag, securityObject.Name); } else if (e.SelectedElement is ISecurityDuty) { ISecurityDuty securityObject = e.SelectedElement as ISecurityDuty; helper.setModelAndLabelFile(metaModelService.GetSecurityDutyModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.DutyTag, securityObject.Name); } else if (e.SelectedElement is ISecurityRole) { ISecurityRole securityObject = e.SelectedElement as ISecurityRole; helper.setModelAndLabelFile(metaModelService.GetSecurityRoleModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.RoleTag, securityObject.Name); } else if (e.SelectedElement is IEdtBase) { IEdtBase edt = e.SelectedElement as IEdtBase; helper.setModelAndLabelFile(metaModelService.GetExtendedDataTypeModelInfo(edt.Name)); labelPrefix = String.Format("{0}_{1}", Tags.EDTTag, edt.Name); } else if (e.SelectedElement is IMenuItem) { IMenuItem AxMenuItem = e.SelectedElement as IMenuItem; labelPrefix = String.Format("{0}_{1}", Tags.MenuItemTag, AxMenuItem.Name); if (AxMenuItem is IMenuItemAction) { helper.setModelAndLabelFile(metaModelService.GetMenuItemActionModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemDisplay) { helper.setModelAndLabelFile(metaModelService.GetMenuItemDisplayModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemOutput) { helper.setModelAndLabelFile(metaModelService.GetMenuItemOutputModelInfo(AxMenuItem.Name)); } } else if (e.SelectedElement is IReportDataSetField) { IReportDataSetField dataField = e.SelectedElement as IReportDataSetField; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(dataField.DataSet.Report.Name)); labelPrefix = String.Format("{0}_{1}_{2}", dataField.DataSet.Report.Name, dataField.DataSet.Name, dataField.Name); } helper.createPropertyLabels(e.SelectedElement, labelPrefix); } catch (Exception ex) { Microsoft.Dynamics.Framework.Tools.MetaModel.Core.CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <summary> /// Sets the Home field. /// </summary> /// <param name="homeField"></param> public void SetHomeField(IBaseField homeField) { this.HomeField = (IHomeField)homeField; }
/// <summary> /// Sets the Enemy Field, which needed for working of some methods. /// </summary> /// <param name="enemyField"></param> public void SetEnemyField(IBaseField enemyField) { this.EnemyField = (IEnemyField)enemyField; }
public BaseDataMap(Database db, string connectionString, Item importItem) { //instantiate log log = new StringBuilder(); //setup import details SitecoreDB = db; DatabaseConnectionString = connectionString; //get query Query = importItem.Fields["Query"].Value; if (string.IsNullOrEmpty(Query)) { Log("Error", "the 'Query' field was not set"); } //get parent and store it string parentID = importItem.Fields["Import To Where"].Value; if (!string.IsNullOrEmpty(parentID)) { Item parent = SitecoreDB.Items[parentID]; if (parent.IsNotNull()) { Parent = parent; } else { Log("Error", "the 'To Where' item is null"); } } else { Log("Error", "the 'To Where' field is not set"); } //get new item template string templateID = importItem.Fields["Import To What Template"].Value; if (!string.IsNullOrEmpty(templateID)) { Item templateItem = SitecoreDB.Items[templateID]; if (templateItem.IsNotNull()) { NewItemTemplate = templateItem; } else { Log("Error", "the 'To What Template' item is null"); } } else { Log("Error", "the 'To What Template' field is not set"); } //more properties ItemNameDataField = importItem.Fields["Pull Item Name from What Fields"].Value; ItemNameMaxLength = int.Parse(importItem.Fields["Item Name Max Length"].Value); //foldering information FolderByDate = ((CheckboxField)importItem.Fields["Folder By Date"]).Checked; FolderByName = ((CheckboxField)importItem.Fields["Folder By Name"]).Checked; DateField = importItem.Fields["Date Field"].Value; if (FolderByName || FolderByDate) { //setup a default type to an ordinary folder Sitecore.Data.Items.TemplateItem FolderItem = SitecoreDB.Templates["{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"]; //if they specify a type then use that string folderID = importItem.Fields["Folder Template"].Value; if (!string.IsNullOrEmpty(folderID)) { FolderItem = SitecoreDB.Templates[folderID]; } FolderTemplate = FolderItem; } //start handling fields Item Fields = GetItemByTemplate(importItem, FieldsFolderID); if (Fields.IsNotNull()) { ChildList c = Fields.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Log("Error", string.Format("the field:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bf != null) { FieldDefinitions.Add(bf); } else { Log("Error", string.Format("the field: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Log("Warn", "there are no fields to import"); } } else { Log("Warn", "there is no 'Fields' folder"); } }
protected virtual List <IBaseField> GetFieldDefinitions(Item i) { List <IBaseField> l = new List <IBaseField>(); //check for fields folder Item Fields = i.GetChildByTemplate(FieldsFolderTemplateID); if (Fields.IsNull()) { Logger.Log(i.Paths.FullPath, "there is no 'Fields' folder on the import item", ProcessStatus.ImportDefinitionError); return(l); } //check for any children if (!Fields.HasChildren) { Logger.Log(i.Paths.FullPath, "there are no fields to import on on the import item", ProcessStatus.ImportDefinitionError); return(l); } ChildList c = Fields.GetChildren(); foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); //check for assembly if (string.IsNullOrEmpty(bm.HandlerAssembly)) { Logger.Log(child.Paths.FullPath, "the field's Handler Assembly is not defined", ProcessStatus.ImportDefinitionError, child.Name, bm.HandlerAssembly); continue; } //check for class if (string.IsNullOrEmpty(bm.HandlerClass)) { Logger.Log(child.Paths.FullPath, "the field's Handler Class is not defined", ProcessStatus.ImportDefinitionError, child.Name, bm.HandlerClass); continue; } //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Logger.Log(child.Paths.FullPath, "the field's binary specified could not be found", ProcessStatus.ImportDefinitionError, child.Name, bm.HandlerAssembly); } if (bf != null) { l.Add(bf); } else { Logger.Log(child.Paths.FullPath, "the field's class type could not be instantiated", ProcessStatus.ImportDefinitionError, child.Name, bm.HandlerClass); } } return(l); }