private void SetNoteHeader(SinacorNoteDto sn) { var noteHeaderRect = RectanglePositions.GetRectangle(NotePosition.NoteIdRectangle); try { int n = PdfDocument.GetNumberOfPages(); for (int i = 1; i <= n; i++) { PdfPage page = PdfDocument.GetPage(i); var header = ReaderExtensions.ExtractText(page, noteHeaderRect).FirstOrDefault(); var headerItens = header.Split(' '); sn.Id = headerItens[0]; //sn.PageNumber = int.Parse(headerItens[1]); sn.Date = DateTime.Parse(headerItens[2]); return; } throw new Exception("BrokerName not found"); } catch (Exception) { throw; } }
private DateTime GetNegotiationDate(PdfPage page) { var addressRect = SinacorNotePosition.GetRectangle(SinacorNotePosition.NegotiationDate); var ret = ReaderExtensions.ExtractText(page, addressRect).FirstOrDefault(); return(DateTime.ParseExact(ret, "dd/MM/yyyy", CultureInfo.InvariantCulture)); }
private string GetBrokerName() { var addressRect = RectanglePositions.GetRectangle(NotePosition.BrokerNameRectangle); PdfPage page = PdfDocument.GetPage(1); return(ReaderExtensions.ExtractText(page, addressRect).FirstOrDefault()); throw new Exception("BrokerName not found"); }
private List <OperationType> ProcessOperationTypeColumn(PdfPage page) { var addressRect = SinacorNotePosition .GetRectangle(SinacorNotePosition.NegotiationColumnsPosition.OperationTypeColumn); var operationTypeCells = ReaderExtensions.ExtractText(page, addressRect).First() .Split(Environment.NewLine.ToCharArray()).Select(x => x == "C" ? OperationType.Buy : OperationType.Sell); return(operationTypeCells.ToList()); }
private List <decimal> ProcessStockPriceColumn(PdfPage page) { var addressRect = SinacorNotePosition .GetRectangle(SinacorNotePosition.NegotiationColumnsPosition.StockPriceColumn); var stockAmountCells = ReaderExtensions.ExtractText(page, addressRect) .First().Split(Environment.NewLine.ToCharArray()).Select(x => decimal.Parse(x)); return(stockAmountCells.ToList()); }
private List <string> ProcessStockNameColumn(PdfPage page) { var addressRect = SinacorNotePosition .GetRectangle(SinacorNotePosition.NegotiationColumnsPosition.StockNameColumn); var ret = ReaderExtensions.ExtractText(page, addressRect) .First().Split(Environment.NewLine.ToCharArray()); //Removing stock's specifications like ordinárias (ON) ou preferenciais (PN), //this usually occurs after two consecultive spaces after stock's name var stockNameCells = ret.Select(X => X.Split(new string[] { " " }, StringSplitOptions.None)[0]).ToList(); return(stockNameCells); }
public decimal GetTotalBuys() { var financialResume = RectanglePositions.GetRectangle(NotePosition.TotalBuys); try { var negotiations = new List <string>(); int n = PdfDocument.GetNumberOfPages(); for (int i = 1; i <= n; i++) { PdfPage page = PdfDocument.GetPage(i); var text = ReaderExtensions.ExtractText(page, financialResume).FirstOrDefault(); var sells = text.Split(' '); return(decimal.Parse(sells[3])); } throw new Exception("TotalBuys not found"); } catch (Exception) { throw new Exception("Error while parsing buys"); } }
public void Should_Deserialize_Simple_via_manual_CSharp_code() { DeserializerDlg <Word> dlgWord = /*DeserializerDlg<Word>*/ (ref ReadOnlySequence <Byte> input, Word value, out Int64 bytesRead) => { SequenceReader <Byte> reader; String wordValue; reader = new SequenceReader <Byte>(input); if (ReaderExtensions.TryReadValue <String>( ref reader, out wordValue) == false) { bytesRead = reader.Consumed; return(false); } value.Value = wordValue; bytesRead = reader.Consumed; return(true); }; DeserializerDlg <Simple> dlgSimple = /*DeserializerDlg<Simple>*/ (ref ReadOnlySequence <Byte> input, Simple value, out Int64 bytesRead) => { SequenceReader <Byte> reader; Int32 identifier; Word[] content; Byte contentLength; reader = new SequenceReader <Byte>(input); if (ReaderExtensions.TryReadValue <Int32>( ref reader, out identifier) == false) { bytesRead = reader.Consumed; return(false); } if (ReaderExtensions.TryReadValue <Byte>( ref reader, out contentLength) == false) { bytesRead = reader.Consumed; return(false); } if (Serializer.TryDeserializeValues <Word>( ref reader, (Int32)contentLength, out content) == false) { bytesRead = reader.Consumed; return(false); } value.Identifier = identifier; value.Sentence = content; bytesRead = reader.Consumed; return(true); }; Serializer.Setup(dlgWord); Serializer.Setup(dlgSimple); RunDeserializer(); }
/// <summary> /// This is our async callback, used to accept TCP clients. The code is quite a ride! /// </summary> /// <param name="ar"></param> private async void EndAccept(IAsyncResult ar) { var listener = (TcpListener)ar.AsyncState; if (listener == null) { return; } if (Running) { listener.BeginAcceptTcpClient(EndAccept, listener); } try { var client = listener.EndAcceptTcpClient(ar); var address = (client.Client.RemoteEndPoint as IPEndPoint).Address.ToString(); if (QEDetector.IsAttacking(((IPEndPoint)(client.Client.RemoteEndPoint)).Address)) { if (!AttackerAddresses.Contains(address)) { ApiServer.Push( $"Under denial of service attack from: {address}! The address has been booted from accessing the HTTP server, for 5 minutes. Please take action!", "-HIGHEST PRIORITY/CRITICAL-", Structures.MessageFlag.ConsoleLogMessage); AttackerAddresses.Add(address); } return; } var ns = SelectProtocol(client); using (var reader = new StreamReader(ns)) { var strData = await ReaderExtensions.ReadLineSizedBuffered(reader, ReadSize).ConfigureAwait(false); if (strData == null) { return; } var startPos = 0; if (strData.Substring(0, 3) != "GET") { //only GET is allowed. await WriteDocument(DocumentTypeNotSupported, "text/html", ns, status : StatusCodes.NotImplemented501).ConfigureAwait(false); await ns.DisposeAsync().ConfigureAwait(false); client.Dispose(); return; } // Extract the request. startPos = strData.IndexOf("HTTP", 1, StringComparison.InvariantCultureIgnoreCase); var version = strData.Substring(startPos, 8); var request = strData.Substring(0, startPos - 1); request = request.Replace("\\", "/"); if ((request.IndexOf(".", StringComparison.InvariantCultureIgnoreCase) < 1) && (!request.EndsWith("/"))) { request += "/"; } startPos = request.LastIndexOf("/", StringComparison.CurrentCultureIgnoreCase) + 1; var file = request.Substring(startPos); var directory = request.Substring(request.IndexOf("/", StringComparison.InvariantCultureIgnoreCase), request.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase) - 3); await Process(directory, file, version, address, ns).ConfigureAwait(false); } await ns.DisposeAsync().ConfigureAwait(false); client.Dispose(); } catch (Exception ex) { if (!this.Running) { return; } MainClass.LogManager.LogError($"{ex.Message}", Shared.ErrorLocation.HttpServer); } }
private string GetBrokerName(PdfPage page) { var addressRect = SinacorNotePosition.GetRectangle(SinacorNotePosition.BrokerNameRectangle); return(ReaderExtensions.ExtractText(page, addressRect).FirstOrDefault()); }