public bool TryMatchFormat(string fileName, byte[] header, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { var formats = _repository.Formats.OfType <SerilogFileFormat>(); foreach (var serilogFormat in formats) { var parser = serilogFormat.Parser; using (var memoryStream = new MemoryStream(header)) using (var reader = new StreamReader(memoryStream, serilogFormat.Encoding ?? encoding)) { if (TryParseFormat(reader, parser)) { format = serilogFormat; certainty = Certainty.Sure; return(true); } } } certainty = header.Length >= 512 ? Certainty.Sure : Certainty.Uncertain; format = null; return(false); }
internal ChangeType SetNumbers(IEnumerable <int> numbers, Certainty certainty = defaultCertaintySetNumbers) { ChangeType returnValue = ChangeType.None; if (numbers.Count() > 1) { if (CertaintyIsOfSingleInstance(certainty)) { throw new Exception(exceptionNotMoreThenOneOfCertainty + certainty.ToString()); } } foreach (int number in numbers) { ChangeType newChange = SetNumber(number, certainty, false); if (newChange != ChangeType.None) { if (newChange != returnValue) { returnValue = newChange; } } } bool figuredOut = TryFigureOut(); if (figuredOut == true) { return(ChangeType.FiguredOut); } return(returnValue); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(r => r.Load()).Returns(_Configuration); _Plotter = Factory.Singleton.Resolve <IPolarPlotter>(); _SanityChecker = TestUtilities.CreateMockImplementation <IAircraftSanityChecker>(); _CheckAltitudeResult = Certainty.ProbablyRight; _SanityChecker.Setup(r => r.CheckAltitude(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>())).Returns((int id, DateTime date, int alt) => { return(_CheckAltitudeResult); }); _SanityChecker.Setup(r => r.FirstGoodAltitude(It.IsAny <int>())).Returns(() => { throw new InvalidOperationException(); }); _CheckPositionResult = Certainty.ProbablyRight; _SanityChecker.Setup(r => r.CheckPosition(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <double>(), It.IsAny <double>())).Returns((int id, DateTime date, double lat, double lng) => { return(_CheckPositionResult); }); _SanityChecker.Setup(r => r.FirstGoodPosition(It.IsAny <int>())).Returns(() => { throw new InvalidOperationException(); }); _SavedPolarPlot = new SavedPolarPlot(); }
public bool TryMatchFormat(string fileName, byte[] header, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { try { if (_inner == null) { format = null; certainty = Certainty.Sure; return(false); } return(_inner.TryMatchFormat(fileName, header, encoding, out format, out certainty)); } catch (Exception e) { Log.ErrorFormat("Caught unexpected exception: {0}", e); format = null; certainty = Certainty.Uncertain; return(false); } }
internal ChangeType SetNumber(int number, Certainty certainty = defaultCertaintySetNumber, bool test = true) { ChangeType returnValue = ChangeType.None; foreach (Option option in Options) { if (option.Number == number) { if (option.Certainty == certainty) { return(ChangeType.None); } else if (CertaintyIsOfSingleInstance(certainty)) { returnValue = ChangeType.FiguredOut; } else { returnValue = ChangeType.Excluding; } if (certainty == Certainty.CanNotBe) { if (option.Certainty == Certainty.CanBe || option.Certainty == Certainty.CanNotBeOnGuess) { option.Certainty = certainty; } } else if (certainty == Certainty.CanNotBeOnGuess) { if (option.Certainty == Certainty.CanBe) { option.Certainty = certainty; } } else { option.Certainty = certainty; } } else if (certainty == Certainty.Set || certainty == Certainty.FiguredOut) { option.Certainty = Certainty.CanNotBe; } else if ((certainty == Certainty.FiguredOutOnGuess || certainty == Certainty.Guess) && option.Certainty == Certainty.CanBe) { option.Certainty = Certainty.CanNotBeOnGuess; } } if (test == true || CertaintyIsOfSingleInstance(certainty)) { bool figuredOut = TryFigureOut(); if (figuredOut == true) { return(ChangeType.FiguredOut); } } return(returnValue); }
internal void RemoveAllBut(Certainty certainty = Certainty.Set) { foreach (Option option in Options) { if (option.Certainty != certainty) { option.Certainty = Certainty.CanBe; } } }
public void PolarPlotter_AddCoordinate_Ignores_CertainlyWrong_Positions() { _CheckPositionResult = Certainty.CertainlyWrong; StandardInitialise(); _Plotter.AddCoordinate(1, 12, 52.231, 1.234); var slices = _Plotter.TakeSnapshot(); Assert.AreEqual(0, slices.Count(r => r.PolarPlots.Count(i => i.Value.Distance != 0) > 0)); }
public void PolarPlotter_AddCoordinate_Ignores_Uncertain_Altitudes() { _CheckAltitudeResult = Certainty.Uncertain; StandardInitialise(); _Plotter.AddCoordinate(1, 12, 52.231, 1.234); var slices = _Plotter.TakeSnapshot(); Assert.AreEqual(0, slices.Count(r => r.PolarPlots.Count(i => i.Value.Distance != 0) > 0)); }
private bool CertaintyIsOfSingleInstance(Certainty certainty) { if (certainty == Certainty.Set || certainty == Certainty.FiguredOut || certainty == Certainty.FiguredOutOnGuess || certainty == Certainty.Guess) { return(true); } else { return(false); } }
public void PolarPlotter_AddCoordinate_Allows_ProbablyRight_Positions() { _CheckPositionResult = Certainty.ProbablyRight; StandardInitialise(); _Plotter.AddCoordinate(1, 12, 52.231, 1.234); var slices = _Plotter.TakeSnapshot(); var plot = slices.Single(r => r.AltitudeLower == 10 && r.AltitudeHigher == 19).PolarPlots.Values.Single(r => r.Distance != 0); Assert.AreEqual(12, plot.Altitude); }
public bool TryMatchFormat(string fileName, byte[] header, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { Header = header; Encoding = encoding; NumInvocations++; format = Format; certainty = Certainty; return(format != null); }
/// <summary> /// Compares another source citation to the current instance. /// </summary> /// <param name="citation">A citation.</param> /// <returns> /// <0 if this citation precedes the other in the sort order; /// >0 if the other citation precedes this one; /// 0 if the citations are equal /// </returns> public int CompareTo(GedcomSourceCitation citation) { if (citation == null) { return(1); } var compare = Certainty.CompareTo(citation.Certainty); if (compare != 0) { return(compare); } compare = GedcomGenericComparer.SafeCompareOrder(Date, citation.Date); if (compare != 0) { return(compare); } compare = GedcomGenericComparer.SafeCompareOrder(EventType, citation.EventType); if (compare != 0) { return(compare); } compare = GedcomGenericComparer.SafeCompareOrder(Page, citation.Page); if (compare != 0) { return(compare); } compare = GedcomGenericComparer.SafeCompareOrder(Role, citation.Role); if (compare != 0) { return(compare); } compare = GedcomGenericComparer.SafeCompareOrder(Text, citation.Text); if (compare != 0) { return(compare); } return(compare); }
private bool TryFigureOut() { if (GetNumber() == null) { int? number = null; bool guess = false; foreach (Option option in Options) { if (option.Certainty == Certainty.CanBe) { if (number == null) { number = option.Number; } else { return(false); } } if (guess == false) { if (option.Certainty == Certainty.CanNotBeOnGuess) { guess = true; } } } if (number != null) { Certainty certainty = Certainty.FiguredOut; if (guess == true) { certainty = Certainty.FiguredOutOnGuess; } SetNumber((int)number, certainty, false); return(true); } } return(false); }
public bool TryMatchFormat(string fileName, byte[] data, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { // In this example we are able to detect our log format by the custom extension // 'mylog' as well as by a file-name pattern "log_*.logv2". If the filename // matches either of these, then we assume that we're dealing with the desired // format and forward its descriptor to Tailviewer. // Other plugins may then compare log file format descriptors and thereby choose // which formats they want to be used for (and which ones they do not). var extension = Path.GetExtension(fileName); if (extension == "mylog") { format = MyCustomFormat; certainty = Certainty.Sure; return(true); } var name = Path.GetFileName(fileName); if (Regex.Match(name, "log_*\\.logv2").Success) { format = MyCustomFormat; certainty = Certainty.Sure; return(true); } // Since the filename doesn't match our expectations, we can say with 100% certainty // that we don't know what type of log file this is. // This causes Tailviewer to no longer invoke this matcher for that file anymore, even // if the file changes / is appended to / etc... format = null; certainty = Certainty.Sure; return(false); }
public bool TryMatchFormat(string fileName, byte[] header, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { var pluginLoader = _services.Retrieve <IPluginLoader>(); var matchers = pluginLoader.LoadAllOfType <ILogFileFormatMatcherPlugin>() .Select(x => new NoThrowLogFileFormatMatcher(x, _services)) .ToList(); foreach (var matcher in matchers) { if (matcher.TryMatchFormat(fileName, header, encoding, out format, out certainty)) { return(true); } } format = null; certainty = Certainty.None; return(false); }
private ILogFileFormat TryFindFormatOf(string fileName, Stream stream, Encoding encoding, out Certainty certainty) { stream.Position = 0; const int maxHeaderLength = 512; var length = Math.Min(maxHeaderLength, stream.Length); var header = new byte[length]; stream.Read(header, offset: 0, header.Length); _formatMatcher.TryMatchFormat(fileName, header, encoding, out var format, out certainty); if (format != null) { return(format); } certainty = header.Length >= maxHeaderLength ? Certainty.Sure : Certainty.Uncertain; return(LogFileFormats.GenericText); }
public SimpleLogFileFormatMatcher(ILogFileFormat format, Certainty certainty) { Format = format; Certainty = certainty; }
public static string ToSerialString(this Certainty value) => value switch {
public ApproxDateTime() { _timeCertainty = Certainty.Unspecified; this.CenturyCertainty = Certainty.Unspecified; this.DayCertainty = Certainty.Unspecified; this.DecadeCertainty = Certainty.Unspecified; this.MonthCertainty = Certainty.Unspecified; this.YearNumCertainty = Certainty.Unspecified; }
public override ErrorList Validate() { var result = new ErrorList(); result.AddRange(base.Validate()); if (Subject != null) { result.AddRange(Subject.Validate()); } if (Encounter != null) { result.AddRange(Encounter.Validate()); } if (Asserter != null) { result.AddRange(Asserter.Validate()); } if (DateAssertedElement != null) { result.AddRange(DateAssertedElement.Validate()); } if (Code != null) { result.AddRange(Code.Validate()); } if (Category != null) { result.AddRange(Category.Validate()); } if (StatusElement != null) { result.AddRange(StatusElement.Validate()); } if (Certainty != null) { result.AddRange(Certainty.Validate()); } if (Severity != null) { result.AddRange(Severity.Validate()); } if (Onset != null) { result.AddRange(Onset.Validate()); } if (Abatement != null) { result.AddRange(Abatement.Validate()); } if (Stage != null) { result.AddRange(Stage.Validate()); } if (Evidence != null) { Evidence.ForEach(elem => result.AddRange(elem.Validate())); } if (Location != null) { Location.ForEach(elem => result.AddRange(elem.Validate())); } if (RelatedItem != null) { RelatedItem.ForEach(elem => result.AddRange(elem.Validate())); } if (NotesElement != null) { result.AddRange(NotesElement.Validate()); } return(result); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as Condition; if (dest != null) { base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (Encounter != null) { dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy(); } if (Asserter != null) { dest.Asserter = (Hl7.Fhir.Model.ResourceReference)Asserter.DeepCopy(); } if (DateAssertedElement != null) { dest.DateAssertedElement = (Hl7.Fhir.Model.Date)DateAssertedElement.DeepCopy(); } if (Code != null) { dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy(); } if (Category != null) { dest.Category = (Hl7.Fhir.Model.CodeableConcept)Category.DeepCopy(); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.Condition.ConditionStatus>)StatusElement.DeepCopy(); } if (Certainty != null) { dest.Certainty = (Hl7.Fhir.Model.CodeableConcept)Certainty.DeepCopy(); } if (Severity != null) { dest.Severity = (Hl7.Fhir.Model.CodeableConcept)Severity.DeepCopy(); } if (Onset != null) { dest.Onset = (Hl7.Fhir.Model.Element)Onset.DeepCopy(); } if (Abatement != null) { dest.Abatement = (Hl7.Fhir.Model.Element)Abatement.DeepCopy(); } if (Stage != null) { dest.Stage = (Hl7.Fhir.Model.Condition.ConditionStageComponent)Stage.DeepCopy(); } if (Evidence != null) { dest.Evidence = new List <Hl7.Fhir.Model.Condition.ConditionEvidenceComponent>(Evidence.DeepCopy()); } if (Location != null) { dest.Location = new List <Hl7.Fhir.Model.Condition.ConditionLocationComponent>(Location.DeepCopy()); } if (RelatedItem != null) { dest.RelatedItem = new List <Hl7.Fhir.Model.Condition.ConditionRelatedItemComponent>(RelatedItem.DeepCopy()); } if (NotesElement != null) { dest.NotesElement = (Hl7.Fhir.Model.FhirString)NotesElement.DeepCopy(); } return(dest); } else { throw new ArgumentException("Can only copy to an object of the same type", "other"); } }
public void SetCertainty(Certainty value) { certainty = value; }