예제 #1
0
        /// <summary>
        /// Return an instance as appropriate for this instance of the given factory.
        /// </summary>
        /// <param name="factoryInstance">FactoryInstance used to retrieve the object instance.</param>
        /// <returns>The Object instance to use for the given operation for the current destination.</returns>
		public object Lookup(FactoryInstance factoryInstance)
		{
			DotNetFactoryInstance dotNetFactoryInstance = factoryInstance as DotNetFactoryInstance;
			switch(dotNetFactoryInstance.Scope)
			{
                case FactoryInstance.ApplicationScope:
                    {
                        object instance = dotNetFactoryInstance.ApplicationInstance;
                        if (FluorineContext.Current != null && FluorineContext.Current.ApplicationState != null && dotNetFactoryInstance.AttributeId != null)
                            FluorineContext.Current.ApplicationState[dotNetFactoryInstance.AttributeId] = instance;
                        return instance;
                    }
				case FactoryInstance.SessionScope:
					if( FluorineContext.Current.Session != null )
					{
						object instance = FluorineContext.Current.Session[dotNetFactoryInstance.AttributeId];
						if( instance == null )
						{
							instance = dotNetFactoryInstance.CreateInstance();
							FluorineContext.Current.Session[dotNetFactoryInstance.AttributeId] = instance;
						}
                        return instance;
                    }
					break;
				default:
					return dotNetFactoryInstance.CreateInstance();
			}
			return null;
		}
예제 #2
0
        /// <summary>
        /// Return an instance as appropriate for this instance of the given factory.
        /// </summary>
        /// <param name="factoryInstance">FactoryInstance used to retrieve the object instance.</param>
        /// <returns>The Object instance to use for the given operation for the current destination.</returns>
        public object Lookup(FactoryInstance factoryInstance)
        {
            DotNetFactoryInstance dotNetFactoryInstance = factoryInstance as DotNetFactoryInstance;

            switch (dotNetFactoryInstance.Scope)
            {
            case FactoryInstance.ApplicationScope:
            {
                object instance = dotNetFactoryInstance.ApplicationInstance;
                if (FluorineContext.Current != null && FluorineContext.Current.ApplicationState != null && dotNetFactoryInstance.AttributeId != null)
                {
                    FluorineContext.Current.ApplicationState[dotNetFactoryInstance.AttributeId] = instance;
                }
                return(instance);
            }

            case FactoryInstance.SessionScope:
                if (FluorineContext.Current.Session != null)
                {
                    object instance = FluorineContext.Current.Session[dotNetFactoryInstance.AttributeId];
                    if (instance == null)
                    {
                        instance = dotNetFactoryInstance.CreateInstance();
                        FluorineContext.Current.Session[dotNetFactoryInstance.AttributeId] = instance;
                    }
                    return(instance);
                }
                break;

            default:
                return(dotNetFactoryInstance.CreateInstance());
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Returns the FactoryInstance used by the Destination to create object instances.
        /// </summary>
        /// <returns></returns>
        public FactoryInstance GetFactoryInstance()
        {
            if (_factoryInstance != null)
            {
                return(_factoryInstance);
            }

            MessageBroker messageBroker = this.Service.GetMessageBroker();
            IFlexFactory  factory       = messageBroker.GetFactory(this.FactoryId);

            _factoryInstance = factory.CreateFactoryInstance(this.Id, _destinationDefinition.Properties);
            return(_factoryInstance);
        }
예제 #4
0
        /// <summary>
        /// Initializes the current Destination.
        /// </summary>
        /// <param name="adapterDefinition">Adapter definition.</param>
        public virtual void Init(AdapterDefinition adapterDefinition)
        {
            if (_initialized)
            {
                throw new NotSupportedException(__Res.GetString(__Res.Destination_Reinit, this.Id, this.GetType().Name));
            }
            _initialized = true;
            if (adapterDefinition != null)
            {
                string typeName = adapterDefinition.Class;
                Type   type     = ObjectFactory.Locate(typeName);
                if (type != null)
                {
                    _adapter = ObjectFactory.CreateInstance(type) as ServiceAdapter;
                    _adapter.SetDestination(this);
                    _adapter.SetAdapterSettings(adapterDefinition);
                    _adapter.SetDestinationSettings(_destinationDefinition);
                    _adapter.Init();
                }
                else
                {
                    log.Error(__Res.GetString(__Res.Type_InitError, adapterDefinition.Class));
                }
            }
            else
            {
                log.Error(__Res.GetString(__Res.MessageServer_MissingAdapter, this.Id, this.GetType().Name));
            }
            MessageBroker messageBroker = this.Service.GetMessageBroker();

            messageBroker.RegisterDestination(this, _service);

            //If the source has application scope create an instance here, so the service can listen for SessionCreated events for the first request
            if (this.Scope == "application")
            {
                FactoryInstance factoryInstance = GetFactoryInstance();
                object          inst            = factoryInstance.Lookup();
            }
        }
예제 #5
0
        /// <summary>
        /// Returns the FactoryInstance used by the Destination to create object instances.
        /// </summary>
        /// <returns></returns>
		public FactoryInstance GetFactoryInstance()
		{
			if( _factoryInstance != null )
				return _factoryInstance;

			MessageBroker messageBroker = this.Service.GetMessageBroker();
			IFlexFactory factory = messageBroker.GetFactory(this.FactoryId);
			_factoryInstance = factory.CreateFactoryInstance(this.Id, _destinationDefinition.Properties);
			return _factoryInstance;
		}