Пример #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;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Fails the safe start storage provider.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="storageId">The storage id.</param>
        /// <param name="dataFormatter">The data formatter.</param>
        /// <param name="compressContent">if set to <c>true</c> [compress content].</param>
        /// <param name="enableReset">if set to <c>true</c> [enable reset].</param>
        /// <param name="hasError">if set to <c>true</c> [has error].</param>
        /// <returns></returns>
        public static HibernateStorageProvider <T> FailSafeStartStorageProvider <T>(string storageId, IDataFormatter <T> dataFormatter, bool compressContent, bool enableReset, out bool hasError)
        {
            HibernateStorageProvider <T> result = null;

            hasError = false;

            try
            {
                result = new HibernateStorageProvider <T>(storageId, dataFormatter, compressContent);
                IEnumeratorSpecialized <T> iterator = result.GetEnumerator();
                while (iterator.MoveNext())
                {
                    // check data consistency
                }
            }
            catch (Exception ex)
            {
                if (LOGGER.IsErrorEnabled)
                {
                    LOGGER.Error(string.Format("NHIBERNATE_STORAGE_PROVIDER, failed to initialize storage provider: '{0}'. Reset allowed: {1}", storageId, enableReset.ToString()), ex);
                }
                hasError = true;
                if (enableReset)
                {
                    // reset the content of the storage provider
                    CategoryPropertyItem root       = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, "NHibernateProvider");
                    CategoryPropertyItem removeItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, "KnownStorageIdsToReset");
                    if (removeItem == null)
                    {
                        removeItem    = new CategoryPropertyItem();
                        removeItem.Id = "KnownStorageIdsToReset";
                        root.PropertyItems.Add(removeItem);
                    }

                    CategoryPropertyItem storeItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(removeItem.PropertyItems, storageId);
                    if (storeItem == null)
                    {
                        storeItem    = new CategoryPropertyItem();
                        storeItem.Id = storageId;
                        removeItem.PropertyItems.Add(storeItem);
                        try
                        {
                            result = new HibernateStorageProvider <T>(storageId, dataFormatter, compressContent);
                        }
                        finally
                        {
                            removeItem.PropertyItems.Remove(storeItem);
                        }
                    }
                }
                else
                {
                    throw;
                }
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Availables the service providers changed event handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ServiceProvidersChangedEventArgs"/> instance containing the event data.</param>
        protected virtual void AvailableServiceProvidersChangedEventHandler(object sender, ServiceProvidersChangedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                EventHandler <ServiceProvidersChangedEventArgs> d = new EventHandler <ServiceProvidersChangedEventArgs>(AvailableServiceProvidersChangedEventHandler);
                ((ConnectControl)d.Target).Invoke(d, sender, e);
                return;
            }

            ListSpecialized <ServiceProvider> providers = e.ServiceProviders;

            List <ListViewItem> removableItems = new List <ListViewItem>();

            // kidobom azokat az elemeket a listviewból, amelyek már nincsennek
            foreach (ListViewItem item in lvServices.Items)
            {
                ServiceProvider savedProvider = item.Tag as ServiceProvider;
                if (!providers.Contains(savedProvider))
                {
                    removableItems.Add(item);
                }
            }
            removableItems.ForEach(i => i.Remove());
            removableItems.Clear();

            // felveszem azokat, akik még nincsennek a listában
            IEnumeratorSpecialized <ServiceProvider> spEnum = providers.GetEnumerator();

            while (spEnum.MoveNext())
            {
                ServiceProvider provider = spEnum.Current;
                if (!NetworkManager.Instance.Localhost.Equals(provider.NetworkPeer))
                {
                    bool found = false;
                    foreach (ListViewItem item in lvServices.Items)
                    {
                        ServiceProvider savedProvider = item.Tag as ServiceProvider;
                        if (savedProvider.Equals(provider))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ListViewItem item = new ListViewItem(provider.NetworkPeer.Id);
                        item.Tag = provider;
                        lvServices.Items.Add(item);
                    }
                }
            }
            lvServices.Sort();
            lvServices_SelectedIndexChanged(null, null);
        }
Пример #4
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);
        }
Пример #5
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();
                    }
                }
            }
        }
Пример #6
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;
             }
         }
     }
 }
Пример #7
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();
                 }
             }
         }
     }
 }
Пример #8
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();
                        }
                    }
                }
            }
        }
Пример #9
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();
        }
Пример #10
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);
                    }
                }
            }
        }
Пример #11
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);
            }
        }