public IActionResult GetAllTrips() { var query = new GetAllTripsQuery(); var queryResult = QueryDispatcher.Execute <GetAllTripsQuery, GetAllTripsQueryResult>(query); return(Ok(queryResult.Trips)); }
public IActionResult GetAll() { var query = new GetAllLocationsQuery(); var queryResult = QueryDispatcher.Execute <GetAllLocationsQuery, GetAllLocationsQueryResult> (query); return(Ok(queryResult.Locations)); }
public void Start() { //Get old transactions var transactions = GetOpenPositions(Stocks); var positions = QueryDispatcher.Execute(new OpenPositionsAllQuery()); foreach (var pos in positions) { var oldOpenTrans = transactions.Values.Where(t => t.Stock.Id == pos.ProductId).ToList(); if (!oldOpenTrans.Any()) { LoggingService.Warn($"Unknown position of {pos.Shares}x{pos.PricePerShare}"); } else if (pos.Shares != oldOpenTrans.Sum(t => t.Shares)) { LoggingService.Warn($"Diffent amount of shares for {oldOpenTrans.FirstOrDefault().Stock.Name} {pos.Shares}x{pos.PricePerShare}"); } else { LoggingService.Info($"Open position ok for {oldOpenTrans.FirstOrDefault().Stock.Name} ({pos.Shares}x{pos.PricePerShare}={pos.PositionSize})"); } } }
public void Start() { //Import LoggingService.Info("Download Quotations "); var stocks = QueryDispatcher.Execute(new StockAllQuery()); foreach (var stock in stocks) { var quotationsBefore = QueryDispatcher.Execute(new StockQuotationsCountByIdQuery(stock.Id)); var quotations = new QuotationServiceClient(QueryDispatcher, new StockQuoteExternalService(LoggingService)).Get(stock.Id).ToList(); if (!quotations.Any()) { LoggingService.Info($"No quotations for stock {stock.Name} imported (Qty Before: {quotationsBefore})"); continue; } var cmd = new StockQuotationsAddOrChangeCommand( stock.Id, stock.OriginalVersion, quotations); CommandDispatcher.Execute(cmd); //Statistics var existentQuotations = QueryDispatcher.Execute(new StockQuotationsByIdQuery(stock.Id)).Count(); var diff = existentQuotations - quotationsBefore; LoggingService.Info($"{diff} Quotation(s) for stock {stock.Name} imported (Qty After: {existentQuotations},Qty Before: {quotationsBefore})"); } }
public IActionResult Index(Guid employeeId) { EnsureArg.IsNotEmpty(employeeId); var query = new GetEmployeeByIdQuery(employeeId); var queryResult = QueryDispatcher.Execute <GetEmployeeByIdQuery, GetEmployeeByIdQueryResult>(query); return(Ok(queryResult.Employee)); }
public IActionResult Index(Guid tripId) { EnsureArg.IsNotEmpty(tripId); var query = new GetTripByIdQuery(tripId); var queryResult = QueryDispatcher.Execute <GetTripByIdQuery, GetTripByIdQueryResult>(query); return(Ok(queryResult.Trip)); }
public IActionResult Index(Guid locationId) { EnsureArg.IsNotEmpty(locationId); var query = new GetLocationByIdQuery(locationId); var queryResult = QueryDispatcher.Execute <GetLocationByIdQuery, GetLocationByIdQueryResult>(query); return(Ok(queryResult.Location)); }
public IActionResult GetStudent(Guid id_student) { EnsureArg.IsNotEmpty(id_student); var query = new GetStudentByIdQuery(id_student); var queryResult = QueryDispatcher.Execute <GetStudentByIdQuery, GetStudentByIdQueryResult>(query); return(Ok(queryResult.Student)); }
public void DispatchReal() { var handler = Substitute.For<IExecuteQuery<FakeQuery, string>>(); var registrar = new ContainerRegistrar(); registrar.RegisterInstance(handler); var dispatcher = new QueryDispatcher(registrar.Build()); dispatcher.Execute(new FakeQuery()); }
public void Dispatch() { var serviceLocator = Substitute.For<Griffin.Container.IServiceLocator>(); var handler = Substitute.For<IExecuteQuery<FakeQuery, string>>(); serviceLocator.Resolve(typeof(IExecuteQuery<FakeQuery, string>)).Returns(handler); var dispatcher = new QueryDispatcher(serviceLocator); dispatcher.Execute(new FakeQuery()); }
public void QueryDispatcherShouldThrowExceptionIfHandlerNotFound() { DependencyServiceMock.SetMock(new DependencyDescriptor(typeof(IQueryHandler <TestQuery, Test>), null)); var dispatcher = new QueryDispatcher(PerformanceCounterMock.GetMock()); Action act = () => dispatcher.Execute(new TestQuery()); act.Should().Throw <QueryDispatcherException>(); }
public IActionResult GetAllStudentsByExamId(Guid exam_Id) { EnsureArg.IsNotEmpty(exam_Id); var query = new GetAllStudentsByExamIdQuery(exam_Id); var queryResult = QueryDispatcher.Execute <GetAllStudentsByExamIdQuery, GetAllStudentsByExamIdQueryResult>(query); return(Ok(queryResult.Students)); }
public void Dispatch() { var serviceLocator = Substitute.For <Griffin.Container.IServiceLocator>(); var handler = Substitute.For <IExecuteQuery <FakeQuery, string> >(); serviceLocator.Resolve(typeof(IExecuteQuery <FakeQuery, string>)).Returns(handler); var dispatcher = new QueryDispatcher(serviceLocator); dispatcher.Execute(new FakeQuery()); }
public void DispatchReal() { var handler = Substitute.For <IExecuteQuery <FakeQuery, string> >(); var registrar = new ContainerRegistrar(); registrar.RegisterInstance(handler); var dispatcher = new QueryDispatcher(registrar.Build()); dispatcher.Execute(new FakeQuery()); }
public void QueryDispatcherShouldReturnObjectOfQueryHandler() { var resultObj = new Test(Guid.NewGuid()); DependencyServiceMock.SetMock(new DependencyDescriptor(typeof(IQueryHandler <TestQuery, Test>), QueryHandlerMock.GetMock(resultObj))); var dispatcher = new QueryDispatcher(PerformanceCounterMock.GetMock()); var result = dispatcher.Execute(new TestQuery()); result.Should().Equals(resultObj); }
public IActionResult GetAllGradesByStudentId(Guid studentId) { EnsureArg.IsNotEmpty(studentId); var query = new GetAllGradesByStudentIdQuery(studentId); var queryResult = QueryDispatcher.Execute <GetAllGradesByStudentIdQuery, GetAllGradesByStudentIdQueryResult>(query); var values = new List <double>(); foreach (var grade in queryResult.Grades) { values.Add(grade.Value); } return(Ok(values)); }
public IActionResult GetResultsByExamId(Guid exam_Id) { EnsureArg.IsNotEmpty(exam_Id); var queryStudents = new GetAllStudentsByExamIdQuery(exam_Id); var students = QueryDispatcher.Execute <GetAllStudentsByExamIdQuery, GetAllStudentsByExamIdQueryResult>(queryStudents).Students; var queryGrades = new GetAllGradesByExamIdQuery(exam_Id); var grades = QueryDispatcher.Execute <GetAllGradesByExamIdQuery, GetAllGradesByExamIdQueryResult>(queryGrades).Grades; using (var package = new ExcelPackage()) { var worksheet = package.Workbook.Worksheets.Add("Sheet1"); worksheet.Cells[1, 1].Value = "First name"; worksheet.Cells[1, 2].Value = "Last name"; worksheet.Cells[1, 3].Value = "Grade"; worksheet.Cells[1, 4].Value = "Final grade"; for (int i = 0; i < grades.Count(); i++) { worksheet.Cells[i + 2, 1].Value = students.ElementAt(i).FirstName; worksheet.Cells[i + 2, 2].Value = students.ElementAt(i).LastName; worksheet.Cells[i + 2, 3].Value = grades.ElementAt(i).Value; worksheet.Cells[i + 2, 4].Value = grades.ElementAt(i).FinalGrade; } byte[] fileContents = package.GetAsByteArray(); if (fileContents == null || fileContents.Length == 0) { return(NotFound()); } return(File( fileContents: fileContents, contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileDownloadName: "test.xlsx" )); } }
public void Start() { //Stocks var stocks = QueryDispatcher.Execute(new StockAllQuery()).ToList(); LoggingService.Info($"Found {stocks.Count()} stocks"); foreach (var item in stocks) { var query = QueryDispatcher.Execute(new StockByIdQuery(item.Id)); } //Quotations var sumQuotations = 0; foreach (var item in stocks) { sumQuotations += QueryDispatcher.Execute(new StockQuotationsCountByIdQuery(item.Id)); } LoggingService.Info($"Found {sumQuotations} quotations"); //Feedback var feedbacks = QueryDispatcher.Execute(new FeedbackAllQuery()).ToList(); LoggingService.Info($"Found {feedbacks.Count()} feedbacks"); foreach (var item in feedbacks) { var query = QueryDispatcher.Execute(new FeedbackByIdQuery(item.Id)); } //Calculations var calculations = QueryDispatcher.Execute(new CalculationAllQuery()).ToList(); LoggingService.Info($"Found {calculations.Count()} calculations"); foreach (var item in calculations) { var query = QueryDispatcher.Execute(new CalculationByIdQuery(item.Id)); } //Strategies var strategies = QueryDispatcher.Execute(new StrategyAllQuery()).ToList(); LoggingService.Info($"Found {strategies.Count()} strategies"); foreach (var item in strategies) { var query = QueryDispatcher.Execute(new StrategyByIdQuery(item.Id)); } //Transactions var transactions = QueryDispatcher.Execute(new TransactionAllQuery()).ToList(); LoggingService.Info($"Found {transactions.Count()} transactions"); foreach (var item in transactions) { var query = QueryDispatcher.Execute(new TransactionByIdQuery(item.Id)); //TODO: Test if every translation was found and no null was returned } //Performances var performance = QueryDispatcher.Execute(new TransactionPerformanceAllQuery()).ToList(); LoggingService.Info($"Found {performance.Count()} performances"); foreach (var item in performance) { var query = QueryDispatcher.Execute(new TransactionPerformanceByIdQuery(item.Id)); } }
public void Start() { //Get old statistics var stats = GetStatistics(); foreach (var stat in stats) { var statistics = stat.Value; var transaction = Transactions[statistics.OldTransactionEndId]; var errorOccured = false; ITransactionPerformance query = null; var date = DateTime.MinValue; var desc = string.Empty; //Selling if (transaction is SellingTransactionDto sellingTransaction) { query = QueryDispatcher.Execute(new TransactionPerformanceByIdQuery(sellingTransaction.Id)); date = sellingTransaction.OrderDate; desc = $"{sellingTransaction.Stock.Name} ({sellingTransaction.Shares} x {sellingTransaction.PricePerShare})"; } //Dividend if (transaction is DividendTransactionDto dividendTransaction) { query = QueryDispatcher.Execute(new TransactionPerformanceByIdQuery(dividendTransaction.Id)); date = dividendTransaction.OrderDate; desc = $"{dividendTransaction.Stock.Name} ({dividendTransaction.Shares} x {dividendTransaction.PricePerShare})"; } if (query == null) { LoggingService.Warn($"Statistics: {stat.Key} not found"); continue; } //Already checked and results of new implementation are correct if (!new List <int>() { }.Contains(stat.Key)) { //Comparison if (query.ProfitAbsolute.Equals(statistics.ProfitAbsolute) && !query.ProfitPercentage.Equals(statistics.ProfitPercentage)) { //Absolute profit is equal, but percentage is not LoggingService.Warn( $"{date} Statistics: {stat.Key} has same abs. Profit but diff. Percentage ({query.ProfitPercentage} vs {statistics.ProfitPercentage}) / {desc}"); errorOccured = true; } else { if (!query.ProfitAbsolute.Equals(statistics.ProfitAbsolute)) { LoggingService.Warn( $"{date} Statistics: {stat.Key} has different ProfitAbsolute ({query.ProfitAbsolute} vs {statistics.ProfitAbsolute}) / {desc}"); errorOccured = true; } if (!query.ProfitPercentage.Equals(statistics.ProfitPercentage)) { LoggingService.Warn( $"{date} Statistics: {stat.Key} has different ProfitPercentage ({query.ProfitPercentage} vs {statistics.ProfitPercentage}) / {desc}"); errorOccured = true; } } if (!query.EntryEfficiency.Equals(statistics.EntryEfficiency)) { LoggingService.Warn( $"{date} Statistics: {stat.Key} has different EntryEfficiency ({query.EntryEfficiency} vs {statistics.EntryEfficiency}) / {desc}"); errorOccured = true; } if (!query.ExitEfficiency.Equals(statistics.ExitEfficiency)) { LoggingService.Warn( $"{date} Statistics: {stat.Key} has different ExitEfficiency ({query.ExitEfficiency} vs {statistics.ExitEfficiency}) / {desc}"); errorOccured = true; } } if (!errorOccured) { LoggingService.Info($"{date} Statistics: {stat.Key} is fine"); } } }
public void Start() { const string queryString = "SELECT [Date],[High],[Close],[Open],[Low],[Stock_ID],[Changed] FROM [dbo].[Quotations] ORDER BY [Date] ASC"; const string countString = "SELECT COUNT([Stock_ID]) AS COUNT FROM [dbo].[Quotations]"; //Load from db using (var connection = new SqlConnection(SourceConnectionString)) { connection.Open(); using (var command = new SqlCommand(countString, connection)) { var count = (int)command.ExecuteScalar(); LoggingService.Info($" ({count})"); } using (var command = new SqlCommand(queryString, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Quotation( DateTime.Parse(reader["Date"].ToString()), DateTime.Parse(reader["Changed"].ToString()), decimal.Parse(reader["Open"].ToString()), decimal.Parse(reader["Close"].ToString()), decimal.Parse(reader["High"].ToString()), decimal.Parse(reader["Low"].ToString())); //Stock_id var stockId = int.Parse(reader["Stock_ID"].ToString()); if (!Items.ContainsKey(stockId)) { Items.Add(int.Parse(reader["Stock_ID"].ToString()), new List <Quotation>()); } Items[stockId].Add(item); } } } } //Import LoggingService.Info("Quotations "); foreach (var item in Items) { var stockOld = StockItems.FirstOrDefault(s => s.OldId == item.Key); if (stockOld == null || stockOld.IsDividend) { continue; } var stock = QueryDispatcher.Execute(new StockByIdQuery(stockOld.Id)); var version = stock.OriginalVersion; var cmd = new StockQuotationsAddOrChangeCommand( stockOld.Id, version, item.Value); CommandDispatcher.Execute(cmd); LoggingService.Info($"{item.Value.Count} Quotation(s) for stock {stock.Name} ({stockOld.OldId})"); } }
public async Task <IActionResult> Get() { var result = await QueryDispatcher.Execute(new GetEventsQuery()); return(Ok(result)); }
public async Task <IActionResult> GetAvailable(string eventName) { var result = await QueryDispatcher.Execute(new GetAvailableTicketsQuery { EventName = eventName }); return(Ok(result)); }