Esempio n. 1
0
        protected override Type GetConfigurationType(string formatterName)
        {
            LoggingConfigurationView loggingConfigurationView = (LoggingConfigurationView)CreateConfigurationView();
            FormatterData            data = loggingConfigurationView.GetFormatterData(formatterName);

            return(GetType(data.TypeName));
        }
Esempio n. 2
0
        /// <devdoc>
        /// Get a cloned instance of the formatter.
        /// </devdoc>
        /// <returns>An instance of the ILogFormatter.
        /// May return null if no format is specified and the default format does not exist.</returns>
        private ILogFormatter CreateFormatter(string formatterName)
        {
            ILogFormatter formatter     = null;
            FormatterData formatterData = null;

            if (formatterName != null && formatterName.Length > 0)
            {
                formatterData = loggingConfigurationView.GetFormatterData(formatterName);
            }
            // if the format isn't defined in the configuration settings
            if (formatterData == null)
            {
                // get the default format
                formatterData = loggingConfigurationView.GetDefaultFormatterData();

                // if the default format doesn't exist, log a warning in the event log
                if (formatterData == null)
                {
                    this.events.LogMissingDefaultFormatterError();
                }
            }
            if (formatterData != null)
            {
                LogFormatterFactory factory = new LogFormatterFactory(loggingConfigurationView.ConfigurationContext);
                formatter = factory.CreateFormatter(formatterData.Name);
            }
            return(formatter);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates node with specified configuration data.
 /// </summary>
 protected FormatterNode(FormatterData formatterData) : base()
 {
     if (formatterData == null)
     {
         throw new ArgumentNullException("formatterData");
     }
     this.formatterData = formatterData;
 }
            public ILoggingConfigurationSendToCustomTraceListener FormatWith(IFormatterBuilder formatBuilder)
            {
                FormatterData formatter = formatBuilder.GetFormatterData();

                customListener.Formatter = formatter.Name;
                LoggingSettings.Formatters.Add(formatter);

                return(this);
            }
        public void BinaryFormatterNodeTest()
        {
            string name = "some name";
            BinaryFormatterNode formatterNode = new BinaryFormatterNode();

            formatterNode.Name = name;
            FormatterData nodeData = formatterNode.FormatterData;

            Assert.AreEqual(name, nodeData.Name);
        }
 /// <summary>
 /// Returns the output file or null if does not use a file.
 /// </summary>
 protected FileInfo GetOutput(FormatterData formatterData, NUnitTestData test)
 {
     if (formatterData.UseFile)
     {
         string filename    = test.OutFile + formatterData.Extension;
         string absFilename = Path.Combine(test.ToDir, filename);
         return(new FileInfo(absFilename));
     }
     return(null);
 }
 private void CreateFormatterNode(FormatterData formatterData)
 {
     FormatterNode formatterNode = NodeCreationService.CreateNodeByDataType(formatterData.GetType(), new object[] { formatterData }) as FormatterNode;
     if (null == formatterNode)
     {
         LogNodeMapError(node, formatterData.GetType());
         return;
     }
     node.AddNode(formatterNode);
 }
Esempio n. 8
0
        private void CreateFormatterNode(FormatterData formatterData)
        {
            FormatterNode formatterNode = NodeCreationService.CreateNodeByDataType(formatterData.GetType(), new object[] { formatterData }) as FormatterNode;

            if (null == formatterNode)
            {
                LogNodeMapError(node, formatterData.GetType());
                return;
            }
            node.AddNode(formatterNode);
        }
Esempio n. 9
0
        /// <summary>
        /// Initialize a new instance of a <see cref="TextFormatter"/>.  Reads the template from
        /// configuration parameters.
        /// </summary>
        /// <param name="configurationView">Dynamic view into the configuration information needed by the <see cref="TextFormatter"></see></param>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof(LoggingConfigurationView));

            LoggingConfigurationView loggingConfigurationView = (LoggingConfigurationView)configurationView;
            FormatterData            formatterData            = loggingConfigurationView.GetFormatterData(ConfigurationName);

            ArgumentValidation.CheckExpectedType(textFormatterData, typeof(TextFormatterData));

            textFormatterData = (TextFormatterData)formatterData;
            RegisterTemplate();
        }
            public ILoggingConfigurationSendToEmailTraceListener FormatWith(IFormatterBuilder formatBuilder)
            {
                if (formatBuilder == null)
                {
                    throw new ArgumentNullException("formatBuilder");
                }

                FormatterData formatter = formatBuilder.GetFormatterData();

                emailTraceListener.Formatter = formatter.Name;
                LoggingSettings.Formatters.Add(formatter);

                return(this);
            }
Esempio n. 11
0
 public Task <List <Profile> > LoadProfilesAsync()
 {
     return(Task.Run(() =>
     {
         var fileName = GetProfilesPath();
         FormatterData data = null;
         try
         {
             data = JsonConvert.DeserializeObject <FormatterData>(System.IO.File.ReadAllText(fileName));
         }
         catch
         {
             // nothing
         }
         return data?.Profiles ?? GetDefaultProfiles();
     }));
 }
Esempio n. 12
0
        public Task SaveProfilesAsync(List <Profile> profiles)
        {
            return(Task.Run(() =>
            {
                try
                {
                    EnsureProfileIds(profiles);
                    var data = new FormatterData()
                    {
                        Profiles = profiles
                    };
                    EnsureAppDataFolderExists();

                    var fileName = GetProfilesPath();
                    System.IO.File.WriteAllText(fileName, JsonConvert.SerializeObject(data));
                }
                catch
                {
                    // nothing, log this maybe?
                }
            }));
        }
Esempio n. 13
0
        /// <summary>
        /// Will show save file dialog and save profiles to path
        /// </summary>
        public void ExportProfiles(List <Profile> profiles)
        {
            // Create OpenFileDialog
            var dlg = new Microsoft.Win32.SaveFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".json";
            dlg.Filter     = "JSON Files (*.json)|*.json";


            // Display OpenFileDialog by calling ShowDialog method
            var result = dlg.ShowDialog();


            // Get the selected file name and display in a TextBox
            if (result.HasValue && result.Value)
            {
                var data = new FormatterData()
                {
                    Profiles = profiles
                };
                System.IO.File.WriteAllText(dlg.FileName, JsonConvert.SerializeObject(data));
            }
        }
Esempio n. 14
0
 public ServicePropertyType()
 {
     Properties = new List <ServiceProperty>();
     Formatter  = new FormatterData();
 }
 protected FormatterSetting(FormatterData sourceElement, string name)
     : base(sourceElement, name)
 {
 }
Esempio n. 16
0
        public static IDictionary <string, object> GetMorestachioFormatterDocumentation()
        {
            var values         = new Dictionary <string, object>();
            var formatterTypes = new List <FormatterData>();

            values["Data"] = formatterTypes;

            var formatterService = ContextObject.DefaultFormatter as MorestachioFormatterService;

            foreach (var formatterServiceFormatter in formatterService
                     .Formatters
                     .SelectMany(f => f.Value)
                     .GroupBy(e => e.Function.DeclaringType))
            {
                var formatter = new FormatterData();
                formatter.DeclaringType = formatterServiceFormatter.Key;

                var methods = new List <FormatterData.FormatterMethod>();
                formatter.Methods = methods;
                foreach (var formatterMethod in formatterServiceFormatter
                         .GroupBy(e => e.Function))
                {
                    foreach (var morestachioFormatterModel in formatterMethod.GroupBy(e => e.IsGlobalFormatter))
                    {
                        var methodMeta = new FormatterData.FormatterMethod();
                        methodMeta.MethodName = formatterMethod.Key.Name;

                        var methodFunctions = new List <FormatterData.FormatterMethod.MethodFunction>();
                        foreach (var fncGrouped in morestachioFormatterModel)
                        {
                            var function = new FormatterData.FormatterMethod.MethodFunction();
                            function.FormatterName = string.IsNullOrWhiteSpace(fncGrouped.Name) ? "{Null}" : fncGrouped.Name;
                            var mOperator = MorestachioOperator.Operators.FirstOrDefault(f => ("op_" + f.Key.ToString()) == function.FormatterName).Value;
                            if (mOperator != null)
                            {
                                function.FormatterName = mOperator.OperatorText;
                                function.IsOperator    = true;
                            }
                            function.Returns     = fncGrouped.OutputType ?? fncGrouped.Function.ReturnType;
                            function.Description = fncGrouped.Description;
                            methodFunctions.Add(function);
                        }


                        methodMeta.Functions = methodFunctions;
                        var parameters = new List <FormatterData.FormatterMethod.MethodParameter>();
                        var metaData   = morestachioFormatterModel.First();
                        methodMeta.Returns = metaData.Function.ReturnType;
                        foreach (var inputDescription in metaData.MetaData)
                        {
                            var paramter = new FormatterData.FormatterMethod.MethodParameter();
                            paramter.Name           = inputDescription.Name;
                            paramter.Type           = inputDescription.ParameterType;
                            paramter.IsOptional     = inputDescription.IsOptional;
                            paramter.IsSourceObject = inputDescription.IsSourceObject;
                            paramter.IsInjected     = inputDescription.IsInjected;
                            paramter.IsRestObject   = inputDescription.IsRestObject;
                            parameters.Add(paramter);
                        }

                        methodMeta.Parameters = parameters;
                        methods.Add(methodMeta);
                    }
                }
                formatterTypes.Add(formatter);
            }

            return(values);
        }
        public void LogFormatterWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(FormatterData), registeredProvider);
            provider = new LoggingSettingsManageabilityProvider(subProviders);

            FormatterData logFormatter1Data = new FormatterData("logFormatter1", typeof(Object));
            section.Formatters.Add(logFormatter1Data);
            FormatterData logFormatter2Data = new FormatterData("logFormatter2", typeof(Object));
            section.Formatters.Add(logFormatter2Data);

            MockRegistryKey machineLogFormattersKey = new MockRegistryKey(false);
            machineKey.AddSubKey(LoggingSettingsManageabilityProvider.LogFormattersKeyName, machineLogFormattersKey);
            MockRegistryKey machineLogFormatter2Key = new MockRegistryKey(false);
            machineLogFormattersKey.AddSubKey("logFormatter2", machineLogFormatter2Key);
            machineLogFormatter2Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, section.Formatters.Count);
            Assert.IsNotNull(section.Formatters.Get("logFormatter1"));
            Assert.IsNotNull(section.Formatters.Get("logFormatter2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineLogFormattersKey, machineLogFormatter2Key));
        }
Esempio n. 18
0
        public static IDictionary <string, object> GetMorestachioFormatterDocumentation()
        {
            FormatterData EnumerateFormatters(IGrouping <Type, MorestachioFormatterModel> formatterServiceFormatter, bool includeInstanceMethods)
            {
                var formatter = new FormatterData();

                formatter.DeclaringType = formatterServiceFormatter.Key;

                var methods = new List <FormatterData.FormatterMethod>();

                formatter.Methods = methods;
                foreach (var formatterMethod in formatterServiceFormatter
                         .Where(e => e.LinkFunctionTarget == includeInstanceMethods)
                         .GroupBy(e => e.Function))
                {
                    foreach (var morestachioFormatterModel in formatterMethod.GroupBy(e => e.IsGlobalFormatter))
                    {
                        var methodMeta = new FormatterData.FormatterMethod();
                        methodMeta.MethodName = formatterMethod.Key.Name;

                        var methodFunctions = new List <FormatterData.FormatterMethod.MethodFunction>();
                        foreach (var fncGrouped in morestachioFormatterModel)
                        {
                            var function = new FormatterData.FormatterMethod.MethodFunction();
                            function.FormatterName = string.IsNullOrWhiteSpace(fncGrouped.Name) ? "{Null}" : fncGrouped.Name;
                            var mOperator = MorestachioOperator.Operators
                                            .FirstOrDefault(f => ("op_" + f.Key.ToString()) == function.FormatterName).Value;
                            if (mOperator != null)
                            {
                                function.FormatterName = mOperator.OperatorText;
                                function.IsOperator    = true;
                            }

                            function.Returns            = fncGrouped.OutputType ?? fncGrouped.Function.ReturnType;
                            function.Description        = fncGrouped.Description;
                            function.IsInstanceFunction = fncGrouped.LinkFunctionTarget;
                            methodFunctions.Add(function);
                        }


                        methodMeta.Functions = methodFunctions;
                        var parameters = new List <FormatterData.FormatterMethod.MethodParameter>();
                        var metaData   = morestachioFormatterModel.First();
                        methodMeta.Returns = metaData.Function.ReturnType;
                        foreach (var inputDescription in metaData.MetaData)
                        {
                            var paramter = new FormatterData.FormatterMethod.MethodParameter();
                            paramter.Name           = inputDescription.Name;
                            paramter.Type           = inputDescription.ParameterType;
                            paramter.IsOptional     = inputDescription.IsOptional;
                            paramter.IsSourceObject = inputDescription.IsSourceObject;
                            paramter.IsInjected     = inputDescription.IsInjected;
                            paramter.IsRestObject   = inputDescription.IsRestObject;
                            parameters.Add(paramter);
                        }

                        methodMeta.Parameters = parameters;
                        methods.Add(methodMeta);
                    }
                }

                return(formatter);
            }

            ServicePropertyType EnumerateObject(Type csType,
                                                MorestachioFormatterService formatterService,
                                                ICollection <ServicePropertyType> servicePropertyTypes)
            {
                var type = new ServicePropertyType();

                type.Type            = csType;
                type.IsFrameworkType = true;
                servicePropertyTypes.Add(type);
                foreach (var formatterServiceFormatter in formatterService
                         .Formatters
                         .SelectMany(f => f.Value)
                         .Where(e => e.LinkFunctionTarget)
                         .Where(e => e.Function.DeclaringType == csType)
                         .GroupBy(e => e.Function.DeclaringType))
                {
                    type.Formatter = EnumerateFormatters(formatterServiceFormatter, true);
                }

                foreach (var propertyInfo in csType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                {
                    var prop = new ServiceProperty();
                    prop.Name = propertyInfo.Name;

                    if (propertyInfo.PropertyType.Namespace.StartsWith("Morestachio"))
                    {
                        prop.PropType = EnumerateObject(propertyInfo.PropertyType, formatterService, servicePropertyTypes);
                    }
                    else
                    {
                        prop.PropType = new ServicePropertyType()
                        {
                            Type            = propertyInfo.PropertyType,
                            IsFrameworkType = false
                        };
                    }

                    type.Properties.Add(prop);
                }

                return(type);
            }

            var values         = new Dictionary <string, object>();
            var formatterTypes = new List <FormatterData>();

            values["FormatterData"] = formatterTypes;

            var parserOptions = new ParserOptions();

            parserOptions
            .RegisterFileSystem(() => new FileSystemService())
            .RegisterLocalizationService(() => new MorestachioLocalizationService());

            var formatterService = parserOptions.Formatters as MorestachioFormatterService;

            foreach (var formatterServiceFormatter in formatterService
                     .Formatters
                     .SelectMany(f => f.Value)
                     .GroupBy(e => e.Function.DeclaringType))
            {
                var data = EnumerateFormatters(formatterServiceFormatter, false);
                if (data.Methods.Any())
                {
                    formatterTypes.Add(data);
                }
            }

            var services = new List <ServiceData>();

            values["ServiceData"] = services;
            foreach (var service in formatterService.Services.Enumerate())
            {
                var serviceData = new ServiceData();
                serviceData.ServiceName = service.Key.Name;
                serviceData.Types       = new HashSet <ServicePropertyType>();
                EnumerateObject(service.Key, formatterService, serviceData.Types);
                services.Add(serviceData);
            }

            var constants = new List <ServiceData>();

            values["ConstData"] = constants;
            foreach (var service in formatterService.Constants)
            {
                var serviceData = new ServiceData();
                serviceData.ServiceName = service.Key;
                serviceData.Types       = new HashSet <ServicePropertyType>();
                EnumerateObject(service.Value.GetType(), formatterService, serviceData.Types);
                constants.Add(serviceData);
            }

            return(values);
        }