Esempio n. 1
0
        public static StockHandle CreateStockHandle( string companyName, string isin, string currency )
        {
            var company = new Company( companyName );
            var stock = new Stock( company, isin );
            var exchange = new StockExchange( "Xetra", "DE", new Currency( currency, currency ) );
            var tradedStock = new TradedStock( stock, exchange );

            return new StockHandle( tradedStock );
        }
Esempio n. 2
0
File: Stock.cs Progetto: bg0jr/Maui
        public Stock( Company company, string isin )
        {
            if ( company == null )
            {
                throw new ArgumentNullException( "company" );
            }

            Company = company;
            Isin = isin;
        }
Esempio n. 3
0
        protected void AddDummyStock(string isin)
        {
            var company = new Company( "C" );
            var stock = new Stock( company, isin );
            var exchange = new StockExchange( "Xetra", "De", new Currency( "Euro", "Euro" ) );
            var tradedStock = new TradedStock( stock, exchange );

            Interpreter.Context.Scope.Stock = new StockHandle( tradedStock );
        }
Esempio n. 4
0
 /// <summary>
 /// Create a new Company object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Company CreateCompany(global::System.Int64 id, global::System.String name)
 {
     Company company = new Company();
     company.Id = id;
     company.Name = name;
     return company;
 }
Esempio n. 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Companies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCompanies(Company company)
 {
     base.AddObject("Companies", company);
 }
Esempio n. 6
0
        // TODO: dublicate of Functions.Stocks.GetOrCreateStock() but we first need some
        // kind of protocol (for user and developer) before we can remove this code here
        public StockHandle Create( StockDescriptor stockDescriptor )
        {
            if ( stockDescriptor.Isin.IsNullOrTrimmedEmpty() )
            {
                throw new ArgumentException( "Isin not set" );
            }
            if ( stockDescriptor.StockExchange.IsNullOrTrimmedEmpty() )
            {
                throw new ArgumentException( "Stock exchange not set" );
            }

            myLogger.Notice( "Creating stock: {0}", stockDescriptor.Isin );

            using ( var tom = Engine.ServiceProvider.CreateEntityRepository() )
            {
                var tradedStock = tom.TradedStocks.FindTradedStockByDescription( stockDescriptor );
                if ( tradedStock != null )
                {
                    var sh = new StockHandle( tradedStock );

                    myLogger.Info( "Stock already exists: Company = {0},Isin = {1}, Symbol = {2}, Exchange = {3}",
                        sh.Company.Name, stockDescriptor.Isin, sh.TradedStock.Symbol, stockDescriptor.StockExchange );

                    return sh;
                }

                // TODO: this is somehow duplicate code from StockHandle.GetOrCreate - remove StockHandle.GetOrCreate

                // ok - so no traded stock available for the given description - but maybe a stock is already there?
                var stock = tom.Stocks.FirstOrDefault( s => s.Isin == stockDescriptor.Isin );
                if ( stock == null )
                {
                    var companyName = stockDescriptor.Name;
                    if ( companyName.IsNullOrTrimmedEmpty() )
                    {
                        companyName = DatumLocatorDefinitions.Standing.CompanyName.FetchSingle<string>( stockDescriptor.Isin ).Value;
                    }

                    // company name is not uniq enough so lets create a new one
                    var company = new Company( companyName );
                    stock = new Stock( company, stockDescriptor.Isin );
                }

                // we got a stock so lets create a traded stock - we already checked that there is none

                // but first we need a stockexchange
                var se = tom.StockExchanges.FindBySymbolOrName( stockDescriptor.StockExchange );
                if ( se == null )
                {
                    throw new InvalidOperationException( "Could not find StockExchange by symbol or name with: " + stockDescriptor.StockExchange );
                }

                var symbol = stockDescriptor.Symbol;
                if ( symbol.IsNullOrTrimmedEmpty() )
                {
                    symbol = DatumLocatorDefinitions.Standing.StockSymbol.FetchSingle<string>( stockDescriptor.Isin ).Value;
                }
                var wpkn = DatumLocatorDefinitions.Standing.Wpkn.FetchSingle<string>( stockDescriptor.Isin ).Value;

                tradedStock = new TradedStock( stock, se );
                tradedStock.Symbol = symbol;
                tradedStock.Wpkn = wpkn;

                tom.TradedStocks.AddObject( tradedStock );

                tom.SaveChanges();

                myLogger.Info( "Created stock with: Company = {0},Isin = {1}, Symbol = {2}, Exchange = {3}",
                    stock.Company.Name, stock.Isin, symbol, stockDescriptor.StockExchange );

                return new StockHandle( tradedStock );
            }
        }