Beispiel #1
0
        /// <summary>
        /// The main entry point for the application
        /// </summary>
        /// <param name="args">Arguments passed at start up</param>
        private static void Main(string[] args)
        {
            System.Console.Title = "Stock Bandit Console";

            Log.Info("*********** Stock Bandit Server Console Started ***********");
            Log.InfoFormat("Service Version: {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString(4));
            Log.InfoFormat("Running on {0} ({1})", System.Environment.MachineName, System.Environment.OSVersion.VersionString);

            string cmd = string.Empty;

            // Create controller for instantiating the server
            ConfigurationController configurationController = new ConfigurationController();
            StockServer             server = configurationController.SetupServer(new LogQueue(1000));

            if (server == null)
            {
                System.Console.WriteLine("********** Console cannot be started due to these errors: ************");
                foreach (string errorMessage in configurationController.ErrorMessages)
                {
                    System.Console.WriteLine("{0} - {1}", DateTime.Now.ToString("HH:mm:ss.fff"), errorMessage);
                }
                System.Console.ReadLine();
                return;
            }

            if (server.StartServer())
            {
                // Server has started successfully
                Log.Info("**************** Server Started ********************");

                // Send an email for compliance sites
                server.SendStartedEmail();

                cmd = System.Console.ReadLine();
                while (cmd.ToUpper() != "QUIT")
                {
                    switch (cmd.ToUpper())
                    {
                    case "EVALUATE":
                        server.PriceFetchTimerElapsed(null);
                        break;

                    default:
                        System.Console.WriteLine(string.Format("Unrecognised command - {0}", cmd.ToUpper()));
                        break;
                    }

                    cmd = System.Console.ReadLine();
                }

                Log.Info("**************** Stopping Server ********************");
                server.StopServer();
                Log.Info("**************** Server Stopped ********************");
            }
            else
            {
                System.Console.WriteLine("Server failed to start - press ENTER to close");
                System.Console.ReadLine();
            }
        }
 public AbstractYahooMarketServer(Country country)
 {
     this.country = country;
     this.stockServer = getStockServer(country);
     /* Hack on Malaysia Market! The format among Yahoo and CIMB are difference. */
     if (country == Country.Malaysia)
     {
         List<Index> tmp = new List<Index>();
         foreach (Index index in Utils.getStockIndices(country))
         {
             if (IndexHelper.Instance().GetIndexCode(index).toString().StartsWith("^"))
             {
                 tmp.Add(index);
             }
         }
         this.indicies = tmp;
     }
     else
     {
         this.indicies = Utils.getStockIndices(country);
     }
     if (this.indicies.Count == 0)
     {
         throw new ArgumentException(country.ToString());
     }
     foreach (Index index in indicies)
     {
         Code curCode = IndexHelper.Instance().GetIndexCode(index);
         codes.Add(curCode);
         codeToIndexMap.Add(curCode, index);
     }
 }
Beispiel #3
0
 public AbstractYahooMarketServer(Country country)
 {
     this.country     = country;
     this.stockServer = getStockServer(country);
     /* Hack on Malaysia Market! The format among Yahoo and CIMB are difference. */
     if (country == Country.Malaysia)
     {
         List <Index> tmp = new List <Index>();
         foreach (Index index in Utils.getStockIndices(country))
         {
             if (IndexHelper.Instance().GetIndexCode(index).toString().StartsWith("^"))
             {
                 tmp.Add(index);
             }
         }
         this.indicies = tmp;
     }
     else
     {
         this.indicies = Utils.getStockIndices(country);
     }
     if (this.indicies.Count == 0)
     {
         throw new ArgumentException(country.ToString());
     }
     foreach (Index index in indicies)
     {
         Code curCode = IndexHelper.Instance().GetIndexCode(index);
         codes.Add(curCode);
         codeToIndexMap.Add(curCode, index);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Initiates everything required for the service
        /// </summary>
        private void DoStart()
        {
            try
            {
                this.WriteLogHeader();

                this.stockServer = this.configurationController.SetupServer(new LogQueue(1000));
                if (this.stockServer == null)
                {
                    this.Stop();
                    return;
                }

                Log.Info("Attempting to start server");
                if (!this.stockServer.StartServer())
                {
                    Log.Error("Server failed to start");
                    this.Stop();
                    return;
                }

                // Server is now running.
                Log.Info("**************** Server Started ********************");

                // Send a started email
                this.stockServer.SendStartedEmail();
            }
            catch (Exception ex)
            {
                Log.Error("Error occurred in service", ex);
                this.Stop();
                return;
            }
        }
Beispiel #5
0
        /// <summary>
        /// The start method of the service
        /// </summary>
        /// <param name="args">Arguments passed at start up</param>
        protected override void OnStart(string[] args)
        {
            this.configurationController = new ConfigurationController();
            this.stockServer             = null;

            ThreadStart mainThreadStart = new ThreadStart(this.DoStart);

            this.mainThread = new Thread(mainThreadStart);
            this.mainThread.Start();
            this.mainThread.Join();
        }
        public StockQuote GetStockQuote(string symbol)
        {
            var stocks = new StockServer();
            var quote  = stocks.GetStockQuote(symbol);

            if (quote == null)
            {
                throw new ArgumentException("Invalid symbol passed.");
            }

            return(quote);
        }
 private YahooStockServerFactory(Country country)
 {
     this.country = country;
     stockServer = new YahooStockServer(country);
     marketServer = new YahooMarketServer(country);
 }