private IDictionary <IColumnIdentifier, Tolerance> BuildTolerances(InclusionXml inclusionXml) { var columnIdentifierFactory = new ColumnIdentifierFactory(); var toleranceFactory = new ToleranceFactory(); var tuples = inclusionXml?.Mappings.Where(mapping => !string.IsNullOrEmpty(mapping.Tolerance)) .Select(mapping => new { Identifier = columnIdentifierFactory.Instantiate(mapping.Candidate), Tolerance = toleranceFactory.Instantiate(mapping.Type, mapping.Tolerance) } ) .Union( inclusionXml?.Usings.Where(@using => !string.IsNullOrEmpty(@using.Tolerance)) .Select(@using => new { Identifier = columnIdentifierFactory.Instantiate(@using.Column), Tolerance = toleranceFactory.Instantiate(@using.Type, @using.Tolerance) } )); var dico = new Dictionary <IColumnIdentifier, Tolerance>(); foreach (var tuple in tuples) { dico.Add(tuple.Identifier, tuple.Tolerance); } return(dico); }
protected override void SpecificBuild() { var ctrXml = ConstraintXml as LookupExistsXml; ctrXml.ResultSet.Settings = ctrXml.Settings; var factory = new ColumnIdentifierFactory(); var mappings = new ColumnMappingCollection( ctrXml.Join?.Mappings .Select(mapping => new ColumnMapping( factory.Instantiate(mapping.Candidate) , factory.Instantiate(mapping.Reference) , mapping.Type)) .Union( ctrXml.Join?.Usings.Select(@using => new ColumnMapping( factory.Instantiate(@using.Column) , @using.Type) ))); var builder = new ResultSetServiceBuilder(); builder.Setup(Helper.InstantiateResolver(ctrXml.ResultSet)); builder.Setup(Helper.InstantiateAlterations(ctrXml.ResultSet)); var service = builder.GetService(); var ctr = ctrXml.IsReversed ? new LookupReverseExistsConstraint(service) : new LookupExistsConstraint(service); Constraint = ctr.Using(mappings); }
private IEnumerable <ColumnMapping> BuildMappings(JoinXml joinXml) { var factory = new ColumnIdentifierFactory(); return(joinXml?.Mappings.Select(mapping => new ColumnMapping( factory.Instantiate(mapping.Candidate) , factory.Instantiate(mapping.Reference) , mapping.Type)) .Union( joinXml?.Usings.Select(@using => new ColumnMapping( factory.Instantiate(@using.Column) , @using.Type) ))); }
protected object EvaluateExpression(IColumnExpression expression, DataRow row) { if (expression.Language == LanguageType.NCalc) { var exp = new NCalc.Expression(expression.Value); var factory = new ColumnIdentifierFactory(); exp.EvaluateParameter += delegate(string name, NCalc.ParameterArgs args) { args.Result = GetValueFromRow(row, factory.Instantiate(name)); }; return(exp.Evaluate()); } else if (expression.Language == LanguageType.Native) { var parse = expression.Value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var variable = new ColumnIdentifierFactory().Instantiate(parse.ElementAt(0)); var value = GetValueFromRow(row, variable); foreach (var nativeFunction in parse.Skip(1)) { var factory = new NativeTransformationFactory(); var transformer = factory.Instantiate(nativeFunction); value = transformer.Evaluate(value); } return(value); } else { throw new ArgumentOutOfRangeException($"The language {expression.Language} is not supported during the evaluation of an expression."); } }
public void Instantiate_SsasNameWithDoubleBrackets_NameIdentifier() { var factory = new ColumnIdentifierFactory(); var id = factory.Instantiate("[[dimension].[hierarchy].[level]]"); Assert.That(id, Is.TypeOf <ColumnNameIdentifier>()); Assert.That((id as ColumnNameIdentifier).Name, Is.EqualTo("[dimension].[hierarchy].[level]")); }
public void Instantiate_SsasName_NameIdentifier(string identifier) { var factory = new ColumnIdentifierFactory(); var id = factory.Instantiate(identifier); Assert.That(id, Is.TypeOf <ColumnNameIdentifier>()); Assert.That((id as ColumnNameIdentifier).Name, Is.EqualTo(identifier)); }
public void Instantiate_Ordinal_PositionIdentifier(int identifier) { var factory = new ColumnIdentifierFactory(); var id = factory.Instantiate("#" + identifier.ToString()); Assert.That(id, Is.TypeOf <ColumnOrdinalIdentifier>()); Assert.That((id as ColumnOrdinalIdentifier).Ordinal, Is.EqualTo(identifier)); }
protected object EvaluateExpression(IColumnExpression expression, DataRow row) { var exp = new NCalc.Expression(expression.Value); var factory = new ColumnIdentifierFactory(); exp.EvaluateParameter += delegate(string name, NCalc.ParameterArgs args) { args.Result = GetValueFromRow(row, factory.Instantiate(name)); }; return(exp.Evaluate()); }
public void Execute_DuplicatedIdentifiers_ColumnFilterped(string id1, string id2) { var rs = new NBi.Core.ResultSet.ResultSet(); rs.Load("a;1;120"); rs.Columns[0].ColumnName = "Foo"; rs.Columns[1].ColumnName = "Col1"; rs.Columns[2].ColumnName = "Col2"; var factory = new ColumnIdentifierFactory(); var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) })); filter.Execute(rs); Assert.That(rs.Columns.Count, Is.EqualTo(1)); }
public void Execute_NonExistingIdentifiers_ColumnSkipped(string id) { var rs = new NBi.Core.ResultSet.ResultSet(); rs.Load("a;1;120"); rs.Columns[0].ColumnName = "Foo"; rs.Columns[1].ColumnName = "Col1"; rs.Columns[2].ColumnName = "Col2"; var factory = new ColumnIdentifierFactory(); var skip = new ProjectAwayEngine(new ProjectAwayArgs(new[] { factory.Instantiate(id) })); skip.Execute(rs); Assert.That(rs.Columns.Count, Is.EqualTo(3)); }
public void Execute_MultipleIdentifiersNotSameOrder_ColumnFilteredOrderChanged(string id1, string id2) { var rs = new NBi.Core.ResultSet.ResultSet(); rs.Load("a;1;120"); rs.Columns[0].ColumnName = "Foo"; rs.Columns[1].ColumnName = "Col1"; rs.Columns[2].ColumnName = "Bar"; var factory = new ColumnIdentifierFactory(); var project = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) })); project.Execute(rs); Assert.That(rs.Columns.Count, Is.EqualTo(2)); Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Bar")); Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Foo")); }
public void Instantiate_Ordinal_Failure(string identifier) { var factory = new ColumnIdentifierFactory(); Assert.Throws <ArgumentException>(() => factory.Instantiate(identifier)); }