示例#1
0
 public void Save(string filename)
 {
     try
     {
         WsgFileStream fs = null;
         try
         {
             fs = new WsgFileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);
             Save(FileVersion, fs);
             fs.Close();
         }
         catch (System.Exception ex)
         {
             if (fs != null)
             {
                 fs.Close();
             }
             throw ex;
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (string s in this.Keys)
                 {
                     fs.WriteString(s);
                     DepositContent content = null;
                     if (this.TryGetValue(s, out content))
                     {
                         content.Save(fv, fs);
                     }
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         Player currentplayer = null;
         if (fv.Major > 0)
         {
             int c = fs.ReadInt();
             for (int i = 0; i < c; i++)
             {
                 Player player = new Player(NextPlayerId, fv, fs, obj);
                 if (player.IsYou)
                 {
                     currentplayer = player;
                 }
                 this.Add(player);
             }
         }
         return(currentplayer);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteString(Id);
             fs.WriteString(Name);
             fs.WriteInt(StockIndexes.Count);
             if (StockIndexes.Count > 0)
             {
                 foreach (StockIndex stockindex in StockIndexes.Values)
                     fs.WriteString(stockindex.Id);
             }
             PriceHistory.Save(fv, fs);
             if (fv.Major > 0 && fv.Minor >= 1)
             {
                 fs.WriteDouble(MinPrice);
                 fs.WriteDouble(MaxPrice);
             }
             fs.WriteDouble(Price);
             fs.WriteInt(Available);
             fs.WriteInt(OwnedByPlayers);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             while (this.Count > 0)
             {
                 this.Clear();
             }
             int c = fs.ReadInt();
             if (c > 0)
             {
                 for (int i = 0; i < c; i++)
                 {
                     this.Add(fs.ReadDouble());
                 }
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public StockIndex(Version fv, WsgFileStream fs, System.Object obj) : base()
 {
     try
     {
         Stocks = new Stocks();
         Load(fv, fs, obj);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public Stock(Version fv, WsgFileStream fs, System.Object obj) : base()
 {
     try
     {
         StockIndexes = new StockIndexes();
         PriceHistory = new DoubleHistory();
         Load(fv, fs, obj);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#8
0
 public Player(int id, Version fv, WsgFileStream fs, System.Object obj) : base()
 {
     try
     {
         Id           = id;
         Deposit      = new Deposit(this, (Stocks)obj);
         ValueHistory = new DoubleHistory();
         Load(fv, fs, obj);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#9
0
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (BeforeSaveEvent != null)
         {
             BeforeSaveEvent();
         }
         if (fv.Major > 0)
         {
             while (PlayTimer.Enabled)
             {
                 PlayTimer.Stop();
             }
             fs.Seek(0, System.IO.SeekOrigin.Begin);
             FileVersion.Save(fv, fs);
             StockIndexes.Save(fv, fs);
             Stocks.Save(fv, fs);
             Players.Save(fv, fs);
             MarketState.Save(fv, fs);
             fs.Flush();
             FileName = fs.Name;
             while (!PlayTimer.Enabled)
             {
                 PlayTimer.Start();
             }
         }
         if (AfterSaveEvent != null)
         {
             AfterSaveEvent();
         }
         if (UpdateStockInformationsEvent != null)
         {
             UpdateStockInformationsEvent();
         }
         if (UpdatePlayerInformationsEvent != null)
         {
             UpdatePlayerInformationsEvent();
         }
     }
     catch (System.Exception ex)
     {
         while (!PlayTimer.Enabled)
         {
             PlayTimer.Start();
         }
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteString(Id);
             fs.WriteString(Name);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteByte(fv.Major);
             fs.WriteByte(fv.Minor);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             Id   = fs.ReadString();
             Name = fs.ReadString();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#13
0
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteInt((int)State);
             fs.WriteInt(Epochs);
             fs.WriteDouble(Brokerage);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteInt(Count);
             fs.WriteDouble(LastBuyPrice);
             fs.WriteDouble(LastSellPrice);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#15
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             Id = fs.ReadString();
             Name = fs.ReadString();
             int c = fs.ReadInt();
             if (c > 0)
             {
                 StockIndexes stockindexes = (StockIndexes) obj;
                 for (int i = 0; i < c; i++)
                 {
                     string id = fs.ReadString();
                     StockIndex stockindex = null;
                     if (stockindexes.TryGetValue(id, out stockindex))
                     {
                         stockindex.Stocks.Add(Id, this);
                         StockIndexes.Add(stockindex.Id, stockindex);
                     }
                 }
             }
             PriceHistory.Load(fv, fs, obj);
             if (fv.Major > 0 && fv.Minor >= 1)
             {
                 MinPrice = fs.ReadDouble();
                 MaxPrice = fs.ReadDouble();
             }
             else
             {
                 MinPrice = MIN_PRICE;
                 MaxPrice = MAX_PRICE;
             }
             Price = fs.ReadDouble();
             if (PriceHistory.Count > 0)
                 PriceHistory.RemoveAt(PriceHistory.Count - 1);
             Available = fs.ReadInt();
             OwnedByPlayers = fs.ReadInt();
         }
         return this;
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             Count         = fs.ReadInt();
             LastBuyPrice  = fs.ReadDouble();
             LastSellPrice = fs.ReadDouble();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#17
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             State     = (MarketStateType)fs.ReadInt();
             Epochs    = fs.ReadInt();
             Brokerage = fs.ReadDouble();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#18
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             int c = fs.ReadInt();
             for (int i = 0; i < c; i++)
             {
                 Stock stock = new Stock(fv, fs, obj);
                 this.Add(stock.Id, stock);
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#19
0
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteString(Company);
             fs.WriteString(Name);
             fs.WriteBool(IsComputer);
             fs.WriteBool(IsYou);
             Deposit.Save(fv, fs);
             ValueHistory.Save(fv, fs);
             fs.WriteDouble(Capital);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (double d in this)
                 {
                     fs.WriteDouble(d);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#21
0
 public void Save(Version fv, WsgFileStream fs)
 {
     try
     {
         if (fv.Major > 0)
         {
             fs.WriteInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (IStoreable s in this.Values)
                 {
                     s.Save(fv, fs);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#22
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             Company    = fs.ReadString();
             Name       = fs.ReadString();
             IsComputer = fs.ReadBool();
             IsYou      = fs.ReadBool();
             Deposit.Load(fv, fs, obj);
             ValueHistory.Load(fv, fs, obj);
             Capital = fs.ReadDouble();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             byte major = (byte)fs.ReadByte();
             byte minor = (byte)fs.ReadByte();
             if (major <= 0 || major > fv.Major || (major == fv.Major && minor > fv.Minor))
             {
                 throw new VersionNotSupportedException(new Version(major, minor), fv);
             }
             return(new Version(major, minor));
         }
         return(new Version(0, 0));
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#24
0
 public void Load(string filename)
 {
     try
     {
         WsgFileStream fs = null;
         try
         {
             fs = new WsgFileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None);
             Load(FileVersion, fs, null);
             fs.Close();
         }
         catch (VersionNotSupportedException ex)
         {
             if (fs != null)
             {
                 fs.Close();
             }
             throw ex;
         }
         catch (System.Exception ex)
         {
             if (fs != null)
             {
                 fs.Close();
             }
             throw ex;
         }
     }
     catch (System.NotSupportedException ex)
     {
         throw ex;
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (fv.Major > 0)
         {
             int c = fs.ReadInt();
             for (int i = 0; i < c; i++)
             {
                 string         s       = fs.ReadString();
                 DepositContent content = null;
                 if (this.TryGetValue(s, out content))
                 {
                     content.Load(fv, fs, obj);
                 }
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#26
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (BeforeLoadEvent != null)
         {
             BeforeLoadEvent();
         }
         if (fv.Major > 0)
         {
             while (PlayTimer.Enabled)
             {
                 PlayTimer.Stop();
             }
             fs.Seek(0, System.IO.SeekOrigin.Begin);
             Version loadedfv = (Version)FileVersion.Load(fv, fs, null);
             while (StockIndexes.Count > 0)
             {
                 StockIndexes.Clear();
             }
             while (Stocks.Count > 0)
             {
                 Stocks.Clear();
             }
             while (Players.Count > 0)
             {
                 Players.Clear();
             }
             MarketState.Reset(Random);
             CurrentPlayer = null;
             StockIndexes.Load(loadedfv, fs, null);
             Stocks.Load(loadedfv, fs, StockIndexes);
             CurrentPlayer = (Player)Players.Load(loadedfv, fs, Stocks);
             MarketState.Load(loadedfv, fs, null);
             FileName = fs.Name;
             while (!PlayTimer.Enabled)
             {
                 PlayTimer.Start();
             }
         }
         if (AfterLoadEvent != null)
         {
             AfterLoadEvent();
         }
         if (UpdateStockInformationsEvent != null)
         {
             UpdateStockInformationsEvent();
         }
         if (UpdatePlayerInformationsEvent != null)
         {
             UpdatePlayerInformationsEvent();
         }
         return(this);
     }
     catch (VersionNotSupportedException ex)
     {
         while (!PlayTimer.Enabled)
         {
             PlayTimer.Start();
         }
         throw ex;
     }
     catch (System.Exception ex)
     {
         while (!PlayTimer.Enabled)
         {
             PlayTimer.Start();
         }
         throw ex;
     }
 }