示例#1
0
        // ----------------------------------------------------------------------------------------
        #endregion

        #region AbstractSession constructors
        // ----------------------------------------------------------------------------------------
        // AbstractSession constructors
        // ----------------------------------------------------------------------------------------

        /// <summary>
        /// Abstract session constructor.
        /// </summary>
        /// <param name="communicationService">The communication service.</param>
        /// <param name="sessionId">The session id.</param>
        /// <param name="description">The description.</param>
        public AbstractSession(IGenericCommunicationService communicationService, int sessionId, string description)
        {
            this.communicationService = communicationService;
            this.sessionId            = sessionId;
            this.description          = description;
            this.pendingRequests      = new ConcurrentDictionary <long, IInvokeState>();
            this.isActive             = true; // session is active on creation
        }
示例#2
0
        /// <summary>
        /// Inits the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="loggerName">Name of the logger.</param>
        /// <param name="configXml">The config XML.</param>
        public void Init(IGenericCommunicationService source, string loggerName, XElement configXml)
        {
            this.source        = source;
            this.log           = source.Logger;
            this.name          = loggerName;
            this.messageFormat = source.Serializer.MessageFormat;

            if (dataStreamQueue == null)
            {
                UnboundedChannelOptions channelOptions = new UnboundedChannelOptions();
                channelOptions.SingleReader = true;
                channelOptions.SingleWriter = false;

                dataStreamQueue = Channel.CreateUnbounded <StreamLogItem>(channelOptions);
                queueWriter     = dataStreamQueue.Writer;
            }
            else
            {
                throw new InvalidOperationException("Logger \"" + name + "\" already initialized!");
            }

            // load config
            XElement targetDirElement;

            if (configXml != null &&
                (targetDirElement = configXml.Element("TargetDir")) != null)
            {
                this.TargetDir = targetDirElement.Value;
            }
            else
            {
                if (!string.IsNullOrEmpty(this.TargetDir))
                {
                    this.TargetDir = Path.GetFullPath(this.TargetDir);
                }
                else
                {
                    this.TargetDir = Environment.CurrentDirectory;
                }
            }

            XElement keepStreamLogsDaysElement;

            if (configXml != null &&
                (keepStreamLogsDaysElement = configXml.Element("KeepStreamLogsDays")) != null)
            {
                keepStreamLogsDays = int.Parse(keepStreamLogsDaysElement.Value);
            }

            // start logging
            Task.Run(StoreLogItemsThread);
        }
示例#3
0
        public void InitGenericCommunication(IGenericCommunicationService communicationService, bool initShareContext, bool initSubContainers)
        {
            lock (TalkCompositionHost.syncObj)
            {
                if (!isInitalized)  // only inialize once
                {
                    isInitalized = true;
                    this.CommunicationService = communicationService;

                    this.remoteServiceInterfaceTypesResolved       = remoteServiceInterfaceTypes.ToArray();
                    this.localSessionServiceInterfaceTypesResolved = localSessionServiceInterfaceTypes.ToArray();

                    communicationService.SessionCreated    += OnCommunicationService_SessionCreated;
                    communicationService.SessionTerminated += OnCommunicationService_SessionTerminated;

                    RegisterHostSessionsSharedInstance(communicationService);

                    // init dependency injection
                    // check if logger is already added to share context
                    bool exportNewLogger = false;
                    if (localShare.TryGetCachedLocalExport(typeof(ILogger), out object loggerObj))
                    {
                        this.logger = (ILogger)loggerObj;
                    }
                    else
                    {
                        exportNewLogger = true;
                    }

                    // register communication host for response processing
                    communicationService.RegisterContainerHost(this, logger);

                    if (exportNewLogger)
                    {
                        RegisterLocalSharedService <ILogger>(communicationService.Logger);
                        this.logger = communicationService.Logger;
                    }

                    if (initShareContext)
                    {
                        localShare.Init(initSubContainers);
                    }
                }
            }
        }
示例#4
0
 public void InitGenericCommunication(IGenericCommunicationService communicationService)
 {
     this.InitGenericCommunication(communicationService, true, false);
 }
 public PersistentClientCommunicationHost(IGenericCommunicationService underlyingCommunication)
 {
     this.underlyingCom = underlyingCommunication;
     this.underlyingCom.SessionCreated    += UnderlyingCom_SessionCreated;
     this.underlyingCom.SessionTerminated += UnderlyingCom_SessionTerminated;
 }
示例#6
0
        internal bool TryRaiseInMemorySessionCreated(Type serviceType, object serviceInstance, TalkCompositionHost host, IGenericCommunicationService communicationService)
        {
            SessionChangeSubscription subscr;

            if (sessionCreatedSubscriptions.TryGetValue(serviceType, out subscr))
            {
                if (inMemorySession == null)
                {
                    inMemorySession         = new Session(communicationService, 0, "In-Memory Session");
                    inMemorySessionContract = new SessionContract(host, inMemorySession, new object[0], new object[0]);
                }

                subscr.Invoke(serviceInstance, inMemorySessionContract, inMemorySession);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#7
0
        // ----------------------------------------------------------------------------------------
        // Session fields
        // ----------------------------------------------------------------------------------------

        // ----------------------------------------------------------------------------------------
        #endregion

        #region Session constructors
        // ----------------------------------------------------------------------------------------
        // Session constructors
        // ----------------------------------------------------------------------------------------

        /// <summary>
        /// Creates a new instance of the <c>Session</c> class.
        /// </summary>
        /// <param name="communicationService">The communication service.</param>
        /// <param name="sessionId">The session id.</param>
        /// <param name="description">The description.</param>
        public Session(IGenericCommunicationService communicationService, int sessionId, string description)
            : base(communicationService, sessionId, description)
        {
        }