示例#1
0
        public void ManageabilityProviderGeneratesProperAdmContentWithRegisteredProviders()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(ExceptionHandlingSettings.SectionName, section);

            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");

            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType11 = new ExceptionTypeData("type11", typeof(Exception), PostHandlingAction.None);

            policy1.ExceptionTypes.Add(exceptionType11);
            ExceptionHandlerData handler11 = new ExceptionHandlerData("handler11", typeof(object));

            exceptionType11.ExceptionHandlers.Add(handler11);

            MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider(false, true);
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(ExceptionHandlerData), subProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(new ExceptionHandlingSettingsManageabilityProvider(subProviders));

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.InvokeAddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            MockAdmContent            content = contentBuilder.GetMockContent();
            IEnumerator <AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();

            Assert.IsTrue(categoriesEnumerator.MoveNext());
            Assert.AreEqual(Resources.SectionCategoryName, categoriesEnumerator.Current.Name);
            IEnumerator <AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();

            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            Assert.AreEqual(policy1.Name, subCategoriesEnumerator.Current.Name);
            IEnumerator <AdmPolicy> policyPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator();

            Assert.IsTrue(policyPoliciesEnumerator.MoveNext());
            Assert.AreEqual(String.Format(Resources.ExceptionTypePolicyNameTemplate, exceptionType11.Name), policyPoliciesEnumerator.Current.Name);
            IEnumerator <AdmPart> partsEnumerator = policyPoliciesEnumerator.Current.Parts.GetEnumerator();

            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), partsEnumerator.Current.GetType());
            Assert.IsNull(partsEnumerator.Current.KeyName);
            Assert.AreEqual(ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName,
                            partsEnumerator.Current.ValueName);
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmTextPart), partsEnumerator.Current.GetType());
            Assert.AreEqual(Resources.ExceptionTypeHandlersPartName, partsEnumerator.Current.PartName);
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmTextPart), partsEnumerator.Current.GetType());
            Assert.AreEqual(MockConfigurationElementManageabilityProvider.Part, partsEnumerator.Current.PartName);

            Assert.IsFalse(partsEnumerator.MoveNext());
            Assert.IsFalse(policyPoliciesEnumerator.MoveNext());

            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
示例#2
0
 void ProcessCatchHandlers(ExceptionHandlerData data, TryStatement @try)
 {
     foreach (var catch_data in data.Catches)
     {
         @try.CatchClauses.Add(CreateCatchHandler(catch_data));
     }
 }
示例#3
0
 /// <summary>
 /// Constructs a new instance of the <see cref="ExceptionHandlerNode"/> object with
 /// a corresponding runtime configuration data.
 /// </summary>
 /// <param name="exceptionHandlerData">The cooresponding configuration data.</param>
 protected ExceptionHandlerNode(ExceptionHandlerData exceptionHandlerData) : base(/*SR.ExceptionHandler*/)
 {
     if (exceptionHandlerData == null)
     {
         throw new ArgumentNullException("exceptionHandlerData");
     }
     this.exceptionHandlerData = exceptionHandlerData;
 }
        public void ExceptionHandlerDataTest()
        {
            string name = "some name";
            ExceptionHandlerData data = new ExceptionHandlerData();

            data.Name = name;
            ExceptionHandlerNode node = new ExceptionHandlerNodeImpl(data);

            Assert.AreEqual(name, node.Name);
        }
        public void ExceptionHandlerNodeDataTest()
        {
            string name = "some name";
            ExceptionHandlerData exceptionHandlerData = new ExceptionHandlerData();

            exceptionHandlerData.Name = name;
            ExceptionHandlerNode exceptionHandlerNode = new ExceptionHandlerNodeImpl(exceptionHandlerData);
            ExceptionHandlerData nodeData             = exceptionHandlerNode.ExceptionHandlerData;

            Assert.AreEqual(name, nodeData.Name);
        }
        private ExceptionHandlerData GetExceptionHandlerData(ExceptionHandlingSettings settings, string policyName, string exceptionTypeName, string handlerName)
        {
            ExceptionHandlerDataCollection exceptionHandlerDataCollection = GetExceptionHandlerDataCollection(settings, policyName, exceptionTypeName);
            ExceptionHandlerData           data = exceptionHandlerDataCollection[handlerName];

            if (data == null)
            {
                throw new ConfigurationException(SR.ExceptionExceptionHanlderNotFoun(handlerName, exceptionTypeName, policyName));
            }

            return(data);
        }
示例#7
0
        /// <summary>
        /// <para>Initializes the provider with a <see cref="ExceptionHandlingConfigurationView"/>.</para>
        /// </summary>
        /// <param name="configurationView">
        /// <para>A <see cref="ExceptionHandlingConfigurationView"/> object.</para>
        /// </param>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof(ExceptionHandlingConfigurationView));

            ExceptionHandlingConfigurationView exceptionHandlingConfigurationView = (ExceptionHandlingConfigurationView)configurationView;
            ExceptionHandlerData exceptionHandlerData = exceptionHandlingConfigurationView.GetExceptionHandlerData(CurrentPolicyName, CurrentExceptionTypeName, ConfigurationName);

            ArgumentValidation.CheckExpectedType(exceptionHandlerData, typeof(ReplaceHandlerData));

            replaceHandlerData = (ReplaceHandlerData)exceptionHandlerData;
        }
示例#8
0
        void ProcessFinallyHandler(ExceptionHandlerData data, TryStatement @try)
        {
            if (data.FinallyRange == null)
            {
                return;
            }

            var range = data.FinallyRange;

            @try.Finally = new BlockStatement();

            MoveStatementsToBlock(range.Start, range.End, @try.Finally);
        }
示例#9
0
        void ProcessExceptionData(ExceptionHandlerData data)
        {
            var list = GetOrCreateStatementListAt(data.TryRange.Start.Index);

            var @try = new TryStatement(new BlockStatement(), null, null);

            MoveStatementsToBlock(data.TryRange.Start, data.TryRange.End, @try.Try);

            ProcessCatchHandlers(data, @try);

            ProcessFinallyHandler(data, @try);

            list.Add(@try);
        }
        private void SetupEnvironment()
        {
            ExceptionHandlerData exceptionHandlerData = exceptionHandlingConfigurationView.GetExceptionHandlerData(CurrentPolicyName, CurrentExceptionTypeName, ConfigurationName);

            ArgumentValidation.CheckExpectedType(exceptionHandlerData, typeof(LoggingExceptionHandlerData));

            InitProperties((LoggingExceptionHandlerData)exceptionHandlerData);

            Type formatterType = Type.GetType(formatterTypeName, true);

            Type[] types = new Type[] { typeof(TextWriter), typeof(Exception) };
            constructor = formatterType.GetConstructor(types);
            if (constructor == null)
            {
                throw new ExceptionHandlingException(
                          SR.MissingConstructor(formatterType.AssemblyQualifiedName)
                          );
            }

            this.writer = new LogWriter(exceptionHandlingConfigurationView.ConfigurationContext);
        }
        private void ComputeExceptionHandlerData(ExceptionHandlerData data, ExceptionHandler handler)
        {
            BlockRange range = this.ComputeRange(handler.HandlerStart, handler.HandlerEnd);
            switch (handler.HandlerType)
            {
                case ExceptionHandlerType.Catch:
                    data.Catches.Add(new CatchHandlerData(handler.CatchType, range));
                    break;

                case ExceptionHandlerType.Filter:
                    throw new NotImplementedException();

                case ExceptionHandlerType.Finally:
                    data.FinallyRange = range;
                    break;

                case ExceptionHandlerType.Fault:
                    data.FaultRange = range;
                    break;
            }
        }
		private void BuildExceptionHandlerNode(ExceptionTypeNode exceptionTypeNode, ExceptionHandlerData exceptionHandlerData)
		{
			ConfigurationNode exceptionHandlerNode = NodeCreationService.CreateNodeByDataType(exceptionHandlerData.GetType(), new object[] { exceptionHandlerData });
			exceptionTypeNode.AddNode(exceptionHandlerNode);
		}
示例#13
0
		void ComputeExceptionHandlerData (ExceptionHandlerData data, ExceptionHandler handler)
		{
			var range = ComputeRange (handler.HandlerStart, handler.HandlerEnd);
            if (range == null)      // DC
                return;             // DC
			switch (handler.Type) {
			case ExceptionHandlerType.Catch:
				data.Catches.Add (new CatchHandlerData (handler.CatchType, range));
				break;
			case ExceptionHandlerType.Fault:
				data.FaultRange = range;
				break;
			case ExceptionHandlerType.Finally:
				data.FinallyRange = range;
				break;
			case ExceptionHandlerType.Filter:
				throw new NotImplementedException ();
			}
		}
        /// <summary>
        /// <para>Gets the <see cref="Type"/> of <see cref="IExceptionHandler"/> to create based on the name in configuration.</para>
        /// </summary>
        /// <param name="handlerName">
        /// <para>The name in configuraiton of the <see cref="IExceptionHandler"/> to get the <see cref="Type"/>.</para>
        /// </param>
        /// <returns>
        /// <para>The <see cref="Type"/> of the <see cref="IExceptionHandler"/> to create.</para>
        /// </returns>
        protected override Type GetConfigurationType(string handlerName)
        {
            ExceptionHandlerData data = GetExceptionHandlerData(handlerName);

            return(GetType(data.TypeName));
        }
		void ProcessCatchHandlers (ExceptionHandlerData data, TryStatement @try)
		{
			foreach (var catch_data in data.Catches)
				@try.CatchClauses.Add (CreateCatchHandler (catch_data));
		}
		void ProcessFinallyHandler (ExceptionHandlerData data, TryStatement @try)
		{
			if (data.FinallyRange == null)
				return;

			var range = data.FinallyRange;

			@try.Finally = new BlockStatement ();

			MoveStatementsToBlock (range.Start, range.End, @try.Finally);
		}
		void ProcessExceptionData (ExceptionHandlerData data)
		{
			var block_statements = GetOrCreateStatementListAt (data.TryRange.Start.Index);

			var @try = new TryStatement ();
			@try.Try = new BlockStatement ();

			MoveStatementsToBlock (data.TryRange.Start, data.TryRange.End, @try.Try);

			ProcessCatchHandlers (data, @try);

			ProcessFinallyHandler (data, @try);

			block_statements.Add (@try);
		}
示例#18
0
        private void BuildExceptionHandlerNode(ExceptionTypeNode exceptionTypeNode, ExceptionHandlerData exceptionHandlerData)
        {
            ConfigurationNode exceptionHandlerNode = NodeCreationService.CreateNodeByDataType(exceptionHandlerData.GetType(), new object[] { exceptionHandlerData });

            exceptionTypeNode.AddNode(exceptionHandlerNode);
        }
 public ExceptionHandlerNodeImpl(ExceptionHandlerData data)
 {
     this.data = data;
     Rename(data.Name);
 }
        public void ManageabilityProviderGeneratesProperAdmContentWithRegisteredProviders()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(ExceptionHandlingSettings.SectionName, section);

            ExceptionPolicyData policy1 = new ExceptionPolicyData("policy1");
            section.ExceptionPolicies.Add(policy1);
            ExceptionTypeData exceptionType11 = new ExceptionTypeData("type11", typeof(Exception), PostHandlingAction.None);
            policy1.ExceptionTypes.Add(exceptionType11);
            ExceptionHandlerData handler11 = new ExceptionHandlerData("handler11", typeof(object));
            exceptionType11.ExceptionHandlers.Add(handler11);

            MockConfigurationElementManageabilityProvider subProvider =
                new MockConfigurationElementManageabilityProvider(false, true);
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(ExceptionHandlerData), subProvider);
            provider = new ExceptionHandlingSettingsManageabilityProvider(subProviders);

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.AddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            MockAdmContent content = contentBuilder.GetMockContent();
            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            Assert.IsTrue(categoriesEnumerator.MoveNext());
            IEnumerator<AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();

            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            Assert.AreEqual(policy1.Name, subCategoriesEnumerator.Current.Name);
            IEnumerator<AdmPolicy> policyPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator();
            Assert.IsTrue(policyPoliciesEnumerator.MoveNext());
            IEnumerator<AdmPart> partsEnumerator = policyPoliciesEnumerator.Current.Parts.GetEnumerator();
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), partsEnumerator.Current.GetType());
            Assert.IsNull(partsEnumerator.Current.KeyName);
            Assert.AreEqual(ExceptionHandlingSettingsManageabilityProvider.PolicyTypePostHandlingActionPropertyName,
                            partsEnumerator.Current.ValueName);
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmTextPart), partsEnumerator.Current.GetType());
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmTextPart), partsEnumerator.Current.GetType());
            Assert.AreEqual(MockConfigurationElementManageabilityProvider.Part, partsEnumerator.Current.PartName);

            Assert.IsFalse(partsEnumerator.MoveNext());
            Assert.IsFalse(policyPoliciesEnumerator.MoveNext());

            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
示例#21
0
 /// <summary>
 /// Constructs a new instance of the <see cref="ExceptionHandlerNode"/> object with
 /// a corresponding runtime configuration data.
 /// </summary>
 /// <param name="exceptionHandlerData">The cooresponding configuration data.</param>
 protected ExceptionHandlerNode(ExceptionHandlerData exceptionHandlerData)
     : base(/*SR.ExceptionHandler*/)
 {
     if (exceptionHandlerData == null) throw new ArgumentNullException("exceptionHandlerData");
     this.exceptionHandlerData = exceptionHandlerData;
 }