示例#1
0
        public override bool Equals(Object obj)
        {
            TisServiceKey oOther = obj as TisServiceKey;

            if (Object.ReferenceEquals(oOther, null))
            {
                return(false);
            }

            if (!StringUtil.CompareIgnoreCase(
                    ServiceName,
                    oOther.ServiceName))
            {
                return(false);
            }

            if (!StringUtil.CompareIgnoreCase(
                    InstanceName,
                    oOther.InstanceName))
            {
                return(false);
            }

            return(true);
        }
示例#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);
        }
        public void ReleaseService(
            TisServiceKey oServiceKey,
            ITisServiceInfo serviceInfo = null,
            object oService             = null)
        {
            if (oService == null && IsInstantiated(oServiceKey))
            {
                oService = GetService(oServiceKey);
            }

            if (oService != null)
            {
                if (serviceInfo != null)
                {
                    TisServiceEventsAdapterBuilder.ReleaseService(serviceInfo, oService);
                }

                PerformReleaseService(oServiceKey);

                PerformDisposeService(oService);
            }

            // Fire post-deactivate event
            FirePostServiceDeactivate(oServiceKey);

            int nIndex;

            nIndex = m_oServicesLoadOrder.IndexOf(oServiceKey);

            if (nIndex >= 0)
            {
                m_oServicesLoadOrder.RemoveAt(nIndex);
            }
        }
 private void UpdateLoadOrder(TisServiceKey oServiceKey)
 {
     if (m_oServicesLoadOrder.IndexOf(oServiceKey) < 0)
     {
         // Keep load order
         m_oServicesLoadOrder.Add(oServiceKey);
     }
 }
 private void LifetimeManager_OnPostServiceDeactivate(
     string sAppName,
     TisServiceKey oServiceKey)
 {
     if (OnPostServiceDeactivate != null)
     {
         OnPostServiceDeactivate(sAppName, oServiceKey);
     }
 }
示例#6
0
 public TisServiceCreatorContext(
     string applicationName,
     TisServiceKey serviceKey,
     ITisServicesHost servicesHost)
 {
     ApplicationName = applicationName;
     ServiceKey      = serviceKey;
     ServicesHost    = servicesHost;
 }
示例#7
0
 public void SetContext(
     string sAppName,
     TisServiceKey oServiceKey,
     ITisServicesHost oServicesHost)
 {
     m_oContext = new TisServiceCreatorContext(
         sAppName,
         oServiceKey,
         oServicesHost);
 }
示例#8
0
 private void SetCreatorContext(
     ITisServiceCreator oCreator,
     TisServiceKey oServiceKey)
 {
     // Set creator context
     m_oServicesHost.CreatorContextSetter.SetCreatorContext(
         oCreator,
         m_sAppName,
         oServiceKey,
         m_oServicesHost);
 }
        private void LifetimeManager_OnPreServiceDeactivate(
            string sAppName,
            TisServiceKey oServiceKey,
            object oService)
        {
            if (OnPreServiceDeactivate != null)
            {
                OnPreServiceDeactivate(sAppName, oServiceKey);
            }

            ReleaseService(sAppName, oServiceKey.ServiceName, oServiceKey.InstanceName);
        }
        private object GetLocalService(
            string sAppName,
            string sServiceName,
            string sServiceInstanceName)
        {
            // Validate sAppName
            if (!StringUtil.IsStringInitialized(sAppName))
            {
                ExceptionUtil.RaiseArgumentNullException(
                    "sAppName",
                    "sAppName parameter must be initialized",
                    MethodInfo.GetCurrentMethod());
            }

            // Validate sServiceName
            if (!StringUtil.IsStringInitialized(sServiceName))
            {
                ExceptionUtil.RaiseArgumentNullException(
                    "sServiceName",
                    "sServiceName parameter must be initialized",
                    MethodInfo.GetCurrentMethod());
            }

            // Validate sServiceInstanceName
            if (!StringUtil.IsStringInitialized(sServiceInstanceName))
            {
                ExceptionUtil.RaiseArgumentNullException(
                    "sServiceInstanceName",
                    "sServiceInstanceName parameter must be initialized",
                    MethodInfo.GetCurrentMethod());
            }

            ITisServiceProvider oServiceProvider = null;

            // Get service provider for the application
            oServiceProvider = m_oServiceProvidersCache.GetServiceProvider(sAppName);

            ITisServiceInfo oServiceInfo =
                CheckedGetServiceInfo(sAppName, sServiceName);

            // Create service key
            TisServiceKey oKey = new TisServiceKey(
                sServiceName,
                sServiceInstanceName,
                oServiceInfo);

            object oService = oServiceProvider.GetService(
                oKey);

            return(oService);
        }
 private void FirePostServiceDeactivate(TisServiceKey oServiceKey)
 {
     try
     {
         if (OnPostServiceDeactivate != null)
         {
             OnPostServiceDeactivate(m_sAppName, oServiceKey);
         }
     }
     catch (Exception oExc)
     {
         Log.WriteException(oExc);
     }
 }
        private void PerformReleaseService(
            TisServiceKey oServiceKey)
        {
            try
            {
                m_oServicesCache.Revoke(oServiceKey);

                m_oServicesActivator.ReleaseService(
                    oServiceKey);
            }
            catch (Exception oExc)
            {
                Log.WriteException(oExc);
            }
        }
        public void ReleaseService(
            string applicationName,
            string serviceName,
            string serviceInstanceName = TisServicesConst.UNNAMED_INSTANCE)
        {
            ITisServiceProvider serviceProvider = m_oServiceProvidersCache.GetServiceProvider(applicationName);

            ITisServiceInfo serviceInfo =
                CheckedGetServiceInfo(applicationName, serviceName);

            TisServiceKey serviceKey = new TisServiceKey(
                serviceName,
                serviceInstanceName);

            serviceProvider.ReleaseService(serviceKey, serviceInfo);
        }
示例#14
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);
            }
        }
示例#15
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);
            }
        }
        private void LifetimeManager_OnPostServiceActivate(
            string sAppName,
            TisServiceKey oServiceKey,
            object oService)
        {
            ITisServiceInfo serviceInfo = oServiceKey.ServiceInfo;

            if (serviceInfo.SupportedEvents.Count > 0)
            {
                TisServiceEventsAdapterBuilder.AddService(
                    this,
                    sAppName,
                    oService,
                    serviceInfo,
                    oServiceKey.InstanceName);
            }

            if (OnPostServiceActivate != null)
            {
                OnPostServiceActivate(sAppName, oServiceKey);
            }
        }
示例#17
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);
        }
        //
        //	Protected
        //

        protected object ServicesCache_OnCacheMiss(
            object oSender,
            CacheMissEventArgs oArgs)
        {
            TisServiceKey oServiceKey = (TisServiceKey)oArgs.Key;

            //Log.Write(
            //    Log.Severity.DETAILED_DEBUG,
            //    System.Reflection.MethodInfo.GetCurrentMethod(),
            //    "Activating service [{0}] in App [{1}], ServiceCache: {2}",
            //    oServiceKey,
            //    m_sAppName,
            //    GetHashCode());

            // Return the service object from real service provider
            object oObj = m_oServicesActivator.GetService(oServiceKey);

            if (m_oServicesCache.GetCached(oServiceKey) != null)
            {
                return(null);
            }

            // Fire pre-activate event
            FirePreServiceActivate(oServiceKey);

            if (!m_bDisposing)
            {
                // Keep load order
                UpdateLoadOrder(oServiceKey);
            }

            // Fire post-activate event
            FirePostServiceActivate(oServiceKey, oObj);

            return(oObj);
        }
示例#19
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);
            }
        }
示例#20
0
 public bool IsInstantiated(TisServiceKey oServiceKey)
 {
     return(m_oCreatorsCache.IsInCache(oServiceKey));
 }
示例#21
0
 public void AddService(
     TisServiceKey oServiceKey,
     object oService)
 {
 }
        public void Dispose()
        {
            m_bDisposing = true;

            if (m_oServicesLoadOrder.Count == 0)
            {
                return;
            }

            TisServiceKey[] servicesLoadOrderArray = new TisServiceKey[m_oServicesLoadOrder.Count];
            m_oServicesLoadOrder.CopyTo(servicesLoadOrderArray, 0);

            // Allow calling Dispose on the services.
            // Scan in the reverse direction of load order
            for (int i = servicesLoadOrderArray.Length - 1; i > 0; i--)
            {
                TisServiceKey serviceKey = servicesLoadOrderArray[i];
                //Log.Write(
                //    Log.Severity.DETAILED_DEBUG,
                //    System.Reflection.MethodInfo.GetCurrentMethod(),
                //    "Deactivating service [{0}] in App [{1}]",
                //    serviceKey,
                //    m_sAppName);

                // Get service object
                object oService =
                    m_oServicesCache.GetCached(serviceKey);

                // Fire pre-deactivate event
                FirePreServiceDeactivate(serviceKey, oService);

                if (oService != null)
                {
                    PerformReleaseService(
                        serviceKey);

                    PerformDisposeService(
                        oService);
                }
                else
                {
                    Log.Write(
                        Log.Severity.ERROR,
                        System.Reflection.MethodInfo.GetCurrentMethod(),
                        "Service [{0}] (null) in cache",
                        serviceKey
                        );
                }

                // Fire post-deactivate event
                FirePostServiceDeactivate(serviceKey);
            }

            // Clear the cache
            m_oServicesCache.OnCacheMiss -=
                new CacheMissEvent(ServicesCache_OnCacheMiss);

            m_oServicesCache.RevokeAll();

            // Clear load order
            m_oServicesLoadOrder.Clear();

            m_oServicesActivator.Dispose();

            m_bDisposing = false;
        }
示例#23
0
 private ITisServiceCreator GetCreator(TisServiceKey oServiceKey)
 {
     return((ITisServiceCreator)m_oCreatorsCache.Get(oServiceKey));
 }
 public object GetService(
     TisServiceKey oServiceKey)
 {
     return(m_oServicesCache.Get(oServiceKey));
 }
示例#25
0
 protected abstract void SetCreatorContextImpl(
     ITisServiceCreator oCreator,
     string sAppName,
     TisServiceKey oServiceKey,
     ITisServicesHost oServicesHost);
 public void AddService(
     TisServiceKey oServiceKey,
     object oService)
 {
     m_oServicesCache.Put(oServiceKey, oService);
 }
        public bool AddLocalService(
            string applicationName,
            string serviceName,
            object serviceInstance        = null,
            string serviceCreatorFullName = null,
            string serviceTypeFullName    = null,
            string serviceInstanceName    = null)
        {
            if (!StringUtil.IsStringInitialized(serviceName))
            {
                Log.WriteWarning("Try to install service without name.");
                return(false);
            }

            ITisServiceRegistry applicationServiceRegistry = GetServiceRegistry(applicationName);

            bool isServiceInstalled = applicationServiceRegistry.IsServiceInstalled(serviceName);

            if (!isServiceInstalled)
            {
                if (!StringUtil.IsStringInitialized(serviceCreatorFullName))
                {
                    serviceCreatorFullName =
                        typeof(TisUniversalServiceCreator).FullName + "," +
                        typeof(TisUniversalServiceCreator).Assembly.GetName().Name;
                }

                if (!StringUtil.IsStringInitialized(serviceTypeFullName))
                {
                    serviceTypeFullName = String.Empty;
                }

                try
                {
                    applicationServiceRegistry.InstallService(
                        serviceName,
                        serviceCreatorFullName,
                        serviceTypeFullName,
                        TisServicesConst.NO_ROLES_REQUIRED,
                        false);
                }
                catch (Exception exc)
                {
                    Log.WriteWarning("Failed to install service [{0}]. Details : {1}", serviceName, exc.Message);
                }

                isServiceInstalled = applicationServiceRegistry.IsServiceInstalled(serviceName);
            }

            if (serviceInstance != null)
            {
                if (!StringUtil.IsStringInitialized(serviceInstanceName))
                {
                    serviceInstanceName = TisServicesConst.UNNAMED_INSTANCE;
                }

                TisServiceKey serviceKey = new TisServiceKey(
                    serviceName,
                    serviceInstanceName);

                ITisServiceProvider serviceProvider;

                serviceProvider = m_oServiceProvidersCache.GetServiceProvider(applicationName);

                serviceProvider.AddService(serviceKey, serviceInstance);

                ITisServiceInfo serviceInfo =
                    CheckedGetServiceInfo(applicationName, serviceName);

                // The events adapter will include only the services which implement ITisSupportEvents interface.
                TisServiceEventsAdapterBuilder.AddService(
                    this,
                    applicationName,
                    serviceInstance,
                    serviceInfo,
                    serviceInstanceName);
            }

            return(isServiceInstalled);
        }