public void ShouldUseDefaultSerialiserFactory() { ReflectorPropertyAttribute attribute = new ReflectorPropertyAttribute("foo"); IXmlSerialiser serialiser = attribute.CreateSerialiser(member); Assert.IsNotNull(serialiser); }
public AuthnRequestBuilder(ICertificateManager certificateManager, IFederationPartyContextBuilder federationPartyContextBuilder, IXmlSerialiser serialiser, ICompression compression) { this._certificateManager = certificateManager; this._federationPartyContextBuilder = federationPartyContextBuilder; this._serialiser = serialiser; this._compression = compression; }
public void ShouldCreateCollectionSerialiserWhenInstanceTypeIsCollection() { FieldInfo field = typeof(CollectionTestClass).GetField("Stuff"); attribute = (ReflectorPropertyAttribute)field.GetCustomAttributes(false)[0]; IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(field), attribute); Assert.AreEqual(typeof(XmlCollectionSerialiser), serialiser.GetType()); }
public void ShouldCreateCollectionSerialiserWhenCollectionPropertyIsPassed() { DefaultSerialiserFactory factory = new DefaultSerialiserFactory(); PropertyInfo property = typeof(Project).GetProperty("Triggers"); ReflectorPropertyAttribute attribute = (ReflectorPropertyAttribute)property.GetCustomAttributes(false)[0]; IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(property), attribute); Assert.AreEqual(typeof(XmlCollectionSerialiser), serialiser.GetType()); }
public SeriesFileSpec(string rootPath, int aniDbSeriesId, IXmlSerialiser serializer) { this.rootPath = rootPath; this.serializer = serializer; const string seriesQueryUrl = "http://api.anidb.net:9001/httpapi?request=anime&client={0}&clientver=1&protover=1&aid={1}"; this.Url = string.Format(seriesQueryUrl, ClientName, aniDbSeriesId); this.LocalPath = this.GetSeriesCacheFilePath(aniDbSeriesId); }
public TransactionService( ILogger <ITransactionService> logger, IEnumerable <IFileShare> fileStores, IJsonSerialiser jsonSerialiser, IXmlSerialiser xmlSerialiser) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _fileShares = fileStores ?? throw new ArgumentNullException(nameof(fileStores)); _jsonSerialiser = jsonSerialiser ?? throw new ArgumentNullException(nameof(jsonSerialiser)); _xmlSerialiser = xmlSerialiser ?? throw new ArgumentNullException(nameof(xmlSerialiser)); }
public object Read(XmlNode node) { NetReflector.CheckNull(node, "node", typeof(XmlNode)); IXmlSerialiser serialiser = table[node.Name]; if (serialiser == null) { throw new NetReflectorException(string.Format("No loaded type is marked up with a ReflectorType attribute that matches the Xml node ({0}). Xml Source: {1}", node.Name, node.OuterXml)); } return(serialiser.Read(node, table)); }
private string GetReflectorPropertyXmlData(object obj, IXmlSerialiser memberSerialiser) { StringBuilder xml = new StringBuilder(); using (var writer = XmlWriter.Create(xml, new XmlWriterSettings { OmitXmlDeclaration = true })) { memberSerialiser.Write(writer, obj); } return(xml.ToString()); }
// refactor with method above??? protected object ReadValue(XmlNode node, NetReflectorTypeTable table) { IXmlSerialiser serialiser = table[node.Name]; if (serialiser == null) { return(node.InnerText); } else { // fix return(serialiser.Read(node, table)); } }
public AniDbDataCache(IApplicationPaths applicationPaths, IFileCache fileCache, ILogManager logManager, IXmlSerialiser xmlSerializer) { this.applicationPaths = applicationPaths; this.fileCache = fileCache; this.xmlSerializer = xmlSerializer; var titlesFileSpec = new TitlesFileSpec(this.applicationPaths.CachePath, this.xmlSerializer); this.seiyuuFileSpec = new SeiyuuFileSpec(new XmlSerialiser(logManager), this.applicationPaths.CachePath); this.titleListLazy = new Lazy <IEnumerable <TitleListItemData> >(() => { var titleData = this.fileCache.GetFileContentAsync(titlesFileSpec, CancellationToken.None).Result; return(titleData.Match(t => t.Titles, Enumerable.Empty <TitleListItemData>)); }); }
protected virtual object Read(XmlNode childNode, Type instanceType, NetReflectorTypeTable table) { if (ReflectionUtil.IsCommonType(instanceType)) { if ((childNode.Attributes != null) && (childNode.Attributes.Count > 0)) { throw new NetReflectorException( string.Format("Attributes are not allowed on {3} types - {0} attributes(s) found on '{1}'" + Environment.NewLine + "Xml: {2}", childNode.Attributes.Count, childNode.Name, childNode.OuterXml, instanceType.Name)); } return(childNode.InnerText); } else { ReflectorTypeAttribute reflectorTypeAttribute = ReflectorTypeAttribute.GetAttribute(instanceType); if (reflectorTypeAttribute == null) { if (!string.IsNullOrEmpty(attribute.InstanceTypeKey)) { throw new NetReflectorException( string.Format("Unable to find reflector type for '{0}' when deserialising '{1}' - '{3}' has not been set" + Environment.NewLine + "Xml: {2}", instanceType.Name, childNode.Name, childNode.OuterXml, attribute.InstanceTypeKey)); } else { throw new NetReflectorException( string.Format("Unable to find reflector type for '{0}' when deserialising '{1}'" + Environment.NewLine + "Xml: {2}", instanceType.Name, childNode.Name, childNode.OuterXml)); } } IXmlSerialiser serialiser = table[reflectorTypeAttribute.Name]; // null check return(serialiser.Read(childNode, table)); } }
public void Add(Type type) { ReflectorTypeAttribute attribute = ReflectorTypeAttribute.GetAttribute(type); if (attribute == null) { return; } if (!reflectorTypes.Contains(attribute.Name)) { IXmlSerialiser serialiser = attribute.CreateSerialiser(type, instantiator); reflectorTypes.Add(attribute.Name, serialiser); } else if (type != this[attribute.Name].Type) { throw new NetReflectorException(string.Format(@"Multiple types exist with the same ReflectorTypeAttribute name ""{0}"": ({1}, {2})", attribute.Name, type, this[attribute.Name].Type)); } }
protected override void WriteValue(XmlWriter writer, object value) { foreach (object element in ((IEnumerable)value)) { if (element == null) { continue; } ReflectorTypeAttribute attribute = ReflectorTypeAttribute.GetAttribute(element); if (attribute == null) { writer.WriteElementString(elementName, element.ToString()); } else { // make more concise? IXmlSerialiser serialiser = attribute.CreateSerialiser(element.GetType()); serialiser.Write(writer, element); } } }
public TitlesFileSpec(string rootPath, IXmlSerialiser serializer) { this.rootPath = rootPath; this.serializer = serializer; }
public MappingList(IApplicationPaths applicationPaths, IFileCache fileCache, IApiClient xemApiClient, ICustomJsonSerialiser jsonSerialiser, IXmlSerialiser xmlSerializer) { this.mappingsFileSpec = new MappingsFileSpec(applicationPaths.CachePath, xmlSerializer); this.mappingsAniDbXemFileSpec = new XemAniDbMappingsFileSpec(applicationPaths.CachePath, xemApiClient, jsonSerialiser); this.mappingsTvDbXemFileSpec = new XemTvDbMappingsFileSpec(applicationPaths.CachePath, xemApiClient, jsonSerialiser); this.fileCache = fileCache; this.mappingListTaskLazy = new Lazy <Task <IEnumerable <SeriesMapping> > >(() => this.CreateMappingListAsync(CancellationToken.None)); this.xemAniDbMappingListTaskLazy = new Lazy <Task <IEnumerable <SeriesMapping> > >(() => this.CreateXemAniDbMappingListAsync(CancellationToken.None)); this.xemTvDbMappingListTaskLazy = new Lazy <Task <IEnumerable <SeriesMapping> > >(() => this.CreateXemTvDbMappingListAsync(CancellationToken.None)); }
public void ShouldCreateCollectionSerialiserWhenCollectionPropertyIsPassed() { IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(typeof(CollectionTestClass).GetProperty("List")), attribute); Assert.AreEqual(typeof(XmlCollectionSerialiser), serialiser.GetType()); }
public void ShouldCreateArraySerialiserWhenArrayPropertyIsPassed() { IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(typeof(ArrayTestClass).GetProperty("Elements")), attribute); Assert.AreEqual(typeof(XmlArraySerialiser), serialiser.GetType()); }
public ReflectorPropertyUsedPropertyInfo(PropertyInfo prop) { PropertyInfo = prop; MemberSerialiser = GetMemberSerialiser(prop); }
public FileCache(IFileDownloader fileDownloader, IXmlSerialiser serialiser) { _fileDownloader = fileDownloader; _serialiser = serialiser; }
public AuthnRequestSerialiser(IXmlSerialiser serialiser, IMessageEncoding messageEncoding, ILogProvider logProvider) { this._serialiser = serialiser; this._messageEncoding = messageEncoding; this._logProvider = logProvider; }
public SeiyuuFileSpec(IXmlSerialiser xmlSerialiser, string rootPath) { this.xmlSerialiser = xmlSerialiser; this.rootPath = rootPath; }
public SeiyuuFileSpec(IXmlSerialiser xmlSerialiser, string rootPath) { _xmlSerialiser = xmlSerialiser; _rootPath = rootPath; }