示例#1
0
        /// <summary>
        /// The method which handles the sending of keepalive packages to the clients whenever the maximum time is reached.
        /// </summary>
        public void ServerClients()
        {
            while (Running)
            {
                using (_listWriteLock.LockWrite())
                {
                    for (int i = _proxies.Count - 1; i >= 0; i--)
                    {
                        if (!_proxies[i].IsActive)
                        {
                            _proxies.RemoveAt(i);
                            continue;
                        }

                        if ((DateTime.UtcNow - _proxies[i].LastMessageSent) >
                            this.MaximumLastMessageTime)
                        {
                            _proxies[i].Respond(new KeepAliveNotification().GetNotification());
                        }
                    }
                }

                Thread.Sleep(2);
            }
        }
        /// <summary>
        /// Enqueues a new Task to the ThreadedWorker pool
        /// </summary>
        /// <param name="task">the delegate to start</param>
        /// <param name="parameters">the parameters to start the delegate with</param>
        /// <returns>The WorkerTask object for this Job.</returns>
        public WorkerTask EnqueueJob(Delegate task, params object[] parameters)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            WorkerTask ret = new WorkerTask(task, parameters);

            using (_writeLock.LockWrite())
                _tasks.Enqueue(ret);

            return(ret);
        }
示例#3
0
        private void Write(bool a, bool b, bool c)
        {
            if (a)
            {
                using (wla.LockWrite())
                {
                    ba = true;

                    ia++;

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a => " + ia);
                    }

                    ba = false;
                }
            }
            else if (b)
            {
                using (UsableWriteLock.LockWrite(wla, wlb))
                {
                    ba = true;
                    bb = true;

                    ia++;
                    ib++;

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a => " + ia + ", b => " + ib);
                    }

                    ba = false;
                    bb = false;
                }
            }
            else if (c)
            {
                using (UsableWriteLock.LockWrite(wla, wlb, wlc))
                {
                    ba = true;
                    bb = true;
                    bc = true;

                    ia++;
                    ib++;
                    ic++;

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a => " + ia + ", b => " + ib + ", c => " + ic);
                    }

                    ba = false;
                    bb = false;
                    bc = false;
                }
            }
        }
示例#4
0
        private void Read(bool a, bool b, bool c)
        {
            if (a)
            {
                using (wla.LockRead())
                {
                    Assert.IsFalse(ba);

                    string s = " | " + (ba ? "1" : "0");

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a is " + ia + s);
                    }

                    Assert.IsFalse(ba);
                }
            }
            else if (b)
            {
                using (UsableWriteLock.LockRead(wla, wlb))
                {
                    Assert.IsFalse(ba);
                    Assert.IsFalse(bb);

                    string s = " | " + (ba ? "1" : "0") + " | " + (bb ? "1" : "0");

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a is " + ia + ", b is " + ib + s);
                    }

                    Assert.IsFalse(ba);
                    Assert.IsFalse(bb);
                }
            }
            else if (c)
            {
                using (UsableWriteLock.LockRead(wla, wlb, wlc))
                {
                    Assert.IsFalse(ba);
                    Assert.IsFalse(bb);
                    Assert.IsFalse(bc);

                    string s = " | " + (ba ? "1":"0") + " | " + (bb ? "1" : "0") + " | " + (bc ? "1" : "0");

                    using (console.LockWrite())
                    {
                        Console.WriteLine("a is " + ia + ", b is " + ib + ", c is " + ic + s);
                    }

                    Assert.IsFalse(ba);
                    Assert.IsFalse(bb);
                    Assert.IsFalse(bc);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Retrieves a local WebService of a specified Type.
        /// </summary>
        /// <param name="type">The type to generate a local Object of.</param>
        /// <returns>Returns an instance of the local WebService implementation.</returns>
        public object GetLocalService(Type type)
        {
            if (!type.GetInterfaces().Contains(typeof(IWebService)))
            {
                throw new IncompatibleTypeException($"Type '{type}' is not compatible with {nameof(WebServiceHandler)}: Does not implement '{nameof(IWebService)}'.");
            }

            if (type.GetConstructor(new Type[0]) == null)
            {
                throw new IncompatibleTypeException($"Type '{type}' is not compatible with {nameof(WebServiceHandler)}: No empty constructor available.");
            }

            if (type.IsAbstract || type.IsInterface || !type.IsPublic || type.IsSealed)
            {
                throw new IncompatibleTypeException("Only public non-abstract non-sealed Types of classes can be WebServices.");
            }

            bool contained = false;

            using (_listLock.LockRead())
                contained = LocalWebServiceVariants.ContainsKey(type);

            if (contained)
            {
                return(LocalWebServiceVariants[type]);
            }
            else
            {
                object ret = WebServiceImplementationGenerator.GetWebServiceLocalImplementation(type, this);

                using (_listLock.LockWrite())
                    LocalWebServiceVariants.Add(type, ret);

                return(ret);
            }
        }