static void Main(string[] args) { LogManager.Configure(new TraceLogger()); IComponentsConfig config = ConfigurationSettings.GetConfig("components") as IComponentsConfig; INamedServiceProvider srvPrv = new NReco.Winter.ServiceProvider(config); var zz = ConvertManager.ChangeType <IOperation <object> >(srvPrv.GetService("ZZ")); IOperation <IDictionary <string, object> > a = srvPrv.GetService("A") as IOperation <IDictionary <string, object> >; NameValueContext c = new NameValueContext(); Console.WriteLine("NReco 'hello world' sample. Try to type 'hello' or 'what is your name', 'die' for exit"); while (true) { Console.Write("you> "); c["msg"] = Console.ReadLine(); Console.Write("nreco> "); a.Execute(c); if (c.ContainsKey("state") && Convert.ToString(c["state"]) == "exit") { return; } } }
public ServiceProvider(IComponentsConfig config, bool countersEnabled) : base() { CreateValueFactory(); CountersEnabled = countersEnabled; Config = config; }
public void Extract(IComponentsConfig config, Store rdfStore) { foreach (IComponentInitInfo cInfo in config) { ExtractComponent(cInfo, rdfStore); } }
public void Run(IComponentsConfig config, string targetFile) { var rdfStore = new MemoryStore(); rdfStore.Add(new Statement(NS.CSO.classEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity)); rdfStore.Add(new Statement(NS.CSO.interfaceEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity)); var assemblyExtractor = new AssemblyMetadata(); assemblyExtractor.Extract(System.Web.HttpRuntime.BinDirectory, rdfStore); var configExtractor = new WinterMetadata(); var baseUri = String.IsNullOrEmpty(BaseUri) ? "file:///" + System.Web.HttpRuntime.AppDomainAppPath.Replace('\\', '/') + "#" : BaseUri; configExtractor.BaseNs = baseUri; configExtractor.Extract(config, rdfStore); using (RdfXmlWriter wr = new RdfXmlWriter(targetFile)) { wr.BaseUri = NS.NrMeta; wr.Namespaces.AddNamespace(NS.DotNet.Type, "type"); wr.Namespaces.AddNamespace(NS.DotNet.Property, "prop"); wr.Namespaces.AddNamespace(NS.NrMetaTerms, "nr"); wr.Write(rdfStore); } }
public void Run(IComponentsConfig config, string targetFile) { var rdfStore = new MemoryStore(); rdfStore.Add(new Statement(NS.CSO.classEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity)); rdfStore.Add(new Statement(NS.CSO.interfaceEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity)); var assemblyExtractor = new AssemblyMetadata(); assemblyExtractor.Extract( System.Web.HttpRuntime.BinDirectory, rdfStore); var configExtractor = new WinterMetadata(); var baseUri = String.IsNullOrEmpty(BaseUri) ? "file:///"+System.Web.HttpRuntime.AppDomainAppPath.Replace('\\','/')+"#" : BaseUri; configExtractor.BaseNs = baseUri; configExtractor.Extract(config, rdfStore); using (RdfXmlWriter wr = new RdfXmlWriter(targetFile)) { wr.BaseUri = NS.NrMeta; wr.Namespaces.AddNamespace(NS.DotNet.Type, "type"); wr.Namespaces.AddNamespace(NS.DotNet.Property, "prop"); wr.Namespaces.AddNamespace(NS.NrMetaTerms, "nr"); wr.Write(rdfStore); } }
public RunnerThread(IComponentsConfig cfg, string service, RunnerContext context, int iterations, int iterationDelay) { Cfg = cfg; ServiceName = service; Context = context; IterationsCount = iterations; IterationDelay = iterationDelay; ServicePrv = new NReco.Winter.ServiceProvider(Cfg); Thrd = new Thread(new ThreadStart(Execute)); RunnerThreadsMap.Add(Thrd, this); }
protected IModifyXmlDocumentHandler GetPreprocessor(string sectionName, IFileManager fileMgr) { // lets check for custom rule config processor configuration string ruleConfigSectionName = sectionName + ".ruleprocessor"; object ruleConfigObj = ConfigurationSettings.GetConfig(ruleConfigSectionName); if (ruleConfigObj != null) { if (!(ruleConfigObj is IComponentsConfig)) { throw new ConfigurationException(String.Format("Invalid configuration section '{0}': expected IComponentsConfig")); } if (log.IsEnabledFor(LogEvent.Debug)) { log.Write(LogEvent.Debug, new{ Action = "get rule processor", Msg = "found custom config", ConfigSectionName = ruleConfigSectionName }); } IComponentsConfig ruleConfig = (IComponentsConfig)ruleConfigObj; IServiceProvider srvPrv = new NReco.Winter.ServiceProvider(ruleConfig); XmlConfigRuleProcessor preprocessor = srvPrv.GetService(typeof(XmlConfigRuleProcessor)) as XmlConfigRuleProcessor; if (preprocessor != null) { preprocessor.FileManager = fileMgr; return(preprocessor); } else { log.Write(LogEvent.Warn, new{ Action = "get rule processor from custom config", Msg = "RuleConfigProcessor instance not found", ConfigSectionName = ruleConfigSectionName }); } } XmlConfigRuleProcessor defaultPreprocessor = new XmlConfigRuleProcessor(fileMgr); defaultPreprocessor.Rules = new IXmlConfigRule[] { new NReco.Transform.XslTransformXmlConfigRule() }; if (log.IsEnabledFor(LogEvent.Debug)) { log.Write(LogEvent.Debug, new{ Action = "get rule processor", Msg = "default rule processor is used" }); } return(defaultPreprocessor); }
static int Main(string[] args) { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); LogManager.Configure(new TraceLogger(true, false) { TimestampFormat = "{0:hh:mm:ss}" }); IDictionary <string, object> cmdParams; try { cmdParams = ExtractCmdParams(args, paramDescriptors); } catch (Exception ex) { log.Write(LogEvent.Fatal, ex.Message, ex); Console.Error.WriteLine(ex.Message); return(1); } if (!cmdParams.ContainsKey(BasePathParam)) { cmdParams[BasePathParam] = Environment.CurrentDirectory; log.Write(LogEvent.Info, "Base path is not defined, using current directory: {0}", cmdParams[BasePathParam]); } if (!cmdParams.ContainsKey(IsIncrementalParam)) { cmdParams[IsIncrementalParam] = false; log.Write(LogEvent.Info, "Incremental processing is not defined, by default: {0}.", cmdParams[IsIncrementalParam]); } if (!cmdParams.ContainsKey(IsWatchParam)) { cmdParams[IsWatchParam] = false; log.Write(LogEvent.Info, "Watch mode is not defined, by default: {0}.", cmdParams[IsWatchParam]); } string rootFolder = (string)cmdParams[BasePathParam]; RuleStatsTracker ruleStatsTracker = new RuleStatsTracker(); LocalFolderRuleProcessor folderRuleProcessor; MergeConfig mergeConfig = null; try { IComponentsConfig config = ConfigurationSettings.GetConfig("components") as IComponentsConfig; INamedServiceProvider srvPrv = new NReco.Winter.ServiceProvider(config); folderRuleProcessor = srvPrv.GetService("folderRuleProcessor") as LocalFolderRuleProcessor; if (folderRuleProcessor == null) { log.Write(LogEvent.Fatal, "Configuration error: missed or incorrect 'folderRuleProcessor' component"); return(2); } // read merge config if (cmdParams.ContainsKey(MergeParam)) { mergeConfig = new MergeConfig((string)cmdParams[MergeParam], rootFolder); } log.Write(LogEvent.Info, "Reading Folder: {0}", rootFolder); DateTime dt = DateTime.Now; LocalFileManager localFileMgr = new LocalFileManager(rootFolder); localFileMgr.Incremental = (bool)cmdParams[IsIncrementalParam]; localFileMgr.Reading += new FileManagerEventHandler(ruleStatsTracker.OnFileReading); localFileMgr.Writing += new FileManagerEventHandler(ruleStatsTracker.OnFileWriting); folderRuleProcessor.RuleExecuting += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting); folderRuleProcessor.RuleExecuted += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted); folderRuleProcessor.RuleFileReadStart += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuting); folderRuleProcessor.RuleFileReadEnd += new FileRuleEventHandler(ruleStatsTracker.OnRuleExecuted); folderRuleProcessor.FileManager = localFileMgr; localFileMgr.StartSession(); folderRuleProcessor.Execute(); localFileMgr.EndSession(); log.Write(LogEvent.Info, "Apply time: {0}", DateTime.Now.Subtract(dt).TotalSeconds.ToString()); } catch (Exception ex) { log.Write(LogEvent.Fatal, "Transformation failed: {0}", ex.ToString()); return(3); } if (Convert.ToBoolean(cmdParams[IsWatchParam])) { // some delay for avoid watching for just changed files Thread.Sleep(100); Watcher w = new Watcher(rootFolder, ruleStatsTracker, folderRuleProcessor, mergeConfig); log.Write(LogEvent.Info, "Watching for filesystem changes... (press 'q' for exit)"); w.Start(); while (true) { ConsoleKeyInfo keyInfo = System.Console.ReadKey(); if (keyInfo.KeyChar == 'q') { break; } } w.Stop(); } return(0); }
public ServiceProvider(IComponentsConfig config) : base() { CreateValueFactory(); Config = config; }