private void CheckForDuplicateAndAddInterceptors(SyncInterceptorAttribute attr, MethodInfo info, string className, ref MethodInfo nonFilteredInfo, Dictionary <Type, MethodInfo> filteredInfo) { // Check we dont have two non filtered interceptors for same operation if (nonFilteredInfo != null) { throw WebUtil.ThrowDuplicateInterceptorException(className, this.ScopeName, attr); } // Check we dont have a filtered and non filtered interceptors for same operation if ((attr.EntityType != null && nonFilteredInfo != null) || (attr.EntityType == null && filteredInfo.Count != 0)) { throw WebUtil.ThrowFilteredAndNonFilteredInterceptorException(className, this.ScopeName, attr); } if (attr.EntityType != null) { // If filtered, ensure we dont have duplicates in type if (filteredInfo.ContainsKey(attr.EntityType)) { throw WebUtil.ThrowDuplicateInterceptorForArgumentException(className, this.ScopeName, attr, attr.EntityType.FullName); } // Check that argument is of type IOfflineEntity if (!SyncServiceConstants.IOFFLINEENTITY_TYPE.IsAssignableFrom(attr.EntityType)) { throw WebUtil.ThrowInterceptorArgumentNotIOEException(className, this.ScopeName, attr, attr.EntityType.FullName); } // If not then its valid. So add it to the list filteredInfo.Add(attr.EntityType, info); } else { // Its a valid non filtered interceptor. nonFilteredInfo = info; } }
/// <summary> /// Adds the MethodInfo signature for the specified interceptor type and operation. This /// method also ensures that the interceptor is valid and is not a duplicate entry before /// adding it. /// </summary> /// <param name="attr">Interceptor Attribute</param> /// <param name="info">MethodInfo signature</param> /// <param name="className">ClassName for error messages</param> internal void AddInterceptor(SyncInterceptorAttribute attr, MethodInfo info, string className) { if (attr is SyncRequestInterceptorAttribute) { // Its a Request interceptor. Check for Operation if ((attr.Operation & SyncOperations.Download) == SyncOperations.Download) { // Configured for Download. Ensure no duplicates if (this._downloadRequestInterceptor != null) { throw WebUtil.ThrowDuplicateInterceptorException(className, this.ScopeName, attr); } this._downloadRequestInterceptor = info; } if ((attr.Operation & SyncOperations.Upload) == SyncOperations.Upload) { // Configured for Upload. Ensure no duplicates CheckForDuplicateAndAddInterceptors(attr, info, className, ref _uploadRequestInterceptor, _uploadTypedRequestInterceptors); } } else if (attr is SyncResponseInterceptorAttribute) { // Its a Response interceptor. Check for Operation if ((attr.Operation & SyncOperations.Download) == SyncOperations.Download) { // Configured for Download. CheckForDuplicateAndAddInterceptors(attr, info, className, ref _downloadResponseInterceptor, _downloadTypedResponseInterceptors); } if ((attr.Operation & SyncOperations.Upload) == SyncOperations.Upload) { // Configured for Upload. CheckForDuplicateAndAddInterceptors(attr, info, className, ref _uploadResponseInterceptor, _uploadTypedResponseInterceptors); } } else { // Its a conflict interceptor. Check we dont have another conflict interceptor for the same scope CheckForDuplicateAndAddInterceptors(attr, info, className, ref _conflictInterceptor, _conflictTypedInterceptors); } }