public bool WritesCustom(Object obj, Type type, IWriter writer) { if (SyncToAsyncUtil.IsLowLevelSerializationType(type)) { // Those types can never be an entity return(false); } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(type, true); if (metaData == null) { return(false); } int idValue = writer.GetIdOfObject(obj); if (idValue != 0) { writer.WriteStartElement(XmlDictionary.RefElement); writer.WriteAttribute(XmlDictionary.IdAttribute, idValue); writer.WriteEndElement(); } else { writer.AddSubstitutedEntity(obj); IObjRef ori = ObjRefHelper.EntityToObjRef(obj, true); WriteOpenElement(ori, obj, writer); writer.WriteObject(ori.RealType); writer.WriteObject(ori.Id); writer.WriteObject(ori.Version); writer.WriteCloseElement(XmlDictionary.OriWrapperElement); } return(true); }
public TestData getServiceDescriptionTestData() { String dataName = "ServiceDescription"; String xml = GetJavaTestXml(dataName); String xmlCS = GetCsTestXml(dataName); Type[] argTypes = { typeof(int), typeof(Material), typeof(String), typeof(MaterialGroup), typeof(Material), typeof(DateTime) }; MethodInfo serviceMethod = typeof(ITestService).GetMethod("MixedParamsNoReturn", argTypes); Object obj = SyncToAsyncUtil.CreateServiceDescription("TestService", serviceMethod, ColletionData); return(new TestData(xml, xmlCS, obj)); }
protected override Object InterceptApplication(IInvocation invocation, Boolean?isAsyncBegin) { Object[] arguments = invocation.Arguments; MethodInfo method = invocation.Method; if (isAsyncBegin.HasValue && !isAsyncBegin.Value) { return(((IAsyncResult)arguments[0]).AsyncState); } if (isAsyncBegin.HasValue) { AsyncCallback asyncCallback; Object[] syncArguments = SyncToAsyncUtil.BuildSyncArguments(arguments, out asyncCallback); MethodInfo syncMethod = SyncToAsyncUtil.GetSyncMethod(method, GetSyncServiceType()); ServiceDescription serviceDescription = SyncToAsyncUtil.CreateServiceDescription(ServiceName, syncMethod, syncArguments); IAsyncResult asyncResult = Client.BeginCallProgressableService(serviceDescription, delegate(IAsyncResult ar) { try { Object progressedResult = Client.EndCallProgressableService(ar); if (asyncCallback != null) { asyncCallback.Invoke(new AsyncResult(progressedResult)); } } catch (Exception e) { if (Log.ErrorEnabled) { Log.Error(e); } throw; } }, null); return(asyncResult); } ServiceDescription serviceDescription2 = SyncToAsyncUtil.CreateServiceDescription(ServiceName, method, arguments); Object result = Service.CallProgressableService(serviceDescription2); return(result); }
protected override void InterceptIntern(IInvocation invocation) { ParameterInfo[] parameters = invocation.Method.GetParameters(); Object[] arguments = invocation.Arguments; MethodInfo method = invocation.Method; MethodInfo[] asyncMethods = SyncToAsyncUtil.GetAsyncMethods(method, AsyncServiceInterface); MethodInfo beginMethod = asyncMethods[0]; MethodInfo endMethod = asyncMethods[1]; if (AsyncService is IInterceptor) { //TODO: review this code. fail silently? // AsyncService must not be the Interceptor, but the proxy object return; } SyncCallItem syncCallItem = new SyncCallItem(); syncCallItem.ServiceObject = AsyncService; syncCallItem.AsyncEndMethod = endMethod; Delegate mySyncDelegate = Delegate.CreateDelegate(typeof(AsyncCallback), syncCallItem, "CallbackMethod"); Object[] beginArguments = new Object[beginMethod.GetParameters().Length]; Array.Copy(arguments, 0, beginArguments, 0, arguments.Length); beginArguments[beginArguments.Length - 2] = mySyncDelegate; beginArguments[beginArguments.Length - 1] = null; OfflineListenerExtendable.AddOfflineListener(syncCallItem); try { beginMethod.Invoke(AsyncService, beginArguments); invocation.ReturnValue = syncCallItem.GetResult(); } finally { OfflineListenerExtendable.RemoveOfflineListener(syncCallItem); } }
protected override Object InterceptApplication(IInvocation invocation, Attribute annotation, Boolean?isAsyncBegin) { bool oldProcessServiceActive = processServiceActiveTL.Value; if (oldProcessServiceActive || ProcessService == null || !AnnotationUtil.IsAnnotationPresent <ServiceClientAttribute>(invocation.Method.DeclaringType, false)) { return(base.InterceptApplication(invocation, annotation, isAsyncBegin)); } ISecurityScope[] securityScopes = SecurityScopeProvider.SecurityScopes; IServiceDescription serviceDescription = SyncToAsyncUtil.CreateServiceDescription(ServiceName, invocation.Method, invocation.Arguments, securityScopes); processServiceActiveTL.Value = true; try { return(ProcessService.InvokeService(serviceDescription)); } finally { processServiceActiveTL.Value = oldProcessServiceActive; } }
protected override Object InterceptLoad(IInvocation invocation, Attribute annotation, Boolean?isAsyncBegin) { ServiceDescription serviceDescription; IServiceResult serviceResult; MethodInfo method = invocation.Method; Object[] args = invocation.Arguments; CachedAttribute cached = annotation is CachedAttribute ? (CachedAttribute)annotation : null; if (cached == null && pauseCache.Value) { return(base.InterceptLoad(invocation, annotation, isAsyncBegin)); } Type returnType = method.ReturnType; if (ImmutableTypeSet.IsImmutableType(returnType)) { // No possible result which might been read by cache return(base.InterceptLoad(invocation, annotation, isAsyncBegin)); } if (cached == null) { ISecurityScope[] securityScopes = SecurityScopeProvider.SecurityScopes; serviceDescription = SyncToAsyncUtil.CreateServiceDescription(ServiceName, method, args, securityScopes); serviceResult = CacheService.GetORIsForServiceRequest(serviceDescription); return(CreateResultObject(serviceResult, returnType, args, annotation)); } if (args.Length != 1) { throw new Exception("This annotation is only allowed on methods with exactly 1 argument. Please check your " + typeof(CachedAttribute).FullName + " annotation on method " + method.ToString()); } Type entityType = cached.Type; if (entityType == null || typeof(void).Equals(entityType)) { entityType = TypeInfoItemUtil.GetElementTypeUsingReflection(returnType, null); } if (entityType == null || typeof(void).Equals(entityType)) { throw new Exception("Please specify a valid returnType for the " + typeof(CachedAttribute).FullName + " annotation on method " + method.ToString()); } IEntityMetaData metaData = GetSpecifiedMetaData(method, typeof(CachedAttribute), entityType); Member member = GetSpecifiedMember(method, typeof(CachedAttribute), metaData, cached.AlternateIdName); sbyte idIndex; try { idIndex = metaData.GetIdIndexByMemberName(member.Name); } catch (Exception e) { throw new Exception( "Member " + entityType.FullName + "." + cached.AlternateIdName + " is not configured as an alternate ID member. There must be a single-column unique contraint on the respective table column. Please check your " + typeof(CachedAttribute).FullName + " annotation on method " + method.ToString(), e); } bool returnMisses = cached.ReturnMisses; List <IObjRef> orisToGet = new List <IObjRef>(); FillOrisToGet(orisToGet, args, entityType, idIndex, returnMisses); return(CreateResultObject(orisToGet, returnType, returnMisses, annotation)); }