public int CreateReserve(Good[] itemIDAndCount) { int result = -1; lock (_lock) { Console.WriteLine("\nCreateReserve:"); bool allAvailable = true; for (int i = 0, count = itemIDAndCount.Length; i < count; ++i) { int id = itemIDAndCount[i].ItemID; int request = itemIDAndCount[i].Count; Good tmp; int available = 0; bool exists = GoodsContainer.GoodsDictionary.TryGetValue(id, out tmp); if (exists) { available = tmp.Count; } else { allAvailable = false; } Console.WriteLine(" {0}) itemID={1} request={2} available={3}", (i + 1), id, request, available); if (available < request) { allAvailable = false; break; } } if (allAvailable) { for (int i = 0, count = itemIDAndCount.Length; i < count; ++i) { Good g = GoodsContainer.GoodsDictionary[itemIDAndCount[i].ItemID]; //g.Count -= itemIDAndCount[i].Count; GoodsContainer.GoodsDictionary[itemIDAndCount[i].ItemID] = g; } result = itemIDAndCount.Length; } else { result = 0; } Console.WriteLine(" result={0}\n", result); } return result; }
static void Main(string[] args) { string[] lines = null; try { lines = File.ReadAllLines("settings.txt"); } catch (Exception e) { lines = new string[0]; } if (2 < lines.Length) { IDictionary props = new Hashtable(); props["name"] = lines[0]; props["port"] = Convert.ToInt32(lines[1]); Console.WriteLine(" port={0}", lines[1]); int count = lines.Length - 2; Good[] goods = new Good[count]; for (int i = 0; i < count; ++i) { string[] parts = lines[i + 2].Split(' '); goods[i].ItemID = Convert.ToInt32(parts[0]); goods[i].Count = Convert.ToInt32(parts[1]); Console.WriteLine(" {0}) itemID={1} count={2}", (i + 1), goods[i].ItemID, goods[i].Count); } GoodsContainer.Goods = goods; HttpChannel channel = new HttpChannel(props, null, new XmlRpcServerFormatterSinkProvider()); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(SupplyRequest), "SupplierSystem.RPC", WellKnownObjectMode.Singleton); } else { Console.WriteLine("ERROR: \"settings.txt\" file not found"); } Console.WriteLine("Press <ENTER> to shutdown"); Console.ReadLine(); }
public bool CanselReserve(int reserveID) { string[] lines = File.ReadAllLines("settings.txt"); int count = lines.Length - 2; Good[] goods = new Good[count]; for (int i = 0; i < count; ++i) { string[] parts = lines[i + 2].Split(' '); goods[i].ItemID = Convert.ToInt32(parts[0]); goods[i].Count = Convert.ToInt32(parts[1]); Console.WriteLine(" {0}) itemID={1} count={2}", (i + 1), goods[i].ItemID, goods[i].Count); } GoodsContainer.Goods = goods; return true; }