Exemplo n.º 1
0
        private void DelayThread()
        {
            int delay = 0;

            while (true)
            {
                mSemaphore.WaitOne(delay);
                delay = Timeout.Infinite;
                lock (mDelayedConnectionTasks)
                {
                    IEnumeratorSpecialized <ConnectionTask> e = mDelayedConnectionTasks.GetEnumerator();
                    while (e.MoveNext())
                    {
                        ConnectionTask task         = e.Current;
                        long           currentTicks = DateTime.Now.Ticks;
                        if (currentTicks > task.Timeout.Ticks)
                        {
                            // mehet újra
                            e.Remove();
                            mThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ProcessConnection), task);
                        }
                        else
                        {
                            // csökkentem a következő várakozási időt
                            int delayValue = Convert.ToInt32(TimeSpan.FromTicks(task.Timeout.Ticks - currentTicks).TotalMilliseconds);
                            if (delayValue < delay || delay == Timeout.Infinite)
                            {
                                delay = delayValue;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unsubscribe for keys.
        /// </summary>
        /// <param name="subscription">The subscription.</param>
        /// <param name="e">The decimal.</param>
        public void UnsubscribeForKeys(KeysSubscription subscription, EventHandler <SubscribedKeyPressEventArgs> e)
        {
            if (subscription == null)
            {
                ThrowHelper.ThrowArgumentNullException("subscription");
            }
            if (e == null)
            {
                ThrowHelper.ThrowArgumentNullException("e");
            }

            lock (mKeysSubscriptions)
            {
                if (mKeysSubscriptions.ContainsKey(subscription))
                {
                    ListSpecialized <EventHandler <SubscribedKeyPressEventArgs> >        list = mKeysSubscriptions[subscription];
                    IEnumeratorSpecialized <EventHandler <SubscribedKeyPressEventArgs> > en   = list.GetEnumerator();
                    while (en.MoveNext())
                    {
                        if (en.Current.Method.Equals(e.Method) && en.Current.Target.Equals(e.Target))
                        {
                            en.Remove();
                            break;
                        }
                    }
                    if (list.Count == 0)
                    {
                        mKeysSubscriptions.Remove(subscription);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the specified o.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <returns>
        /// True, if the collection modified, otherwise False.
        /// </returns>
        public override bool Remove(T o)
        {
            DoDisposeCheck();
            bool result = false;
            IEnumeratorSpecialized <T> i = GetEnumerator();

            while (i.MoveNext())
            {
                T next = i.Current;
                if (next == null ? o == null : next.Equals(o))
                {
                    i.Remove();
                    result = true;
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retains all.
        /// </summary>
        /// <param name="c">The collection of items.</param>
        public void RetainAll(ICollection <T> c)
        {
            DoDisposeCheck();
            if (c == null)
            {
                ThrowHelper.ThrowArgumentNullException("c");
            }

            lock (mLockObject)
            {
                IEnumeratorSpecialized <T> iterator = (IEnumeratorSpecialized <T>) this.GetEnumerator();
                while (iterator.MoveNext())
                {
                    if (!c.Contains(iterator.Current))
                    {
                        iterator.Remove();
                    }
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Unregisters the proxy.
 /// </summary>
 /// <param name="proxy">The proxy.</param>
 internal static void UnregisterProxy(ProxyBase proxy)
 {
     if (proxy == null)
     {
         ThrowHelper.ThrowArgumentNullException("proxy");
     }
     lock (mContractAndInstancePerSessionAndChannel)
     {
         IEnumeratorSpecialized <ContractAndInstanceStruct> iterator = mContractAndInstancePerSessionAndChannel.GetEnumerator();
         while (iterator.MoveNext())
         {
             ContractAndInstanceStruct s = iterator.Current;
             if (s.Instance.Equals(proxy))
             {
                 iterator.Remove();
                 break;
             }
         }
     }
 }
Exemplo n.º 6
0
 private void ChannelSessionStateChangeEventHandler(object sender, SessionStateEventArgs e)
 {
     // PerSession módban a session-höz tartozó implementációkat meg kell szüntetni
     if (!e.IsConnected)
     {
         Channel channel = (Channel)sender;
         lock (mContractAndInstancePerSessionAndChannel)
         {
             IEnumeratorSpecialized <ContractAndInstanceStruct> iterator = mContractAndInstancePerSessionAndChannel.GetEnumerator();
             while (iterator.MoveNext())
             {
                 ContractAndInstanceStruct s = iterator.Current;
                 if (s.Channel.Equals(channel) && s.SessionId.Equals(e.SessionId))
                 {
                     iterator.Remove();
                     s.Instance.Dispose();
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
        private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
        {
            string name = args.LoadedAssembly.GetName().Name;

            lock (mAssemblyNameVsTypeKey)
            {
                if (mAssemblyNameVsTypeKey.ContainsKey(name))
                {
                    ListSpecialized <TypeKey>        list     = mAssemblyNameVsTypeKey[name];
                    IEnumeratorSpecialized <TypeKey> iterator = list.GetEnumerator();
                    while (iterator.MoveNext())
                    {
                        if (iterator.Current.TypeLookupMode != TypeLookupModeEnum.AllowExactVersions)
                        {
                            mTypeKeyVsType.Remove(iterator.Current);
                            iterator.Remove();
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Channels the unregistered event handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Forge.Net.Remoting.Channels.ChannelRegistrationEventArgs"/> instance containing the event data.</param>
        protected override void ChannelUnregisteredEventHandler(object sender, ChannelRegistrationEventArgs e)
        {
            base.ChannelUnregisteredEventHandler(sender, e);

            Channel channel = e.Channel;

            // leiratkozom az eseményről
            channel.SessionStateChange -= new EventHandler <SessionStateEventArgs>(ChannelSessionStateChangeEventHandler);

            // megszüntetem a channel-hez tartozó PerSession ProxyBase instance-okat
            lock (mContractAndInstancePerSessionAndChannel)
            {
                IEnumeratorSpecialized <ContractAndInstanceStruct> iterator = mContractAndInstancePerSessionAndChannel.GetEnumerator();
                while (iterator.MoveNext())
                {
                    ContractAndInstanceStruct s = iterator.Current;
                    if (s.Channel.Equals(channel))
                    {
                        iterator.Remove();
                        s.Instance.Dispose();
                    }
                }
            }

            // konfiguráció adminisztrációja, törlöm a csatornához köthető információkat
            List <ContractServiceSideDescriptor> list = new List <ContractServiceSideDescriptor>();

            lock (mContractDescriptors)
            {
                list.AddRange(mContractDescriptors.Values);
            }
            foreach (ContractServiceSideDescriptor ss in list)
            {
                lock (ss)
                {
                    ss.ImplementationPerChannel.Remove(channel.ChannelId);
                }
            }
            list.Clear();
        }
Exemplo n.º 9
0
        public void Generate(string outputDir)
        {
            if (outputDir == null)
            {
                ThrowHelper.ThrowArgumentNullException("outputDir");
            }

            if (!mIsCollected)
            {
                // reset fields
                mServiceMethods.Clear();
                mClientMethods.Clear();
                mNeutralMethods.Clear();
                mNeutralProperties.Clear();
                mNeutralEvents.Clear();

                // collect methods
                CollectMethods(ContractType);
                mIsCollected = true;
            }

            FileStream fs = null;

            try
            {
                TypeDescriptor descriptor = new TypeDescriptor(ContractType);
                {
                    DirectoryInfo outDir = new DirectoryInfo(outputDir);
                    if (!outDir.Exists)
                    {
                        outDir.Create();
                    }
                }

                // generate service class(es)
                bool writeOverride = false;
                if (mWellKnownObjectMode == WellKnownObjectModeEnum.PerSession && mClientMethods.Count > 0)
                {
                    // write abstract class
                    FileInfo abstractFile = new FileInfo(Path.Combine(outputDir, String.Format("{0}.cs", descriptor.TypeNameServiceAbstract)));
                    using (fs = new FileStream(abstractFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        GeneratorBase.WriteAbstractProxyClassHeader(ContractType, true, fs);
                        GeneratorBase.WriteEvents(mNeutralEvents, fs);
                        GeneratorBase.WriteProxyContructor(false, descriptor.TypeNameServiceAbstract, fs);
                        GeneratorBase.WriteAbstractProperties(mNeutralProperties, fs);
                        GeneratorBase.WriteAbstractMethods(mServiceMethods, fs);
                        GeneratorBase.WriteAbstractMethods(mNeutralMethods, fs);
                        IEnumerator <MethodComparator> iterator = mClientMethods.GetEnumerator();
                        while (iterator.MoveNext())
                        {
                            MethodComparator mc = iterator.Current;
                            ServiceSideGenerator.GenerateServiceMethod(ContractType, mc.Method, fs);
                        }
                        GeneratorBase.WriteEndClass(fs);
                    }
                    writeOverride = true;
                }
                {
                    FileInfo implFile = new FileInfo(Path.Combine(outputDir, String.Format("{0}.cs", descriptor.TypeNameServiceImpl)));
                    using (fs = new FileStream(implFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        String baseType = string.Empty;
                        if (mWellKnownObjectMode == WellKnownObjectModeEnum.PerSession)
                        {
                            if (mClientMethods.Count > 0)
                            {
                                baseType = descriptor.TypeFullNameServiceAbstract;
                            }
                            else
                            {
                                baseType = typeof(ProxyBase).FullName;
                            }
                        }
                        GeneratorBase.WriteImplementationClassHeader(ContractType, baseType, true, fs);
                        if (!writeOverride)
                        {
                            GeneratorBase.WriteEvents(mNeutralEvents, fs);
                        }
                        if (mWellKnownObjectMode == WellKnownObjectModeEnum.PerSession)
                        {
                            GeneratorBase.WriteProxyContructor(true, descriptor.TypeNameServiceImpl, fs);
                        }
                        else
                        {
                            GeneratorBase.WriteEmptyContructor(true, descriptor.TypeNameServiceImpl, fs);
                        }
                        GeneratorBase.WriteProperties(mNeutralProperties, writeOverride, fs);
                        GeneratorBase.WriteMethods(mServiceMethods, writeOverride, fs);
                        GeneratorBase.WriteMethods(mNeutralMethods, writeOverride, fs);
                        GeneratorBase.WriteEndClass(fs);
                    }
                }

                // generate client class(es)
                writeOverride = false;
                bool disposeDetected = typeof(IDisposable).IsAssignableFrom(ContractType) && mNeutralMethods.Count == 1;
                if ((mClientMethods.Count > 0 || mNeutralMethods.Count > 0) && !disposeDetected)
                {
                    // write abstract class
                    FileInfo abstractFile = new FileInfo(Path.Combine(outputDir, String.Format("{0}.cs", descriptor.TypeNameClientAbstract)));
                    using (fs = new FileStream(abstractFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        GeneratorBase.WriteAbstractProxyClassHeader(ContractType, false, fs);
                        GeneratorBase.WriteEvents(mNeutralEvents, fs);
                        GeneratorBase.WriteProxyContructor(false, descriptor.TypeNameClientAbstract, fs);
                        GeneratorBase.WriteAbstractProperties(mNeutralProperties, fs);
                        GeneratorBase.WriteAbstractMethods(mClientMethods, fs);
                        GeneratorBase.WriteAbstractMethods(mNeutralMethods, fs);
                        IEnumerator <MethodComparator> iterator = mServiceMethods.GetEnumerator();
                        while (iterator.MoveNext())
                        {
                            MethodComparator mc = iterator.Current;
                            ClientSideGenerator.GenerateServiceMethod(ContractType, mc.Method, fs);
                        }
                        GeneratorBase.WriteEndClass(fs);
                    }
                    writeOverride = true;
                }
                {
                    FileInfo implFile = new FileInfo(Path.Combine(outputDir, String.Format("{0}.cs", descriptor.TypeNameClientImpl)));
                    using (fs = new FileStream(implFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        String baseType = typeof(ProxyBase).FullName;
                        if ((mClientMethods.Count > 0 || mNeutralMethods.Count > 0) && !disposeDetected)
                        {
                            baseType = descriptor.TypeFullNameClientAbstract;
                        }
                        GeneratorBase.WriteImplementationClassHeader(ContractType, baseType, false, fs);
                        if (!writeOverride)
                        {
                            GeneratorBase.WriteEvents(mNeutralEvents, fs);
                        }
                        GeneratorBase.WriteProxyContructor(true, descriptor.TypeNameClientImpl, fs);
                        GeneratorBase.WriteProperties(mNeutralProperties, writeOverride, fs);
                        GeneratorBase.WriteMethods(mClientMethods, writeOverride, fs);

                        if (disposeDetected)
                        {
                            // ha az IDisposable interface implementálva van, akkor a dispose() metódust nem szabad generálni kliens oldalon, mert a ProxyBase-ben már benne van
                            IEnumeratorSpecialized <MethodComparator> iterator = mNeutralMethods.GetEnumerator();
                            while (iterator.MoveNext())
                            {
                                MethodComparator mc = iterator.Current;
                                if (mc.Method.Name.Equals("Dispose") && mc.Method.GetParameters().Length == 0)
                                {
                                    iterator.Remove();
                                    break;
                                }
                            }
                        }
                        GeneratorBase.WriteMethods(mNeutralMethods, writeOverride, fs);

                        if (!((mClientMethods.Count > 0 || mNeutralMethods.Count > 0) && !disposeDetected))
                        {
                            IEnumerator <MethodComparator> iterator = mServiceMethods.GetEnumerator();
                            while (iterator.MoveNext())
                            {
                                MethodComparator mc = iterator.Current;
                                ClientSideGenerator.GenerateServiceMethod(ContractType, mc.Method, fs);
                            }
                        }
                        GeneratorBase.WriteEndClass(fs);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ProxyGenerationFailedException("Failed to generate proxy classes.", ex);
            }
        }