Beispiel #1
0
        /// <summary>Fires the notification for a single action.</summary>
        /// <param name="service">Service on which methods should be invoked.</param>
        /// <param name="target">Object to be tracked.</param>
        /// <param name="container">Container in which object is changed.</param>
        /// <param name="action">Action affecting target.</param>
        internal static void FireNotification(IDataService service, object target, ResourceSetWrapper container, UpdateOperations action)
        {
            Debug.Assert(service != null, "service != null");
            AssertActionValues(target, container);

            MethodInfo[] methods = container.ChangeInterceptors;
            if (methods != null)
            {
                object[] parameters = new object[2];
                parameters[0] = target;
                parameters[1] = action;
                for (int i = 0; i < methods.Length; i++)
                {
                    try
                    {
                        methods[i].Invoke(service.Instance, parameters);
                    }
                    catch (TargetInvocationException exception)
                    {
                        ErrorHandler.HandleTargetInvocationException(exception);
                        throw;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>Fires all notifications</summary>
        internal void FireNotifications()
        {
            object[] parameters = new object[2];
            foreach (var item in this.items)
            {
                MethodInfo[] methods = item.Key.ChangeInterceptors;
                Debug.Assert(methods != null, "methods != null - should not have been tracking changes to the container otherwise.");
                foreach (var element in item.Value)
                {
                    parameters[0] = this.service.Updatable.ResolveResource(element.Key);
                    parameters[1] = element.Value;
                    for (int i = 0; i < methods.Length; i++)
                    {
                        try
                        {
                            methods[i].Invoke(this.service.Instance, parameters);
                        }
                        catch (TargetInvocationException exception)
                        {
                            ErrorHandler.HandleTargetInvocationException(exception);
                            throw;
                        }
                    }
                }

                // Make elements elegible for garbage collection.
                item.Value.Clear();
            }

            // Make dictionary elegible for garbage collection.
            this.items = null;
        }
 private void InvokeStaticInitialization(Type type)
 {
     while (type != null)
     {
         MethodInfo info = type.GetMethod("InitializeService", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, new Type[] { typeof(IDataServiceConfiguration) }, null) ?? type.GetMethod("InitializeService", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, new Type[] { typeof(DataServiceConfiguration) }, null);
         if ((info != null) && (info.ReturnType == typeof(void)))
         {
             ParameterInfo[] parameters = info.GetParameters();
             if ((parameters.Length == 1) && !parameters[0].IsOut)
             {
                 object[] objArray = new object[] { this };
                 try
                 {
                     info.Invoke(null, objArray);
                 }
                 catch (TargetInvocationException exception)
                 {
                     ErrorHandler.HandleTargetInvocationException(exception);
                     throw;
                 }
                 return;
             }
         }
         type = type.BaseType;
     }
 }
 internal static Expression ComposeResourceContainer(IDataService service, ResourceSetWrapper container, Expression queryExpression)
 {
     MethodInfo[] queryInterceptors = container.QueryInterceptors;
     if (queryInterceptors != null)
     {
         for (int i = 0; i < queryInterceptors.Length; i++)
         {
             Expression expression;
             try
             {
                 expression = (Expression)queryInterceptors[i].Invoke(service.Instance, WebUtil.EmptyObjectArray);
             }
             catch (TargetInvocationException exception)
             {
                 ErrorHandler.HandleTargetInvocationException(exception);
                 throw;
             }
             if (expression == null)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.DataService_AuthorizationReturnedNullQuery(queryInterceptors[i].Name, queryInterceptors[i].DeclaringType.FullName));
             }
             queryExpression = queryExpression.QueryableWhere((LambdaExpression)expression);
         }
     }
     return(queryExpression);
 }
Beispiel #5
0
 internal void FireNotifications()
 {
     object[] parameters = new object[2];
     foreach (KeyValuePair <ResourceSetWrapper, Dictionary <object, UpdateOperations> > pair in this.items)
     {
         MethodInfo[] changeInterceptors = pair.Key.ChangeInterceptors;
         foreach (KeyValuePair <object, UpdateOperations> pair2 in pair.Value)
         {
             parameters[0] = this.service.Updatable.ResolveResource(pair2.Key);
             parameters[1] = pair2.Value;
             for (int i = 0; i < changeInterceptors.Length; i++)
             {
                 try
                 {
                     changeInterceptors[i].Invoke(this.service.Instance, parameters);
                 }
                 catch (TargetInvocationException exception)
                 {
                     ErrorHandler.HandleTargetInvocationException(exception);
                     throw;
                 }
             }
         }
         pair.Value.Clear();
     }
     this.items = null;
 }
Beispiel #6
0
 internal static void FireNotification(IDataService service, object target, ResourceSetWrapper container, UpdateOperations action)
 {
     MethodInfo[] changeInterceptors = container.ChangeInterceptors;
     if (changeInterceptors != null)
     {
         object[] parameters = new object[] { target, action };
         for (int i = 0; i < changeInterceptors.Length; i++)
         {
             try
             {
                 changeInterceptors[i].Invoke(service.Instance, parameters);
             }
             catch (TargetInvocationException exception)
             {
                 ErrorHandler.HandleTargetInvocationException(exception);
                 throw;
             }
         }
     }
 }
        internal static Expression ComposeQueryInterceptors(IDataService service, ResourceSetWrapper container)
        {
            MethodInfo[] queryInterceptors = container.QueryInterceptors;
            if ((queryInterceptors == null) || (queryInterceptors.Length == 0))
            {
                return(null);
            }
            LambdaExpression expression = null;

            for (int i = 0; i < queryInterceptors.Length; i++)
            {
                Expression expression2;
                try
                {
                    expression2 = (Expression)queryInterceptors[i].Invoke(service.Instance, WebUtil.EmptyObjectArray);
                }
                catch (TargetInvocationException exception)
                {
                    ErrorHandler.HandleTargetInvocationException(exception);
                    throw;
                }
                if (expression2 == null)
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.DataService_AuthorizationReturnedNullQuery(queryInterceptors[i].Name, queryInterceptors[i].DeclaringType.FullName));
                }
                LambdaExpression expression3 = (LambdaExpression)expression2;
                if (expression == null)
                {
                    expression = expression3;
                }
                else
                {
                    ParameterExpression newExpression = expression.Parameters[0];
                    Expression          right         = ParameterReplacerVisitor.Replace(expression3.Body, expression3.Parameters[0], newExpression);
                    expression = Expression.Lambda(Expression.And(expression.Body, right), new ParameterExpression[] { newExpression });
                }
            }
            return(expression);
        }