Example #1
0
        /*=========================*/

        public ServiceStart(ServiceInstanceInfo instance)
        {
            Service s        = null;
            string  typeName = instance.Configuration.Class;

            if (!String.IsNullOrEmpty(typeName))
            {
                Type serviceType = Type.GetType(typeName, true);
                if (!serviceType.IsSubclassOf(typeof(Service)))
                {
                    throw new TypeLoadException("Service type must derive from Service (Easynet.Edge.Core.Services).");
                }

                // Enforce private constructors
                ConstructorInfo ctor = serviceType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { }, null);
                if (ctor == null)
                {
                    throw new MissingMethodException("Service requires a non-public parameterless constructor.");
                }

                // This is not suppoted: ctor.IsDefaultConstructor
                //else if (ctor.DeclaringType != typeof(Service) && !ctor.IsDefaultConstructor)
                //{
                //    throw new Exception("Service constructor cannot be public.");
                //}

                s = (Service)ctor.Invoke(null);
            }
            else
            {
                s = new Service();
            }

            s.Init(instance);
        }
        public ServiceInstanceInfo(ServiceInstance instance)
        {
            _accountID     = instance.AccountID;
            _instanceID    = instance.InstanceID;
            _priority      = instance.Priority;
            _config        = instance.Configuration;
            _rule          = instance.ActiveSchedulingRule;
            _timeStarted   = instance.TimeStarted;
            _timeScheduled = instance.TimeScheduled;
            _serviceUrl    = instance.ServiceUrl;

            if (instance.ParentInstance != null)
            {
                _parentInstanceData = new ServiceInstanceInfo(instance.ParentInstance);
            }
        }
Example #3
0
        /*=========================*/
        #endregion

        #region Initialization
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        internal void Init(ServiceInstanceInfo instance)
        {
            _instance = instance;
            _log      = new Log(instance);

            if (_wcfHost == null)
            {
                _wcfHost = new ServiceEngineHost(this);

                Binding binding = ServiceEngineCommChannel.GetBinding(instance);

                // Other service endpoints are added automatically from configuration
                _wcfHost.AddServiceEndpoint(typeof(IServiceEngine), binding, instance.ServiceUrl);

                // Open the listener
                _wcfHost.Open();
            }

            OnInit();
        }