Esempio n. 1
0
 internal static void ValidateInterceptorSignature(SyncInterceptorAttribute attr, MethodInfo methodInfo, string parentTypeName)
 {
     // Retrieve the set of parameters
     ParameterInfo[] parameters = methodInfo.GetParameters();
     if (attr is SyncRequestInterceptorAttribute || attr is SyncResponseInterceptorAttribute)
     {
         // Ensure methodInfo is of format public void MethodName(SyncOperationContext context)
         if (methodInfo.ReturnType != SyncServiceConstants.VOID_TYPE ||
             parameters.Length != 1 ||
             (parameters[0].ParameterType != SyncServiceConstants.SYNC_OPERATIONCONTEXT_TYPE))
         {
             throw new InvalidOperationException(string.Format(SyncServiceConstants.SYNC_INCORRECT_INTERCEPTOR_SIGNATURE,
                                                               methodInfo.Name,
                                                               parentTypeName,
                                                               attr.GetType().Name,
                                                               SyncServiceConstants.SYNC_REQUEST_INTERCEPTOR_FORMAT));
         }
     }
     else
     {
         // Ensure methodInfo is of format public SyncUploadConflictResolution MethodName(SyncUploadConflictContext context)
         if (methodInfo.ReturnType != SyncServiceConstants.SYNC_CONFLICT_RESOLUTION_TYPE ||
             parameters.Length != 2 ||
             (parameters[0].ParameterType != SyncServiceConstants.SYNC_CONFLICT_CONTEXT_TYPE) ||
             (parameters[1].ParameterType != SyncServiceConstants.IOFFLINEENTITY_BYREFTYPE))
         {
             throw new InvalidOperationException(string.Format(SyncServiceConstants.SYNC_INCORRECT_INTERCEPTOR_SIGNATURE,
                                                               methodInfo.Name,
                                                               parentTypeName,
                                                               attr.GetType().Name,
                                                               SyncServiceConstants.SYNC_CONFLICT_INTERCEPTOR_FORMAT));
         }
     }
 }
        /// <summary>
        /// This method processes a single SyncInterceptorAttribute defined on a method. Processing involves the following
        /// 1. Ensure that the MethodInfo signature is the right one for the interceptor.
        /// 2. Retrieve the ScopeNames defined in the attribute and ensure they are valid scopes configures via the
        /// ISyncScopeConfiguration.SetEnableScope() API.
        /// 3. Create a SyncInterceptorInfoWrapper object for the scope if none is present.
        /// 4. Add the interceptor to the wrapper object.
        /// </summary>
        /// <param name="attr">The SyncInterceptorAttribute to process.</param>
        /// <param name="syncServiceType">Actual SyncService type</param>
        /// <param name="methodInfo">User Method on which the attribute is applied</param>
        private void ProcessSyncInterceptor(SyncInterceptorAttribute attr, Type syncServiceType, MethodInfo methodInfo)
        {
            // Validate the method signature attribute
            WebUtil.ValidateInterceptorSignature(attr, methodInfo, syncServiceType.Name);

            // Read the list of scopeNames from the attribute
            string[] scopeNames = attr.ScopeName.Select(e => e.ToLowerInvariant()).ToArray();

            foreach (string scopeName in scopeNames)
            {
                // Check to ensure the scopeName is valid configured scope.
                if (!this.ScopeNames.Contains(scopeName))
                {
                    // ScopeName is not part of configured scopes. Throw.
                    throw new InvalidOperationException(
                              string.Format(CultureInfo.InvariantCulture, "ScopeName '{0}' defined in '{1}' on method '{2}' is not in the list of configured sync scopes.",
                                            scopeName, attr.GetType().Name, methodInfo.Name));
                }
                SyncInterceptorsInfoWrapper wrapper = null;
                // Check and create the wrapper object for the current scope if none exists.
                if (!this.SyncInterceptors.TryGetValue(scopeName, out wrapper))
                {
                    wrapper = new SyncInterceptorsInfoWrapper(scopeName);
                    this.SyncInterceptors.Add(scopeName, wrapper);
                }

                // Add interceptor to the wrapper.
                wrapper.AddInterceptor(attr, methodInfo, syncServiceType.Name);
            }
        }
Esempio n. 3
0
 internal static Exception ThrowFilteredAndNonFilteredInterceptorException(string className, string scopeName, SyncInterceptorAttribute attr)
 {
     return(new InvalidOperationException(
                string.Format("SyncService '{0}' has both filtered and non-filtered '{1}' interceptor's defined for scope '{2}'.",
                              className,
                              attr.GetType().Name,
                              scopeName)));
 }
Esempio n. 4
0
 internal static Exception ThrowInterceptorArgumentNotIOEException(string className, string scopeName, SyncInterceptorAttribute attr, string argumentName)
 {
     return(new InvalidOperationException(
                string.Format("SyncService '{0}' filtered interceptor definition '{1}' for scope '{2}' declares a Type '{3}' that does not derive from IOfflineEntity.",
                              className,
                              attr.GetType().Name,
                              scopeName,
                              argumentName)));
 }
Esempio n. 5
0
 internal static Exception ThrowDuplicateInterceptorException(string className, string scopeName, SyncInterceptorAttribute attr)
 {
     return(new InvalidOperationException(
                string.Format("SyncService '{0}' has mutiple '{1}' interceptors on SyncOperations '{2}' defined for scopename '{3}'",
                              className,
                              attr.GetType().Name,
                              attr.Operation,
                              scopeName)));
 }
        /// <summary>
        /// This method processes a single SyncInterceptorAttribute defined on a method. Processing involves the following
        /// 1. Ensure that the MethodInfo signature is the right one for the interceptor.
        /// 2. Retrieve the ScopeNames defined in the attribute and ensure they are valid scopes configures via the 
        /// ISyncScopeConfiguration.SetEnableScope() API.
        /// 3. Create a SyncInterceptorInfoWrapper object for the scope if none is present.
        /// 4. Add the interceptor to the wrapper object.
        /// </summary>
        /// <param name="attr">The SyncInterceptorAttribute to process.</param>
        /// <param name="syncServiceType">Actual SyncService type</param>
        /// <param name="methodInfo">User Method on which the attribute is applied</param>
        private void ProcessSyncInterceptor(SyncInterceptorAttribute attr, Type syncServiceType, MethodInfo methodInfo)
        {
            // Validate the method signature attribute
            WebUtil.ValidateInterceptorSignature(attr, methodInfo, syncServiceType.Name);

            // Read the list of scopeNames from the attribute
            string[] scopeNames = attr.ScopeName.Select(e => e.ToLowerInvariant()).ToArray();

            foreach (string scopeName in scopeNames)
            {
                // Check to ensure the scopeName is valid configured scope.
                if (!this.ScopeNames.Contains(scopeName))
                {
                    // ScopeName is not part of configured scopes. Throw.
                    throw new InvalidOperationException(
                        string.Format(CultureInfo.InvariantCulture, "ScopeName '{0}' defined in '{1}' on method '{2}' is not in the list of configured sync scopes.",
                        scopeName, attr.GetType().Name, methodInfo.Name));
                }
                SyncInterceptorsInfoWrapper wrapper = null;
                // Check and create the wrapper object for the current scope if none exists.
                if (!this.SyncInterceptors.TryGetValue(scopeName, out wrapper))
                {
                    wrapper = new SyncInterceptorsInfoWrapper(scopeName);
                    this.SyncInterceptors.Add(scopeName, wrapper);
                }

                // Add interceptor to the wrapper.
                wrapper.AddInterceptor(attr, methodInfo, syncServiceType.Name);
            }
        }