private void InitializeWithInventorydata(InventoryServerOptions options) { Task.Run(async() => { await UpdateQuantityAsync(options.InitialInventory, Options.InitialInventory.Quantity); //.TODO /* USE PROPER ASYNC AWAIT HERE */ await ReserveAsync(options.InitialInventory, Options.InitialInventory.Reserved); //.TODO /* USE PROPER ASYNC AWAIT HERE */ await PlaceHoldAsync(options.InitialInventory, Options.InitialInventory.Holds); //.TODO /* USE PROPER ASYNC AWAIT HERE */ var result = await GetInventoryAsync(Options.InitialInventory.ProductId); if (!result.Successful || result.RealTimeInventory == null || result.RealTimeInventory.ProductId != Options.InitialInventory.ProductId || result.RealTimeInventory.Quantity != Options.InitialInventory.Quantity || result.RealTimeInventory.Reserved != Options.InitialInventory.Reserved || result.RealTimeInventory.Holds != Options.InitialInventory.Holds) { throw new Exception("Error initializing data into remote inventory actor "); } }).Wait(); }
public InventoryServiceServer(IPerformanceService performanceService, IBackUpService backUpService, InventoryServerOptions options = null) { Options = options ?? new InventoryServerOptions(); if (Options.DontUseActorSystem) { DontUseActorSystem = Options.DontUseActorSystem; TestInventoryStorage = Options.StorageType != null ? (IInventoryStorage)Activator.CreateInstance(Options.StorageType) : new Storage.InMemoryLib.InMemory(); if (Options.InitialInventory != null) { TestInventoryStorage.WriteInventoryAsync(Options.InitialInventory); } } else { Sys = Options.ClientActorSystem; InventoryServiceApplication = new InventoryServiceApplication(); if (string.IsNullOrEmpty(Options.InventoryActorAddress)) { Options.InventoryActorAddress = ConfigurationManager.AppSettings["RemoteInventoryActorAddress"]; } InventoryServiceApplication.Start(performanceService, backUpService, Options.OnInventoryActorSystemReady, Options.StorageType, serverEndPoint: Options.ServerEndPoint, serverActorSystemName: Options.ServerActorSystemName, serverActorSystem: Options.ServerActorSystem, serverActorSystemConfig: Options.ServerActorSystemConfig); Sys = Sys ?? InventoryServiceApplication.InventoryServiceServerApp.ActorSystem; var selection = Sys.ActorSelection(Options.InventoryActorAddress); inventoryActor = TryResolveActorSelection(selection); var serverEndPoint = Options.ServerEndPoint;//ConfigurationManager.AppSettings["ServerEndPoint"]; if (!string.IsNullOrEmpty(serverEndPoint)) { OwinRef = WebApp.Start <Startup>(url: serverEndPoint); } if (Options.InitialInventory != null) { InitializeWithInventorydata(Options); } } }