The base class to implements to create a .NetTiers provider.
Inheritance: NetTiersProviderBase
Ejemplo n.º 1
0
		/// <summary>
        /// Enables the DataRepository to programatically create and 
        /// pass in a <c>NetTiersProvider</c> during runtime.
        /// </summary>
        /// <param name="provider">An instatiated NetTiersProvider.</param>
        /// <param name="setAsDefault">ability to set any valid provider as the default provider for the DataRepository.</param>
		public static void LoadProvider(NetTiersProvider provider, bool setAsDefault)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            if (_providers == null)
			{
				lock(SyncRoot)
				{
            		if (_providers == null)
						_providers = new NetTiersProviderCollection();
				}
			}
			
            if (_providers[provider.Name] == null)
            {
                lock (_providers.SyncRoot)
                {
                    _providers.Add(provider);
                }
            }

            if (_provider == null || setAsDefault)
            {
                lock (SyncRoot)
                {
                    if(_provider == null || setAsDefault)
                         _provider = provider;
                }
            }
        }
		/// <summary>
	    /// Adds the specified provider.
	    /// </summary>
	    /// <param name="provider">The provider.</param>
	    public void Add(NetTiersProvider provider)
	    {
	        if (provider == null)
	        {
	            throw new ArgumentNullException("provider");
	        }
	        if (!(provider is NetTiersProvider))
	        {
	            throw new ArgumentException("Invalid provider type", "provider");
	        }
	        base.Add(provider);
	    }
        /// <summary>
        /// Fill a TList&lt;Inventory&gt; From a DataReader.
        /// </summary>
        /// <param name="reader">Datareader</param>
        /// <param name="rows">The collection to fill</param>
        /// <param name="start">Row number at which to start reading, the first row is 0.</param>
        /// <param name="pageLength">number of rows.</param>
        /// <returns>a <see cref="TList&lt;Inventory&gt;"/></returns>
        public static TList <Inventory> Fill(IDataReader reader, TList <Inventory> rows, int start, int pageLength)
        {
            NetTiersProvider currentProvider           = DataRepository.Provider;
            bool             useEntityFactory          = currentProvider.UseEntityFactory;
            bool             enableEntityTracking      = currentProvider.EnableEntityTracking;
            LoadPolicy       currentLoadPolicy         = currentProvider.CurrentLoadPolicy;
            Type             entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;

            // advance to the starting row
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                {
                    return(rows);            // not enough rows, just return
                }
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                {
                    break;                     // we are done
                }
                string key = null;

                PetShop.Business.Inventory c = null;
                if (useEntityFactory)
                {
                    key = new System.Text.StringBuilder("Inventory")
                          .Append("|").Append((string)reader[((int)InventoryColumn.ItemId - 1)]).ToString();
                    c = EntityManager.LocateOrCreate <Inventory>(
                        key.ToString(),               // EntityTrackingKey
                        "Inventory",                  //Creational Type
                        entityCreationFactoryType,    //Factory used to create entity
                        enableEntityTracking);        // Track this entity?
                }
                else
                {
                    c = new PetShop.Business.Inventory();
                }

                if (!enableEntityTracking ||
                    c.EntityState == EntityState.Added ||
                    (enableEntityTracking &&

                     (
                         (currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
                         (currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
                     )
                    ))
                {
                    c.SuppressEntityEvents = true;
                    c.ItemId            = (string)reader[((int)InventoryColumn.ItemId - 1)];
                    c.OriginalItemId    = c.ItemId;
                    c.Qty               = (int)reader[((int)InventoryColumn.Qty - 1)];
                    c.EntityTrackingKey = key;
                    c.AcceptChanges();
                    c.SuppressEntityEvents = false;
                }
                rows.Add(c);
            }
            return(rows);
        }
        /// <summary>
        /// Fill a TList&lt;Account&gt; From a DataReader.
        /// </summary>
        /// <param name="reader">Datareader</param>
        /// <param name="rows">The collection to fill</param>
        /// <param name="start">Row number at which to start reading, the first row is 0.</param>
        /// <param name="pageLength">number of rows.</param>
        /// <returns>a <see cref="TList&lt;Account&gt;"/></returns>
        public static TList <Account> Fill(IDataReader reader, TList <Account> rows, int start, int pageLength)
        {
            NetTiersProvider currentProvider           = DataRepository.Provider;
            bool             useEntityFactory          = currentProvider.UseEntityFactory;
            bool             enableEntityTracking      = currentProvider.EnableEntityTracking;
            LoadPolicy       currentLoadPolicy         = currentProvider.CurrentLoadPolicy;
            Type             entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;

            // advance to the starting row
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                {
                    return(rows);            // not enough rows, just return
                }
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                {
                    break;                     // we are done
                }
                string key = null;

                PetShop.Business.Account c = null;
                if (useEntityFactory)
                {
                    key = new System.Text.StringBuilder("Account")
                          .Append("|").Append((int)reader[((int)AccountColumn.AccountId - 1)]).ToString();
                    c = EntityManager.LocateOrCreate <Account>(
                        key.ToString(),             // EntityTrackingKey
                        "Account",                  //Creational Type
                        entityCreationFactoryType,  //Factory used to create entity
                        enableEntityTracking);      // Track this entity?
                }
                else
                {
                    c = new PetShop.Business.Account();
                }

                if (!enableEntityTracking ||
                    c.EntityState == EntityState.Added ||
                    (enableEntityTracking &&

                     (
                         (currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
                         (currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
                     )
                    ))
                {
                    c.SuppressEntityEvents = true;
                    c.AccountId            = (int)reader[((int)AccountColumn.AccountId - 1)];
                    c.UniqueId             = (int)reader[((int)AccountColumn.UniqueId - 1)];
                    c.Email             = (string)reader[((int)AccountColumn.Email - 1)];
                    c.FirstName         = (string)reader[((int)AccountColumn.FirstName - 1)];
                    c.LastName          = (string)reader[((int)AccountColumn.LastName - 1)];
                    c.Address1          = (string)reader[((int)AccountColumn.Address1 - 1)];
                    c.Address2          = (reader.IsDBNull(((int)AccountColumn.Address2 - 1)))?null:(string)reader[((int)AccountColumn.Address2 - 1)];
                    c.City              = (string)reader[((int)AccountColumn.City - 1)];
                    c.State             = (string)reader[((int)AccountColumn.State - 1)];
                    c.Zip               = (string)reader[((int)AccountColumn.Zip - 1)];
                    c.Country           = (string)reader[((int)AccountColumn.Country - 1)];
                    c.Phone             = (reader.IsDBNull(((int)AccountColumn.Phone - 1)))?null:(string)reader[((int)AccountColumn.Phone - 1)];
                    c.EntityTrackingKey = key;
                    c.AcceptChanges();
                    c.SuppressEntityEvents = false;
                }
                rows.Add(c);
            }
            return(rows);
        }
        /// <summary>
        /// Fill a TList&lt;Profiles&gt; From a DataReader.
        /// </summary>
        /// <param name="reader">Datareader</param>
        /// <param name="rows">The collection to fill</param>
        /// <param name="start">Row number at which to start reading, the first row is 0.</param>
        /// <param name="pageLength">number of rows.</param>
        /// <returns>a <see cref="TList&lt;Profiles&gt;"/></returns>
        public static TList <Profiles> Fill(IDataReader reader, TList <Profiles> rows, int start, int pageLength)
        {
            NetTiersProvider currentProvider           = DataRepository.Provider;
            bool             useEntityFactory          = currentProvider.UseEntityFactory;
            bool             enableEntityTracking      = currentProvider.EnableEntityTracking;
            LoadPolicy       currentLoadPolicy         = currentProvider.CurrentLoadPolicy;
            Type             entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;

            // advance to the starting row
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                {
                    return(rows);            // not enough rows, just return
                }
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                {
                    break;                     // we are done
                }
                string key = null;

                PetShop.Business.Profiles c = null;
                if (useEntityFactory)
                {
                    key = new System.Text.StringBuilder("Profiles")
                          .Append("|").Append((System.Int32)reader[((int)ProfilesColumn.UniqueId - 1)]).ToString();
                    c = EntityManager.LocateOrCreate <Profiles>(
                        key.ToString(),              // EntityTrackingKey
                        "Profiles",                  //Creational Type
                        entityCreationFactoryType,   //Factory used to create entity
                        enableEntityTracking);       // Track this entity?
                }
                else
                {
                    c = new PetShop.Business.Profiles();
                }

                if (!enableEntityTracking ||
                    c.EntityState == EntityState.Added ||
                    (enableEntityTracking &&

                     (
                         (currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
                         (currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
                     )
                    ))
                {
                    c.SuppressEntityEvents = true;
                    c.UniqueId             = (System.Int32)reader[((int)ProfilesColumn.UniqueId - 1)];
                    c.Username             = (System.String)reader[((int)ProfilesColumn.Username - 1)];
                    c.ApplicationName      = (System.String)reader[((int)ProfilesColumn.ApplicationName - 1)];
                    c.IsAnonymous          = (reader.IsDBNull(((int)ProfilesColumn.IsAnonymous - 1)))?null:(System.Boolean?)reader[((int)ProfilesColumn.IsAnonymous - 1)];
                    c.LastActivityDate     = (reader.IsDBNull(((int)ProfilesColumn.LastActivityDate - 1)))?null:(System.DateTime?)reader[((int)ProfilesColumn.LastActivityDate - 1)];
                    c.LastUpdatedDate      = (reader.IsDBNull(((int)ProfilesColumn.LastUpdatedDate - 1)))?null:(System.DateTime?)reader[((int)ProfilesColumn.LastUpdatedDate - 1)];
                    c.EntityTrackingKey    = key;
                    c.AcceptChanges();
                    c.SuppressEntityEvents = false;
                }
                rows.Add(c);
            }
            return(rows);
        }
        /// <summary>
        /// Fill a TList&lt;Order&gt; From a DataReader.
        /// </summary>
        /// <param name="reader">Datareader</param>
        /// <param name="rows">The collection to fill</param>
        /// <param name="start">Row number at which to start reading, the first row is 0.</param>
        /// <param name="pageLength">number of rows.</param>
        /// <returns>a <see cref="TList&lt;Order&gt;"/></returns>
        public static TList <Order> Fill(IDataReader reader, TList <Order> rows, int start, int pageLength)
        {
            NetTiersProvider currentProvider           = DataRepository.Provider;
            bool             useEntityFactory          = currentProvider.UseEntityFactory;
            bool             enableEntityTracking      = currentProvider.EnableEntityTracking;
            LoadPolicy       currentLoadPolicy         = currentProvider.CurrentLoadPolicy;
            Type             entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;

            // advance to the starting row
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                {
                    return(rows);            // not enough rows, just return
                }
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                {
                    break;                     // we are done
                }
                string key = null;

                PetShop.Business.Order c = null;
                if (useEntityFactory)
                {
                    key = new System.Text.StringBuilder("Order")
                          .Append("|").Append((int)reader[((int)OrderColumn.OrderId - 1)]).ToString();
                    c = EntityManager.LocateOrCreate <Order>(
                        key.ToString(),            // EntityTrackingKey
                        "Order",                   //Creational Type
                        entityCreationFactoryType, //Factory used to create entity
                        enableEntityTracking);     // Track this entity?
                }
                else
                {
                    c = new PetShop.Business.Order();
                }

                if (!enableEntityTracking ||
                    c.EntityState == EntityState.Added ||
                    (enableEntityTracking &&

                     (
                         (currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
                         (currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
                     )
                    ))
                {
                    c.SuppressEntityEvents = true;
                    c.OrderId             = (int)reader[((int)OrderColumn.OrderId - 1)];
                    c.UserId              = (string)reader[((int)OrderColumn.UserId - 1)];
                    c.OrderDate           = (System.DateTime)reader[((int)OrderColumn.OrderDate - 1)];
                    c.ShipAddr1           = (string)reader[((int)OrderColumn.ShipAddr1 - 1)];
                    c.ShipAddr2           = (reader.IsDBNull(((int)OrderColumn.ShipAddr2 - 1)))?null:(string)reader[((int)OrderColumn.ShipAddr2 - 1)];
                    c.ShipCity            = (string)reader[((int)OrderColumn.ShipCity - 1)];
                    c.ShipState           = (string)reader[((int)OrderColumn.ShipState - 1)];
                    c.ShipZip             = (string)reader[((int)OrderColumn.ShipZip - 1)];
                    c.ShipCountry         = (string)reader[((int)OrderColumn.ShipCountry - 1)];
                    c.BillAddr1           = (string)reader[((int)OrderColumn.BillAddr1 - 1)];
                    c.BillAddr2           = (reader.IsDBNull(((int)OrderColumn.BillAddr2 - 1)))?null:(string)reader[((int)OrderColumn.BillAddr2 - 1)];
                    c.BillCity            = (string)reader[((int)OrderColumn.BillCity - 1)];
                    c.BillState           = (string)reader[((int)OrderColumn.BillState - 1)];
                    c.BillZip             = (string)reader[((int)OrderColumn.BillZip - 1)];
                    c.BillCountry         = (string)reader[((int)OrderColumn.BillCountry - 1)];
                    c.Courier             = (string)reader[((int)OrderColumn.Courier - 1)];
                    c.TotalPrice          = (decimal)reader[((int)OrderColumn.TotalPrice - 1)];
                    c.BillToFirstName     = (string)reader[((int)OrderColumn.BillToFirstName - 1)];
                    c.BillToLastName      = (string)reader[((int)OrderColumn.BillToLastName - 1)];
                    c.ShipToFirstName     = (string)reader[((int)OrderColumn.ShipToFirstName - 1)];
                    c.ShipToLastName      = (string)reader[((int)OrderColumn.ShipToLastName - 1)];
                    c.AuthorizationNumber = (int)reader[((int)OrderColumn.AuthorizationNumber - 1)];
                    c.Locale              = (string)reader[((int)OrderColumn.Locale - 1)];
                    c.EntityTrackingKey   = key;
                    c.AcceptChanges();
                    c.SuppressEntityEvents = false;
                }
                rows.Add(c);
            }
            return(rows);
        }
Ejemplo n.º 7
0
		///<summary>
		/// Configuration based provider loading, will load the providers on first call.
		///</summary>
		private static void LoadProviders()
        {
            // Avoid claiming lock if providers are already loaded
            if (_provider == null)
            {
                lock (SyncRoot)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Load registered providers and point _provider to the default provider
                        _providers = new NetTiersProviderCollection();

                        ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider));
						_provider = _providers[NetTiersSection.DefaultProvider];

                        if (_provider == null)
                        {
                            throw new ProviderException("Unable to load default NetTiersProvider");
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
		/// <summary>
        /// Enables the DataRepository to programatically create and 
        /// pass in a <c>NetTiersProvider</c> during runtime.
        /// </summary>
        /// <param name="provider">An instatiated NetTiersProvider.</param>
        public static void LoadProvider(NetTiersProvider provider)
        {
			LoadProvider(provider, false);
        }
Ejemplo n.º 9
0
			/// <summary>
			/// Instantiates the configured providers based on the supplied connection string.
			/// </summary>
			private void LoadProviders()
			{
				DataRepository.LoadProviders();

				// Avoid claiming lock if providers are already loaded
				if ( _providers == null )
				{
					lock ( SyncRoot )
					{
						// Do this again to make sure _provider is still null
						if ( _providers == null )
						{
							// apply connection information to each provider
							for ( int i = 0; i < NetTiersSection.Providers.Count; i++ )
							{
								NetTiersSection.Providers[i].Parameters["connectionStringName"] = _connectionStringName;
								// remove previous connection string, if any
								NetTiersSection.Providers[i].Parameters.Remove("connectionString");

								if ( !String.IsNullOrEmpty(_connectionString) )
								{
									NetTiersSection.Providers[i].Parameters["connectionString"] = _connectionString;
								}
							}

							// Load registered providers and point _provider to the default provider
							_providers = new NetTiersProviderCollection();

							ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider));
							_provider = _providers[NetTiersSection.DefaultProvider];
						}
					}
				}
			}