protected override object CreateDataSource(string name, Type type, NamedParameters ctorArgs) { var dataSources = (IList)typeof(List <>).CreateGeneric(type); foreach (var factory in Factories) { if (factory.CanCreate(name, type)) { dataSources.Add(factory.Create(name, type, ctorArgs)); } } var innerType = type.GetGenericArguments().First(); if (type.GetGenericTypeDefinition() == typeof(ISingleDataSource <>)) { return(typeof(StackSingleDataSource <>).CreateGeneric(innerType, name, dataSources)); } if (type.GetGenericTypeDefinition() == typeof(IEnumerableDataSource <>)) { return(typeof(StackEnumerableDataSource <>).CreateGeneric(innerType, name, dataSources)); } else { throw new NotSupportedException(); } }
public override string ToString() { using (var code = new Microsoft.CSharp.CSharpCodeProvider()) { var hasParameters = NamedParameters.Count > 0 || Parameters.Count > 0; var parametersString = new StringBuilder(); if (hasParameters && Parameters.Count > 0) { Parameters.TakeWhile(x => Parameters.Last() != x) .ToList() .ForEach(x => parametersString.Append(string.Format("{0}, ", x))); parametersString.Append(Parameters.Last()); } if (hasParameters && NamedParameters.Count > 0) { NamedParameters.TakeWhile(x => NamedParameters.Last() != x) .ToList() .ForEach(x => parametersString.Append(string.Format("{0} = {1}, ", x.Item1, x.Item2))); parametersString.Append(string.Format("{0} = {1}", NamedParameters.Last().Item1, NamedParameters.Last().Item2)); } var retval = string.Format("[{0}{1}]", AttributeType.Name, hasParameters ? string.Format("({0})", parametersString) : ""); return(retval); } }
public object Create(string name, Type type, NamedParameters ctorArgs) { if (type == typeof(DoubleSetDataSource)) { return(new DoubleSetDataSource(name)); } if (type == typeof(IEnumerableDataSource <SimplePrice>)) { return(myMockery.NewMock <IEnumerableDataSource <SimplePrice> >()); } else if (type == typeof(ISingleDataSource <string>)) { return(new FakeSingleDataSource <string>(name)); } else if (type == typeof(ISingleDataSource <int>)) { return(new FakeSingleDataSource <int>(name)); } else if (type == typeof(ISingleDataSource <double>)) { return(new FakeSingleDataSource <double>(name)); } throw new NotSupportedException("DataSource type not supported: " + type); }
private static void ExecuteNamedParametersExperiments() { PrintIntroText("Named Parameters"); /* [Named Params] * Syntax in a method call: foo(a: 5, name: "Hello"); * * Quote: * "Named parameters are an alternate parameter syntax. They * sometimes result in easier to read and clearer code. * They are checked for correctness by the compiler. By * specifying the formal parameter name, we can reorder * arguments." * (source: https://www.dotnetperls.com/named-parameters ) * **/ NamedParameters paramsmaster = new NamedParameters(); // traditional, normal way of declaring parameters paramsmaster.PrintThese("John", "Cena", "Wrestling", "normal, no named params"); //makes code more readably :) paramsmaster.PrintThese(firstname: "John", lastname: "Cena", hobby: "Wrestling", syntaxmode: "with named params, following parameter list's order"); //you can even mix the order! paramsmaster.PrintThese(hobby: "Wrestling", syntaxmode: "with named params too, but mixed order", firstname: "John", lastname: "Cena"); PrintOutroText("Named Parameters"); }
protected override object CreateDataSource( string name, Type type, NamedParameters ctorArgs ) { var dataSources = (IList)typeof( List<> ).CreateGeneric( type ); foreach ( var factory in Factories ) { if ( factory.CanCreate( name, type ) ) { dataSources.Add( factory.Create( name, type, ctorArgs ) ); } } var innerType = type.GetGenericArguments().First(); if ( type.GetGenericTypeDefinition() == typeof( ISingleDataSource<> ) ) { return typeof( StackSingleDataSource<> ).CreateGeneric( innerType, name, dataSources ); } if ( type.GetGenericTypeDefinition() == typeof( IEnumerableDataSource<> ) ) { return typeof( StackEnumerableDataSource<> ).CreateGeneric( innerType, name, dataSources ); } else { throw new NotSupportedException(); } }
protected override object CreateDataSource( string name, Type type, NamedParameters ctorArgs ) { var innerType = type.GetGenericArguments().First(); var dataSource = new TomStockPricesDataSource(); return dataSource; }
public IEnumerable <SqlExtensionParam> GetParametersByName(string name) { if (NamedParameters.TryGetValue(name, out var list)) { return(list); } return(Enumerable.Empty <SqlExtensionParam>()); }
protected override object CreateDataSource(string name, Type type, NamedParameters ctorArgs) { var innerType = type.GetGenericArguments().First(); var dataSource = new TomStockPricesDataSource(); return(dataSource); }
public void ConvertNamedParameters_Failed() { var funcMeta = BuiltInFactory.GetFunc(NotFunc.FuncName); var namedP = new NamedParameters(null); var err = Assert.Throws <FEELException> (() => BuiltInFactory.ConvertNamedParameter(namedP, funcMeta.Item2, null)); Assert.Equal("Failed coverting named parameters", err.Message); }
protected override object CreateDataSource(string name, Type type, NamedParameters ctorArgs) { if (type == typeof(IPriceSeriesDataSource)) { var realDS = RealFactory.Create <IEnumerableDataSource <SimplePrice> >(name, ctorArgs); var operators = GetOperatorsForDataSource(name); return(new PriceSeriesDataSource(realDS, operators)); } return(RealFactory.Create(name, type, ctorArgs)); }
protected override object CreateDataSource( string name, Type type, NamedParameters ctorArgs ) { if ( type == typeof( IPriceSeriesDataSource ) ) { var realDS = RealFactory.Create<IEnumerableDataSource<SimplePrice>>( name, ctorArgs ); var operators = GetOperatorsForDataSource( name ); return new PriceSeriesDataSource( realDS, operators ); } return RealFactory.Create( name, type, ctorArgs ); }
public override void Invoke() { base.Invoke(); var keys = NamedParameters.Any() ? NamedParameters.Keys : Context.State.Keys; foreach (var key in keys) { Context.Logger.WriteLine($"{key}: {Context.State.GetString(key)}"); } }
public SqlExtensionParam AddParameter(SqlExtensionParam param) { var key = param.Name ?? string.Empty; if (!NamedParameters.TryGetValue(key, out var list)) { list = new List <SqlExtensionParam>(); NamedParameters.Add(key, list); } list.Add(param); return(param); }
protected override object CreateDataSource( string name, Type type, NamedParameters ctorArgs ) { // we need a cache here to allow caching inside the different DataSources var dataSourceId = GetDataSourceId( name, type ); if ( !myDataSourceCache.ContainsKey( dataSourceId ) ) { var dataSource = CreateCachingDataSource( name, type, ctorArgs ); myDataSourceCache[ dataSourceId ] = dataSource; } return myDataSourceCache[ dataSourceId ]; }
protected override object CreateDataSource(string name, Type type, NamedParameters ctorArgs) { // we need a cache here to allow caching inside the different DataSources var dataSourceId = GetDataSourceId(name, type); if (!myDataSourceCache.ContainsKey(dataSourceId)) { var dataSource = CreateCachingDataSource(name, type, ctorArgs); myDataSourceCache[dataSourceId] = dataSource; } return(myDataSourceCache[dataSourceId]); }
protected override object CreateDataSource( string name, Type type, NamedParameters ctorArgs ) { if ( type == typeof( ICurrencyDataSource ) ) { return new XmlCurrencyDataSource( myDataStore ); } else { var innerType = type.GetGenericArguments().First(); var dataSource = typeof( XmlDataSource<> ).CreateGeneric( innerType, name, myDataStore ); return dataSource; } }
protected override object CreateDataSource(string name, Type type, NamedParameters ctorArgs) { if (type == typeof(ICurrencyDataSource)) { return(new XmlCurrencyDataSource(myDataStore)); } else { var innerType = type.GetGenericArguments().First(); var dataSource = typeof(XmlDataSource <>).CreateGeneric(innerType, name, myDataStore); return(dataSource); } }
public void ConvertNamedParameters_Names_Matched() { var funcMeta = BuiltInFactory.GetFunc(NotFunc.FuncName); var nParamDict = new Dictionary <string, IExpression> () { { "negand", new BooleanLiteral("true") } }; var namedP = new NamedParameters(nParamDict); var lParams = BuiltInFactory.ConvertNamedParameter(namedP, funcMeta.Item2, null); var boolVar = funcMeta.Item1.Execute(lParams); Assert.False(boolVar); }
public void AddNamedParameters(object namedParameters, CrudMethod crudMethodType) { if (namedParameters == null) { return; } var ignoreAttribute = new List <Type> { typeof(IgnoreAttribute) }; switch (crudMethodType) { case CrudMethod.Insert: ignoreAttribute.Add(typeof(IgnoreOnInsertAttribute)); break; case CrudMethod.Update: ignoreAttribute.Add(typeof(IgnoreOnUpdateAttribute)); break; } var props = namedParameters.GetType().GetProperties(); foreach (var p in props) { var name = p.Name; var customAttributes = p.GetCustomAttributes(true); if (customAttributes.Any(x => x is ColumnAttribute)) { name = ((ColumnAttribute)customAttributes.Single(x => x is ColumnAttribute)).Name; } if (customAttributes.Any(x => ignoreAttribute.Contains(x.GetType()))) { continue; } var value = p.GetValue(namedParameters, null); if (DBNull.Value.Equals(value)) { value = null; } NamedParameters.Add(new KeyValuePair <string, object>(name, value)); } }
private object CreateCachingDataSource( string name, Type type, NamedParameters ctorArgs ) { var realDataSource = RealFactory.Create( name, type, ctorArgs ); var innerType = type.GetGenericArguments().First(); if ( type.GetGenericTypeDefinition() == typeof( ISingleDataSource<> ) ) { return typeof( CachingSingleDataSource<> ).CreateGeneric( innerType, realDataSource ); } if ( type.GetGenericTypeDefinition() == typeof( IEnumerableDataSource<> ) ) { return typeof( CachingEnumerableDataSource<> ).CreateGeneric( innerType, realDataSource ); } else { throw new NotSupportedException(); } }
public override void Invoke() { base.Invoke(); if (!NamedParameters.ContainsKey("entry")) { Context.Logger.WriteLine("Parameter 'entry' is missing."); return; } var entry = NamedParameters["entry"]; IFileReader fileReader; if (NamedParameters.ContainsKey("manifest")) { var manifest = NamedParameters["manifest"]; var manifestReader = new ManifestResourcesReader(GetType()); var stream = manifestReader.GetStream(manifest); var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false); fileReader = new ZipArchiveReader(zipArchive); } else if (NamedParameters.ContainsKey("archive")) { var archive = NamedParameters["archive"]; var zipArchive = ZipFile.Open(archive, ZipArchiveMode.Read); fileReader = new ZipArchiveReader(zipArchive); } else if (NamedParameters.ContainsKey("dir")) { var dir = NamedParameters["dir"]; fileReader = new FileSystemReader(dir); } else { Context.Logger.WriteLine("You must specify either dir, manifest or archive to define the source location of the entry point."); return; } var taxonomySource = new TaxonomyFileSet(fileReader); Instance.Dts.AddTaxonomy(new Uri(entry), taxonomySource); }
private object CreateCachingDataSource(string name, Type type, NamedParameters ctorArgs) { var realDataSource = RealFactory.Create(name, type, ctorArgs); var innerType = type.GetGenericArguments().First(); if (type.GetGenericTypeDefinition() == typeof(ISingleDataSource <>)) { return(typeof(CachingSingleDataSource <>).CreateGeneric(innerType, realDataSource)); } if (type.GetGenericTypeDefinition() == typeof(IEnumerableDataSource <>)) { return(typeof(CachingEnumerableDataSource <>).CreateGeneric(innerType, realDataSource)); } else { throw new NotSupportedException(); } }
public AttributeInfo(Type attributeType, params object[] namedParameters) { var count = namedParameters.Length % 2 == 0 ? namedParameters.Length / 2 : (namedParameters.Length - 1) / 2; this.NamedParameters = new List <Tuple <string, string> >(count); this.Parameters = new List <string>(count); for (int i = 0; i < count; i += 2) { if (namedParameters[i] == null) { Parameters.Add(namedParameters[i + 1].ToString( )); } else { NamedParameters.Add(new Tuple <string, string>(namedParameters[i].ToString( ), namedParameters[i + 1].ToString( ))); } } this.AttributeType = attributeType; }
public QueryParameters(IDbDataParameter[] parameters) { int i = 0; if (parameters != null) { foreach (IDbDataParameter param in parameters) { _positionalParameterNames[i++] = param.ParameterName; _positionalParameterValues[i++] = param.Value; NamedParameters.Add(param.ParameterName, param.Value); } } else { _positionalParameterNames = new string[] { }; _positionalParameterValues = new object[] { }; NamedParameters = new Dictionary <string, object>(); } }
public override void Invoke() { base.Invoke(); if (!NamedParameters.ContainsKey("format")) { Context.Logger.WriteLine("Parameter 'format' is missing."); return; } var format = NamedParameters["format"]; if (!NamedParameters.ContainsKey("file")) { Context.Logger.WriteLine("Parameter 'file' is missing."); return; } var filename = NamedParameters["file"]; var fileInfo = new FileInfo(filename); if (fileInfo.Exists) { fileInfo.Delete(); } if (format == "XML") { SaveAsXml(fileInfo); } else if (format == "XHTML") { SaveAsInlineXbrl(fileInfo); } else { Context.Logger.WriteLine($"Unknown format '{format}'."); return; } Context.Logger.WriteLine("Exported."); }
public NamedParameters GetConstructorArguments() { if ( ConstructorArugments == null ) { return NamedParameters.Null; } if ( ConstructorArugments.Length % 2 != 0 ) { throw new ArgumentException( "ConstructorArguments must have even length" ); } var args = new NamedParameters(); for ( int i = 0; i < ConstructorArugments.Length; ++i ) { args[ ConstructorArugments[ i ].ToString() ] = ConstructorArugments[ i + 1 ]; i++; } AddTypedConstructorArugments( args ); return args; }
private void Initialize(PipelineNode node) { _arguments = new Dictionary <string, object>(); if (NamedParameters != null) { _hasAdvancedSettings = node.Properties.Keys.Any(t => !NamedParameters.ContainsKey(t)); } _seperator = _hasAdvancedSettings ? "=" : ":"; if (!node.Properties.ContainsKey("LabelColumnName")) { node.Properties.Add("LabelColumnName", "Label"); } node.Properties.Add("FeatureColumnName", "Features"); foreach (var kv in node.Properties) { object value = null; //For Nullable values. if (kv.Value == null) { continue; } Type type = kv.Value.GetType(); if (type == typeof(bool)) { //True to true value = ((bool)kv.Value).ToString(CultureInfo.InvariantCulture).ToLowerInvariant(); } if (type == typeof(float)) { //0.0 to 0.0f value = ((float)kv.Value).ToString(CultureInfo.InvariantCulture) + "f"; } if (type == typeof(int)) { value = ((int)kv.Value).ToString(CultureInfo.InvariantCulture); } if (type == typeof(double)) { value = ((double)kv.Value).ToString(CultureInfo.InvariantCulture); } if (type == typeof(long)) { value = ((long)kv.Value).ToString(CultureInfo.InvariantCulture); } if (type == typeof(string)) { var val = kv.Value.ToString(); if (val == "<Auto>") { continue; // This is temporary fix and needs to be fixed in AutoML SDK } // string to "string" value = "\"" + val + "\""; } if (type == typeof(CustomProperty)) { value = kv.Value; } //more special cases to handle if (NamedParameters != null) { _arguments.Add(_hasAdvancedSettings ? kv.Key : NamedParameters[kv.Key], value); } else { _arguments.Add(kv.Key, value); } } }
public T Create <T>(string name, NamedParameters ctorArgs) { return((T)Create(name, typeof(T), ctorArgs)); }
public Variable Execute(List <Variable> inputParams, VariableContext mainContext, NamedParameters nParams = null) { if (_isExternal) { //TODO: add error logging for no support for external java/PMML function types return(new Variable()); } var context = mainContext ?? new VariableContext(); if (nParams != null) { inputParams = BuiltInFactory.ConvertNamedParameter(nParams, _formalParams.Select(v => v.TwoTuple.a.StringVal).ToArray(), context); } if (inputParams != null && _formalParams.Count > 0) { if (_formalParams.Count != inputParams.Count) { //TODO: Add to error logging for missmatch expected input return(new Variable()); } for (int i = _formalParams.Count - 1; i >= 0; i--) { context.AddToFunctionInputs(_formalParams[i].TwoTuple.a.StringVal, inputParams[i]); } } try { return((Variable)_body.Execute(context)); } catch (Exception) { return(new Variable()); } }
private void SaveAsInlineXbrl(FileInfo fileInfo) { if (!NamedParameters.ContainsKey("template")) { Context.Logger.WriteLine("Parameter 'template' is missing."); return; } var template = NamedParameters["template"]; var xTemplate = XDocument.Load(template); var writerSettings = new InlineXbrlWriterSettings { Title = "iXBRL Export", Culture = new CultureInfo("en-GB"), Scale = 3, IncludeDocumentation = true, IncludeReferences = true, }; var networks = new[] { new PresentationNetwork { Name = "Statement of financial position, current/non-current", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-210000") }, new PresentationNetwork { Name = "Statement of comprehensive income, profit or loss, by function of expense", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-310000") }, new PresentationNetwork { Name = "Statement of cash flows, direct method", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_7_2017-03-09_role-510000") }, new PresentationNetwork { Name = "Statement of changes in equity", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-610000") }, new PresentationNetwork { Name = "Notes - Subclassifications of assets, liabilities and equities", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800100") }, new PresentationNetwork { Name = "Notes - Analysis of income and expense", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800200") }, new PresentationNetwork { Name = "Notes - List of notes", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800500") }, new PresentationNetwork { Name = "Notes - List of accounting policies", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800600") }, new PresentationNetwork { Name = "Notes - Corporate information and statement of IFRS compliance", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-810000") }, new PresentationNetwork { Name = "Notes - Property, plant and equipment", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_16_2017-03-09_role-822100") }, new PresentationNetwork { Name = "Notes - Fair value measurement", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ifrs_13_2017-03-09_role-823000") }, new PresentationNetwork { Name = "Notes - Investment property", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_40_2017-03-09_role-825100") }, new PresentationNetwork { Name = "Notes – Inventories", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_2_2017-03-09_role-826380") }, new PresentationNetwork { Name = "Notes – Revenue", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_18_2017-03-09_role-831110") }, new PresentationNetwork { Name = "Notes - Revenue from contracts with customers", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ifrs_15_2017-03-09_role-831150") }, new PresentationNetwork { Name = "Notes - Impairment of assets", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_36_2017-03-09_role-832410") }, new PresentationNetwork { Name = "Notes - Employee benefits", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_19_2017-03-09_role-834480") }, new PresentationNetwork { Name = "Notes - Operating segments", Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ifrs_8_2017-03-09_role-871100") }, }; //var networks2 = new[] //{ // new PresentationNetwork // { // Name = "Statement of changes in equity", // Role = new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-610000") // }, //}; writerSettings.Scope = new ScopeSettings { PresentationNetworks = networks, IncludeEmptyConcepts = false, IncludeEmptyExplicitMembers = false }; var inlineXbrlWriter = new InlineXbrlWriter(xTemplate, writerSettings); Instance.Save(inlineXbrlWriter); var result = inlineXbrlWriter.Document.ToString(); File.WriteAllText(fileInfo.FullName, result); }
protected virtual void AddTypedConstructorArugments( NamedParameters args ) { // hook for derived classes to add types arguments }
public QueryParameter Add(string name, object value) { NamedParameters.Add(name, value); return(this); }
public void Clear() { DbParameters.Clear(); NamedParameters.Clear(); }