本文整理汇总了C#中IService.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IService.GetType方法的具体用法?C# IService.GetType怎么用?C# IService.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IService
的用法示例。
在下文中一共展示了IService.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterService
public void RegisterService(IService service)
{
IService existingService;
if (services.TryGetValue(service.GetType(), out existingService))
{
// TODO: log: service already exists
existingService = service;
}
else
{
services.Add(service.GetType(), service);
}
}
示例2: RunService
public async Task RunService(IService service, CancellationToken token)
{
_logger.InfoFormat("Running service {0}", service.Name);
await TaskEx.Yield();
var blobs = _client.GetContainerReference("locks");
await blobs.CreateIfNotExistAsync();
var blob = blobs.GetBlobReference(service.Name);
while (!token.IsCancellationRequested)
{
try
{
if (service is IScheduledService)
await HandleScheduledService((IScheduledService)service, blob, token);
else if (service is IClusteredService)
await HandleClusteredService((IClusteredService)service, blob, token);
else if (service is IContinuousService)
await HandleContinuousService((IContinuousService)service, blob, token);
}
catch (OperationCanceledException)
{
// no-op
}
catch (Exception e)
{
_logger.ErrorFormat("The main task of service \"{0}\" threw an exception.", e, service.Name);
}
}
_logger.InfoFormat("Service {0} stopped", service.GetType().Name);
throw new OperationCanceledException(token);
}
示例3: GetEventField
private static FieldInfo GetEventField(IService serviceInstance, EventInfo eventInfo)
{
return serviceInstance.GetType()
.GetField(eventInfo.Name,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public |
BindingFlags.FlattenHierarchy);
}
示例4: GetCustomEvents
public IEnumerable<CustomEventDto> GetCustomEvents(IService serviceInstance)
{
return serviceInstance.GetType().GetEvents()
.Select(x => new CustomEventDto
{
EventName = x.Name,
Handlers = GetCustomEventHandlers(serviceInstance, x)
})
.Where(x => x.Handlers != null && x.Handlers.Any());
}
示例5: RegisterCacheEntry
private void RegisterCacheEntry(IService Service)
{
try
{
if (HttpContext.Current.Cache[Service.GetType().Name] != null)
return;
HttpContext.Current.Cache.Add(Service.GetType().Name, Service, null,
DateTime.Now.AddMinutes(Service.Interval), System.Web.Caching.Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
new CacheItemRemovedCallback(CacheItemRemovedCallback));
}
catch (Exception ex)
{
}
}
示例6: AddService
public void AddService( IService service )
{
services.Add( service );
NTrace.Debug( "Added " + service.GetType().Name );
}
示例7: IsInstanceOfType
// HACK: MONO BUGFIX
// this doesn't work on mono:serviceType.IsInstanceOfType(service)
bool IsInstanceOfType(Type type, IService service)
{
Type serviceType = service.GetType();
foreach (Type iface in serviceType.GetInterfaces()) {
if (iface == type) {
return true;
}
}
while (serviceType != typeof(System.Object)) {
if (type == serviceType) {
return true;
}
serviceType = serviceType.BaseType;
}
return false;
}
示例8: CacheService
private void CacheService(IService Service)
{
//Ping the "CacheService" page which will trigger Application_BeginRequest and register another cache item
WebClient client = new WebClient();
client.DownloadData(new Uri(_url + "/CacheService.aspx?Type=" + Service.GetType().Name));
}
示例9: EventsFromInstance
public static EventInfo[] EventsFromInstance(IService instance)
{
var t = instance.GetType();
return t.GetEvents();
}
示例10: RegisterService
/// <summary>
/// Registers a service into the system.
/// </summary>
/// <param name="serviceInstance"></param>
public void RegisterService(IService serviceInstance)
{
RegisterService(serviceInstance.GetType(), serviceInstance);
}
示例11: AddService
public void AddService(IService service)
{
_services.Add(service);
log.Debug("Added " + service.GetType().Name);
}
示例12: GetCategorizedItems
/// <summary>
/// Gets the categorized items.
/// </summary>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="categoryId">The category id.</param>
/// <param name="showUnnamedEntityItems">if set to <c>true</c> [show unnamed entity items].</param>
/// <returns></returns>
private IQueryable<ICategorized> GetCategorizedItems( IService serviceInstance, int categoryId, bool showUnnamedEntityItems )
{
if ( serviceInstance != null )
{
MethodInfo getMethod = serviceInstance.GetType().GetMethod( "Get", new Type[] { typeof( ParameterExpression ), typeof( Expression ) } );
if ( getMethod != null )
{
ParameterExpression paramExpression = serviceInstance.ParameterExpression;
MemberExpression propertyExpression = Expression.Property( paramExpression, "CategoryId" );
BinaryExpression compareExpression = null;
ConstantExpression constantExpression = Expression.Constant( categoryId );
if ( propertyExpression.Type == typeof( int? ) )
{
var zeroExpression = Expression.Constant( 0 );
var coalesceExpression = Expression.Coalesce( propertyExpression, zeroExpression );
compareExpression = Expression.Equal( coalesceExpression, constantExpression );
}
else
{
compareExpression = Expression.Equal( propertyExpression, constantExpression );
}
var result = getMethod.Invoke( serviceInstance, new object[] { paramExpression, compareExpression } ) as IQueryable<ICategorized>;
if ( !showUnnamedEntityItems )
{
result = result.Where( a => a.Name != null && a.Name != string.Empty );
}
return result;
}
}
return null;
}
示例13: AddService
public bool AddService(IService service)
{
if (!this.CanLoad(service))
{
Debug.WriteLine(this + ": " + service + " konnte nicht geladen werden");
return false;
}
Debug.WriteLine(this + ": loading " + service.GetType());
/* foreach (IService ser in this.services)
{
if ((ser).GetType() == service.GetType())
{
Debug.WriteLine(typeof(this) + ": Service bereits geladen!");
return;
}
}
*/
if (this.services.ContainsKey(service.GetType()))
{
Debug.WriteLine(this + ": Service bereits geladen!");
return false;
}
this.services.Add(service.GetType(), service);
service.Load();
// TODO: return service.Load()
return true;
}
示例14: SearchService
private bool SearchService(Type type, IService service)
{
Type stype = service.GetType();
foreach (Type ia in stype.GetInterfaces())
{
if (type == ia)
return true;
}
while (stype != typeof(object))
{
if (type == stype)
return true;
stype = stype.BaseType;
}
return false;
}
示例15: Unload
public bool Unload(IService service)
{
if (!this.CanUnload(service))
{
Debug.WriteLine(this + ": kann " + service + "nicht entladen");
return false;
}
Debug.WriteLine(this + ": entlade " + service.GetType() + "...");
if (service.Loaded)
service.Unload();
this.services.Remove(service.GetType());
return true;
}