private void Event_KeyUp(object sender, KeyEventArgs e) { ListSpecialized <EventHandler <SubscribedKeyPressEventArgs> > subscribeds = null; KeysSubscription k = new KeysSubscription(e.KeyCode, e.Alt, e.Control, e.Shift); lock (mKeysSubscriptions) { if (mKeysSubscriptions.ContainsKey(k)) { subscribeds = new ListSpecialized <EventHandler <SubscribedKeyPressEventArgs> >(mKeysSubscriptions[k]); } } if (subscribeds != null) { SubscribedKeyPressEventArgs arg = new SubscribedKeyPressEventArgs(k); foreach (EventHandler <SubscribedKeyPressEventArgs> handler in subscribeds) { Raiser.CallDelegatorBySync(handler, new object[] { this, arg }); } } else { IRemoteDesktopClientInternal proxy = mProxy; if (proxy != null && proxy.IsActive) { try { proxy.ClientSendKeyEvent(new KeyboardEventArgs(KeyboardEventTypeEnum.Up, e.KeyCode)); } catch (Exception) { } } //LogKeyEvent(sender, "KEY-UP", e); } }
/// <summary> /// Subscribes for keys. /// </summary> /// <param name="subscription">The subscription.</param> /// <param name="e">The decimal.</param> public void SubscribeForKeys(KeysSubscription subscription, EventHandler <SubscribedKeyPressEventArgs> e) { DoDisposeCheck(); if (subscription == null) { ThrowHelper.ThrowArgumentNullException("subscription"); } if (e == null) { ThrowHelper.ThrowArgumentNullException("e"); } lock (mKeysSubscriptions) { ListSpecialized <EventHandler <SubscribedKeyPressEventArgs> > subscribers = null; if (mKeysSubscriptions.ContainsKey(subscription)) { subscribers = mKeysSubscriptions[subscription]; } else { subscribers = new ListSpecialized <EventHandler <SubscribedKeyPressEventArgs> >(); mKeysSubscriptions[subscription] = subscribers; } subscribers.Add(e); } }
private static ListSpecialized <TEntity> ExecuteQuery <TEntity>(ISession session, QueryParamsBase queryData, DetachedCriteria dc, ICriteria criteria, bool logQuery) where TEntity : EntityBaseWithoutId { if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) BEGIN --->", queryData.Id)); } if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("(ID: {0}) {1}: {2}", queryData.Id, queryData.EntityType.FullName, criteria.ToString())); } } ListSpecialized <TEntity> result = null; try { result = new ListSpecialized <TEntity>(criteria.List <TEntity>()); if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) END, SIZE OF THE RESULT SET: {1} --->", queryData.Id, result == null ? "0" : result.Count.ToString())); } } } catch (Exception ex) { if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) END, FAILED --->", queryData.Id)); } } throw new QueryException(ex.Message, ex); } if (result == null) { result = new ListSpecialized <TEntity>(); } else { for (int i = 0; i < result.Count; i++) { EntityBaseWithoutId eb = result[i]; if (eb is INHibernateProxy) { result[i] = (TEntity)session.GetSessionImplementation().PersistenceContext.UnproxyAndReassociate(eb); } } } return(result); }
/// <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); }
/// <summary> /// Queries the specified session. /// </summary> /// <param name="session">The session.</param> /// <param name="queryData">The query data.</param> /// <param name="logQuery">if set to <c>true</c> [log query].</param> /// <returns>The result list</returns> public static IListSpecialized <EntityBaseWithoutId> Query(ISession session, QueryParamsBase queryData, bool logQuery) { IList queryResult = (System.Collections.IList)mGenericQueryMethod.MakeGenericMethod(queryData.EntityType).Invoke(null, new object[] { session, queryData, logQuery }); IListSpecialized <EntityBaseWithoutId> result = new ListSpecialized <EntityBaseWithoutId>(); foreach (object b in queryResult) { result.Add((EntityBaseWithoutId)b); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="ReportPackage" /> class. /// </summary> /// <param name="loggingEvent">The logging event.</param> /// <param name="logEvents">The log events.</param> public ReportPackage(LoggingEvent loggingEvent, ICollection <LoggingEvent> logEvents) { if (loggingEvent == null) { ThrowHelper.ThrowArgumentNullException("loggingEvent"); } if (logEvents == null) { ThrowHelper.ThrowArgumentNullException("logEvents"); } this.mLogEvents = new ListSpecialized <LoggingEvent>(logEvents); this.ApplicationId = mApplicationId; this.ReportCreated = DateTime.UtcNow; this.LoggingEvent = loggingEvent; }
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(); } } } } }
/// <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); } } } }
private static Type GetTypeFromString(AssemblyName asmName, string typeName, TypeLookupModeEnum typeLookupMode, bool findNewestTypeVersion, bool ignoreCase) { Type result = null; TypeKey typeKey = new TypeKey(asmName, typeName, typeLookupMode, findNewestTypeVersion); lock (mLockObject) { if (mTypeKeyVsType.ContainsKey(typeKey)) { result = mTypeKeyVsType[typeKey]; } else { if (asmName != null) { try { AppDomain.CurrentDomain.Load(asmName); } catch (Exception ex) { // ilyen akkor van, ha a DLL nem betölthető (hibás, nem található, security) if (LOGGER.IsDebugEnabled) { LOGGER.Debug(ex.Message, ex); } } } if (typeName.Contains("[")) { // ez egy array string typeNameWithoutArrayMarks = typeName.Substring(0, typeName.IndexOf("[")); Type elementType = GetTypeFromString(asmName, typeNameWithoutArrayMarks, typeLookupMode, findNewestTypeVersion, ignoreCase); result = Type.GetType(string.Format("{0}{1}, {2}", elementType.FullName, typeName.Substring(typeName.IndexOf("[")), elementType.Assembly.GetName().FullName)); } else { // pontos betöltés result = Type.GetType(typeName, false, ignoreCase); if (result == null && asmName != null) { // betöltés assembly-vel try { result = Type.GetType(string.Format("{0}, {1}", typeName, asmName.FullName), false, ignoreCase); } catch (Exception ex) { // ilyen akkor van, ha a DLL verziója más, mint ami az AppDomain-be be van töltve if (LOGGER.IsDebugEnabled) { LOGGER.Debug(ex.Message, ex); } } } // ha van assembly és nem engedélyezett az azonos verzió, akkor töröljük az eredményt if ((typeLookupMode & TypeLookupModeEnum.AllowExactVersions) == 0 && asmName != null && asmName.Version != null && result != null && result.Assembly.GetName().Version.Equals(asmName.Version)) { // azonos verzió nem engedélyezett result = null; } if (result == null || findNewestTypeVersion) { if (result != null && findNewestTypeVersion && result.IsArray) { // tömböt máshogy kezeljük Type elementType = result.GetElementType(); while (elementType.IsArray) { elementType = elementType.GetElementType(); } Type newestType = GetTypeFromString(elementType.AssemblyQualifiedName, typeLookupMode, true, false, ignoreCase); if (!result.Assembly.GetName().FullName.Equals(newestType.Assembly.GetName().FullName)) { // újabb típus string newTypeStr = string.Format("{0}, {1}", result.FullName, newestType.Assembly.GetName().FullName); result = GetTypeFromString(newTypeStr, TypeLookupModeEnum.AllowExactVersions, false, false, false); } } else { // manuális keresés az AppDomain assembly-k között // 1, ide akkor jutunk, ha a DLL nem létezik vagy a partial name nincs megadva a qualifyAssembly szekcióban // 2, engedélyeztük újabb verziók használatát foreach (Assembly a in new List <Assembly>(AppDomain.CurrentDomain.GetAssemblies())) { if (asmName == null || a.GetName().Name.Equals(asmName.Name)) { Type[] types = null; try { // találkoztam olyan dinamikus DLL-ekkel, amelyeknek a type-jait nem lehetett kiolvasni types = a.GetTypes(); } catch (Exception) { } if (types != null) { foreach (Type t in a.GetTypes()) { if (t.FullName.Equals(typeName)) { if (result == null) { // még nincs kiválasztott típus if (asmName != null && asmName.Version != null) { // van kiinduló verzió if ((typeLookupMode & TypeLookupModeEnum.AllowExactVersions) > 0 && asmName.Version.Equals(a.GetName().Version)) { // azonos verzió engedélyezett result = t; } else if ((typeLookupMode & TypeLookupModeEnum.AllowNewerVersions) > 0 && asmName.Version < a.GetName().Version) { // újabb verzió engedélyezett result = t; } else if ((typeLookupMode & TypeLookupModeEnum.AllowOlderVersions) > 0 && asmName.Version > a.GetName().Version) { // régebbi verzió engedélyezett result = t; } } else { // nincs kiinduló assembly verzió, nincs mihez viszonyítani a verzió, ezért az első alkalmas típus megfelelő result = t; } } else { // már van egy kiválasztott típusunk, attól keresünk megfelelőbbet (vagyis újabb verziót) if (asmName != null && asmName.Version != null) { // van kiinduló verzió if ((typeLookupMode & TypeLookupModeEnum.AllowExactVersions) > 0 && asmName.Version.Equals(a.GetName().Version)) { // azonos verzió engedélyezett result = t; } else if ((typeLookupMode & TypeLookupModeEnum.AllowNewerVersions) > 0 && asmName.Version < a.GetName().Version) { // újabb verzió engedélyezett result = t; } else if ((typeLookupMode & TypeLookupModeEnum.AllowOlderVersions) > 0 && asmName.Version > a.GetName().Version) { // régebbi verzió engedélyezett if (result.Assembly.GetName().Version < a.GetName().Version) { // ha már van exact vagy újabb verziónk, akkor attól régebbire már ne térjünk vissza result = t; } } } else { // nincs referencia verzió assembly, a legfrissebb type keresése if (result.Assembly.GetName().Version < a.GetName().Version) { // újabb verzió result = t; } } } break; } } } } } } } } if (result == null) { throw new TypeLoadException(string.Format("Type '{0}' not found.", typeName)); } string name = result.Assembly.GetName().Name; lock (mAssemblyNameVsTypeKey) { ListSpecialized <TypeKey> typeKeys = null; mTypeKeyVsType[typeKey] = result; if (mAssemblyNameVsTypeKey.ContainsKey(name)) { typeKeys = mAssemblyNameVsTypeKey[name]; } else { typeKeys = new ListSpecialized <TypeKey>(); mAssemblyNameVsTypeKey[name] = typeKeys; } typeKeys.Add(typeKey); } } } return(result); }
protected virtual void FindService() { ListSpecialized <ServiceProvider> providers = new ListSpecialized <ServiceProvider>(); foreach (NetworkContext nc in Forge.Net.TerraGraf.Contexts.NetworkContext.KnownNetworkContexts) { foreach (INetworkPeerRemote peer in nc.KnownNetworkPeers) { if (peer.Distance > 0) { ServiceProvider provider = CheckServiceAvailable(peer); if (provider != null && !providers.Contains(provider)) { providers.Add(provider); } } } } ServiceProvider localhost = CheckServiceAvailable(Forge.Net.TerraGraf.NetworkManager.Instance.Localhost); if (localhost != null && !providers.Contains(localhost)) { providers.Add(localhost); } if (providers.Count > 0) { // vannak kiszolgálók providers.Sort(); ServiceProvider provider = providers[0]; if (this.PreferedServiceProvider == null || !provider.RemoteEndPoint.Equals(this.PreferedServiceProvider.RemoteEndPoint)) { if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, selected service host is '{1}' on port {2}.", LOG_PREFIX, provider.RemoteEndPoint.Host, provider.RemoteEndPoint.Port.ToString())); } this.PreferedServiceProvider = provider; } this.AvailableServiceProviders = providers; if (this.ServiceState == ServiceStateEnum.Unavailable) { OnServiceStateChanged(ServiceStateEnum.Available); } } else { if (this.PreferedServiceProvider != null) { this.PreferedServiceProvider = null; } if (this.AvailableServiceProviders.Count == 0) { // eddig sem voltak kiszolgálók if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service still unavailable.", LOG_PREFIX)); } } else { // most már nincs kiszolgáló if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service unavailable.", LOG_PREFIX)); } this.AvailableServiceProviders = providers; OnServiceStateChanged(ServiceStateEnum.Unavailable); } } providers.Clear(); }
/// <summary> /// Called when [available service provider changed]. /// </summary> /// <param name="serviceProviders">The service providers.</param> protected virtual void OnAvailableServiceProviderChanged(ListSpecialized <ServiceProvider> serviceProviders) { RaiseEvent(EventAvailableServiceProvidersChanged, this, new ServiceProvidersChangedEventArgs(serviceProviders)); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceProvidersChangedEventArgs"/> class. /// </summary> /// <param name="serviceProviders">The service providers.</param> public ServiceProvidersChangedEventArgs(ListSpecialized <ServiceProvider> serviceProviders) { this.mServiceProviders.AddRange(serviceProviders); }