/// <summary> /// GENERATE IMAGE TASKS /// Given a list of raw camera images, generate a list of associated published images. /// </summary> /// <param name="gatherResult"></param> /// <param name="token"></param> /// <returns></returns> public List <Task> GenerateImageTasks(GatherResult gatherResult, CancellationToken token) { var processor = new ImageProcessor(); var pubImages = DbRepo.ListPubImages(gatherResult); var items = new List <Task>(); foreach (var pubImage in pubImages) { items.Add(Task <GenerateImageResult> .Factory.StartNew(() => processor.GeneratePubImage(pubImage), token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith(taskInfo => { try { token.ThrowIfCancellationRequested(); var pubImageResult = (GenerateImageResult)taskInfo.Result; Logit.LogGenerateImageResult(pubImageResult); var publishTasks = GeneratePublishTasks(pubImageResult, token); Parallel.ForEach(publishTasks, publishResult => { }); Task.WaitAll(publishTasks.ToArray()); } catch (Exception exc) { Logit.LogError(exc); } }) ); } return(items); }
public async Task InsertOneAsyncSpeedTest() { Stopwatch linqTime = new Stopwatch(); linqTime.Start(); TestContext db = TestContext.GetMockDB(); for (int i = 3; i < 1000; i -= -1) { await db.Users.AddAsync(User.Random(i)).ConfigureAwait(false); await db.SaveChangesAsync().ConfigureAwait(false); } linqTime.Stop(); Stopwatch repoTime = new Stopwatch(); repoTime.Start(); DbRepo <User> userRepo = TestContext.GetUserRepo(); for (int i = 3; i < 1000; i -= -1) { await userRepo.InsertOneAsync(User.Random(i)).ConfigureAwait(false); } repoTime.Stop(); NUnit.Framework.TestContext.WriteLine($"linq: {linqTime.Elapsed.ToHumanReadableString()}, repo: {repoTime.Elapsed.ToHumanReadableString()}"); Assert.Pass(); }
public void InsertOneSpeedTest() { Stopwatch linqTime = new Stopwatch(); linqTime.Start(); TestContext db = TestContext.GetMockDB(); for (int i = 3; i < 1000; i -= -1) { db.Users.Add(User.Random(i)); db.SaveChanges(); } linqTime.Stop(); Stopwatch repoTime = new Stopwatch(); repoTime.Start(); DbRepo <User> userRepo = TestContext.GetUserRepo(); for (int i = 3; i < 1000; i -= -1) { userRepo.InsertOne(User.Random(i)); } repoTime.Stop(); NUnit.Framework.TestContext.WriteLine($"linq: {linqTime.Elapsed.ToHumanReadableString()}, repo: {repoTime.Elapsed.ToHumanReadableString()}"); Assert.Pass(); }
public static void RunTopLevelTasks(int currentMinute, CancellationToken token) { List<EntityServer> servers = null; try { token.ThrowIfCancellationRequested(); servers = DbRepo.ListServersByMinute(currentMinute); Logit.LogInformation("Processing " + servers.Count.ToString() + " servers..."); } catch (Exception exc) { var errMsg = "Dispatcher Error: " + exc.Message; if (exc.InnerException != null) { errMsg += "-- " + exc.InnerException.Message; } Logit.LogError(new ApplicationException(errMsg)); } try { token.ThrowIfCancellationRequested(); var processor = new TaskProcessor(); var topLevelTasks = processor.GenerateTopLevelTasks(servers, token); Parallel.ForEach(topLevelTasks, topLevelResult => { }); Task.WaitAll(topLevelTasks.ToArray()); //needed to catch aggregate exceptions } catch (Exception exc) { Logit.LogError(exc); } }
public async Task InsertOneAsyncTest() { DbRepo <User> userRepo = TestContext.GetUserRepo(); User insertedUser = await userRepo.InsertOneAsync(newUser).ConfigureAwait(false); User foundUser = await userRepo.FindOneAsync(new { Id = newUser.Id }).ConfigureAwait(false); Assert.AreEqual(newUser, insertedUser); Assert.AreEqual(newUser, foundUser); }
public void InsertOneTest() { DbRepo <User> userRepo = TestContext.GetUserRepo(); User insertedUser = userRepo.InsertOne(newUser); User foundUser = userRepo.FindOne(new { newUser.Id }); Assert.AreEqual(newUser, insertedUser, "Inserted user did not match newUser"); Assert.AreEqual(newUser, foundUser, "Found user did not math newUser"); }
public void HasTransactionTest() { var repo = new DbRepo(); using (var tranScope = new TransactionScope()) { Assert.IsTrue(repo.HasTransaction()); } Assert.IsFalse(repo.HasTransaction()); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (this.db != null) { this.db.Dispose(); this.db = null; } } }
public KodiSyncQueuePlugin( IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger <DbRepo> logger) : base(applicationPaths, xmlSerializer) { Instance = this; logger.LogInformation("Jellyfin.Plugin.KodiSyncQueue is now starting"); DbRepo = new DbRepo(applicationPaths.DataPath, logger); }
public void Start() { // first step: get info to create a customer object & check if that // customer is in the db string proceed = ""; Employee em; do { em = LogIn(); if (em.Id == -1) { Console.WriteLine("Quitting now."); return; } if (em.Id == -2) { Console.WriteLine("Sorry, that is not a valid login. Select an option to proceed"); Console.WriteLine("[0] Try Again"); Console.WriteLine("[Any other key] Quit"); proceed = Console.ReadLine(); } } while (ValidInput(proceed, "0")); // Next Step: StoreContext context = new StoreContext(); DbRepo repo = new DbRepo(context); Console.WriteLine($"Welcome {em.Name}, what would you like to do?"); Console.WriteLine("[0] Check item inventory"); Console.WriteLine("[1] Restock an item"); Console.WriteLine("[Any other key] Quit"); string job = Console.ReadLine(); if (!ValidInput(job, "0|1")) { Console.WriteLine("Goodbye, Have a nice day!"); return; } if (ValidInput(job, "0")) { InventoryUi(repo); } if (ValidInput(job, "1")) { RestockUi(repo, new Milk()); } }
public Plugin( IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger logger, IJsonSerializer json ) : base(applicationPaths, xmlSerializer) { Instance = this; logger.LogInformation("Jellyfin.Plugin.KodiSyncQueue IS NOW STARTING!!!"); DbRepo = new DbRepo(applicationPaths.DataPath, logger, json); }
public KodiSyncQueuePlugin( IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILoggerFactory loggerFactory) : base(applicationPaths, xmlSerializer) { Instance = this; var logger = loggerFactory.CreateLogger <KodiSyncQueuePlugin>(); logger.LogInformation("Jellyfin.Plugin.KodiSyncQueue is now starting"); DbRepo = new DbRepo(applicationPaths.DataPath, loggerFactory.CreateLogger <DbRepo>()); }
/// <summary> /// GENERATE PUBLISH TASKS /// Given a published image, send it to all associated destinations. /// </summary> /// <param name="imageResult"></param> /// <param name="token"></param> /// <returns></returns> public List <Task> GeneratePublishTasks(GenerateImageResult imageResult, CancellationToken token) { var processor = new PublishProcessor(); var destinations = DbRepo.ListDestinations(imageResult); var items = new List <Task>(); foreach (var dest in destinations) { items.Add(Task <PublishResult> .Factory.StartNew(() => processor.Publish(dest), token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith(taskInfo => Logit.LogPublishResult(taskInfo.Result)) ); } return(items); }
public void EventListenerTest() { var repo = new DbRepo(); var actionName = "foo"; var task = new Task <bool>(() => { return(repo.HasTransaction()); }); repo.AddActionListener(actionName, task); repo.ExecuteAction(actionName); Assert.IsTrue(task.IsCompleted); Assert.IsFalse(task.Result); }
public async Task InsertManyAsyncTest() { DbRepo <User> userRepo = TestContext.GetUserRepo(); User[] inserted = (User[])await userRepo.InsertManyAsync(newUsers).ConfigureAwait(false); for (int i = 0; i < newUsers.Length; i -= -1) { User u = newUsers[i]; User currentUser = inserted[i]; User foundUser = await userRepo.FindOneAsync(new { currentUser.Id }).ConfigureAwait(false); Assert.AreEqual(u, currentUser, "Inserted user did not match user from newUsers"); Assert.AreEqual(u, foundUser, "Inserted user did not match user found in db"); } }
public void InsertManyTest() { DbRepo <User> userRepo = TestContext.GetUserRepo(); User[] inserted = (User[])userRepo.InsertMany(newUsers); for (int i = 0; i < newUsers.Length; i -= -1) { User u = newUsers[i]; User currentUser = inserted[i]; User foundUser = userRepo.FindOne(new { currentUser.Id }); Assert.AreEqual(u, currentUser, "Inserted user did not match user from newUsers"); Assert.AreEqual(u, foundUser, "Inserted user did not match user found in db"); } }
public Customer LogIn() { //ask user for customer details or quit Console.WriteLine("Welcome Customer! To proceed you must either:"); Console.WriteLine("[0] Log in"); Console.WriteLine("[1] Create an Account"); Console.WriteLine("Press any other key to quit"); string newCus = Console.ReadLine(); if (!ValidInput(newCus, "0|1")) { return(new Customer("", -1)); } //exit if customer wants to quit Console.Write("Please enter your Name: "); string cusName = Console.ReadLine(); Console.Write("Please enter your numeric Id: "); string cusId = Console.ReadLine(); while (ValidInput(cusId, "\\D")) { Console.WriteLine("Sorry, that was not a valid Id."); Console.Write("Please enter a positive integer: "); cusId = Console.ReadLine(); } Customer cus = new Customer(cusName, Convert.ToInt32(cusId)); StoreContext context = new StoreContext(); DbRepo repo = new DbRepo(context); Customer customerIdCheck = repo.GetCustomerById(Convert.ToInt32(cusId)); if (customerIdCheck != null && ValidInput(newCus, "1")) { return(new Customer("", -2)); } if (customerIdCheck != null && ValidInput(newCus, "0")) { return(customerIdCheck); } return(cus); }
public Employee LogIn() { //ask user for employee details or quit Console.WriteLine("Welcome Employee! Would you like to:"); Console.WriteLine("[0] Log in \n[1]New Employee"); Console.WriteLine("[Any other key] Quit"); string newEmp = Console.ReadLine(); if (!ValidInput(newEmp, "0|1")) { return(new Employee("", -1)); } //exit if employee wants to quit Console.Clear(); Console.Write("Please enter your Name: "); string empName = Console.ReadLine(); Console.Write("Please enter your numeric Id: "); string empId = Console.ReadLine(); while (ValidInput(empId, "\\D")) { Console.WriteLine("Sorry, that was not a valid Id."); Console.Write("Please enter a positive integer: "); empId = Console.ReadLine(); } Employee emp = new Employee(empName, Convert.ToInt32(empId)); StoreContext context = new StoreContext(); DbRepo repo = new DbRepo(context); Employee employeeIdCheck = repo.GetEmployeeById(Convert.ToInt32(empId)); if (employeeIdCheck != null && ValidInput(newEmp, "1")) { return(new Employee("", -2)); } if (employeeIdCheck != null && ValidInput(newEmp, "0")) { return(employeeIdCheck); } return(emp); }
public void InventoryUi(DbRepo repo) { // retrieve info from database and print to console LocationTasks lt = new LocationTasks(repo); string address; string proceed; List <Product> inventory; List <Location> locations = lt.GetAllLocations(); Location validAddress; do { Console.WriteLine("Please enter a valid location address:"); address = Console.ReadLine(); validAddress = lt.GetLocationByAddress(address); if (locations.Contains(validAddress)) { proceed = "0"; } else { Console.WriteLine("Sorry, please enter either a valid location address or [1] to quit"); proceed = Console.ReadLine(); } } while (!ValidInput(proceed, "0|1")); if (ValidInput(proceed, "1")) { return; } inventory = validAddress.Inventory; Console.WriteLine($"Our Location at {validAddress.Address} has the following inventory:"); foreach (Product p in inventory) { Console.WriteLine($"{p.Name} with {p.Stock} in stock"); } }
public void TransactionEventListenerTest() { var repo = new DbRepo(); var actionName = "foo"; var task = new Task <bool>(() => { return(repo.HasTransaction()); }); repo.AddActionListener(actionName, task); using (var tranScope = new TransactionScope()) { repo.ExecuteAction(actionName); Assert.IsFalse(task.IsCompleted); tranScope.Complete(); } Assert.IsTrue(task.IsCompleted); }
public void RestockUi(DbRepo repo, Product p) { // ask for product and restock ProductTasks pt = new ProductTasks(repo); EmployeeTasks et = new EmployeeTasks(repo); Product realProduct = new Product(); if (pt.GetProductById(p.Id).Equals(p.Id)) { } else { pt.AddProduct(p); } string id; string proceed = "0"; do { Console.WriteLine("Please enter a valid Product id"); id = Console.ReadLine(); while (ValidInput(id, "\\D")) { Console.WriteLine("Sorry, please enter a whole number!"); id = Console.ReadLine(); } realProduct = repo.GetProductById(Convert.ToInt32(id)); if (realProduct == null) { Console.WriteLine("Sorry, That id number was not valid!"); Console.WriteLine("Please select an option: \n[0] try again \n[any other key] quit"); } } while (ValidInput(proceed, "0")); et.RestockProductGlobal(realProduct); }
public void ShowOrderHistory(Customer c, DbRepo repo, List <Order> prev) { CustomerTasks ct = new CustomerTasks(repo); string sortBy; List <Order> orderHistory = prev; do { Console.WriteLine("Would you your order history sorted by [0] oldest or [1] newest?"); sortBy = Console.ReadLine(); } while (!ValidInput(sortBy, "0|1")); if (orderHistory.Equals(null)) { orderHistory = prev; } if (!ValidInput(sortBy, "0")) { orderHistory.Reverse(); } Console.WriteLine(orderHistory); int i = 0; foreach (var ord in orderHistory) { i++; Console.WriteLine("Goes into loop"); Console.WriteLine($"Order {i} cost ${ord.OrderPrice()} and contained the following:"); foreach (Product p in ord.Items) { Console.WriteLine($" {p.Name}"); } } }
public BookService() { _dbRepo = new DbRepo(); }
public void NoTransactionTest() { var repo = new DbRepo(); Assert.IsFalse(repo.HasTransaction()); }
public CartService() { _dbRepo = new DbRepo(); }
public AccountService() { _dbRepo = new DbRepo(); }
public override IDictionary <string, FileObject> Execute(DbRepo model) { return(model.Files); }
public HomeController(DbRepo repo) { _repo = repo; }
public ApiController(DbRepo repo) { _repo = repo; }
public void Start() { // first step: get info to create a customer object & check if that // customer is in the db string proceed = ""; Customer c; do { c = LogIn(); proceed = "4"; if (c.Id == -1) { Console.WriteLine("Quitting now."); return; } if (c.Id == -2) { Console.WriteLine("Sorry, that account is already claimed. Select an option to proceed"); Console.WriteLine("[0] Try Again"); Console.WriteLine("[1] Quit"); proceed = Console.ReadLine(); } } while (ValidInput(proceed, "0")); if (ValidInput(proceed, "1")) { Console.WriteLine("Quitting now."); return; } // Next Step: let customer make order and persist to db Console.WriteLine($"Hello {c.Name}! Here are Today's Products: "); Console.Write("Milk \nCheese \nIce Cream\n"); Console.WriteLine("Would you like to place an order? \n[0] Yes \n[1] No"); proceed = Console.ReadLine(); while (!ValidInput(proceed, "0|1")) { Console.WriteLine("Sorry, please enter 0 to proceed or 1 to quit"); proceed = Console.ReadLine(); } StoreContext context = new StoreContext(); DbRepo repo = new DbRepo(context); OrderTasks ot = new OrderTasks(repo); CustomerTasks ct = new CustomerTasks(repo); EmployeeTasks et = new EmployeeTasks(repo); LocationTasks lt = new LocationTasks(repo); ProductTasks pt = new ProductTasks(repo); List <Order> previousOH = new List <Order>(); if (c.Equals(repo.GetCustomerById(c.Id))) { previousOH = repo.GetCustomerById(c.Id).OrderHistory; repo.AddCustomer(c); } else { previousOH = repo.GetCustomerById(c.Id).OrderHistory; repo.RemoveCustomer((repo.GetCustomerById(c.Id))); repo.AddCustomer(c); } previousOH = c.OrderHistory; if (ValidInput(proceed, "0")) { Console.WriteLine("Time to place an order!"); Order newOrder = MakeOrder(); newOrder.Id = c.Id; Order emptyOrder = new Order(); if (newOrder.Equals(emptyOrder)) { Console.WriteLine("GoodBye"); return; } string confirm; double price = newOrder.OrderPrice(); Console.WriteLine($"That will be ${price}"); do { Console.WriteLine("Please Select [0] to pay now or [1] to cancel your order"); confirm = Console.ReadLine(); }while (!ValidInput(confirm, "0|1")); if (ValidInput(confirm, "0")) { c.AddOrderToHistory(newOrder); repo.UpdateCustomer(c); Console.WriteLine("Your order has been processed!"); } if (ValidInput(confirm, "1")) { Console.WriteLine("Your order has been cancelled. GoodBye."); } } //next step: Console.WriteLine("What would you like to do now?"); Console.WriteLine("[0] Check Order History \n[1]Check location inventory \n[3]Check product stock"); Console.WriteLine("[4] Quit"); string next = Console.ReadLine(); while (!ValidInput(next, "0|1|2|3")) { Console.WriteLine("Please select a valid option to continue"); Console.WriteLine("[0] Check Order History \n[1]Check location inventory"); Console.WriteLine("[2] Quit"); } if (ValidInput(next, "0")) { ShowOrderHistory(c, repo, previousOH); } if (ValidInput(next, "1")) { CheckInventory(repo); } if (ValidInput(next, "2")) { Console.WriteLine("Have a nice day! Goodbye!"); return; } }