patrick

patrick

  • NA
  • 422
  • 0

Binary stream access manager.

Jul 30 2009 10:25 AM
Here Is the code I am using: (I know the empty catches shouldnt be there)
public static void serializeAndStoreOrder(Order O)
{
List orderList = new List();
BinaryFormatter binaryFormatter = new BinaryFormatter();
try
{
using (FileStream fileStream = new FileStream(Properties.Settings.Default.OrdersLocation+"\\Orders.dat", FileMode.OpenOrCreate, FileAccess.Read))
{
if (fileStream.Length > 0)
{
orderList = (List)binaryFormatter.Deserialize(fileStream);
}
}
}
catch
{
}
orderList.Add(O);
try
{
using (FileStream fileStream = new FileStream(Properties.Settings.Default.OrdersLocation + "\\Orders.dat", FileMode.OpenOrCreate, FileAccess.Write))
{
binaryFormatter.Serialize(fileStream, orderList);
}
}
catch
{
}
}
public static Order retrieveOldOrder(int orderNumber)
{
Order O = new Order();
List orderList = new List(10);
BinaryFormatter binaryFormatter = new BinaryFormatter();
try
{
using (FileStream fileStream = new FileStream(Properties.Settings.Default.OrdersLocation + "\\Orders.dat", FileMode.OpenOrCreate, FileAccess.Read))
{
if (fileStream.Length > 0)
{
orderList = (List)binaryFormatter.Deserialize(fileStream);
}
}
}
catch
{
}
for (int i = 0; i < orderList.Count; i++)
{
if (orderList[i].OrderId == orderNumber)
{
O = orderList[i];
}
}
return O;
}


What I need is to make this code able to handle 2 or more computers accessing it at once, either by allowing an open connection or by retying until it can successfully add the order.