private void GetMeanVectorAndSelectedPoints(StreamWriter wr1, StreamWriter wr2, StreamWriter wr3, UnitOfWork work) { var dfoDataRepository = RepositoryContainer.GetRepository <DataAccess.DFOdata>(work); //BySpiralFasion(wr1, wr2, dfoDataRepository); ByGridFasion(wr1, wr2, wr3, dfoDataRepository); }
public T Create <T>() where T : IMyAppBaseRepository { var repo = RepositoryContainer.GetRepository <T>(); repo.ConnectionString = ConnectionString; repo.CommandTimeout = CommandTimeout; return(repo); }
public void InsertNewDFOData() { var folderPath = GetDataFolderPath(); var xyFilePath = folderPath + "\\paresedXY.txt"; var velocityPath = folderPath + "\\parsedVelocity.txt"; var xyFileLines = File.ReadAllLines(xyFilePath); var velocityFileLines = File.ReadAllLines(velocityPath); try { using (var work = new UnitOfWork()) { var dfoDataRepository = RepositoryContainer.GetRepository <DataAccess.DFOdata>(work); for (int i = 0; i < xyFileLines.Count(); i++) { var xyFileLine = xyFileLines.ElementAt(i).Split(','); var velocityFileLine = velocityFileLines.ElementAt(i).Split(','); if (xyFileLine.Count() == 3 && velocityFileLine.Count() == 3) { var x = float.Parse(xyFileLine[1], CultureInfo.InvariantCulture.NumberFormat); var y = float.Parse(xyFileLine[2], CultureInfo.InvariantCulture.NumberFormat); var u = float.Parse(velocityFileLine[1], CultureInfo.InvariantCulture.NumberFormat); var v = float.Parse(velocityFileLine[2], CultureInfo.InvariantCulture.NumberFormat); var dfOdata = new DataAccess.DFOdata() { X = x, Y = y, U = u, V = v }; dfoDataRepository.Insert(dfOdata); Console.WriteLine(xyFileLine[0]); } else { throw new Exception("txt files is not in perfect format !"); } } Console.WriteLine("Saving new data"); work.SaveChanges(); Console.WriteLine("Done"); } } catch (Exception ex) { } }
public void DupmCellMeanVectors() { var wr = GetFileWriterForDumpingCellMeanVectors(); using (var work = new UnitOfWork()) { var dfoDataCellRepository = RepositoryContainer.GetRepository <Cell>(work); var sqlQuery = string.Format("Select * from Cells"); var dfoDataCells = dfoDataCellRepository.ExecuteCommand <Cell>(sqlQuery); var msg = string.Format("Total {0} cell mean vector is being dumping ...", dfoDataCells.Count); Console.WriteLine(msg); foreach (var dfoDataCell in dfoDataCells) { wr.WriteLine("{0},{1},{2},{3}", dfoDataCell.X, dfoDataCell.Y, dfoDataCell.U, dfoDataCell.V); } } wr.Close(); Console.WriteLine("Done!!"); }
public PlaceNewOrderTest() { using (var orderRepository = RepositoryContainer.GetRepository <IOrderRepository>()) { using (var userRepository = RepositoryContainer.GetRepository <IUserRepository>()) { using (var bookRepository = RepositoryContainer.GetRepository <IBookRepository>()) { using ( var bookInventoryRepository = RepositoryContainer.GetRepository <IBookInventoryRepository>()) { using ( var creditCarcChargeRepository = RepositoryContainer.GetRepository <ICreditCardChargeRepository>()) { Task.WaitAll(orderRepository.Clear(), userRepository.Clear(), bookRepository.Clear(), bookInventoryRepository.Clear(), creditCarcChargeRepository.Clear()); Task.WaitAll( bookRepository .Add(new Book { Id = 1, Name = "TestBook", Price = 100 }), bookInventoryRepository .Add(new BookInventory { BookId = 1, Inventory = 100 }), userRepository .Add(new User { Id = 1, Credit = 1000, Name = "zjhe" })); } } } } } }
public void DeletePreviousData() { try { using (var work = new UnitOfWork()) { Console.WriteLine("Deleting Previous Data"); var dfoDataRepository = RepositoryContainer.GetRepository <DataAccess.DFOdata>(work); dfoDataRepository.ExecuteCommandDirectly("delete from DFOdata"); //foreach (var dfOdata in dfoDataRepository.All()) //{ // dfoDataRepository.Remove(dfOdata); //} //work.SaveChanges(); Console.WriteLine("Done"); } } catch (Exception ex) { throw new Exception("Data deletion fails !"); } }
public async Task place_a_new_order() { var orderService = new OrderService(); await orderService.PlaceNewOrder(1, 1, 5); using (var userRepository = RepositoryContainer.GetRepository <IUserRepository>()) { var user = await userRepository.Get(1); Assert.Equal(500, user.Credit); } using (var orderRepository = RepositoryContainer.GetRepository <IOrderRepository>()) { var orders = await orderRepository.AllOrders(); Assert.Equal(1, orders.Count()); var order = orders.First(); Assert.Equal(1, order.UserId); Assert.Equal(1, order.BookId); Assert.Equal(5, order.Amount); } }
public async Task <long> PlaceNewOrder(long userId, long bookId, int bookAmount) { long orderId = 0; using (var transactionScope = new TransactionScope()) { using (var bookRepository = RepositoryContainer.GetRepository <IBookRepository>()) { var book = await bookRepository.Get(bookId); var bookPrice = book.Price; var total = bookPrice * bookAmount; using (var userRepository = RepositoryContainer.GetRepository <IUserRepository>()) { var user = await userRepository.Get(userId); if (user.Credit < total) { throw new NoEnoughCreditException( $"No enough user credit, current is {user.Credit}, need {total}"); } using ( var bookInventoryRepository = RepositoryContainer.GetRepository <IBookInventoryRepository>()) { var bookInventory = await bookInventoryRepository.Get(bookId); if (bookInventory.Inventory < bookAmount) { throw new NoEnoughInventoryException( $"No enough book inventory, current is {bookInventory}, need {bookAmount}"); } using (var creditCardChargeRepository = RepositoryContainer.GetRepository <ICreditCardChargeRepository>()) { if (await creditCardChargeRepository.Add(new CreditCardCharge { Amount = total, UserId = userId, Id = Interlocked.Increment(ref _id) }) != 1) { throw new DbOperationFailedException(); } if (await userRepository.ChargeCredit(userId, total) != 1) { throw new DbOperationFailedException(); } if (await bookInventoryRepository.AddInventory(bookId, -bookAmount) != 1) { throw new DbOperationFailedException(); } using (var orderRepository = RepositoryContainer.GetRepository <IOrderRepository>()) { orderId = Interlocked.Increment(ref _id); if ( await orderRepository.Add(new Order { Amount = bookAmount, BookId = bookId, UserId = userId, Id = orderId }) != 1) { throw new DbOperationFailedException(); } } } } } } transactionScope.Complete(); } return(orderId); }