/// <summary>Switch to the given data map.</summary> /// <param name="map">The data map to select.</param> private void SetMap(IDataMap map) { this.CurrentMap = map; this.Legend = this.CurrentMap.Legend.ToArray(); this.TileGroups = this.EmptyTileGroups; this.UpdateCountdown = 0; }
public static DataTable ToOlapDataTable(IDataReader reader, IDataMap dataMap, DataTableCallback callback) { DataTable schemaTable = reader.GetSchemaTable(); DataTable dataTable = new DataTable(); dataTable.Locale = CultureInfo.InvariantCulture; List <string> columnNames = new List <string>(); List <bool> nullables = new List <bool>(); List <Type> types = new List <Type>(); AddPrimaryKeyColumn(dataTable); for (int i = 0; i < schemaTable.Rows.Count; i++) { DataRow schemaTableRow = schemaTable.Rows[i]; if (!dataTable.Columns.Contains(schemaTableRow["ColumnName"].ToString())) { string columnName = schemaTableRow["ColumnName"].ToString(); IDataMapEntry entry = dataMap.FindOlapColumn(columnName); DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = entry.FieldName; dataColumn.Unique = Convert.ToBoolean(schemaTableRow["IsUnique"], CultureInfo.InvariantCulture); dataColumn.AllowDBNull = Convert.ToBoolean(schemaTableRow["AllowDBNull"], CultureInfo.InvariantCulture); dataColumn.ReadOnly = Convert.ToBoolean(schemaTableRow["IsReadOnly"], CultureInfo.InvariantCulture); dataColumn.DataType = (entry.TypeName == null) ? (Type)schemaTableRow["DataType"] : Type.GetType(entry.TypeName); dataColumn.ExtendedProperties.Add("DataColumnInfo", DataColumnInfo.FromSchemaRow(schemaTableRow)); columnNames.Add(columnName); types.Add(dataColumn.DataType); nullables.Add(dataColumn.AllowDBNull); dataTable.Columns.Add(dataColumn); } } foreach (DataColumn column in callback.NewColumns) { dataTable.Columns.Add(column); } while (reader.Read()) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < columnNames.Count; i++) { string name = dataMap.FindOlapColumn(columnNames[i]).FieldName; object value = reader[columnNames[i]]; dataRow[name] = ConversionHelper.Convert(value, types[i], ConversionHelper.DefaultValue(types[i], nullables[i])); } if (callback.RegisterRow(dataRow)) { dataTable.Rows.Add(dataRow); } } return(dataTable); }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { if (string.IsNullOrEmpty(importValue)) { return; } //try to parse date value DateTime date; if (!DateTimeUtil.ParseInformaDate(importValue, out date)) { map.Logger.Log(newItem.Paths.FullPath, "Date parse error", ProcessStatus.DateParseError, ItemName(), importValue); return; } Field f = newItem.Fields[NewItemField]; if (f == null) { return; } f.Value = date.ToDateFieldValue(); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importItem = (Item)importRow; if (importItem == null) { return; } var mediaItem = MediaService.GetImage(importItem, ExistingDataNames); if (mediaItem == null) { return; } var newMedia = MediaService.FindOrCreateMediaItem(map, mediaItem); if (newMedia == null) { return; } ImageField f = newItem.Fields[ToWhatField]; if (f == null) { return; } f.MediaID = newMedia.ID; }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue)) { return; } double value = 0; var style = NumberStyles.Number; if (!double.TryParse(importValue.Trim(), style, ImportCulture, out value)) { return; } Field f = newItem.Fields[ToWhatField]; if (f == null) { return; } f.Value = value.ToString(TargetCulture ?? Context.Culture); }
public Item FindDatasource(IDataMap map, Item item, RenderingDefinition rendering) { var ds = rendering.DynamicProperties.FirstOrDefault(a => a.LocalName.Equals("ds")); if (string.IsNullOrWhiteSpace(ds?.Value)) { Logger.Log("The rendering has no datasource property", item.Paths.FullPath, Providers.LogType.PresentationService, "rendering", rendering.ToXml()); return(null); } Item dsItem = null; if (ID.IsID(ds.Value)) { dsItem = map.ToDB.GetItem(new ID(ds.Value)); } else if (ds.Value.Contains("local:")) { dsItem = map.ToDB.GetItem($"{item.Paths.FullPath}{ds.Value.Replace("local:", "")}"); } else { dsItem = map.ToDB.GetItem(ds.Value); } if (dsItem == null) { Logger.Log("The datasource item is null", item.Paths.FullPath, Providers.LogType.PresentationService, "ds.Value", ds.Value); } return(dsItem); }
private ID ImportMediaItem(IDataMap map, Item newItem, ImageField field) { var media = new MediaItem(field.MediaItem); var newMedia = HandleMediaItem(map, BuildMediaPath(newItem.Database, media.InnerItem.Paths.ParentPath), media.Path, media); return(newMedia.ID); }
public override void FillField(IDataMap map, ref Item newItem, string importValue) { if (string.IsNullOrEmpty(importValue)) { return; } //try to parse date value DateTime date; if (!DateTime.TryParse(importValue, out date) && !DateTime.TryParseExact(importValue, new string[] { "yyyyMMdd", "d/M/yyyy", "d/M/yyyy HH:mm:ss", "yyyyMMddTHHmmss", "yyyyMMddTHHmmssZ" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { map.Logger.Log("ToDate.FillField", string.Format("Date parse error for date {0} on item {1}", importValue, newItem.Paths.FullPath)); return; } Field f = newItem.Fields[NewItemField]; if (f == null) { return; } f.Value = date.ToDateFieldValue(); }
public MediaItem FindOrCreateMediaItem(IDataMap map, MediaItem originalItem) { // see if it exists in med lib var newMediaItem = map.ToDB.GetItem(originalItem.InnerItem.Paths.FullPath); MediaItem m = null; if (newMediaItem != null) { m = new MediaItem(newMediaItem); } else { var parent = map.ToDB.GetItem(originalItem.InnerItem.Paths.ParentPath); if (parent == null) { BuildMediaPath(map.ToDB, originalItem.InnerItem.Paths.ParentPath); } m = ImportMedia(originalItem); } if (m == null) { map.Logger.Log("Image Not Found", $"item '{m.Path}', image '{m.Name}'"); } else { CopyFields(originalItem, m); } return(m); }
private void RouteMarkedEdges(LayoutGraph graph, IDataMap markedEdgesMap) { if (MarkedEdgeRouter == null) { return; } IDataProvider backupDp = null; if (EdgeSelectionKey != null) { backupDp = graph.GetDataProvider(EdgeSelectionKey); graph.AddDataProvider(EdgeSelectionKey, markedEdgesMap); } if (MarkedEdgeRouter is StraightLineEdgeRouter) { var router = (StraightLineEdgeRouter)MarkedEdgeRouter; router.Scope = Scope.RouteAffectedEdges; router.AffectedEdgesDpKey = EdgeSelectionKey; } MarkedEdgeRouter.ApplyLayout(graph); if (EdgeSelectionKey != null) { graph.RemoveDataProvider(EdgeSelectionKey); if (backupDp != null) { graph.AddDataProvider(EdgeSelectionKey, backupDp); } } }
/// <summary> /// uses the import value to search for a matching item in the SourceList and then stores the GUID /// </summary> /// <param name="map">provides settings for the import</param> /// <param name="newItem">newly created item</param> /// <param name="importValue">imported value to match</param> public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { if (string.IsNullOrEmpty(importValue)) { return; } //get parent item of list to search Item i = InnerItem.Database.GetItem(SourceList); if (i == null) { return; } //loop through children and look for anything that matches by name string cleanName = StringUtility.GetValidItemName(importValue, map.ItemNameMaxLength); IEnumerable <Item> t = i.Axes.GetDescendants().Where(c => c.DisplayName.Equals(cleanName)); //if you find one then store the id if (!t.Any()) { return; } Field f = newItem.Fields[NewItemField]; if (f == null) { return; } f.Value = t.First().ID.ToString(); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { Field f = newItem.Fields[ToWhatField]; if (f == null) { return; } var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (importValue.IsNullOrEmpty()) { f.Value = "0"; return; } bool b = PositiveValuesList.Contains(importValue); if (b || NegativeValuesList.Contains(importValue)) { f.Value = (b) ? "1" : "0"; } else { map.Logger.Log("Couldn't parse the boolean value", newItem.Paths.FullPath, LogType.FieldError, Name, importValue); } }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue)) { return; } int value = 0; if (!int.TryParse(importValue.Trim(), out value)) { map.Logger.Log("Couldn't parse the integer value", newItem.Paths.FullPath, LogType.FieldError, Name, importValue); return; } Field f = newItem.Fields[ToWhatField]; if (f == null) { return; } f.Value = value.ToString(CultureInfo.InvariantCulture); }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { if (string.IsNullOrEmpty(importValue)) { return; } var values = importValue.Split(Delimiter[0]); //store the imported value as is Field f = newItem.Fields[NewItemField]; foreach (var value in values) { if (string.IsNullOrEmpty(value)) { continue; } if (f != null) { f.Value = value; break; } } }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { Field f = newItem.Fields[ToWhatField]; if (f == null) { return; } if (string.IsNullOrWhiteSpace(SubitemQuery)) { return; } var importItem = importRow is Item ? (Item)importRow : null; if (importItem == null) { return; } var queriedItems = importItem.Axes.SelectItems(SubitemQuery); var result = queriedItems .SelectMany(a => ExistingDataNames .Select(b => GetValue(a, b)) .Where(c => !string.IsNullOrWhiteSpace(c))) .ToList(); result.Insert(0, f.Value); f.Value = string.Join(Delimiter, result); }
/// <summary> /// Generates a string valid to be printed in the console. /// </summary> public static string ToConsoleString(this IDataMap map, int spaces = 0) { var header = spaces <= 0 ? string.Empty : new string(' ', spaces); var sb = new StringBuilder(); sb.AppendFormat("{0}", map == null ? "<null>" : map.ToString()); if (map != null && !map.IsDisposed) { if (map.IsValidated) { sb.AppendFormat("\n{0}- Validated: true", header); } if (map.VersionColumn.Name != null) { sb.AppendFormat("\n{0}- Version Column: {1}", header, map.VersionColumn); } if (map.Columns.Count != 0) { sb.AppendFormat("\n{0}- Columns: {1}", header, map.Columns); } foreach (var member in map.Members) { sb.AppendFormat("\n{0}- Member: {1}", header, member); } } return(sb.ToString()); }
protected MediaItem HandleMediaItem(IDataMap map, Item parentItem, string itemPath, MediaItem item) { var itemName = StringUtility.GetValidItemName(item.Name, 100); //date info string newFilePath = string.Format("{0}/{1}", parentItem.Paths.FullPath, itemName); // see if it exists in med lib IEnumerable <Item> matches = parentItem.Axes.GetDescendants() .Where(a => a.Paths.FullPath.EndsWith(itemName)); if (matches != null && matches.Any()) { if (matches.Count().Equals(1)) { return(new MediaItem(matches.First())); } map.Logger.Log("MediaFileMapping.HandleMediaItem", string.Format("Sitecore image lookup matched {0} for item {1}", matches.Count(), itemPath)); return(null); } ItemManager.AddFromTemplate(itemName, TemplateIDs.UnversionedImage, BuildMediaPath(map.ToDB, item.InnerItem.Paths.ParentPath), item.ID); MediaItem m = ImportMediaItem(item.GetMediaStream(), itemName + "." + item.Extension, newFilePath); if (m == null) { map.Logger.Log("MediaFileMapping.HandleMediaItem", string.Format("Image Not Found for item '{0}'", itemPath)); } return(m); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { Field f = newItem.Fields[ToWhatField]; if (f == null) { return; } var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue)) { f.Value = string.Empty; return; } //try to parse date value DateTime date; string cleanImportValue = importValue.Split(':').FirstOrDefault() ?? string.Empty; if (!DateTime.TryParse(cleanImportValue, out date) && !DateTime.TryParseExact(cleanImportValue, new string[] { "d/M/yyyy", "d/M/yyyy HH:mm:ss", "yyyyMMddTHHmmss", "yyyyMMddTHHmmssZ" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { map.Logger.Log("Date parse error", newItem.Paths.FullPath, LogType.DateParseError, Name, cleanImportValue); return; } f.Value = date.ToDateFieldValue(); }
public void FillField(IDataMap map, ref Item newItem, Item importRow) { if (importRow.Children == null || string.IsNullOrEmpty(FieldName) || string.IsNullOrEmpty(ChildTemplate)) { return; } var templateList = ChildTemplate.Split('|'); var firstChild = importRow.Children.FirstOrDefault(x => templateList.Contains(x.TemplateID.ToString())); if (firstChild == null) { return; } var value = GetItemField(firstChild, FieldName); if (string.IsNullOrEmpty(value)) { return; } Field f = newItem.Fields[NewItemField]; if (f != null) { f.Value = value; } }
// Use this for initialization void Start() { CsvLoader loader = new CsvLoader(); CsvTable csvTable = loader.LoadCSV("Config/test"); TestDataMap tMap = new TestDataMap(); IDataMap tempMap = tMap as IDataMap; loader.LoadCSV("Config/test", ref tempMap); //tMap.Load(ref csvTable); Dictionary <int, TestData> Dic = tMap.GetMap() as Dictionary <int, TestData>; //tMap.GetMap(ref Dic); //tMap.clearMap(); foreach (var t in Dic) { Debug.Log("!!!!!!!" + t.Key + "=" + t.Value.Name); } //CsvTable csvTable = loader.LoadCSV("Config/" + str); foreach (CsvRecord record in csvTable.Records) { foreach (string header in csvTable.Headers) { Debug.Log(header + ":" + record.GetField(header)); text.text = text.text + (header + ":" + record.GetField(header)); } } }
public string CleanHtml(IDataMap map, string itemPath, string html, Item importRow) { if (String.IsNullOrEmpty(html)) { return(html); } var document = new HtmlDocument(); document.LoadHtml(html); HtmlNodeCollection tryGetNodes = document.DocumentNode.SelectNodes("./*|./text()"); if (tryGetNodes == null || !tryGetNodes.Any()) { return(html); } var nodes = new Queue <HtmlNode>(tryGetNodes); while (nodes.Any()) { HandleNextNode(nodes, map, itemPath, importRow); } return(document.DocumentNode.InnerHtml); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrWhiteSpace(Component) || !ID.IsID(Component)) { var path = importRow is Item ? ((Item)importRow).Paths.FullPath : "N/A"; Logger.Log($"The Component value is empty or is not an id", path, LogType.FieldToComponent, "Component", Component); return; } var deviceItem = PresentationService.FindDeviceDefinition(newItem, Device); var dsName = DatasourcePath.Contains("/") ? DatasourcePath.Substring(DatasourcePath.LastIndexOf("/") + 1) : DatasourcePath; if (!OverwriteExisting) { var datasource = PresentationService.CreateDatasource(map, newItem, deviceItem, dsName, DatasourceFolder, DatasourcePath, Component, OverwriteExisting); if (datasource == null) { return; } var isSet = SetField(map, datasource, importRow, importValue); if (!isSet) { datasource.Delete(); } else { PresentationService.AddComponent(newItem, datasource, Placeholder, Component, Device, Parameters, IsSXA); } } else { var rendering = PresentationService.FindRendering(deviceItem, Placeholder, Component); if (rendering == null) { Logger.Log($"There was no rendering matching device:{Device} - placeholder:{Placeholder} - component:{Component}", newItem.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); return; } var datasource = PresentationService.FindDatasourceByName(map, newItem, rendering, dsName); if (datasource == null) { Logger.Log($"There was no datasource found matching name:{dsName}", newItem.Paths.FullPath, LogType.MultilistToComponent, "rendering xml", rendering.ToXml()); return; } var isSet = SetField(map, datasource, importRow, importValue); if (!isSet) { datasource.Delete(); PresentationService.RemoveComponent(newItem, rendering, Device); } } }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { List <string> selectedList = new List <string>(); if (string.IsNullOrEmpty(SelectionRootItem)) { return; } var master = Factory.GetDatabase("master"); Item root = master.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } List <string> importvalues = importValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (!importvalues.Any()) { return; } foreach (Item value in selectionValues) { foreach (var temp in importvalues) { Field t = value.Fields["Text"]; if (t == null) { continue; } if (!temp.Trim().ToLower().Equals(t.Value.Trim().ToLower())) { continue; } selectedList.Add(value.ID.ToString()); } } Field f = newItem.Fields[NewItemField]; if (f == null || !selectedList.Any()) { return; } f.Value = string.Join("|", selectedList); }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { if (string.IsNullOrEmpty(importValue)) { return; } var sourceItems = GetSourceItems(newItem.Database); if (sourceItems == null) { return; } Field f = newItem.Fields[NewItemField]; if (f == null) { return; } Dictionary <string, string> d = GetMapping(); var values = importValue.Split(GetFieldValueDelimiter()?[0] ?? ','); foreach (var val in values) { string lowerValue = val.ToLower(); string transformValue = (d.ContainsKey(lowerValue)) ? d[lowerValue] : string.Empty; if (string.IsNullOrEmpty(transformValue)) { map.Logger.Log(newItem.Paths.FullPath, "Device Market Area(s) not converted", ProcessStatus.FieldError, NewItemField, val); continue; } string[] parts = transformValue.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); //loop through children and look for anything that matches by name foreach (string area in parts) { string cleanName = StringUtility.GetValidItemName(area, map.ItemNameMaxLength); IEnumerable <Item> t = sourceItems.Where(c => c.DisplayName.Equals(cleanName)); //if you find one then store the id if (!t.Any()) { map.Logger.Log(newItem.Paths.FullPath, "Device Market Area(s) not found in list", ProcessStatus.FieldError, NewItemField, area); continue; } string ctID = t.First().ID.ToString(); if (!f.Value.Contains(ctID)) { f.Value = (f.Value.Length > 0) ? $"{f.Value}|{ctID}" : ctID; } } } }
//fills it's own field public void FillField(IDataMap map, ref Item newItem, Item importRow) { Field f = newItem.Fields[NewItemField]; if (f != null) { f.Value = LinkManager.GetDynamicUrl(importRow); } }
public void SetUp() { _database = GetSampleDb(); var defItem = _database.GetItem(TestingConstants.FromChildValueToText.DefinitionId); _log = new DefaultLogger(); _sut = new FromChildValueToText(defItem, _log); _dataMap = Substitute.For <IDataMap>(); }
//fills it's own field public void FillField(IDataMap map, ref Item newItem, Item importRow) { Field f = newItem.Fields[NewItemField]; if (f != null) { f.Value = importRow.Paths.FullPath; } }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { Field f = newItem.Fields[NewItemField]; if (f != null) { f.Value = CleanHtml(map, newItem.Paths.FullPath, importValue); } }
protected void HandleImport(IDataMap map, DefaultLogger l) { ImportProcessor p = new ImportProcessor(map, l); p.Process(); txtMessage.Text = l.GetLog(); WriteLogs(l); }
public void SetUp() { _database = GetSampleDb(); var defItem = _database.GetItem(TestingConstants.ToStaticValue.DefinitionId); _log = new DefaultLogger(); _sut = new ToStaticValue(defItem, _log); _dataMap = Substitute.For <IDataMap>(); }
public static void AssignDataMap(this JobDetailImpl jobDetail, ITypeInfo typeInfo, IDataMap jobDataMap) { typeInfo.Members.Where(CanBeMapped()).Each(info => jobDetail.JobDataMap.MapValue(jobDataMap, info)); }