public static Parameter Load(XmlReaderContext context) { var type = DecodeTypeName(context.LoadFromAttribute("Type")); if (type == null) { throw new NotSupportedException(); } var name = context.CurrentName; IXmlPersister persister = null; if (type.IsEnum) { Persisters.TryGetValue(typeof(Enum), out persister); } else if (type.IsArray) { Persisters.TryGetValue(typeof(Array), out persister); } else { Persisters.TryGetValue(type, out persister); } if (persister != null) { return(new Parameter(name, type, persister.LoadValue(context))); } else { return(new Parameter(name, type, null)); } }
public IRecordPersister <T> RecordPersister <T>() { return((IRecordPersister <T>)Persisters.First(persister => { var memberInfo = persister.GetType().BaseType; return memberInfo != null && memberInfo.GenericTypeArguments[0] == typeof(T); })); }
public static void Store(XmlWriterContext context, Parameter parameter) { IXmlPersister persister = null; if (parameter.Type.IsEnum) { Persisters.TryGetValue(typeof(Enum), out persister); } else if (parameter.Type.IsArray) { Persisters.TryGetValue(typeof(Array), out persister); } else { Persisters.TryGetValue(parameter.Type, out persister); } if (persister != null) { persister.Store(context, parameter); } }
/// <summary> /// Instruments message <paramref name="message"/>. /// </summary> /// <param name="message"></param> private void InternalInstrument(IMessage message) { lock (syncRoot) { if (!IsInstrumentationEnabled) { return; } // // Resolving persister names. string[] persisterNames; persisterNames = ResolvePersisterNames(message); if (persisterNames == null || persisterNames.GetLength(0) == 0) { throw new InstrumentationException(string.Format( Strings.InstrumentationManager_InternalInstrument_UnableToResolvePersistersForMessage, message.GetType().FullName, message.Source, message.Severity)); } // // Persisting message. foreach (string persisterName in persisterNames) { if (!Persisters.ContainsKey(persisterName)) { throw new InstrumentationException(string.Format( Strings.InstrumentationManager_InternalInstrument_NoPersistersWithGivenNameRegistered, persisterName)); } IPersister persister = Persisters[persisterName]; persister.Persist(message); } // foreach } // lock }
/// <summary> /// Initializes a new instance of <see cref="InstrumentationManager"/> class. /// </summary> private InstrumentationManager() { // // First off, check whether the configuration section is present. If // it is, proceed with configuring InstrumentationManager. if (ConfigurationManager.ConfigurationSection != null) { // // Adding persisters. foreach (PersisterElement persister in ConfigurationManager.ConfigurationSection.Persisters) { IPersister persisterInstance = ObjectFactory.CreatePersister(persister); persisterInstance.Configure(persister.CustomProperties.ToStringDictionary()); Persisters.Add(persister.Name, persisterInstance); } // foreach // // Adding formatters. foreach (FormatterElement formatter in ConfigurationManager.ConfigurationSection.Formatters) { IFormatter formatterInstance = ObjectFactory.CreateFormatter(formatter); FormattingManager.AddFormatter(formatterInstance); } // // Creating binders. foreach (BindingElement binding in ConfigurationManager.ConfigurationSection.Bindings) { Binders.Add(binding.PersisterName, CreateBinder(binding)); } isInstrumentationEnabled = true; } // if }
public OperationStep ToStream(Action <Stream> streamAction) => To(Persisters.ToStream(streamAction));
public OperationStep ToStream(Stream targetStream) => To(Persisters.ToStream(targetStream));
public OperationStep ToFiles(Func <string, string> fileNameTransformationFunc) => To(Persisters.ToFiles(fileNameTransformationFunc));
public OperationStep ToFiles(Func <string> fileGlobFunc) => To(Persisters.ToFiles(fileGlobFunc));
public OperationStep ToFiles(string fileGlob) => To(Persisters.ToFiles(fileGlob));
public OperationStep ToFiles() => To(Persisters.ToFiles());
/// <summary> /// Emits the final output to the specified file function relative to the target directory /// </summary> /// <param name="relativeFilePathFunc"></param> /// <returns></returns> public OperationStep ToFile(Func <string> relativeFilePathFunc) => To(Persisters.ToFile(relativeFilePathFunc));
/// <summary> /// Emits the final output to the specified file relative to the target directory /// </summary> /// <param name="relativeFilePath"></param> /// <returns></returns> public OperationStep ToFile(string relativeFilePath) => To(Persisters.ToFile(relativeFilePath));