public ActivationForwardLayer( ActivatorType type, MessageShape inputMessageShape) : base(inputMessageShape, inputMessageShape) { Activator = ActivatorFactory.Produce(type); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); var config = new ChoETL.ChoCSVRecordConfiguration { FileHeaderConfiguration = new ChoETL.ChoCSVFileHeaderConfiguration { HasHeaderRecord = false, }, }; using (var reader = new StreamReader(stream)) using (var csvReader = new global::ChoETL.ChoCSVReader(reader, config).AsDataReader()) { var count = 0; while (csvReader.Read()) { count++; var record = activate(); record.Read(i => csvReader.GetString(i)); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { // bit of a hack, since this only works for T == PackageAsset var engine = new global::FileHelpers.FileHelperAsyncEngine <PackageAssetData>(); using (engine.BeginReadStream(reader)) { foreach (var item in engine) { // it seems like it would be slow to create a PackageAssetData // and then subsequently copy all the fields to a PackageAsset // but this approach is actually faster than having FileHelpers // bind directly to the PackageAsset. var record = activate(); record.Read(i => item.GetString(i)); allRecords.Add(record); } } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); // 64 should fully cover the values in the dataset. var stringPool = new StringPool(64); using (var reader = new StreamReader(stream)) { var options = new CsvDataReaderOptions { HasHeaders = false, BufferSize = 0x10000, StringFactory = stringPool.GetString, }; var csvReader = CsvDataReader.Create(reader, options); while (csvReader.Read()) { var record = activate(); record.Read(i => csvReader.GetString(i)); allRecords.Add(record); } } return(allRecords); }
public Bootstrapper() { CreateInversionOfControlContainer(); Container.Install(new DataFactoryInstaller(), new CqrsInstaller()); ActivatorFactory.Resolve <NancyBootstrapper>(Container); CheckForPotentiallyMisconfiguredComponents(Container); }
public static InstanceFactory GetFactory(Type type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } if (!_factories.TryGetValue(type, out var factory)) { if (type.IsValueType) { var factoryTypeDefinition = typeof(StructFactory <>); var factoryType = factoryTypeDefinition.MakeGenericType(type); factory = (InstanceFactory)Activator.CreateInstance(factoryType); } else { factory = new ActivatorFactory(type); } _factories.Add(type, factory); } return(factory); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); string text; using (var reader = new StreamReader(stream)) { text = reader.ReadToEnd(); } if (!string.IsNullOrEmpty(text)) { var doc = ComLib.CsvParse.Csv.LoadText(text, false); foreach (var row in doc.Parse()) { var record = activate(); record.Read(i => row[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); // This only works for data with exactly 25 columns. // You must either provide the column types, or the types will be // guessed. Can't allow guessing, because the round-trip back to string doesn't preserve the exact text. // Must know the number of columns to provide the schema, so this isn't general-purpose for any <T>. DataFrame frame; try { frame = DataFrame.LoadCsv(stream, header: false, guessRows: 0, dataTypes: types); } catch (FormatException e) { if (e.Message == "Empty file") { return(allRecords); } throw; } foreach (var row in frame.Rows) { var record = activate(); record.Read(i => row[i].ToString()); allRecords.Add(record); } return(allRecords); }
/// <summary> /// GameOnOnGameLoad - Load Every Plugin/Addon /// </summary> /// <param name="args"></param> private static void GameOnOnGameLoad(EventArgs args) { #region Subscriptions Game.PrintChat( "<font color='#0993F9'>[SurvivorSeries AIO]</font> <font color='#FF8800'>Successfully Loaded.</font>"); Game.PrintChat("<font color='#b756c5'>[SurvivorSeries] NEWS: </font>" + SSNews); #endregion RootMenu = new RootMenu("SurvivorSeries AIO"); #region Utility Loads new VersionCheck.VersionCheck().UpdateCheck(); SpellCast.RootConfig = RootMenu; ChampionFactory.Load(ObjectManager.Player.ChampionName, RootMenu); ActivatorFactory.Create(ObjectManager.Player.ChampionName, RootMenu); AutoLevelerFactory.Create(ObjectManager.Player.ChampionName, RootMenu); #endregion }
public void ParameterlessConstructor_Activator() { var activator = ActivatorFactory.Build(typeof(Class)); for (var i = 0; i < trials; i++) { activator(); } }
/// <summary> /// Gets one instance of <typeparamref name="T"/> from data reader. /// </summary> /// <typeparam name="T">Type of an instance.</typeparam> /// <param name="reader">Source data reader.</param> /// <param name="ctorParamMappings">Column constructor parameter mappings.</param> /// <param name="propMappings">Property column mappings.</param> /// <param name="breakAfterFirst">true to break after the first read record; false to not. if false throws exception if more than one record.</param> /// <returns>A single instance read from reader or null.</returns> private static T GetInstance <T>(DbDataReader reader, ColumnConstructorParameterMappingCollection <T> ctorParamMappings, IEnumerable <PropertyColumnMapping> propMappings, bool breakAfterFirst) where T : class { T instance = null; if (reader.HasRows) { //// create activator to create instance with constructor var activator = ActivatorFactory.GetActivator <T>(ctorParamMappings.Constructor); Dictionary <string, int> propertyColumnLookupTable = null; //// if contains property mappings, get lookup table if (propMappings != null) { propertyColumnLookupTable = GetColumnIndexLookupTable(reader, propMappings.Select(x => x.ColumnName)); } /// mappings between ctor params and columns var ctorColumnLookupTable = GetColumnIndexLookupTable(reader, ctorParamMappings.Select(x => x.ColumnName)); bool first = true; while (reader.Read()) { if (!first) { throw new InvalidOperationException("Reader contains more than expected 1 record."); } object[] arguments = null; //// get constructor arguments if (ctorParamMappings.HasParameters) { arguments = GetConstructorParameters(reader, ctorColumnLookupTable, ctorParamMappings); } //// create instance instance = activator.Invoke(arguments); //// if contains property mappings, read values if (propMappings != null) { ReadData(instance, reader, propMappings, propertyColumnLookupTable); } if (breakAfterFirst) { break; } first = false; } } return(instance); }
public void CreateOnlyOne() { Resolver.GetConfigurator().Bind <IBoundAttribTest>().To <BoundAttribTest>().SetSingletonScope().DisableOverride(); ActivatorFactory.SetBoundActivator(); var actual1 = ActivatorFactory.Activator.Activate <IBoundTest>(typeof(BoundTestOnlyOneInstance)); var actual2 = ActivatorFactory.Activator.Activate <IBoundTest>(typeof(BoundTestOnlyOneInstance)); Assert.AreSame(actual1.BoundAttribute, actual2.BoundAttribute); ActivatorFactory.ResetActivator(); }
/// <summary> /// Gets all instances from data reader. /// </summary> /// <typeparam name="T">Type of an object read.</typeparam> /// <param name="reader">The source <see cref="DbDataReader"/> instance.</param> /// <param name="ctorMappings">The mappings between constructor arguments and columns.</param> /// <param name="propMappings">The mappings between properties and columns.</param> /// <returns>A enumerable of <typeparamref name="T"/> instances.</returns> public static IEnumerable <T> GetRecords <T>(this DbDataReader reader, ColumnConstructorParameterMappingCollection <T> ctorMappings, IEnumerable <PropertyColumnMapping> propMappings) where T : class { if (reader == null) { throw new ArgumentNullException("reader"); } if (ctorMappings == null) { throw new ArgumentNullException("ctorMappings"); } var result = new List <T>(); if (reader.HasRows) { var activator = ActivatorFactory.GetActivator <T>(ctorMappings.Constructor); Dictionary <string, int> propertyColumnLookupTable = null; //// if contains property mappings, get lookup table if (propMappings != null) { propertyColumnLookupTable = GetColumnIndexLookupTable(reader, propMappings.Select(x => x.ColumnName)); } /// mappings between ctor params and columns var ctorColumnLookupTable = GetColumnIndexLookupTable(reader, ctorMappings.Select(x => x.ColumnName)); while (reader.Read()) { object[] arguments = null; //// get constructor arguments if (ctorMappings.HasParameters) { arguments = GetConstructorParameters(reader, ctorColumnLookupTable, ctorMappings); } var instance = activator.Invoke(arguments); //// if contains property mappings, read values if (propMappings != null) { ReadData(instance, reader, propMappings, propertyColumnLookupTable); } result.Add(instance); } } return(result); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); var csvReader = Sky.Data.Csv.CsvReader.Create(stream); foreach (var row in csvReader) { var record = activate(); record.Read(i => row[i]); allRecords.Add(record); } return(allRecords); }
public void AddDetectorLayer(ActivatorType activatorType) { if (_layers.Any()) { _layers.Add(new DetectorLayer( _layers.Last().LayerIndex + 1, ActivatorFactory.Produce(activatorType), _layers.OfType <FilterLayer>().Last().GetOutputFilterMeta())); } else { _layers.Add(new DetectorLayer( 1, ActivatorFactory.Produce(activatorType), new FilterMeta(_networkConfig.InputDimenision, _networkConfig.InputChannels))); } }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var parser = new global::FastCsvParser.CsvReader(stream, Encoding.UTF8)) { while (parser.MoveNext()) { var record = activate(); record.Read(i => parser.Current[i]); allRecords.Add(record); } } return(allRecords); }
public void AddFullyConnectedLayer(int numberOfNeurons, ActivatorType activatorType, LearningRateAnnealerType lrat) { if (!_layers.OfType <FullyConnectedLayer>().Any()) { var last = _layers.OfType <FilterLayer>().Last(); var fm = last.GetOutputFilterMeta(); _layers.Add(new FlattenLayer(fm.Channels, fm.Size, last.LayerIndex + 1)); } _layers.Add(new FullyConnectedLayer( ActivatorFactory.Produce(activatorType), numberOfNeurons, _layers.Last().GetNumberOfOutputValues(), _layers.Last().LayerIndex + 1, _weightInitializer, lrat)); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) using (var txt = new global::TxtCsvHelper.Parser()) { while (reader.Peek() >= 0) { var strings = txt.MixedSplit(reader.ReadLine()).ToList(); var record = activate(); record.Read(i => strings[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); using (var reader = new StreamReader(stream)) { var cols = new FSharpOption <FSharpFunc <Tuple <int, string>, FSharpOption <Type> > >(new Types()); var table = Table.Load(reader, new ReadSettings(Delimiter.Comma, false, false, FSharpOption <int> .None, cols)); var allRecords = new List <T>(table.RowsCount); for (int r = 0; r < table.RowsCount; r++) { var item = activate(); item.Read(i => table[i].Rows.Item(r).AsString); allRecords.Add(item); } return(allRecords); } }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { var lines = EnumerateLines(reader); foreach (var row in lines.ParseCsv()) { var record = activate(); record.Read(i => row[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(reader, hasHeaders: false)) { while (csvReader.ReadNextRecord()) { var record = activate(); record.Read(i => csvReader[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new SoftCircuits.CsvParser.CsvReader(stream)) { string[] columns = null; while (reader.ReadRow(ref columns)) { var record = activate(); record.Read(i => columns[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { var csvReader = new NReco.Csv.CsvReader(reader); while (csvReader.Read()) { var record = activate(); record.Read(i => csvReader[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { // this library only allows loading from a file. // so write to a local file, use the length of the memory stream // to write to a different file based on the input data // this will be executed during the first "warmup" run var file = "data" + stream.Length + ".csv"; if (!File.Exists(file)) { using var data = File.Create(file); stream.CopyTo(data); } var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); var mlc = new MLContext(); using (var reader = new StreamReader(stream)) { var schema = new TextLoader.Column[25]; for (int i = 0; i < schema.Length; i++) { schema[i] = new TextLoader.Column("" + i, DataKind.String, i); } var opts = new TextLoader.Options() { HasHeader = false, Separators = new[] { ',' }, Columns = schema }; var l = mlc.Data.LoadFromTextFile(file, opts); var rc = l.GetRowCursor(l.Schema); var cols = l.Schema.ToArray(); var getters = cols.Select(c => rc.GetGetter <ReadOnlyMemory <char> >(c)).ToArray(); while (rc.MoveNext()) { var record = activate(); record.Read(i => { ReadOnlyMemory <char> s = null; getters[i](ref s); return(s.ToString()); }); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { var pieces = line.Split(','); var record = activate(); record.Read(i => pieces[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); var fields = new List <string>(); var builder = new StringBuilder(); using (var reader = new StreamReader(stream)) { while (CsvUtility.TryReadLine(reader, fields, builder)) { var record = activate(); record.Read(i => fields[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { var parser = new NotVisualBasic.FileIO.CsvTextFieldParser(reader); while (!parser.EndOfData) { var fields = parser.ReadFields(); var record = activate(); record.Read(i => fields[i]); allRecords.Add(record); } } return(allRecords); }
public App() { InitializeComponent(); AutoFacFactory autoFacFactory = new AutoFacFactory(); ActivatorFactory activatorFactory = new ActivatorFactory(); NavigationPageNavigator navigator = new NavigationPageNavigator(autoFacFactory, activatorFactory); Pages.MainPage mainPage = new Pages.MainPage() { }; NavigationPage navPage = new NavigationPage(mainPage); navigator.NavigationPage = navPage; ContainerBuilder containerBuilder = new ContainerBuilder(); containerBuilder.RegisterInstance <INavigator>(navigator).SingleInstance(); var thisAssembly = this.GetType().Assembly; navigator.RegisterPagesInAssembly(thisAssembly); RegisterViewModels(containerBuilder, thisAssembly); containerBuilder.RegisterType <Wisconsin511.WisconsinService>().As <Wisconsin511.IWisconsinService>().SingleInstance(); var container = containerBuilder.Build(Autofac.Builder.ContainerBuildOptions.None); autoFacFactory.Container = container; var vm = container.Resolve <Pages.MainPageViewModel>(); mainPage.BindingContext = vm; MainPage = mainPage; }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var parser = new TextFieldParser(stream)) { parser.Delimiters = new[] { "," }; while (!parser.EndOfData) { var fields = parser.ReadFields(); var record = activate(); record.Read(i => fields[i]); allRecords.Add(record); } } return(allRecords); }
public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new() { var activate = ActivatorFactory.Create <T>(_activationMethod); var allRecords = new List <T>(); using (var reader = new StreamReader(stream)) { var splitter = new global::FluentCsv.CsvParser.Splitters.Rfc4180DataSplitter(); string line; while ((line = reader.ReadLine()) != null) { var row = splitter.SplitColumns(line, ","); var record = activate(); record.Read(i => row[i]); allRecords.Add(record); } } return(allRecords); }
private IEnumerator loadLevelHelper(string levelPath) { Debug.Log("Loading..."); MapEditor.Get().destroy(); yield return null; // Wait for managers to be destroyed Map map = MapEditor.Get().map(); // Creates the new managers yield return null; // Wait for all managers Start() methods to be called if (!Directory.Exists(levelPath)) yield break; XmlDocument doc = new XmlDocument(); doc.Load(levelPath + "/gamedata.xml"); XmlElement root = doc.FirstChild as XmlElement; XmlElement tilesElement = null; XmlElement staticWallsElement = null; XmlElement doorsElement = null; XmlElement activatorsElement = null; foreach (XmlNode child in root) { XmlElement iterator = child as XmlElement; if (iterator == null) continue; switch (iterator.Name) { case "tiles": tilesElement = iterator; break; case "staticwalls": staticWallsElement = iterator; break; case "doors": doorsElement = iterator; break; case "activators": activatorsElement = iterator; break; } } // Create Tiles foreach (XmlNode _tile in tilesElement.ChildNodes) { XmlElement tileElement = _tile as XmlElement; if (tileElement == null) continue; string stringPosition = tileElement.GetAttribute("position"); Vec2Int tilePos = new Vec2Int(stringPosition); Tile tile = map.getTile(tilePos); QuadNodeProcessors.createTile(tile.node(), tile.position()); } // Create Static Walls StaticWallFactory staticWallFactory = new StaticWallFactory(); if (staticWallsElement != null) { foreach (XmlNode _staticWallElem in staticWallsElement.ChildNodes) { XmlElement staticWallElement = _staticWallElem as XmlElement; if (staticWallElement == null) continue; staticWallFactory.create(staticWallElement); } } // Create Static Walls to Place Doors Over if (doorsElement != null) { foreach (XmlNode _doorElem in doorsElement.ChildNodes) { XmlElement doorElement = _doorElem as XmlElement; if (doorElement == null) continue; staticWallFactory.create(doorElement); } } // Create Doors DoorFactory doorFactory = new DoorFactory(); if (doorsElement != null) { foreach (XmlNode _doorElem in doorsElement.ChildNodes) { XmlElement doorElement = _doorElem as XmlElement; if (doorElement == null) continue; doorFactory.create(doorElement); } } // Create Activators ActivatorFactory activatorFactory = new ActivatorFactory(doorFactory); if (activatorsElement != null) { foreach (XmlNode _activatorElem in activatorsElement.ChildNodes) { XmlElement activatorElement = _activatorElem as XmlElement; if (activatorElement == null) continue; activatorFactory.create(activatorElement); } } ObjectManipulator.Get().activate(); }