IMediaBasedReaderFactory CreateReaderFactory() { var repo = new ResourcesFormatsRepository(System.Reflection.Assembly.GetExecutingAssembly()); ILogProviderFactoryRegistry reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, new TempFilesManager()); LogJoint.RegularGrammar.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); return(reg.Find("David Marshall", "OSWtop") as IMediaBasedReaderFactory); }
private void ParseAndVerifyLog(ExpectedLog expectedLog, string logContent, XmlDocument formatDocument) { var formatXml = formatDocument.OuterXml; var repo = new TestFormatsRepository(XDocument.Parse(formatXml).Root); ILogProviderFactoryRegistry reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, tempFilesManager); RegularGrammar.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); ReaderIntegrationTest.Test(reg.Find("Test", "Test") as IMediaBasedReaderFactory, logContent, expectedLog, Encoding.UTF8); }
IMediaBasedReaderFactory CreateFactory(string formatDescription) { var repo = new SingleEntryFormatsRepository(formatDescription); ITempFilesManager tempFilesManager = new TempFilesManager(); ILogProviderFactoryRegistry reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, tempFilesManager, new TraceSourceFactory()); JsonFormat.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); var factory = reg.Items.FirstOrDefault(); Assert.IsNotNull(factory); return(factory as IMediaBasedReaderFactory); }
public static IMediaBasedReaderFactory CreateFactoryFromAssemblyResource(Assembly asm, string companyName, string formatName) { var repo = new ResourcesFormatsRepository(asm); ILogProviderFactoryRegistry reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, tempFilesManager, new TraceSourceFactory()); LogJoint.RegularGrammar.UserDefinedFormatFactory.Register(formatsManager); LogJoint.XmlFormat.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); var factory = reg.Find(companyName, formatName); Assert.IsNotNull(factory); return(factory as IMediaBasedReaderFactory); }
public static IMediaBasedReaderFactory CreateFactoryFromAssemblyResource(Assembly asm, string companyName, string formatName) { var repo = new DirectoryFormatsRepository(Path.Combine(Path.GetDirectoryName(asm.Location), "formats")); ILogProviderFactoryRegistry reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, tempFilesManager, new TraceSourceFactory(), RegularExpressions.FCLRegexFactory.Instance, Mocks.SetupFieldsProcessorFactory()); LogJoint.RegularGrammar.UserDefinedFormatFactory.Register(formatsManager); LogJoint.XmlFormat.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); var factory = reg.Find(companyName, formatName); Assert.IsNotNull(factory); return(factory as IMediaBasedReaderFactory); }
static void Main(string[] argsArray) { CommandLineArgs args = new CommandLineArgs(argsArray); Console.WriteLine("Precompiling for platform \"{0}\"", args.Platform); var referencedAsms = new Dictionary <string, Assembly>(); foreach (string r in args.References) { Console.Write("Referencing assembly \"{0}\"", r); var asm = Assembly.ReflectionOnlyLoadFrom(r); referencedAsms.Add(asm.FullName, asm); Console.WriteLine(" OK"); } var repo = new FormatsRepository(); foreach (string f in args.InputFiles) { repo.AddFormatDescription(f); } var reg = new LogProviderFactoryRegistry(); IUserDefinedFormatsManager formatsManager = new UserDefinedFormatsManager(repo, reg, new TempFilesManager()); LogJoint.RegularGrammar.UserDefinedFormatFactory.Register(formatsManager); formatsManager.ReloadFactories(); XmlWriter output = null; if (args.Output != "") { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = Encoding.UTF8; Console.WriteLine("Writing output package to \"{0}\"", args.Output); output = XmlTextWriter.Create(args.Output, settings); output.WriteStartDocument(); output.WriteStartElement("formats"); } foreach (var factory in formatsManager.Items) { string factoryName = factory.CompanyName + "/" + factory.FormatName; Console.WriteLine("Handling \"{1}\" from \"{0}\"", factory.Location, factoryName); Console.Write(" "); IUserCodePrecompile precompileIntf = factory as IUserCodePrecompile; if (precompileIntf == null) { Console.WriteLine("{0} doesn't support precompilation", factoryName); continue; } var userCodeType = precompileIntf.CompileUserCodeToType(CompilationTargetFx.Silverlight, asmName => referencedAsms[asmName].Location); var userCodeAsm = userCodeType.Assembly; var asmFiles = userCodeAsm.GetFiles(true); if (asmFiles.Length != 1) { Console.WriteLine("Failed to precompile. More than one file in type's assembly"); continue; } var asmFile = asmFiles[0]; byte[] data = new byte[asmFile.Length]; asmFile.Position = 0; asmFile.Read(data, 0, data.Length); string asmAsString = Convert.ToBase64String(data); XmlDocument fmtDoc = new XmlDocument(); fmtDoc.Load(factory.Location); var fmtRoot = fmtDoc.SelectSingleNode("format"); if (fmtRoot == null) { Console.WriteLine("Wrong file format"); continue; } if (args.DumpAsms) { asmFile.Position = 0; using (var tmp = new FileStream(factory.FormatName + ".dll", FileMode.Create)) asmFile.CopyTo(tmp); } var userCodeNode = fmtRoot.SelectSingleNode("precompiled-user-code"); if (userCodeNode == null) { userCodeNode = fmtRoot.AppendChild(fmtDoc.CreateElement("precompiled-user-code")); } ((XmlElement)userCodeNode).SetAttribute("platform", args.Platform.ToString().ToLower()); ((XmlElement)userCodeNode).SetAttribute("type", userCodeType.Name); userCodeNode.InnerText = asmAsString; if (output == null) { fmtDoc.Save(factory.Location); } else { fmtDoc.Save(output); } Console.WriteLine("Precompiled ok"); } if (output != null) { output.WriteEndElement(); output.WriteEndDocument(); output.Close(); } Console.WriteLine("All done"); }