Ejemplo n.º 1
0
        internal SubscriptionObserver(IObserver <WspEvent> observer)
        {
            this.id       = Guid.NewGuid();
            this.observer = observer;

            eventQueueCounter = new PerformanceCounter();
            eventQueueCounter.InstanceLifetime = PerformanceCounterInstanceLifetime.Process;
            eventQueueCounter.CategoryName     = "WspEventRouterApplication";
            eventQueueCounter.CounterName      = "SubscriptionQueueSize";
            eventQueueCounter.InstanceName     = "PID" + Process.GetCurrentProcess().Id.ToString() + ":" + this.id.ToString();
            eventQueueCounter.ReadOnly         = false;

            this.queue = new SynchronizationQueueGeneric <WspEvent>(eventQueueCounter, Guid.Empty);

            this.observerThread = new Thread(Start);
            observerThread.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The ObservableSubscription constructor is used to create an observable filtered subscription to then subscribe to via Rx
        /// </summary>
        /// <remarks>
        /// The method will obviously consume more overhead, so only use when necessary. If referenced assemblies, they must be
        /// deployed and accessible by the WspEventRouter on ALL computers running Wsp.
        /// </remarks>
        /// <param name="eventType">The event type to subscribe to</param>
        /// <param name="localOnly">True if only local events are to be subscribed to</param>
        /// <param name="methodBody">Method body defining the filter</param>
        /// <param name="usingLibraries">List of using libraries which the method requires, null if none required</param>
        /// <param name="referencedAssemblies">List of referenced assemblies which the method requires, null if none required</param>
        public WspEventObservable(Guid eventType, bool localOnly, string methodBody, List <string> usingLibraries, List <string> referencedAssemblies)
        {
            this.id                   = Guid.NewGuid();
            this.eventType            = eventType;
            this.localOnly            = localOnly;
            this.usingLibraries       = null;
            this.referencedAssemblies = null;
            this.filterMethod         = null;

            if (string.IsNullOrEmpty(methodBody) == true)
            {
                this.methodBody = string.Empty;
            }
            else
            {
                this.methodBody = methodBody;

                if (usingLibraries != null)
                {
                    this.usingLibraries = new List <string>(usingLibraries.Count);
                    for (int i = 0; i < usingLibraries.Count; i++)
                    {
                        this.usingLibraries[i] = usingLibraries[i];
                    }
                }

                if (referencedAssemblies != null)
                {
                    this.referencedAssemblies = new List <string>(referencedAssemblies.Count);
                    for (int i = 0; i < referencedAssemblies.Count; i++)
                    {
                        this.referencedAssemblies[i] = referencedAssemblies[i];
                    }
                }

                CompilerResults results;

                bool rc = CompileFilterMethod(this.methodBody, this.usingLibraries, this.referencedAssemblies, out this.filterMethod, out results);

                if (rc == false)
                {
                    throw new PubSubCompileException(results.Errors.ToString());
                }
            }

            eventQueueCounter = new PerformanceCounter();
            eventQueueCounter.InstanceLifetime = PerformanceCounterInstanceLifetime.Process;
            eventQueueCounter.CategoryName     = "WspEventRouterApplication";
            eventQueueCounter.CounterName      = "SubscriptionQueueSize";
            eventQueueCounter.InstanceName     = "PID" + Process.GetCurrentProcess().Id.ToString() + ":" + eventType.ToString() + ":" + Guid.NewGuid().ToString().GetHashCode().ToString();
            eventQueueCounter.ReadOnly         = false;

            this.queue = new SynchronizationQueueGeneric <WspEvent>(eventQueueCounter, eventType);

            observableThread = new Thread(ObservableThread);
            observableThread.Start();

            lock (lockObj)
            {
                if (wspSubscriptionThread == null)
                {
                    wspSubscriptionManager = new SubscriptionManager();
                    wspSubscriptionThread  = new Thread(wspSubscriptionManager.Listener);
                    wspSubscriptionThread.Start();
                }
            }
        }