Пример #1
0
        public static DatumOrigin GetOrCreate(this IObjectSet <DatumOrigin> origins, string name)
        {
            var origin = origins.FirstOrDefault(o => o.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (origin != null)
            {
                return(origin);
            }

            origin = new DatumOrigin(name);
            origins.AddObject(origin);

            return(origin);
        }
Пример #2
0
        /// <summary>
        /// Imports the given result into TOM.
        /// </summary>
        public static void Import( this MauiX.IImport self, StockHandle stock, IResultPolicy result )
        {
            using ( var tom = Engine.ServiceProvider.CreateEntityRepository() )
            {
                var originName = result.Sites.First().Name;
                var origin = tom.DatumOrigins.FirstOrDefault( o => o.Name == originName );
                if ( origin == null )
                {
                    origin = new DatumOrigin( originName );
                    tom.DatumOrigins.AddObject( origin );
                    tom.SaveChanges();
                }

                var currencyName = result.Sites.First().Content.Currency;
                var currency = tom.Currencies.FirstOrDefault( c => c.Name == currencyName );

                MauiX.Import.Import( stock, result.ResultTable, origin, currency );
            }
        }
Пример #3
0
        /// <summary>
        /// Imports the given table into TOM.
        /// <remarks>
        /// The values of the table belong to the given origin and the given currency.
        /// All rows are owned by the given stock. The table name identifies the datum
        /// (and so the target table).
        /// </remarks>
        /// </summary>
        public static void Import( this MauiX.IImport self, StockHandle stock, DataTable table, DatumOrigin origin, Maui.Entities.Currency currency )
        {
            // XXX: how to handle origin and currency if we allow "merged results"?
            //  then we actually already need to enrich the result table from the policy
            //  with origin and currency ...

            var tomScripting = Engine.ServiceProvider.TomScripting();

            var datum = table.TableName;

            using ( TransactionScope trans = new TransactionScope() )
            {
                // we have a datum so we need the table now
                var mgr = tomScripting.GetManager( datum );
                if ( mgr == null )
                {
                    throw new Exception( "No table found for datum: " + datum );
                }

                // get scoped data for owner id
                long ownerId = stock.GetId( mgr.Schema.OwnerIdColumn );
                ScopedTable output = mgr.Query( ownerId );

                var resultColumns = table.Columns.ToSet();
                var dateCol = resultColumns.FirstOrDefault( c => c.IsDateColumn() );

                // setting date and values depend on the format
                Action<DataRow, DataRow> SetValues = null;
                // default date setter: assume there is no date
                Action<DataRow, DataRow> SetDate = ( dest, src ) => { };
                if ( dateCol != null )
                {
                    SetDate = ( dest, src ) => dest.SetDate( mgr.Schema, src.GetDate( dateCol.ColumnName ) );
                }

                var datumCols = output.Schema.DatumColumns
                    .Where( col => resultColumns.Any( c => c.ColumnName.Equals( col.ColumnName, StringComparison.OrdinalIgnoreCase ) ) );
                SetValues = ( dest, src ) =>
                {
                    foreach ( var col in datumCols )
                    {
                        dest[ col.ColumnName ] = src[ col.ColumnName ];
                    }
                };

                // ok - now import the data

                DateIdCache<long> cache = new DateIdCache<long>();
                if ( output.Schema.DateColumn != null )
                {
                    cache.Fill( output );
                }

                foreach ( DataRow row in table.Rows )
                {
                    var newRow = output.NewRow();

                    // set owner id
                    newRow[ output.Schema.OwnerIdColumn ] = ownerId;

                    // a "datum" always need a date
                    SetDate( newRow, row );

                    // set values
                    SetValues( newRow, row );

                    // set currency (the value is of no use when there is no currency)
                    // -> currency might implicitly available through TradedStock->StockExchange
                    if ( output.Schema.CurrencyColumn != null )
                    {
                        newRow[ output.Schema.CurrencyColumn ] = currency.Id;
                    }

                    // set origin (optional)
                    if ( output.Schema.OriginColumn != null )
                    {
                        newRow[ output.Schema.OriginColumn ] = origin.Id;
                    }

                    if ( output.Schema.DateColumn != null && cache.Contains( newRow.GetDate( output.Schema ) ) )
                    {
                        long id = cache[ newRow.GetDate( output.Schema ) ];
                        output.Update( id, newRow );
                    }
                    else
                    {
                        output.Add( newRow );
                    }
                }

                trans.Complete();
            }
        }
Пример #4
0
        private static IEnumerable<DatumOrigin> GetOrCreate( params string[] names )
        {
            using ( var tom = Engine.ServiceProvider.CreateEntityRepository() )
            {
                foreach ( var name in names )
                {
                    var origin = tom.DatumOrigins.FirstOrDefault( o => o.Name == name );
                    if ( origin == null )
                    {
                        origin = new DatumOrigin( name );
                        tom.DatumOrigins.AddObject( origin );
                    }

                    yield return origin;
                }
                tom.SaveChanges();
            }
        }
Пример #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the DatumOrigins EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDatumOrigins(DatumOrigin datumOrigin)
 {
     base.AddObject("DatumOrigins", datumOrigin);
 }
Пример #6
0
 /// <summary>
 /// Create a new DatumOrigin object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static DatumOrigin CreateDatumOrigin(global::System.Int64 id, global::System.String name)
 {
     DatumOrigin datumOrigin = new DatumOrigin();
     datumOrigin.Id = id;
     datumOrigin.Name = name;
     return datumOrigin;
 }