コード例 #1
0
 /// <summary>
 /// Wipes clean the bid, input, and output streams so that a re-launch of the application will not result in an exception
 /// </summary>
 /// <param name="state"></param>
 public static void ClearBidAndIoStreams(StreamStates state)
 {
     foreach (string filename in state.Filenames.Streams)
     {
         File.WriteAllText(filename, String.Empty);
     }
     File.WriteAllText(state.Filenames.ControlInput, String.Empty);
     File.WriteAllText(state.Filenames.ControlOutput, String.Empty);
 }
コード例 #2
0
 /// <summary>
 /// Replaces current history file with all the bids in the current bid streams
 /// </summary>
 /// <param name="state"></param>
 public static void SaveHistory(StreamStates state)
 {
     using (StreamWriter writer = new StreamWriter(state.Filenames.History, false))
     {
         writer.WriteLine(state.ListOfTodaysBids.Count);
         foreach (int bid in state.ListOfTodaysBids)
         {
             writer.WriteLine(bid);
         }
     }
 }
コード例 #3
0
ファイル: StreamStates.cs プロジェクト: clemmy/TSimulator
        /// <summary>
        /// Callback method for when control input is changed
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        //private void OnInputChanged(object source, FileSystemEventArgs e)
        //{
        //    try
        //    {
        //        _inputWatcher.EnableRaisingEvents = false;
        //        //code to read file here

        //        //this.ControlInputStream.UpdateCurrentCommand();
        //        Console.WriteLine("le change occurred");
        //    }

        //    finally
        //    {
        //        System.Threading.Thread.Sleep(300);
        //        _inputWatcher.EnableRaisingEvents = true;
        //    }
        //}

        /// <summary>
        /// Factory method that creates a streamStates object
        /// Expect streams to be empty
        /// </summary>
        /// <param name="filenames"></param>
        /// <returns></returns>
        public static StreamStates InitializeStreamStates(Filenames filenames)
        {
            var s = new StreamStates()
            {
                BidStreamModels  = new BidStreamModel[4],
                Filenames        = filenames,
                ListOfTodaysBids = new List <int>()
            };

            s.HistoryStream      = s.ReadHistoryFile(filenames.History);
            s.ListOfBids         = s.HistoryStream.Bids;
            s.ControlInputStream = new ControlInputModel();
            return(s);
        }
コード例 #4
0
ファイル: Simulator.cs プロジェクト: clemmy/TSimulator
        static void Main(string[] args)
        {
            try
            {
                var filenames = new Filenames();
                filenames.Initialize(args);

                OutputHelper.SetUpDefaults();

                var streamStates = StreamStates.InitializeStreamStates(filenames);
                //note control input watcher is on main thread, while other watchers are on separate threads
                streamStates.StartWatching();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error has occurred, with the following details: " + e.Message);
            }
        }