/// <summary>
        /// Tries to compress the outgoing holder.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="holder">The holder.</param>
        /// <returns>Returns true if the Content is serialized correctly to a binary blob.</returns>
        public static bool TrySerialize(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, ServiceHandlerContext holder)
        {
            string id;

            if (!ServiceHandlerContainer.ExtractContentType(holder, out id))
            {
                return(false);
            }

            IServiceHandlerSerialization sr = null;

            if (!collection.TryGet(id, out sr))
            {
                return(false);
            }

            return(sr.TrySerialize(holder));
        }
예제 #2
0
        /// <summary>
        /// This is the Microservice constructor.
        /// </summary>
        /// <param name="name">The Microservice name.</param>
        /// <param name="serviceId">The service id.</param>
        /// <param name="description">An optional description for the Microservice.</param>
        /// <param name="policySettings">The policy settings.</param>
        /// <param name="properties">Any additional property key.</param>
        /// <param name="serviceVersionId">This is the version id of the calling assembly as a string.</param>
        public Microservice(
            string name          = null
            , string serviceId   = null
            , string description = null
            , IEnumerable <PolicyBase> policySettings          = null
            , IEnumerable <Tuple <string, string> > properties = null
            , string serviceVersionId = null
            )
            : base(name)
        {
            Policies = new PolicyWrapper(policySettings, () => Status);
            //Id
            if (string.IsNullOrEmpty(name))
            {
                name = GetType().Name;
            }

            Id = new MicroserviceId(name
                                    , serviceId: serviceId
                                    , description: description
                                    , serviceVersionId: serviceVersionId ?? Assembly.GetCallingAssembly().GetName().Version.ToString()
                                    , serviceEngineVersionId: GetType().Assembly.GetName().Version.ToString()
                                    , properties: properties);

            //Service Handlers
            mServiceHandlers = InitialiseServiceHandlerContainer();
            ServiceHandlers  = new ServiceHandlerWrapper(mServiceHandlers, () => Status);
            //Communication
            mCommunication = InitialiseCommunicationContainer();
            Communication  = new CommunicationWrapper(mCommunication, () => Status);
            //Commands
            mCommands = InitialiseCommandContainer();
            Commands  = new CommandWrapper(mCommands, () => Status);
            //Resources
            mResourceMonitor = InitialiseResourceMonitor();
            ResourceMonitor  = new ResourceWrapper(mResourceMonitor, () => Status);
            //Data Collection
            mDataCollection = InitialiseDataCollectionContainer();
            DataCollection  = new DataCollectionWrapper(mDataCollection, () => Status);
            //Events
            mEventsWrapper = new EventsWrapper(this, mDataCollection, () => Status);
            Events         = mEventsWrapper;
        }
예제 #3
0
 internal ServiceHandlerWrapper(ServiceHandlerContainer container, Func <ServiceStatus> getStatus) : base(getStatus)
 {
     mContainer = container ?? throw new ArgumentNullException("container");
 }