/// <summary> /// Initializes a new AudioManager class. /// </summary> /// <param name="audioInitializer">The AudioInitializer.</param> internal AudioManager(IAudioInitializer audioInitializer) { _audioEffectGroups = new List <AudioEffectGroup>(); var logger = LogManager.GetClassLogger(); if (audioInitializer == null) { logger.Warn("The specified audio initializer was null."); } else if (!audioInitializer.IsSupported) { logger.Warn("The specified AudioProvider is not supported."); } else { AudioInitializer = audioInitializer; _audioProvider = audioInitializer.Create(); _audioProvider.PlaybackChanged += PlaybackChanged; #if DEBUG var metadata = MetaDataReader.ReadMetaData(_audioProvider); if (metadata.ContainsKey("Name")) { logger.Info("Audiosystem initialized with {0}.", metadata["Name"]); } else { logger.Info("Audiosystem initialized with unknown."); } #endif } }
private String thePath; // Path of this file // ------------------------------------------------------------------------------------------ /// <summary> /// Constructor /// </summary> /// <param name="path">Path of the file to be parsed</param> public AudioFileReader(String path) { thePath = path; theFactory = AudioReaderFactory.GetInstance(); audioData = theFactory.GetDataReader(path); metaData = theFactory.GetMetaReader(path, audioData); }
public void Setup() { var dbContainer = MultiContainerMemoryDB.Create(); using (var db = dbContainer.NewDB(ConfigureIndexes)) { db.Store(new ClassWithoutFields()); db.Store(new ClassWithFields()); db.Store(new RecursiveClass()); db.Store(new WithBuiltInGeneric()); db.Store(new Generic <string>()); db.Store(new Generic <string, List <string> >()); db.Store(new Base()); db.Store(new SubClass()); db.Store(new ClassWithArrays()); db.Store(new SystemTypeArrays()); db.Store(new ClassWithAutoProperty()); db.Store(new ClassWithSelfUsingArray()); db.Store(new WithMixedGeneric()); db.Store(new ClassWithIndexedFields()); db.Store(new ClassWithHalfKnownGeneric()); db.Store(new NestedGenerics <string>()); db.Store(new NestedGenerics <string> .InnerGeneric <string, int>()); } database = dbContainer.NewDB(); this.generatedClassses = MetaDataReader.Read(database, TestUtils.TestTypeResolver()); }
[TestCase("http://www.google.com")] //not odata support public void GeneratePocoInvalidODataOrUrlTest(string url) { var code = ""; var metaDataReader = new MetaDataReader(url); Assert.Throws<WebException>(async () => code = await metaDataReader.GeneratePocoAsync()); Assert.IsEmpty(code); >>>>>>> develop }
public void FindClassesFromAssembly() { this.generatedClassses = MetaDataReader.Read(database); var classMeta = For <ClassWithoutFields>(); var type = classMeta.TryResolveType(TestUtils.FindNothingTypeResolver).Value; Assert.AreEqual(typeof(ClassWithoutFields), type); }
public void ShouldReturnDefaultValue() { var whales = "./resources/MetaDataWithDefault"; var metaDataReader = new MetaDataReader(); var metaData = metaDataReader.ReadMetaData(whales); var coreFileMetaData = new CoreFileMetaData(metaData.Core); var fieldMetaData = coreFileMetaData.Fields[Terms.datasetID]; }
public async void GeneratePocoWithValidAccountTes() { string url = "http://localhost/odata2/api/northwind"; var metaDataReader = new MetaDataReader(url, "user", "password"); var code = await metaDataReader.GeneratePocoAsync(); Assert.IsNotEmpty(code); }
public void ReadsIndexStateForKnownType() { this.generatedClassses = MetaDataReader.Read(database); var classMeta = For <ClassWithFields>(); var fieldInfo = classMeta.Fields; Assert.IsTrue(fieldInfo.Any(f => f.IndexingState == IndexingState.NotIndexed)); }
//expecteCount: count of classes /Entities public void Test2(string url, int expecteCount) { var gen = new MetaDataReader(url).Generate(new PocoSetting()); var product = gen["Product"]; var code = gen.ToString(); Assert.IsNotEmpty(code); StringAssert.Contains("public class Product", code); }
public void ShouldReturnDefaultMetaData() { var whales = "./resources/whales"; var metaDataReader = new MetaDataReader(); var metaData = metaDataReader.ReadMetaData(whales); Assert.Equal("whales.txt", metaData.Core.Files.FirstOrDefault()); Assert.Equal("\\n", metaData.Core.LinesTerminatedBy); }
public async Task <string> GenerateAsync(OdataConnectionString odataConnString) { MetaData = await MetaDataReader.LoadMetadataAsync(odataConnString); var gen = GenerateModel(MetaData); CodeText = gen.ToString(); return(CodeText); }
public void GeneratePocoWithInValidAccountTest() { var msg = "The remote server returned an error: (401) Unauthorized"; string url = "http://localhost/odata2/api/northwind"; MetaDataReader metaDataReader = new MetaDataReader(url, "user_invalid", "password"); var ex = Assert.Throws<WebException>(async () => await metaDataReader.GeneratePocoAsync()); StringAssert.Contains(msg, ex.Message); }
public async void GeneratePocoFromXmlFileV4Test() { string url = @"data\northwindV4.xml"; MetaDataReader metaDataReader = new MetaDataReader(url); metaDataReader.LoadMetaData(); Assert.IsNotNull(await metaDataReader.GeneratePocoAsync()); var count = metaDataReader.ClassList.Count; Assert.AreEqual(count, 11); }
private void RunTestWith(string dbName, Action <IEnumerable <ITypeDescription> > context) { TestUtils.CopyTestDB(dbName); using (var ctx = Db4oEmbedded.OpenFile(dbName)) { var metaData = MetaDataReader.Read(ctx, TypeLoader.Create(new string[0])); context(metaData); } }
//expecteCount: count of classes /Entities public void Test2(string url, int expecteCount) { var gen= new MetaDataReader(url).Generate(new PocoSetting() ); var product = gen["Product"]; var code = gen.ToString(); Assert.IsNotEmpty(code); StringAssert.Contains("public class Product", code); }
public void CanHandleSameTypeTwiceScenario() { var contex = MultiContainerMemoryDB.Create(); StoreAPerson(contex); StoreAPerson(contex); using (var db = contex.NewDB()) { this.generatedClassses = MetaDataReader.Read(db); Assert.IsTrue(generatedClassses.Any()); } }
public void DBWithoutAllTypesInList() { var reflector = new NetReflector(); var colorHolderType = reflector.ForClass(typeof(ColorHolder)); var dbMock = new Mock <IObjectContainer>(); dbMock.Setup(c => c.Ext().KnownClasses()).Returns(new[] { colorHolderType }); var classInfos = MetaDataReader.Read(dbMock.Object, TestUtils.TestTypeResolver()); Assert.IsTrue(1 < classInfos.Count()); }
public void ShouldDisplayANiceMessage_WhenFileIsInaccessible() { var moq = new Moq.Mock <IFileReader>(); moq .Setup(x => x.ReadFile(Moq.It.IsAny <string>())) .Throws <Exception>(); var metaDataReader = new MetaDataReader(moq.Object); metaDataReader.ReadVideoFile("video.mp4"); Assert.AreEqual(1, meaDataReader.Errors.Count); }
[TestCase("http://services.odata.org/V3/OData/OData.svc", 11)] //v3 //expectedCount: number of generated classes public void GeneratePocoFromHttpTest(string url, int expecteCount) { var metaDataReader = new MetaDataReader(url); <<<<<<< HEAD var code = metaDataReader.Generate(new PocoSetting()).ToString(); Assert.IsNotEmpty(code); StringAssert.Contains("public class Product", code); Assert.AreEqual(metaDataReader.Generate(new PocoSetting()).ClassList.Count, expecteCount); ======= var code = metaDataReader.GeneratePoco(); Assert.IsNotEmpty(code); StringAssert.Contains("public class Product", code); StringAssert.Contains("public class FeaturedProduct", code); Assert.AreEqual(metaDataReader.ClassList.Count, expecteCount); }
//public O2P Generate(string fname = "poco.cs") //{ // Generate(Setting); // File.WriteAllText(fname, CodeText); // return this; //} public O2P Generate(string fname = "meta.xml") //PocoSetting pocoSetting) { if (Url == null) { throw new NullReferenceException("Url is empty"); } _metaDataReader = string.IsNullOrEmpty(User) ? new MetaDataReader(Url) : new MetaDataReader(Url, User, Password); //Console.WriteLine("o2p generate key: {0}", Setting.AddKeyAttribute); var gen = _metaDataReader.Generate(Setting); CodeText = gen.ToString(); //CodeText = gen.GeneratePoco(); File.WriteAllText(fname, CodeText); //ClassList = gen.ClassDictionary.Select(kvp => kvp.Value).ToList(); ClassList = gen.ClassList; return(this); }
/// <summary> /// Loads a new instance of <see cref="CILModule"/> with a contents from <paramref name="stream"/>. /// Useful for multi-module assemblies when one doesn't want to load whole assembly. /// </summary> /// <param name="ctx">The current <see cref="CILReflectionContext"/>.</param> /// <param name="stream">The stream to load module from.</param> /// <param name="eArgs">The <see cref="EmittingArguments"/> during loading. After successful module load, the additional information about the module will be available in this object.</param> /// <returns>A new instance of <see cref="CILModule"/> form the contents of the <paramref name="stream"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="ctx"/> or <paramref name="stream"/> or <paramref name="eArgs"/> is <c>null</c>.</exception> /// <exception cref="BadImageFormatException">If the headers or metadata section of the stream has invalid values, or stream contents are otherwise malformed.</exception> /// <remarks> /// If the module returned by this method is main module, that is, its <c>Assembly</c> table has exactly one row, then the <see cref="EmittingArguments.ModuleAssemblyLoader"/> callback of <paramref name="eArgs"/> will never be used. /// Therefore it is ok to pass <c>null</c> as the callback to <paramref name="eArgs"/> if the caller is certain the module will always be the main module. /// However, when the module is not the main module, the callback will be used. /// If in that situation the callback is <c>null</c>, <see cref="InvalidOperationException"/> is thrown. /// The callback may be invoked only by accessing the <see cref="CILModule.Assembly"/> property of the returned <see cref="CILModule"/>. /// </remarks> public static CILModule LoadModule(this CILReflectionContext ctx, Stream stream, EmittingArguments eArgs) { ModuleReader mr = null; MetaDataReader md = null; var ownerAssembly = eArgs.ModuleAssemblyLoader; var result = LoadModule((CILReflectionContextImpl)ctx, stream, eArgs, mod => { CILAssemblyImpl ass; if (md.assembly.Length == 1) { ass = LoadAssembly((CILReflectionContextImpl)ctx, null, eArgs, mr, md, mod); } else { if (ownerAssembly == null) { throw new InvalidOperationException("The callback to get assembly of this module was not provided."); } ass = (CILAssemblyImpl)ownerAssembly(mod); var mods = ass.InternalModules; lock (mods.Lock) { if (!mods.Value.CQ.Contains(mod)) { mods.Value.Add(mod); } } } return(ass); }, out mr, out md); if (!eArgs.LazyLoad) { ForceLoadModule(result); } return(result); }
/// <summary> /// Gets the appropriate metadata reader for a given file / physical data reader /// </summary> /// <param name="path">Path of the file</param> /// <param name="theDataReader">AudioDataReader produced for this file</param> /// <returns>Metadata reader able to give metadata info for this file (or the dummy reader if the format is unknown)</returns> public MetaDataReader GetMetaReader(String path, AudioDataReader theDataReader) { MetaDataReader theMetaReader = null; // Step 1 : The physical reader may have already parsed the metadata for (int i = 0; i < TAG_TYPE_COUNT; i++) { if ((TAG_ID3V1 == tagPriority[i]) && (theDataReader.ID3v1.Exists)) { theMetaReader = theDataReader.ID3v1; break; } if ((TAG_ID3V2 == tagPriority[i]) && (theDataReader.ID3v2.Exists)) { theMetaReader = theDataReader.ID3v2; break; } if ((TAG_APE == tagPriority[i]) && (theDataReader.APEtag.Exists)) { theMetaReader = theDataReader.APEtag; break; } } // Step 2 : Nothing found in step 1 -> considerate specific tagging (data+meta file formats) if (null == theMetaReader) { //# improve something here /* * if (theDataReader is BinaryLogic.TOggVorbis) * { * BinaryLogic.TOggVorbis theVorbis = new BinaryLogic.TOggVorbis(); * theVorbis.ReadFromFile(path); * theMetaReader = theVorbis; * } * * if (theDataReader is BinaryLogic.TWMAfile) * { * BinaryLogic.TWMAfile theWMA = new BinaryLogic.TWMAfile(); * theWMA.ReadFromFile(path); * theMetaReader = theWMA; * } * * if (theDataReader is BinaryLogic.TFLACFile) * { * BinaryLogic.TFLACFile theFLAC = new BinaryLogic.TFLACFile(); * theFLAC.ReadFromFile(path); * theMetaReader = theFLAC; * } * * if (theDataReader is BinaryLogic.TPSFFile) * { * BinaryLogic.TPSFFile thePSF = new BinaryLogic.TPSFFile(); * thePSF.ReadFromFile(path); * theMetaReader = thePSF; * } * * if (theDataReader is BinaryLogic.TSPCFile) * { * BinaryLogic.TSPCFile theSPC = new BinaryLogic.TSPCFile(); * theSPC.ReadFromFile(path); * theMetaReader = theSPC; * }*/ if ((theDataReader is BinaryLogic.TOggVorbis) || (theDataReader is BinaryLogic.TWMAfile) || (theDataReader is BinaryLogic.TFLACFile) || (theDataReader is BinaryLogic.TPSFFile) || (theDataReader is BinaryLogic.TSPCFile)) { theMetaReader = (MetaDataReader)theDataReader; // Boorish but correct cast } } // Step 3 : default (no tagging at all - provides the dummy reader) if (null == theMetaReader) { theMetaReader = new BinaryLogic.DummyTag(); } return(theMetaReader); }
public static IMetaData Import(string _projectFilePath) { XmlDocument document = new XmlDocument(); document.Load(_projectFilePath); XmlElement root = document.DocumentElement; MetaDataManager.MetaData outputMetaData = new MetaDataManager.MetaData(); outputMetaData = MetaDataReader.LoadProjectAttributes(root, outputMetaData); // Read in variables IList <IVariable> variablesList = new List <IVariable>(); IList <IList <TimeStepDataAsset> > timestampLisList = new List <IList <TimeStepDataAsset> >(); if (root.ChildNodes.Count == 0) { Log.ThrowValueNotFoundException("MetaDataReader", root.Name + "is empty"); } foreach (XmlNode varNode in root.ChildNodes) { if (varNode.Name == Globals.VARIABLE_ELEMENT) { // Read name from variable node string varNodeName = varNode.Attributes[Globals.VARIABLE_NAME_ATTRIBUTE].Value; double varNodeMin = Utils.ReadAttribute(varNode, Globals.VARIABLE_MIN_ATTRIBUTE); double varNodeMax = Utils.ReadAttribute(varNode, Globals.VARIABLE_MAX_ATTRIBUTE); Debug.Log("Min and Max are " + varNodeMin + " and " + varNodeMax); List <TimeStepDataAsset> varTimestampList = new List <TimeStepDataAsset>(); if (varNodeName != null) { variablesList.Add(new MetaDataManager.Variable() { Name = varNodeName, Min = varNodeMin, Max = varNodeMax }); // Create a new list for timestamps timestampLisList.Add(varTimestampList); } else { Log.ThrowValueNotFoundException("MetaDataReader", Globals.VARIABLE_NAME_ATTRIBUTE); } if (varNode.ChildNodes.Count == 0) { Log.ThrowValueNotFoundException("MetaDataReader", varNode.Name); } foreach (XmlNode timestampNode in varNode.ChildNodes) { if (timestampNode.Name == Globals.TIME_STAMP_LIST_ELEMENT) { TimeStepDataAsset newTimestamp = MetaDataReader.ReadTimeStamp(timestampNode); // fill last list with timestamps varTimestampList.Add(newTimestamp); } } } } outputMetaData.Timestamps = timestampLisList; outputMetaData.Variables = variablesList; return(outputMetaData); }
public static IMetaData Load(string _projectFilePath) { return(MetaDataReader.Import(_projectFilePath)); }
private static CILAssemblyImpl LoadAssembly(CILReflectionContextImpl cctx, Stream stream, EmittingArguments eArgs, ModuleReader existingModuleReader, MetaDataReader existingMD, CILModule existingModule) { ArgumentValidator.ValidateNotNull("Reflection context", cctx); ArgumentValidator.ValidateNotNull("Emitting arguments", eArgs); var fileStreamOpener = eArgs.FileStreamOpener ?? THROW_INVALID_OPERATION; var moduleReader = existingModuleReader; var md = existingMD; var thisModule = existingModule; CILAssemblyImpl result = null; result = (CILAssemblyImpl)cctx.Cache.NewAssembly(id => new CILAssemblyImpl( cctx, id, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => { // Force evaluation of module types ( to get stuff populated in module reader) var dummy = thisModule.DefinedTypes; return(moduleReader.ReadAssemblyCustomAttributes(id)); }), () => { var aRow = md.assembly[0]; var aFlags = aRow.Item6; if (!aRow.Item7.IsNullOrEmpty()) { aFlags |= AssemblyFlags.PublicKey; } return(new CILAssemblyName(aRow.Item8, aRow.Item2, aRow.Item3, aRow.Item4, aRow.Item5, aRow.Item1, aFlags, aRow.Item7, aRow.Item9)); }, () => { var list = new List <CILModule>(); list.Add(thisModule); list.AddRange(md.file .Where(f => f.Item1.ContainsMetadata()) .Select(f => { using (var strm = fileStreamOpener(thisModule, f.Item2)) { ModuleReader mRdr; MetaDataReader mdRdr; return(LoadModule(cctx, strm, eArgs, mod => result, out mRdr, out mdRdr)); } })); return(cctx.CollectionsFactory.NewListProxy(list)); }, () => cctx.CollectionsFactory.NewDictionaryProxy(md.exportedType .Where(eRow => eRow.Item1.IsTypeForwarder() && eRow.Item5.table == Tables.AssemblyRef || eRow.Item5.table == Tables.ExportedType) .Select(eRow => moduleReader.ResolveExportedType(eRow.Item5, (TypeAttributes)eRow.Item1, eRow.Item4, eRow.Item3)) .GroupBy(tf => Tuple.Create(tf.Name, tf.Namespace)) .ToDictionary(g => g.Key, g => g.First())), () => thisModule )); if (thisModule == null) { thisModule = LoadModule(cctx, stream, eArgs, mod => result, out moduleReader, out md); } if (md.assembly.Length != 1) { throw new BadImageFormatException("Assembly table had " + (md.assembly.Length == 0 ? "too few" : "too many") + " rows, exactly one expected, but had " + md.assembly.Length + "."); } return(result); }
[TestCase("http://services.odata.org/V3/OData/OData.svc", 11)] //v3 //expectedCount: number of generated classes public void GeneratePocoFromHttpTest(string url, int expecteCount) { var metaDataReader = new MetaDataReader(url);
//public O2P Generate(string fname = "poco.cs") //{ // Generate(Setting); // File.WriteAllText(fname, CodeText); // return this; //} public O2P Generate(string fname = "meta.xml") //PocoSetting pocoSetting) { if (Url == null) throw new NullReferenceException("Url is empty"); _metaDataReader = string.IsNullOrEmpty(User) ? new MetaDataReader(Url) : new MetaDataReader(Url, User, Password); //Console.WriteLine("o2p generate key: {0}", Setting.AddKeyAttribute); var gen = _metaDataReader.Generate(Setting); CodeText = gen.ToString(); //CodeText = gen.GeneratePoco(); File.WriteAllText(fname, CodeText); //ClassList = gen.ClassDictionary.Select(kvp => kvp.Value).ToList(); ClassList = gen.ClassList; return this; }
public void GeneratePocoFromFileNotExistTest() { string code = ""; string url = "file_not_exist"; MetaDataReader metaDataReader = new MetaDataReader(url); Assert.Throws<FileNotFoundException>(async () => code = await metaDataReader.GeneratePocoAsync()); Assert.IsEmpty(code); }
private static CILModule LoadModule(CILReflectionContextImpl cctx, Stream stream, EmittingArguments eArgs, Func <CILModule, CILAssembly> modOwnerLoader, out ModuleReader moduleReaderOut, out MetaDataReader mdOut) { ArgumentValidator.ValidateNotNull("Reflection context", cctx); ArgumentValidator.ValidateNotNull("Stream", stream); ArgumentValidator.ValidateNotNull("Emitting arguments", eArgs); DLLFlags dllFlags; TargetRuntime targetRuntime; ModuleReader moduleReader; MetaDataReader md; IDictionary <String, ManifestResource> mResources; try { moduleReaderOut = new ModuleReader(cctx, stream, eArgs, out targetRuntime, out dllFlags, out mdOut, out mResources); moduleReader = moduleReaderOut; md = mdOut; eArgs.AssemblyRefs.Clear(); foreach (var aRef in md.assemblyRef) { eArgs.AssemblyRefs.Add(new CILAssemblyName(aRef.Item7, aRef.Item1, aRef.Item2, aRef.Item3, aRef.Item4, AssemblyHashAlgorithm.None, aRef.Item5, aRef.Item6, aRef.Item8)); } } catch (Exception x) { if (x is BadImageFormatException) { throw; } else { throw new BadImageFormatException("Exception when loading assembly (" + x + ").", x); } } var retVal = cctx.Cache.NewModule(mID => new CILModuleImpl( cctx, mID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => { // Force evaluation of module types ( to get stuff populated in module reader) var dummy = cctx.Cache.ResolveModuleID(mID).DefinedTypes; return(moduleReader.ReadModuleCustomAttributes(mID)); }), () => modOwnerLoader(cctx.Cache.ResolveModuleID(mID)), md.module[0].Item2, () => moduleReader.GetModuleInitializer(), () => moduleReader.CreateLogicalStructure(), () => moduleReader._mscorLibRef.Value, mResources )); moduleReader.SetThisModule(retVal); eArgs.SetCLREntryPoint(() => { CILMethod epMethod; if (moduleReader.HasEntryPoint()) { // Initialize logical structures first var dummy = retVal.DefinedTypes; // Get the CILMethod epMethod = moduleReader.GetEntryPoint(); } else { epMethod = null; } return(epMethod); }); return(retVal); }
public void GeneratePocoFromNotValidXmlFileTest() { string code = ""; string url = @"data\invalidxml.xml"; MetaDataReader metaDataReader = new MetaDataReader(url); Assert.Throws<XmlException>(async () => code = await metaDataReader.GeneratePocoAsync()); Assert.IsEmpty(code); }