Esempio n. 1
0
        public void CanReadWrittenFilterConfiguration()
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "test.exe.config";
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            rwConfiguration.Sections.Remove(LoggingSettings.SectionName);
            LoggingSettings rwLoggingSettings = new LoggingSettings();

            rwConfiguration.Sections.Add(LoggingSettings.SectionName, rwLoggingSettings);
            rwLoggingSettings.LogFilters.Add(new LogEnabledFilterData("enabled", true));
            NamedElementCollection <CategoryFilterEntry> categoryEntries = new NamedElementCollection <CategoryFilterEntry>();

            categoryEntries.Add(new CategoryFilterEntry("foo"));
            categoryEntries.Add(new CategoryFilterEntry("bar"));
            categoryEntries.Add(new CategoryFilterEntry("baz"));
            rwLoggingSettings.LogFilters.Add(new CategoryFilterData("category", categoryEntries, CategoryFilterMode.DenyAllExceptAllowed));
            rwLoggingSettings.LogFilters.Add(new PriorityFilterData("priority", 5));
            File.SetAttributes(fileMap.ExeConfigFilename, FileAttributes.Normal);
            rwConfiguration.Save();
            System.Configuration.Configuration roConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            LoggingSettings roLoggingSettings = (LoggingSettings)roConfiguration.Sections[LoggingSettings.SectionName];

            Assert.AreEqual(3, roLoggingSettings.LogFilters.Count);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("enabled").GetType(), typeof(LogEnabledFilterData));
            Assert.AreEqual(true, ((LogEnabledFilterData)roLoggingSettings.LogFilters.Get("enabled")).Enabled);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("category").GetType(), typeof(CategoryFilterData));
            Assert.AreEqual(3, ((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Count);
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("foo"));
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("bar"));
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("baz"));
            Assert.AreEqual(CategoryFilterMode.DenyAllExceptAllowed, ((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilterMode);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("priority").GetType(), typeof(PriorityFilterData));
            Assert.AreEqual(5, ((PriorityFilterData)roLoggingSettings.LogFilters.Get("priority")).MinimumPriority);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     Debug.Assert(provider != null, "No service provider; we cannot edit the value");
     if (provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
         if (edSvc != null)
         {
             IWindowsFormsEditorService service         = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             CategoryFilterEditorUI     dialog          = new CategoryFilterEditorUI();
             CategoryFilterNode         currentSettings = (CategoryFilterNode)context.Instance;
             InitializeDialog(dialog, currentSettings);
             if (DialogResult.OK == service.ShowDialog(dialog))
             {
                 CategoryFilterMode categoryFilterMode = dialog.FilterMode;
                 NamedElementCollection <CategoryFilterEntry> categoryFilters = new NamedElementCollection <CategoryFilterEntry>();
                 foreach (string category in dialog.SelectedCategoryNames)
                 {
                     CategoryFilterEntry categoryFilter = new CategoryFilterEntry();
                     categoryFilter.Name = category;
                     categoryFilters.Add(categoryFilter);
                 }
                 return(new CategoryFilterSettings(categoryFilterMode, categoryFilters));
             }
         }
     }
     return(value);
 }
Esempio n. 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));

                    CategoryFilterEditorUI dialog = new CategoryFilterEditorUI();
                    CategoryFilterNode currentSettings = (CategoryFilterNode)context.Instance;
                    InitializeDialog(dialog, currentSettings);

                    service.ShowDialog(dialog);

                    CategoryFilterMode categoryFilterMode = dialog.FilterMode;

                    NamedElementCollection<CategoryFilterEntry> categoryFilters = new NamedElementCollection<CategoryFilterEntry>();
                    foreach (string category in dialog.SelectedCategoryNames)
                    {
                        CategoryFilterEntry categoryFilter = new CategoryFilterEntry();
                        categoryFilter.Name = category;
                        categoryFilters.Add(categoryFilter);
                    }

                    return new CategoryFilterSettings(categoryFilterMode, categoryFilters);
                }
            }
            return value;
        }
        public void CanCreateCategoryFilterFromNonEmptyCategoryConfiguration()
        {
            NamedElementCollection<CategoryFilterEntry> categoryEntries = new NamedElementCollection<CategoryFilterEntry>();
            categoryEntries.Add(new CategoryFilterEntry("foo"));
            categoryEntries.Add(new CategoryFilterEntry("bar"));
            categoryEntries.Add(new CategoryFilterEntry("baz"));
            CategoryFilterData filterData = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.AllowAllExceptDenied);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            ILogFilter filter = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache); ;

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(3, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("foo"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("bar"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("baz"));
            Assert.IsFalse(((CategoryFilter)filter).CategoryFilters.Contains("foobar"));
            Assert.AreEqual(CategoryFilterMode.AllowAllExceptDenied, ((CategoryFilter)filter).CategoryFilterMode);
        }
Esempio n. 5
0
        public void CanCreateCategoryFilterFromNonEmptyCategoryConfiguration()
        {
            NamedElementCollection <CategoryFilterEntry> categoryEntries = new NamedElementCollection <CategoryFilterEntry>();

            categoryEntries.Add(new CategoryFilterEntry("foo"));
            categoryEntries.Add(new CategoryFilterEntry("bar"));
            categoryEntries.Add(new CategoryFilterEntry("baz"));
            CategoryFilterData   filterData = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.AllowAllExceptDenied);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();
            ILogFilter           filter     = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(3, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("foo"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("bar"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("baz"));
            Assert.IsFalse(((CategoryFilter)filter).CategoryFilters.Contains("foobar"));
            Assert.AreEqual(CategoryFilterMode.AllowAllExceptDenied, ((CategoryFilter)filter).CategoryFilterMode);
        }
        public void CanCreateCategoryFilterFromNonEmptyCategoryConfiguration()
        {
            NamedElementCollection <CategoryFilterEntry> categoryEntries = new NamedElementCollection <CategoryFilterEntry>();

            categoryEntries.Add(new CategoryFilterEntry("category1"));
            categoryEntries.Add(new CategoryFilterEntry("category2"));
            categoryEntries.Add(new CategoryFilterEntry("category3"));
            CategoryFilterData filterData = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.AllowAllExceptDenied);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(3, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category1"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category2"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category3"));
            Assert.IsFalse(((CategoryFilter)filter).CategoryFilters.Contains("category4"));
            Assert.AreEqual(CategoryFilterMode.AllowAllExceptDenied, ((CategoryFilter)filter).CategoryFilterMode);
        }
        public void CanReadWrittenFilterConfiguration()
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = "test.exe.config";
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            rwConfiguration.Sections.Remove(LoggingSettings.SectionName);
            LoggingSettings rwLoggingSettings = new LoggingSettings();
            rwConfiguration.Sections.Add(LoggingSettings.SectionName, rwLoggingSettings);

            rwLoggingSettings.LogFilters.Add(new LogEnabledFilterData("enabled", true));

            NamedElementCollection<CategoryFilterEntry> categoryEntries = new NamedElementCollection<CategoryFilterEntry>();
            categoryEntries.Add(new CategoryFilterEntry("foo"));
            categoryEntries.Add(new CategoryFilterEntry("bar"));
            categoryEntries.Add(new CategoryFilterEntry("baz"));
            rwLoggingSettings.LogFilters.Add(new CategoryFilterData("category", categoryEntries, CategoryFilterMode.DenyAllExceptAllowed));

            rwLoggingSettings.LogFilters.Add(new PriorityFilterData("priority", 5));

            File.SetAttributes(fileMap.ExeConfigFilename, FileAttributes.Normal);
            rwConfiguration.Save();

            System.Configuration.Configuration roConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            LoggingSettings roLoggingSettings = (LoggingSettings)roConfiguration.Sections[LoggingSettings.SectionName];
            Assert.AreEqual(3, roLoggingSettings.LogFilters.Count);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("enabled").GetType(), typeof(LogEnabledFilterData));
            Assert.AreEqual(true, ((LogEnabledFilterData)roLoggingSettings.LogFilters.Get("enabled")).Enabled);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("category").GetType(), typeof(CategoryFilterData));
            Assert.AreEqual(3, ((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Count);
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("foo"));
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("bar"));
            Assert.IsNotNull(((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilters.Get("baz"));
            Assert.AreEqual(CategoryFilterMode.DenyAllExceptAllowed, ((CategoryFilterData)roLoggingSettings.LogFilters.Get("category")).CategoryFilterMode);
            Assert.AreEqual(roLoggingSettings.LogFilters.Get("priority").GetType(), typeof(PriorityFilterData));
            Assert.AreEqual(5, ((PriorityFilterData)roLoggingSettings.LogFilters.Get("priority")).MinimumPriority);
        }
        public void CanAddDropDownListPartForConfigurationElementsCollectionAllowingNoneAndEmptyDefault()
        {
            NamedElementCollection<NamedConfigurationElement> collection = new NamedElementCollection<NamedConfigurationElement>();
            collection.Add(new NamedConfigurationElement("name1"));
            collection.Add(new NamedConfigurationElement("name2"));
            collection.Add(new NamedConfigurationElement("name3"));

            AdmContentBuilder builder = new AdmContentBuilder();

            builder.StartCategory("category");
            builder.StartPolicy("policy", "key");
            builder.AddDropDownListPartForNamedElementCollection<NamedConfigurationElement>("part", "value", collection, "", true);
            builder.EndPolicy();
            builder.EndCategory();
            AdmContent content = builder.GetContent();

            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            categoriesEnumerator.MoveNext();
            IEnumerator<AdmPolicy> policiesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();
            policiesEnumerator.MoveNext();
            IEnumerator<AdmPart> partsEnumerator = policiesEnumerator.Current.Parts.GetEnumerator();
            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), partsEnumerator.Current.GetType());
            Assert.AreEqual("part", ((AdmDropDownListPart)partsEnumerator.Current).PartName);
            Assert.AreEqual(null, ((AdmDropDownListPart)partsEnumerator.Current).KeyName);
            Assert.AreEqual("value", ((AdmDropDownListPart)partsEnumerator.Current).ValueName);
            IEnumerator<AdmDropDownListItem> itemsEnumerator = ((AdmDropDownListPart)partsEnumerator.Current).Items.GetEnumerator();
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual(AdmContentBuilder.NoneListItem, itemsEnumerator.Current.Value);
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("name1", itemsEnumerator.Current.Name);
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("name2", itemsEnumerator.Current.Name);
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("name3", itemsEnumerator.Current.Name);
            Assert.IsFalse(itemsEnumerator.MoveNext());
        }
        public void CanCreateCategoryFilterFromNonEmptyCategoryConfiguration()
        {
            NamedElementCollection<CategoryFilterEntry> categoryEntries = new NamedElementCollection<CategoryFilterEntry>();
            categoryEntries.Add(new CategoryFilterEntry("category1"));
            categoryEntries.Add(new CategoryFilterEntry("category2"));
            categoryEntries.Add(new CategoryFilterEntry("category3"));
            CategoryFilterData filterData = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.AllowAllExceptDenied);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(3, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category1"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category2"));
            Assert.IsTrue(((CategoryFilter)filter).CategoryFilters.Contains("category3"));
            Assert.IsFalse(((CategoryFilter)filter).CategoryFilters.Contains("category4"));
            Assert.AreEqual(CategoryFilterMode.AllowAllExceptDenied, ((CategoryFilter)filter).CategoryFilterMode);
        }
        public static List <ErrorType> GetErrorTypes(string opCoCode, string policyName, string sortExpression)
        {
            List <ErrorType> errorTypes = new List <ErrorType>();

            //find all the exception policies
            NamedElementCollection <ExceptionPolicyData> allPolicies = null;

            allPolicies = ((ExceptionHandlingSettings)ConfigurationSourceFactory.Create().GetSection("exceptionHandling")).ExceptionPolicies;


            if (allPolicies != null)
            {
                NamedElementCollection <ExceptionPolicyData> policies = new NamedElementCollection <ExceptionPolicyData>();

                if (!string.IsNullOrEmpty(policyName))
                {
                    //find just the one specified
                    ExceptionPolicyData specifiedPolicy = allPolicies.Get(policyName);

                    policies.Add(specifiedPolicy);
                }
                else
                {
                    policies = allPolicies;
                }

                foreach (ExceptionPolicyData policy in policies)
                {
                    policy.ExceptionTypes.ForEach(delegate(ExceptionTypeData currentExceptionType)
                    {
                        //go to db for some details
                        ErrorType errorType;
                        errorType =
                            PopulateErrorType(policy.Name, opCoCode,
                                              currentExceptionType);

                        errorTypes.Add(errorType);
                    }
                                                  );
                }
            }


            #region Useful Code
            //policies.ForEach(delegate(ExceptionPolicyData currentPolicy)
            //                     {
            //                         Response.Write("CategoryName: " + currentPolicy.Name + "<br>");

            //                         currentPolicy.ExceptionTypes.ForEach(delegate(ExceptionTypeData currentExceptionType)
            //                                                                  {
            //                                                                      Response.Write("Exception Type: " +
            //                                                                                     currentExceptionType.Name +
            //                                                                                     "<br>");

            //                                                                      currentExceptionType.ExceptionHandlers.
            //                                                                          ForEach(
            //                                                                          delegate(
            //                                                                              ExceptionHandlerData
            //                                                                              currentHandlerData)
            //                                                                              {
            //                                                                                  Response.Write(
            //                                                                                      "Exception Handler: " +
            //                                                                                      currentHandlerData.Name +
            //                                                                                      "<br>");
            //                                                                                  if (currentHandlerData is LoggingExceptionHandlerData)
            //                                                                                  {
            //                                                                                      Response.Write(
            //                                                                                          "CategoryName: " + (currentHandlerData as LoggingExceptionHandlerData).CategoryName.ToString() + "<br>");
            //                                                                                      Response.Write(
            //                                                                                          "Event Id: " + (currentHandlerData as LoggingExceptionHandlerData).EventId.ToString() + "<br>");
            //                                                                                  }

            //                                                                              });
            //                                                                  }
            //                             );
            //                     }
            //    );
            #endregion


            //sort the results
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "ExceptionDescription";
            }
            errorTypes.Sort(new UniversalComparer <ErrorType>(sortExpression));


            return(errorTypes);
        }