Пример #1
0
        public void TestCreateAndExecuteCommand()
        {
            _subject.Register(r => r.Literal("foo").Executes(_command));

            _subject.Execute("foo", _source).Should().Be(42);
            _command.Received().Invoke(Arg.Any <CommandContext <object> >());
        }
Пример #2
0
        private void ImportDividend(DividendTransactionDto item)
        {
            //Import
            var cmd = new TransactionDividendCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                null,
                item.Stock.Id,
                item.Taxes);

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }
        }
        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})");
            }
        }
Пример #4
0
        private void ImportSelling(SellingTransactionDto item)
        {
            //Import
            var cmd = new TransactionSellCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                item.Image,
                item.Stock.Id,
                item.Taxes,
                item.MAE,
                item.MFE,
                item.Feedback.Select(f => f.Id));

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Sell {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Sell {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }
        }
        public void Start()
        {
            Items = GetItems();

            //Import
            foreach (var item in Items)
            {
                var cmd = new StrategyAddCommand(
                    item.Id,
                    -1,
                    item.Name,
                    item.Description,
                    null);

                CommandDispatcher.Execute(cmd);

                //Image
                if (ImportImage(cmd, item.OldId))
                {
                    LoggingService.Info($"Stock {item.Name} ({item.OldId}) + IMAGE");
                }
                else
                {
                    LoggingService.Info($"Stock {item.Name} ({item.OldId})");
                }
            }
        }
Пример #6
0
        private void ImportBuying(BuyingTransactionDto item)
        {
            //Import
            var cmd = new TransactionBuyCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                item.Image,
                item.InitialSL,
                item.InitialTP,
                item.Stock.Id,
                item.Strategy.Id);

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Buy {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Buy {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }
        }
Пример #7
0
        public void CheckIfCommandIsNull()
        {
            CommandDispatcher cd = new CommandDispatcher();
            var exception        = Record.Exception(() => cd.Execute <TestCommand>(null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Пример #8
0
        public void Start()
        {
            const string queryString      = "SELECT [ID],[Name],[Description] FROM [dbo].[Strategies] ORDER BY [ID] ASC";
            const string countString      = "SELECT COUNT([ID]) AS COUNT FROM [dbo].[Strategies]";
            const string connectionString = "Server=.;Database=TransactionManagement;User Id=stocktrading;Password=stocktrading;";

            //Load from db
            using (var connection = new SqlConnection(connectionString))
            {
                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 StrategyDto();

                            item.OldId       = int.Parse(reader["ID"].ToString());
                            item.Name        = reader["Name"].ToString();
                            item.Description = reader["Description"].ToString();

                            Items.Add(item.OldId, item);
                        }
                    }
                }
            }

            //Import
            foreach (var item in Items)
            {
                var cmd = new StrategyAddCommand(
                    item.Value.Id,
                    -1,
                    item.Value.Name,
                    item.Value.Description,
                    null);

                CommandDispatcher.Execute(cmd);

                //Image
                if (ImportImage(cmd, item.Value.OldId))
                {
                    LoggingService.Info($"Stock {item.Value.Name} ({item.Value.OldId}) + IMAGE");
                }
                else
                {
                    LoggingService.Info($"Stock {item.Value.Name} ({item.Value.OldId})");
                }
            }
        }
Пример #9
0
        public IActionResult UpdateLocation([FromBody] LocationDto locationDto)
        {
            EnsureArg.IsNotNull(locationDto);
            var command = new UpdateLocationCommand(locationDto);

            CommandDispatcher.Execute(command);

            return(NoContent());
        }
Пример #10
0
        public IActionResult UpdateEmployee([FromBody] EmployeeDto employeeDto)
        {
            EnsureArg.IsNotNull(employeeDto);
            var command = new UpdateEmployeeCommand(employeeDto);

            CommandDispatcher.Execute(command);

            return(NoContent());
        }
Пример #11
0
        public IActionResult AddGrade(Guid studentId, [FromBody] GradeDto grade)
        {
            EnsureArg.IsNotEmpty(studentId);

            var command = new AddGradeCommand(grade, studentId);

            CommandDispatcher.Execute(command);
            return(Created("/api/students/{studentId}/grades", command));
        }
Пример #12
0
        public IActionResult UpdateTrip([FromBody] TripDto tripDto)
        {
            EnsureArg.IsNotNull(tripDto);
            var command = new UpdateTripCommand(tripDto);

            CommandDispatcher.Execute(command);

            return(NoContent());
        }
Пример #13
0
        public IActionResult AddStudent([FromBody] StudentDto student)
        {
            EnsureArg.IsNotNull(student);

            var command = new AddStudentCommand(student);

            CommandDispatcher.Execute(command);
            return(Created("/api/students", command));
        }
Пример #14
0
        public IActionResult AddProfessor([FromBody] ProfessorDto professor)
        {
            EnsureArg.IsNotNull(professor);

            var command = new AddProfessorCommand(professor);

            CommandDispatcher.Execute(command);
            return(Created("/api/professors/", command));
        }
Пример #15
0
        public IActionResult AddExam([FromBody] ExamDto exam)
        {
            EnsureArg.IsNotNull(exam);

            var command = new AddExamCommand(exam);

            CommandDispatcher.Execute(command);
            return(Created("/api/exams", command));
        }
Пример #16
0
        public IActionResult UpdateStudentAttendance(Guid id_student)
        {
            EnsureArg.IsNotEmpty(id_student);

            var command = new UpdateStudentAttendanceCommand(id_student);

            CommandDispatcher.Execute(command);
            return(NoContent());
        }
        public void CommandDispatcherShouldThrowExceptionIfHandlerNotFound()
        {
            DependencyServiceMock.SetMock(new DependencyDescriptor(typeof(ICommandHandler <TestCommand>), null));

            var dispatcher = new CommandDispatcher(PerformanceCounterMock.GetMock());

            Action act = () => dispatcher.Execute(new TestCommand());

            act.Should().Throw <CommandDispatcherException>();
        }
Пример #18
0
        public IActionResult DeleteLocation(Guid employeeId)
        {
            EnsureArg.IsNotEmpty(employeeId);

            var command = new DeleteEmployeeCommand(employeeId);

            CommandDispatcher.Execute(command);

            return(NoContent());
        }
Пример #19
0
        public IActionResult DeleteLocation(Guid tripId)
        {
            EnsureArg.IsNotEmpty(tripId);

            var command = new DeleteTripCommand(tripId);

            CommandDispatcher.Execute(command);

            return(NoContent());
        }
Пример #20
0
        public void CheckIfCommandIsValid()
        {
            List <string> stringList = new List <string>();
            string        msg        = "This is my message";

            CommandDispatcher cd = new CommandDispatcher();

            cd.Execute(new TestCommand(stringList, msg));

            Assert.Equal(msg, stringList[0]);
        }
Пример #21
0
        public void Start()
        {
            const string queryString      = "SELECT [ID],[WKN],[Name],[Type],[IsDividend],[LongShort] FROM [dbo].[Stocks] ORDER BY [ID] ASC";
            const string countString      = "SELECT COUNT([ID]) AS COUNT FROM [dbo].[Stocks]";
            const string connectionString = "Server=.;Database=TransactionManagement;User Id=stocktrading;Password=stocktrading;";

            //Load from db
            using (var connection = new SqlConnection(connectionString))
            {
                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 StockDto();

                            item.OldId      = int.Parse(reader["ID"].ToString());
                            item.IsDividend = bool.Parse(reader["IsDividend"].ToString());
                            item.LongShort  = reader["LongShort"].ToString();
                            item.Name       = reader["Name"].ToString();
                            item.Type       = reader["Type"].ToString();
                            item.Wkn        = reader["WKN"].ToString();

                            Items.Add(item.OldId, item);
                        }
                    }
                }
            }

            //Import
            foreach (var item in Items.Where(i => !i.Value.IsDividend))
            {
                var cmd = new StockAddCommand(
                    item.Value.Id,
                    -1,
                    item.Value.Name,
                    item.Value.Wkn,
                    item.Value.Type,
                    item.Value.LongShort);

                CommandDispatcher.Execute(cmd);

                LoggingService.Info($"Stock {item.Value.Name} (Old ID:{item.Value.OldId}, New ID:{item.Value.Id})");
            }
        }
Пример #22
0
        private ITransactionDto ImportSelling(IDataRecord reader)
        {
            var item = new SellingTransactionDto();

            item.OldId           = int.Parse(reader["ID"].ToString());
            item.Shares          = decimal.Parse(reader["Units"].ToString());
            item.Description     = reader["Description"].ToString();
            item.OrderCosts      = decimal.Parse(reader["OrderCosts"].ToString());
            item.OrderDate       = DateTime.Parse(reader["OrderDate"].ToString());
            item.OriginalVersion = -1;
            item.PricePerShare   = decimal.Parse(reader["PricePerUnit"].ToString());
            item.Stock           = StockItems[int.Parse(reader["Stock_ID"].ToString())];
            item.Tag             = reader["Tag"].ToString();
            item.Taxes           = decimal.Parse(reader["Taxes"].ToString());
            item.MAE             = string.IsNullOrEmpty(reader["MAE"].ToString()) ? default(decimal?) : decimal.Parse(reader["MAE"].ToString());
            item.MFE             = string.IsNullOrEmpty(reader["MFE"].ToString()) ? default(decimal?) : decimal.Parse(reader["MFE"].ToString());
            item.Image           = ImportImage(item.Id, item.OldId);
            item.Feedback        = ImportFeedback(item.OldId);

            //Import
            var cmd = new TransactionSellCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                item.Image,
                item.Stock.Id,
                item.Taxes,
                item.MAE,
                item.MFE,
                item.Feedback.Select(f => f.Id));

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Sell {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Sell {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }

            return(item);
        }
Пример #23
0
        public void IsCheckedForSecurity(string userInterface, bool useVersion)
        {
            DynamicPermissionMap.SetRoles(item, Permission.Read, "None");
            if (useVersion)
                item = MakeVersion(item);
            var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, userInterface, CreatePrincipal("someone"), new NullBinder<CommandContext>(), new NullValidator<CommandContext>());

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(context.ValidationErrors.Count, Is.EqualTo(1));
            Assert.That(context.ValidationErrors.First().Name, Is.EqualTo("Unauthorized"));
        }
Пример #24
0
        private void ImportSplit(DateTime orderDate, StockDto stock, decimal newShares, decimal newPrice)
        {
            //Import
            var cmd = new TransactionSplitCommand(
                Guid.NewGuid(),
                -1,
                orderDate,
                newShares,
                newPrice,
                stock.Id);

            CommandDispatcher.Execute(cmd);

            LoggingService.Info($"Split {stock.Name} ({newShares} x {newPrice})");
        }
Пример #25
0
        private ITransactionDto ImportBuying(IDataRecord reader)
        {
            var item = new BuyingTransactionDto();

            item.OldId           = int.Parse(reader["ID"].ToString());
            item.Shares          = decimal.Parse(reader["Units"].ToString());
            item.Description     = reader["Description"].ToString();
            item.OrderCosts      = decimal.Parse(reader["OrderCosts"].ToString());
            item.OrderDate       = DateTime.Parse(reader["OrderDate"].ToString());
            item.OriginalVersion = -1;
            item.PricePerShare   = decimal.Parse(reader["PricePerUnit"].ToString());
            item.Stock           = StockItems[int.Parse(reader["Stock_ID"].ToString())];
            item.Tag             = reader["Tag"].ToString();
            item.Image           = ImportImage(item.Id, item.OldId);
            item.InitialSL       = string.IsNullOrEmpty(reader["InitialSL"].ToString()) ? decimal.Zero : decimal.Parse(reader["InitialSL"].ToString());
            item.InitialTP       = string.IsNullOrEmpty(reader["InitialTP"].ToString()) ? decimal.Zero : decimal.Parse(reader["InitialTP"].ToString());
            item.Strategy        = StrategyItems[int.Parse(reader["Strategy_ID"].ToString())];

            //Import
            var cmd = new TransactionBuyCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                item.Image,
                item.InitialSL,
                item.InitialTP,
                item.Stock.Id,
                item.Strategy.Id);

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Buy {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Buy {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }

            return(item);
        }
Пример #26
0
        private bool ImportImage(StrategyAddCommand addCommand, int oldId)
        {
            string       queryString      = $"SELECT [ID],[Data],[ContentType],[OriginalName],[Description],[RefererID],[Referer] FROM [dbo].[Images] WHERE [Referer] = 2 AND [RefererID]= {oldId}";
            const string connectionString = "Server=.;Database=TransactionManagement;User Id=stocktrading;Password=stocktrading;";

            Image image = null;

            //Load from db
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = new SqlCommand(queryString, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            image = new Image(addCommand.AggregateId);

                            image.Data         = GetImage(reader["Data"].ToString());
                            image.ContentType  = reader["ContentType"].ToString();
                            image.OriginalName = reader["OriginalName"].ToString();
                            image.Description  = reader["Description"].ToString();
                            break;
                        }
                    }
                }
            }

            if (image == null)
            {
                return(false);
            }

            //Import
            var cmd = new StrategyChangeCommand(
                addCommand.AggregateId,
                0,
                addCommand.Name,
                addCommand.Description,
                image);

            CommandDispatcher.Execute(cmd);

            return(true);
        }
Пример #27
0
        private ITransactionDto ImportDividend(IDataRecord reader)
        {
            var item = new DividendTransactionDto();

            var dividendStock = StockItems[int.Parse(reader["Stock_ID"].ToString())];

            item.OldId           = int.Parse(reader["ID"].ToString());
            item.Shares          = decimal.Parse(reader["Units"].ToString());
            item.Description     = reader["Description"].ToString();
            item.OrderCosts      = decimal.Parse(reader["OrderCosts"].ToString());
            item.OrderDate       = DateTime.Parse(reader["OrderDate"].ToString());
            item.OriginalVersion = -1;
            item.PricePerShare   = decimal.Parse(reader["PricePerUnit"].ToString());
            item.Stock           = StockItems.FirstOrDefault(s => s.Value.Wkn.Equals(dividendStock.Wkn) && s.Value.OldId != dividendStock.OldId).Value;
            item.Tag             = reader["Tag"].ToString();
            item.Taxes           = decimal.Parse(reader["Taxes"].ToString());
            item.Image           = ImportImage(item.Id, item.OldId);

            //Import
            var cmd = new TransactionDividendCommand(
                item.Id,
                -1,
                item.OrderDate,
                item.Shares,
                item.PricePerShare,
                item.OrderCosts,
                item.Description,
                item.Tag,
                null,
                item.Stock.Id,
                item.Taxes);

            CommandDispatcher.Execute(cmd);

            //Image
            if (item.Image != null)
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare}) + IMAGE");
            }
            else
            {
                LoggingService.Info($"Dividend {item.Stock.Name} ({item.Shares} x {item.PricePerShare})");
            }

            return(item);
        }
Пример #28
0
        public void Start()
        {
            Items = GetItems();
            //Import
            foreach (var item in Items)
            {
                var cmd = new FeedbackAddCommand(
                    item.Id,
                    -1,
                    item.Name,
                    item.Description);

                CommandDispatcher.Execute(cmd);

                LoggingService.Info($"Feedback {item.Name} ({item.OldId})");
            }
        }
        public void Start()
        {
            Items         = GetItems().Where(i => !i.IsDividend).ToList();
            DividendItems = GetItems().Where(i => i.IsDividend).ToList();

            //Import
            foreach (var item in Items)
            {
                var cmd = new StockAddCommand(
                    item.Id,
                    -1,
                    item.Name,
                    item.Wkn,
                    item.Type,
                    item.LongShort);

                CommandDispatcher.Execute(cmd);

                LoggingService.Info($"Stock {item.Name} (Old ID:{item.OldId}, New ID:{item.Id})");
            }
        }
Пример #30
0
        public void Start()
        {
            const string queryString      = "SELECT [ID],[Name],[WKN],[Multiplier],[StrikePrice],[Underlying],[InitialSL],[InitialTP],[PricePerUnit],[OrderCosts],[Description],[Units],[IsLong] FROM [dbo].[Calculations] ORDER BY [ID] ASC";
            const string countString      = "SELECT COUNT([ID]) AS COUNT FROM [dbo].[Calculations]";
            const string connectionString = "Server=.;Database=TransactionManagement;User Id=stocktrading;Password=stocktrading;";

            //Load from db
            using (var connection = new SqlConnection(connectionString))
            {
                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 CalculationDto();

                            item.OldId        = int.Parse(reader["ID"].ToString());
                            item.Name         = reader["Name"].ToString();
                            item.Wkn          = reader["WKN"].ToString();
                            item.Multiplier   = decimal.Parse(reader["Multiplier"].ToString());
                            item.StrikePrice  = decimal.Parse(reader["StrikePrice"].ToString());
                            item.Underlying   = reader["Underlying"].ToString();
                            item.InitialSl    = decimal.Parse(reader["InitialSL"].ToString());
                            item.InitialTp    = decimal.Parse(reader["InitialTP"].ToString());
                            item.PricePerUnit = decimal.Parse(reader["PricePerUnit"].ToString());
                            item.OrderCosts   = decimal.Parse(reader["OrderCosts"].ToString());
                            item.Description  = reader["Description"].ToString();
                            item.Units        = decimal.Parse(reader["Units"].ToString());
                            item.IsLong       = bool.Parse(reader["IsLong"].ToString());

                            Items.Add(item.OldId, item);
                        }
                    }
                }
            }

            //Import
            foreach (var item in Items)
            {
                var cmd = new CalculationAddCommand(
                    item.Value.Id,
                    -1,
                    item.Value.Name,
                    item.Value.Wkn,
                    item.Value.Multiplier,
                    item.Value.StrikePrice,
                    item.Value.Underlying,
                    item.Value.InitialSl,
                    item.Value.InitialTp,
                    item.Value.PricePerUnit,
                    item.Value.OrderCosts,
                    item.Value.Description,
                    item.Value.Units,
                    item.Value.IsLong);

                CommandDispatcher.Execute(cmd);

                LoggingService.Info($"Calculation {item.Value.Name} ({item.Value.OldId})");
            }
        }