public static ILogProviderFactory ParseFactoryPart(ILogProviderFactoryRegistry registry, string recentLogEntryString) { var m = MatchRecentLogEntryString(recentLogEntryString); string company = m.Groups["company"].Value; string name = m.Groups["name"].Value; return(registry.Find(company, name)); }
public RecentLogEntry(ILogProviderFactoryRegistry registry, string recentLogEntryString, string annotation, DateTime?useTimestampUtc) { var m = MatchRecentLogEntryString(recentLogEntryString); string company = m.Groups["company"].Value; string name = m.Groups["name"].Value; this.Factory = registry.Find(company, name); if (Factory == null) { throw new FormatNotRegistedException(company, name); } this.ConnectionParams = new ConnectionParams(m.Groups["connectStr"].Value); ConnectionParamsUtils.ValidateConnectionParams(ConnectionParams, Factory); this.Annotation = annotation; this.UseTimestampUtc = useTimestampUtc; }
bool ValidateInput() { string msg = null; if (view[ControlId.FormatNameEdit] == "") { msg = "Format name is mandatory"; view.SetFocus(ControlId.FormatNameEdit); } if (newFormatMode && registry.Find(view[ControlId.CompanyNameEdit], view[ControlId.FormatNameEdit]) != null) { msg = "Format with this company name/format name combination already exists"; view.SetFocus(ControlId.FormatNameEdit); } if (msg != null) { alerts.ShowPopup("Validation", msg, AlertFlags.Ok | AlertFlags.WarningIcon); return(false); } return(true); }
static async Task <DetectedFormat> DetectFormat( string fileName, string loggableName, Func <ILogProviderFactory, int> mruIndexGetter, ILogProviderFactoryRegistry factoriesRegistry, CancellationToken cancellation, IFormatAutodetectionProgress progress, ITraceSourceFactory traceSourceFactory, LogMedia.IFileSystem fileSystem) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException("fileName"); } if (mruIndexGetter == null) { throw new ArgumentNullException("mru"); } Func <Task <SimpleFileMedia> > createFileMedia = () => SimpleFileMedia.Create(fileSystem, SimpleFileMedia.CreateConnectionParamsFromFileName(fileName)); var log = traceSourceFactory.CreateTraceSource("App", string.Format("fdtc.{0}", Interlocked.Increment(ref lastPerfOp))); using (new Profiling.Operation(log, string.Format("format detection of {0}", loggableName))) using (ILogSourceThreadsInternal threads = new LogSourceThreads()) using (var localCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellation)) { var candidateFactories = GetOrderedListOfRelevantFactories(fileName, mruIndexGetter, factoriesRegistry).ToArray(); var ret = (await Task.WhenAll(candidateFactories.Select((factory, index) => (factory, index)).Select(async candidate => { var(factory, idx) = candidate; try { using (var perfOp = new Profiling.Operation(log, factory.ToString())) using (var fileMedia = await createFileMedia()) using (var reader = ((IMediaBasedReaderFactory)factory).CreateMessagesReader( new MediaBasedReaderParams(threads, fileMedia, MessagesReaderFlags.QuickFormatDetectionMode, parentLoggingPrefix: log.Prefix))) { if (progress != null) { progress.Trying(factory); } if (localCancellation.IsCancellationRequested) { perfOp.Milestone("cancelled"); return(fmt: (DetectedFormat)null, idx); } await reader.UpdateAvailableBounds(false); perfOp.Milestone("bounds detected"); var parser = await reader.CreateParser(new CreateParserParams(0, null, MessagesParserFlag.DisableMultithreading | MessagesParserFlag.DisableDejitter, MessagesParserDirection.Forward)); try { if (await parser.ReadNext() != null) { log.Info("Autodetected format of {0}: {1}", fileName, factory); localCancellation.Cancel(); return(fmt: new DetectedFormat(factory, ((IFileBasedLogProviderFactory)factory).CreateParams(fileName)), idx); } } finally { await parser.Dispose(); } } } catch (Exception e) { log.Error(e, "Failed to load '{0}' as {1}", fileName, factory); } return(fmt: (DetectedFormat)null, idx); }))).Where(x => x.fmt != null).OrderBy(x => x.idx).Select(x => x.fmt).FirstOrDefault(); if (ret != null) { return(ret); } using (var fileMedia = await createFileMedia()) { if (!await IOUtils.IsBinaryFile(fileMedia.DataStream)) { log.Info("File does not look binary"); var factory = factoriesRegistry.Find( PlainText.Factory.CompanyName, PlainText.Factory.FormatName) as IFileBasedLogProviderFactory; if (factory != null) { log.Info("Fall back to plaintext format"); return(new DetectedFormat(factory, factory.CreateParams(fileName))); } } } } return(null); }
static DetectedFormat DetectFormat( string fileName, string loggableName, Func <ILogProviderFactory, int> mruIndexGetter, ILogProviderFactoryRegistry factoriesRegistry, CancellationToken cancellation, IFormatAutodetectionProgress progress, ITempFilesManager tempFilesManager) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException("fileName"); } if (mruIndexGetter == null) { throw new ArgumentNullException("mru"); } Func <SimpleFileMedia> createFileMedia = () => new SimpleFileMedia(SimpleFileMedia.CreateConnectionParamsFromFileName(fileName)); var log = new LJTraceSource("App", string.Format("fdtc.{0}", Interlocked.Increment(ref lastPerfOp))); using (new Profiling.Operation(log, string.Format("format detection of {0}", loggableName))) using (ILogSourceThreads threads = new LogSourceThreads()) using (var localCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellation)) { var ret = GetOrderedListOfRelevantFactories(fileName, mruIndexGetter, factoriesRegistry).AsParallel().Select(factory => { try { using (var perfOp = new Profiling.Operation(log, factory.ToString())) using (var fileMedia = createFileMedia()) using (var reader = ((IMediaBasedReaderFactory)factory).CreateMessagesReader( new MediaBasedReaderParams(threads, fileMedia, tempFilesManager, MessagesReaderFlags.QuickFormatDetectionMode, parentLoggingPrefix: log.Prefix))) { if (progress != null) { progress.Trying(factory); } if (localCancellation.IsCancellationRequested) { perfOp.Milestone("cancelled"); return(null); } reader.UpdateAvailableBounds(false); perfOp.Milestone("bounds detected"); using (var parser = reader.CreateParser(new CreateParserParams(0, null, MessagesParserFlag.DisableMultithreading | MessagesParserFlag.DisableDejitter, MessagesParserDirection.Forward))) { if (parser.ReadNext() != null) { log.Info("Autodetected format of {0}: {1}", fileName, factory); localCancellation.Cancel(); return(new DetectedFormat(factory, ((IFileBasedLogProviderFactory)factory).CreateParams(fileName))); } } } } catch (Exception e) { log.Error(e, "Failed to load '{0}' as {1}", fileName, factory); } return(null); }).FirstOrDefault(x => x != null); if (ret != null) { return(ret); } using (var fileMedia = createFileMedia()) { if (!IOUtils.IsBinaryFile(fileMedia.DataStream)) { log.Info("File does not look binary"); var factory = factoriesRegistry.Find( PlainText.Factory.CompanyName, PlainText.Factory.FormatName) as IFileBasedLogProviderFactory; if (factory != null) { log.Info("Fall back to plaintext format"); return(new DetectedFormat(factory, factory.CreateParams(fileName))); } } } } return(null); }