コード例 #1
0
        private ITisServiceCreator InstanciateCreator(
            ITisServiceInfo oServiceInfo)
        {
            // Get creator type
            string sCreatorType =
                oServiceInfo.ServiceCreatorType;

            // Create Creator instance
            object oObjCreator = ActivatorHelper.CreateInstance(
                sCreatorType,
                EmptyArrays.ObjectArray);

            ITisServiceCreator oCreator = null;

            try
            {
                // Try to cast
                oCreator = (ITisServiceCreator)oObjCreator;
            }
            catch (InvalidCastException oExc)
            {
                throw new TisException(
                          oExc, // Inner
                          "Object [{0}] doesn't implements ITisServiceCreator",
                          oObjCreator);
            }

            return(oCreator);
        }
コード例 #2
0
        public object GetService(
            TisServiceKey oServiceKey)
        {
            object oService = null;

            try
            {
                // Obtain service creator
                ITisServiceCreator oCreator = GetCreator(oServiceKey);

                // Create the service instance using creator
                oService = oCreator.CreateService();
            }
            catch (Exception oExc)
            {
                Log.WriteError(
                    "ServiceActivator.GetService({0}) Failed, {1}",
                    oServiceKey,
                    oExc.Message);

                throw;
            }


            // Return the service
            return(oService);
        }
コード例 #3
0
 private void SetCreatorContext(
     ITisServiceCreator oCreator,
     TisServiceKey oServiceKey)
 {
     // Set creator context
     m_oServicesHost.CreatorContextSetter.SetCreatorContext(
         oCreator,
         m_sAppName,
         oServiceKey,
         m_oServicesHost);
 }
コード例 #4
0
        public void ReleaseService(
            TisServiceKey oServiceKey,
            ITisServiceInfo serviceInfo = null,
            object oService             = null)
        {
            if (oService == null && IsInstantiated(oServiceKey))
            {
                oService = m_oCreatorsCache.Get(oServiceKey);
            }

            if (oService != null)
            {
                // Obtain service creator
                ITisServiceCreator oCreator = GetCreator(oServiceKey);

                oCreator.ReleaseService(oService);
            }
        }
コード例 #5
0
        protected override void SetCreatorContextImpl(
            ITisServiceCreator oCreator,
            string sAppName,
            TisServiceKey oServiceKey,
            ITisServicesHost oServicesHost)
        {
            // Query for ISupportsCreatorContext interface
            ISupportsCreatorContext oTarget =
                oCreator as ISupportsCreatorContext;

            if (oTarget != null)
            {
                // Set context
                oTarget.SetContext(
                    sAppName,
                    oServiceKey,
                    oServicesHost);
            }
        }
コード例 #6
0
        private object CreatorsCache_OnCacheMiss(
            object oSender,
            CacheMissEventArgs oArgs)
        {
            TisServiceKey oServiceKey = (TisServiceKey)oArgs.Key;

            // Obtain service info
            ITisServiceInfo oServiceInfo =
                m_oServicesHost.CheckedGetServiceInfo(m_sAppName, oServiceKey.ServiceName);

            // Validate we can host the service
            ValidateCanHostService(oServiceInfo);

            // Obtain service creator
            ITisServiceCreator oCreator =
                InstanciateCreator(oServiceInfo);

            // Set creator context
            SetCreatorContext(oCreator, oServiceKey);

            return(oCreator);
        }
コード例 #7
0
        public virtual void SetCreatorContext(
            ITisServiceCreator oCreator,
            string sAppName,
            TisServiceKey oServiceKey,
            ITisServicesHost oServicesHost)
        {
            // Perform context set
            SetCreatorContextImpl(
                oCreator,
                sAppName,
                oServiceKey,
                oServicesHost);

            // If has next setter in the chain
            if (Next != null)
            {
                // Forward the request to next setter
                Next.SetCreatorContext(
                    oCreator,
                    sAppName,
                    oServiceKey,
                    oServicesHost);
            }
        }
コード例 #8
0
 protected abstract void SetCreatorContextImpl(
     ITisServiceCreator oCreator,
     string sAppName,
     TisServiceKey oServiceKey,
     ITisServicesHost oServicesHost);