public override string ToString() { if (toString == null) { IProxyTargetAccessor proxy = this as IProxyTargetAccessor; if (proxy == null) { toString = base.ToString(); } else { var target = proxy.DynProxyGetTarget(); if (target == null) { toString = base.ToString(); } else { toString = target.ToString(); } } } // return the cached value return(toString); }
public override void ProcessInvocation(IInvocation invocation) { IProxyTargetAccessor accessor = invocation?.Proxy as IProxyTargetAccessor; if (accessor == null) { return; } MethodInfo target = accessor.DynProxyGetTarget().GetType().GetMethod("SetMessages"); try { invocation.Proceed(); } catch (DbException dbEx) { object[] parameters = GetMessages(dbEx, TipoExcepciones.BaseDeDatos); target.Invoke(invocation.InvocationTarget, parameters); Logger.Error(dbEx); } catch (Exception ex) { object[] parameters = GetMessages(ex, TipoExcepciones.Generico); target.Invoke(invocation.InvocationTarget, parameters); Logger.Error(ex); } }
public override int GetHashCode() { if (cachedHashCode == null) { IProxyTargetAccessor proxy = this as IProxyTargetAccessor; if (proxy == null) { cachedHashCode = base.GetHashCode(); } else { var target = proxy.DynProxyGetTarget(); if (target == null) { cachedHashCode = base.GetHashCode(); } else { cachedHashCode = target.GetHashCode(); } } } // return the cached value return(cachedHashCode.Value); }
public ShadowProperty(GraphContextBase context, PropertyInfo property, IProxyTargetAccessor proxyAccessor) { Context = context ?? throw new ArgumentNullException(nameof(context)); Property = property ?? throw new ArgumentNullException(nameof(property)); ProxyAccessor = proxyAccessor ?? throw new ArgumentNullException(nameof(proxyAccessor)); Attach(); }
private IProxyTargetAccessor GetNestedAccessor(IProxyTargetAccessor accessor) { var nested = accessor.DynProxyGetTarget() as IProxyTargetAccessor; if (nested != null) { return(GetNestedAccessor(nested)); } return(accessor); }
protected void SetupProxy(Guid id, IEnumerable <string> fieldNames, IProxyTargetAccessor target) { var searchInterceptor = target.GetInterceptors().FirstOrDefault(x => x is SearchInterceptor) as SearchInterceptor; if (searchInterceptor == null) { return; } searchInterceptor.Id = new ID(id); searchInterceptor.TypeConfiguration = _sitecoreContext.GlassContext.GetTypeConfiguration <SitecoreTypeConfiguration>(target); searchInterceptor.IndexFields = fieldNames; }
private Type GetNestedType(object accessor) { IProxyTargetAccessor nested = accessor as IProxyTargetAccessor; if (nested == null) { return(accessor.GetType()); } nested = GetNestedAccessor(nested); return(nested.DynProxyGetTarget().GetType()); }
/// <summary> /// Turns given object and all associates to untrackable objects (i.e. POCO objects). /// </summary> /// <param name="some">The whole object to untrack</param> /// <returns>The untracked version of given object</returns> internal static object ToUntypedUntracked(this object some) { if (some == null) { return(some); } IChangeTrackableObject trackable = some as IChangeTrackableObject; if (trackable != null) { IProxyTargetAccessor proxyTargetAccessor = (IProxyTargetAccessor)trackable; object target = proxyTargetAccessor.DynProxyGetTarget(); object unwrapped = target.CloneIt(some.GetType().GetActualTypeIfTrackable()); ObjectChangeTracker changeTracker = (ObjectChangeTracker)trackable.GetChangeTracker(); foreach (KeyValuePair <string, ObjectPropertyChangeTracking> dynamicProperty in changeTracker.DynamicPropertyTrackings) { object propertyValueToSet; IChangeTrackableCollection trackableCollection = dynamicProperty.Value.CurrentValue as IChangeTrackableCollection; if (trackableCollection != null) { propertyValueToSet = ((IEnumerable)trackableCollection).ToUntrackedEnumerable(trackableCollection.GetType()); } else { propertyValueToSet = dynamicProperty.Value.CurrentValue.ToUntracked(); } unwrapped.SetDynamicMember ( dynamicProperty.Value.PropertyName, propertyValueToSet ); } Contract.Assert(() => !(unwrapped is IProxyTargetAccessor), "To convert a tracked object to untracked one the whole tracked object must be created from a pre-existing object"); return(unwrapped); } else { return(some); } }
protected void SetupProxy(ID id, IDictionary <string, object> fieldValues, IProxyTargetAccessor target) { if (target == null) { return; } var searchInterceptor = target.GetInterceptors().FirstOrDefault(x => x is SearchInterceptor) as SearchInterceptor; if (searchInterceptor == null) { return; } searchInterceptor.Id = id; searchInterceptor.TypeConfiguration = new SitecoreContext().GlassContext.GetTypeConfiguration <SitecoreTypeConfiguration>(target); }
public Object PostProcessBean(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type beanType, Object targetBean, ISet <Type> requestedTypes) { IProxyTargetAccessor factory = null; ICascadedInterceptor cascadedInterceptor = null; Object proxiedTargetBean = targetBean; if (targetBean is IProxyTargetAccessor) { factory = (IProxyTargetAccessor)targetBean; IInterceptor[] interceptors = factory.GetInterceptors(); IInterceptor callback = (interceptors != null && interceptors.Length > 0 ? interceptors[0] : null); if (callback is ICascadedInterceptor) { cascadedInterceptor = (ICascadedInterceptor)callback; proxiedTargetBean = cascadedInterceptor.Target; } } ICascadedInterceptor interceptor = HandleServiceIntern(beanContextFactory, beanContext, beanConfiguration, proxiedTargetBean.GetType(), requestedTypes); if (interceptor == null) { return(targetBean); } if (log.DebugEnabled) { log.Debug("Proxying bean with name '" + beanConfiguration.GetName() + "' by " + GetType().FullName); } Object target; if (cascadedInterceptor != null) { target = cascadedInterceptor; } else { target = proxiedTargetBean; } interceptor.Target = target; Object proxy = ProxyFactory.CreateProxy(requestedTypes.ToArray(), interceptor); postHandleServiceIntern(beanContextFactory, beanContext, beanConfiguration, proxiedTargetBean.GetType(), requestedTypes, proxy); return(proxy); }
public static Type GetUnproxiedType(object instance) { if (!RemotingServices.IsTransparentProxy(instance)) { IProxyTargetAccessor accessor = instance as IProxyTargetAccessor; if (accessor != null) { object target = accessor.DynProxyGetTarget(); if (target != null) { if (ReferenceEquals(target, instance)) { return(instance.GetType().BaseType); } instance = target; } } } return(instance.GetType()); }
/// <summary> /// 判断一个对象是不是动态实现类 /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsDynamicImplemented(this object value) { if (!(value is IProxyTargetAccessor)) { return(false); } IProxyTargetAccessor proxyTargetAccessor = value as IProxyTargetAccessor; IInterceptor[] interceptors = proxyTargetAccessor.GetInterceptors(); if (interceptors == null) { return(false); } IEnumerable <ImplementorAttributeExecuteInterceptor> myInterceptor = interceptors.OfType <ImplementorAttributeExecuteInterceptor>(); if (!myInterceptor.Any()) { return(false); } return(true); }
public override bool Equals(object obj) { bool eq; IProxyTargetAccessor proxy = this as IProxyTargetAccessor; if (proxy == null) { eq = base.Equals(obj); } else { var target = proxy.DynProxyGetTarget(); if (target == null) { eq = base.Equals(obj); } else { eq = target.Equals(obj); } } return(eq); }
public static IEnumerable <T> GetInterceptors <T>(IProxyTargetAccessor item) where T : IInterceptor { return(item.GetInterceptors().Where(x => x is T).Cast <T>()); }
public ShadowSingle(GraphContextBase context, PropertyInfo property, IProxyTargetAccessor proxyAccessor) : base(context, property, proxyAccessor) { }
public static PropertyInfo GetTargetPropertyInfo(this IProxyTargetAccessor accessor) { return(accessor.GetCommonData().ParentProxy?.GetType().BaseType? .GetProperties() .SingleOrDefault(x => Equals(x.GetValue(accessor.GetCommonData().ParentProxy, null), accessor))); }
public static CommonData GetCommonData(this IProxyTargetAccessor accessor) { var interceptor = accessor.GetInterceptors().SingleOrDefault(x => x is GeneralGetInterceptor) as GeneralGetInterceptor; return(interceptor?.GetCommonData()); }