internal static string ExpandLine(string line) { var obj = new EntryParser(line).Parse(); var entry = obj as Статья; if (entry == null) { return(null); } string lemma; string symbol; int[] secAccPos; new EntryParser(line).ParseCommonPart(out lemma, out symbol, out secAccPos); bool failed = false; var forms = FormGenerator.GetAccentedFormsWithCorrectCase(line, delegate { failed = true; }); if (failed) { return(null); } return(lemma + "," + symbol + "," + string.Join(",", forms.Skip(1) .Select(form => Stress.StripStressMarks(form.AccentedForm)))); }
public static void Main (string[] args) { Configuration configuration = GetConfiguration (args); BlogLocator blogLocator = new BlogLocator(configuration.UserName, configuration.Password); EntryParser entryParser = new EntryParser(configuration.FileName); string blogPostUrl = blogLocator.FindBlogByTitle(configuration.BlogTitle).PostUri.Content; PostPublisher postPublisher = new PostPublisher(configuration.UserName, configuration.Password, blogPostUrl); ImportPosition importPosition = new ImportPosition(); Thread.Sleep(importPosition.TimeToNextImport); var blogEntries = entryParser.Entries.Skip(importPosition.BlogIndex).Take(50); try { foreach(var blogEntry in blogEntries) { postPublisher.Publish(blogEntry); importPosition++; } } catch(Exception e) { System.Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } importPosition.Save(); }
public async Task FunctionHandler(S3NotificationEvent input, ILambdaContext context) { var data = input?.GetFileData(); var retriever = new S3ObjectRetriever(data.Value.objectsKey, RegionEndpoint.GetBySystemName(data.Value.region)); using var connection = new DbConnection(); await connection.GetConnection().OpenAsync().ConfigureAwait(false); var logSaver = new LogSaver(connection.GetConnection()); string logId = await logSaver.GetAssociatedLogIdAsync(data.Value.objectsKey).ConfigureAwait(false); if (!String.IsNullOrEmpty(logId)) { var entries = retriever.GetObjectDataAsync().Select( logLine => EntryParser.ProcessLogLine(logLine)); await logSaver.SaveLogsAsync(logId, entries).ConfigureAwait(false); if (NotificationSender.IsNotificationNecessary(data.Value.objectsKey)) { await NotificationSender.TryPublishNotification(data.Value.objectsKey).ConfigureAwait(false); } } else { throw new Exception($"Log with given object name " + $"({data.Value.objectsKey}) has no associated record in database"); } }
public string Solve(string[] input) { var parser = new EntryParser(); var list = input.Select(parser.Parse); var cc = new ChecksumComputer(); var realRooms = list.Where(r => r.DeclaredChecksum == cc.Compute(r.EncryptedName)); return(realRooms.Sum(r => r.SectorId).ToString()); }
public string Solve(string[] input) { var parser = new EntryParser(); var list = input.Select(parser.Parse); var cc = new ChecksumComputer(); var realRooms = list.Where(r => r.DeclaredChecksum == cc.Compute(r.EncryptedName)); var shifter = new Shifter(); var decrypted = realRooms.Select(r => new { name = shifter.Shift(r.EncryptedName, r.SectorId), r.SectorId }); var northPole = decrypted.FirstOrDefault(x => x.name.Contains("northpole")); return(northPole?.SectorId.ToString() ?? "Not found"); }
public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: ocr-kata </path/to/file>"); } var filePath = args.Single(); var entries = EntryParser.Parse(filePath, 3); foreach (var entry in entries) { Console.WriteLine(Format(entry)); } }
public void TestProcessLogLineMatchResponseCode(string logLine, int expectedResponseCode) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedResponseCode, logEntry.ResponseCode); }
public void TestProcessLogLineMatchIP(string logLine, string expectedIP) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedIP, logEntry.ClientIp); }
public void TestProcessLogLineMatchRequestTime(string logLine, DateTime expectedRequestTime) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedRequestTime, logEntry.RequestTime); }
public void TestProcessLogLineMatchResource(string logLine, string expectedResource) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedResource, logEntry.Resource); }
public void TestProcessLogLineMatchMethod(string logLine, LogEntry.RequestType expectedMethod) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedMethod, logEntry.Method); }
public void UseCaseOneShouldHave11Entries() { var pathToUseCase = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../ExampleFiles/UseCase1.txt"); Assert.That(EntryParser.Parse(pathToUseCase, 3), Has.Count.EqualTo(11)); }
public static Entry First(string hashTagString) { var parser = new EntryParser(hashTagString); return(parser.Parse()); }
public void Initialize() { _entryParser = _mocker.CreateInstance <EntryParser>(); }
public void TestProcessLogLineMatchRawEntry(string logLine) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(logLine, logEntry.RawEntry); }
public void TestProcessLogLineMatchUserAgent(string logLine, string expectedUserAgent) { var logEntry = EntryParser.ProcessLogLine(logLine); Assert.Equal(expectedUserAgent, logEntry.UserAgent); }
//todo handle current line in file passing and updating public static Batch ParseStream(System.IO.StreamReader reader, out string messages, out uint linesRead, uint currentLine) { linesRead = 0; messages = ""; Batch batch = new Batch(); int recordType; if ((recordType = reader.Peek()) != -1) { if (recordType != ACHParser.BATCH_HEADER_RECORD_TYPE_ASCII_VALUE) { //consume line, message that not expected string notBatchHeader = reader.ReadLine(); if (notBatchHeader != null) { messages += "\nDid not receive batch header as expected: " + notBatchHeader; ++linesRead; } else { //TODO error message that its null } } else { //assume next line to consume is a batch header //TODO check null? string batchHeader = reader.ReadLine(); if (batchHeader != null) { ParseHeader(batchHeader, batch); ++linesRead; //TODO if batchheadermsg not null/ws then add to messages //if not 94 chars then error message } bool expectingEntryType = true;//if true, then expecting entry, else expecting the last entry's addenda //for testing just for the moment //while not a batch control or end of file, consume a line string devnull; while ((recordType = reader.Peek()) != -1 && recordType != ACHParser.BATCH_CONTROL_RECORD_TYPE_ASCII_VALUE && recordType != ACHParser.ACH_CONTROL_RECORD_TYPE_ASCII_VALUE) { //TODO more checks needed, must be an entry type, would be an error to get an ACH header here, or some random character //if not an entry record type then error message if (recordType == ACHParser.ENTRY_RECORD_TYPE_ASCII_VALUE) { if (!expectingEntryType) { //TODO log error that was expecting an addenda } //add entry (even if was expecting addenda) Entry entry = EntryParser.ParseEntry(reader.ReadLine()); //TODO if entry msgs not null/ws then log batch.Entries.Add(entry); ++linesRead; //if entry says it has an addenda then set expecting entry to false if (entry.AddendaRecord.Equals("1")) { expectingEntryType = false; } } else if (recordType == ACHParser.ADDENDA_RECORD_TYPE_ASCII_VALUE) { if (expectingEntryType) { //TODO log error that wasn't expecting addenda } Addenda addenda = AddendaParser.ParseAddenda(reader.ReadLine()); //TODO if addendamsgs not null/ws, log if (batch.Entries.Count <= 0) { //TODO log no entries to append this addenda } else { //TODO do a while addenda, can have many addenda for each entry ((Entry)batch.Entries[batch.Entries.Count - 1]).AddendaList.Add(addenda); } ++linesRead; expectingEntryType = true; } else { //TODO log error that wasn't entry or addenda inside a batch } /*batch.Entries.Add(reader.ReadLine()); * ++linesRead;*/ //if not 94 chars then error message } //TODO shoudl be batch control, check then get that, would be an error if -1 if (recordType != ACHParser.BATCH_CONTROL_RECORD_TYPE_ASCII_VALUE) { //check if peek to next record type is batch control as expected, or something else or end of file which are errors if (recordType == -1) { //TODO add to msg unected end of file } else { //TODO devnull = reader.ReadLine(); ++linesRead; } } else { string batchControl = reader.ReadLine(); //TODO if not 94 chars then error if (batchControl != null) { string batchMessages; ParseControl(batchControl, batch); //TODO if batchcontrolmsg not null/ws then add to msgs batchMessages = batch.Verify(); ++linesRead; } else { //TODO add to message that batch control was null } } } } else { //message that we got an unexpected emtpy file } return(batch); }