public override void ApplyToData(DataElement data) { Dictionary <int, object> dataToSort = new Dictionary <int, object>(); int columnNo = data.Columns.IndexOf(data.Column(Index)); for (int i = 0; i < data.Rows.Count; i++) { dataToSort.Add(i, data.Rows[i].Data[columnNo]); } DataElement temp = data.Clone(); data.Rows.Clear(); foreach (Column column in data.Columns) { column.Data.Clear(); } List <KeyValuePair <int, object> > sortedData; if (SortOrder == Commands.SortOrder.Ascending) { sortedData = dataToSort.OrderBy(k => k.Value).ToList(); } else { sortedData = dataToSort.OrderByDescending(k => k.Value).ToList(); } foreach (KeyValuePair <int, object> kvp in sortedData) { data.Rows.Add(temp.Rows[kvp.Key]); } data.Normalize(); }
public virtual void FindShapeData(IList <DataElement> data) { if (Data != null) { return; } DataElement applicableData = data.FirstOrDefault(d => d.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)); if (applicableData != null) { Data = applicableData.Clone(); foreach (DataElementDescriptor additionalDataDescriptor in AdditionalDataDescriptors) { DataElement additionalDataElement = data.FirstOrDefault(d => d.Name.Equals(additionalDataDescriptor.Name, StringComparison.OrdinalIgnoreCase));; if (additionalDataElement != null && !additionalDataElement.Name.Equals(Data.Name, StringComparison.OrdinalIgnoreCase)) { Data.MergeWith(additionalDataElement); } } } else { Logger logger = LogManager.GetLogger("Generator"); logger.Debug("Unable to find data for {0} on slide {1}.", FullName, Slide.Number); } }
public void TestClone_TranslatableDisplayName() { IPolicyObjectCollection<IDataItem> collection = new PolicyObjectCollection<IDataItem>(); DataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("content"), new TranslateableLanguageItem("Word or phrase"), DataType.StringArray, collection); DataElement dataElementCopy = dataElement.Clone() as DataElement; Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier); Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value); Assert.AreNotEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier); }
public void TestClone() { DataElement elem = new DataElement( new TranslateableLanguageItem(Guid.NewGuid()), new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "it's a string, init") ); IDataElement copy = elem.Clone() as IDataElement; Assert.AreEqual(elem.DisplayName.Value, copy.DisplayName.Value); Assert.AreNotEqual(elem.Identifier, copy.Identifier); Assert.AreNotEqual(elem.Name.Identifier, copy.Name.Identifier); Assert.AreEqual(elem.Name.Value, copy.Name.Value); Assert.AreEqual(elem.ReadOnly, copy.ReadOnly); Assert.AreEqual(elem.Type, copy.Type); }
public void TestClone_CollectionOfItems() { PolicyObjectCollection<IDataItem> items = new PolicyObjectCollection<IDataItem>(); items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 1")); items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 2")); items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 3")); DataElement elem = new DataElement( new TranslateableLanguageItem(Guid.NewGuid()), new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, items ); DataElement copy = elem.Clone() as DataElement; Assert.IsNotNull(copy.Data); PolicyObjectCollection<IDataItem> copyOfItems = copy.Data as PolicyObjectCollection<IDataItem>; Assert.IsNotNull(copyOfItems); Assert.AreEqual(3, copyOfItems.Count); for (int i = 0; i < copyOfItems.Count; i++) { IDataItem item = items[i]; IDataItem copyOfItem = copyOfItems[i]; Assert.IsNotNull(item); Assert.IsNotNull(copyOfItem); Assert.AreNotEqual(item.Identifier, copyOfItem.Identifier); Assert.AreNotEqual(item.Name.Identifier, copyOfItem.Name.Identifier); Assert.AreEqual(item.Name.Value, copyOfItem.Name.Value); Assert.AreEqual(item.ReadOnly, copyOfItem.ReadOnly); Assert.AreEqual(item.Value, copyOfItem.Value); } }
public override void ApplyToData(DataElement data) { DataElement temp = data.Clone(); data.Rows.Clear(); data.Columns.Clear(); foreach (Column column in temp.Columns) { Row row = new Row { Header = column.Header, MappedHeader = column.MappedHeader, IsHidden = column.IsHidden, IsCore = column.IsCore }; row.Data.AddRange(column.Data); row.Legends.AddRange(column.Legends); data.Rows.Add(row); } foreach (Row row in temp.Rows) { data.Columns.Add(new Column { Header = row.Header, MappedHeader = row.MappedHeader, IsHidden = row.IsHidden, IsCore = row.IsCore }); } data.Normalize(); data.IsTransposed = !data.IsTransposed; }
public void CloneCopiesAllDataToNewObject() { DataElement da = Helpers.CreateTestDataElement(); DataElement clone = da.Clone(); Assert.AreNotSame(da, clone); Assert.ReferenceEquals(da, da.Rows[0].ParentElement); Assert.ReferenceEquals(da, da.Rows[1].ParentElement); Assert.ReferenceEquals(da, da.Columns[0].ParentElement); Assert.ReferenceEquals(da, da.Columns[1].ParentElement); Assert.ReferenceEquals(da, da.Columns[2].ParentElement); Assert.AreEqual(1.0, da.Columns[0].Data[0]); Assert.AreEqual(5.05, da.Columns[0].Data[1]); Assert.AreEqual("client 1", da.Columns[1].Data[0]); Assert.AreEqual("client 2", da.Columns[1].Data[1]); Assert.AreEqual(false, da.Columns[2].Data[0]); Assert.AreEqual(true, da.Columns[2].Data[1]); Assert.AreEqual(da.Columns[0].Data[0], da.Rows[0].Data[0]); Assert.AreEqual(da.Columns[0].Data[1], da.Rows[1].Data[0]); Assert.AreEqual(da.Columns[1].Data[0], da.Rows[0].Data[1]); Assert.AreEqual(da.Columns[1].Data[1], da.Rows[1].Data[1]); Assert.AreEqual(da.Columns[2].Data[0], da.Rows[0].Data[2]); Assert.AreEqual(da.Columns[2].Data[1], da.Rows[1].Data[2]); }
public void TestClone_NonTranslatebleName() { DataItem item = DataItem.CreateDataItem( new NonTranslateableLanguageItem("name"), DataType.String, "stuff" ); DataElement elem = new DataElement( new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("display name"), DataType.String, item ); DataElement copy = elem.Clone() as DataElement; Assert.IsNotNull(copy); Assert.AreEqual(Guid.Empty, copy.Name.Identifier); Assert.AreEqual(elem.Name.Value, copy.Name.Value); DataItem copyItem = copy.Data as DataItem; Assert.IsNotNull(copyItem); Assert.AreEqual(item.Name.Identifier, copyItem.Name.Identifier); Assert.AreEqual(item.Name.Value, copyItem.Name.Value); Assert.AreEqual(item.Value, copyItem.Value); }