コード例 #1
0
        public void ShouldUseDefaultSerialiserFactory()
        {
            ReflectorPropertyAttribute attribute  = new ReflectorPropertyAttribute("foo");
            IXmlSerialiser             serialiser = attribute.CreateSerialiser(member);

            Assert.IsNotNull(serialiser);
        }
コード例 #2
0
 public AuthnRequestBuilder(ICertificateManager certificateManager, IFederationPartyContextBuilder federationPartyContextBuilder, IXmlSerialiser serialiser, ICompression compression)
 {
     this._certificateManager            = certificateManager;
     this._federationPartyContextBuilder = federationPartyContextBuilder;
     this._serialiser  = serialiser;
     this._compression = compression;
 }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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));
 }
コード例 #7
0
        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));
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        // 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));
            }
        }
コード例 #10
0
        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>));
            });
        }
コード例 #11
0
 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));
     }
 }
コード例 #12
0
        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));
            }
        }
コード例 #13
0
        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);
                }
            }
        }
コード例 #14
0
 public TitlesFileSpec(string rootPath, IXmlSerialiser serializer)
 {
     this.rootPath   = rootPath;
     this.serializer = serializer;
 }
コード例 #15
0
 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));
 }
コード例 #16
0
        public void ShouldCreateCollectionSerialiserWhenCollectionPropertyIsPassed()
        {
            IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(typeof(CollectionTestClass).GetProperty("List")), attribute);

            Assert.AreEqual(typeof(XmlCollectionSerialiser), serialiser.GetType());
        }
コード例 #17
0
        public void ShouldCreateArraySerialiserWhenArrayPropertyIsPassed()
        {
            IXmlSerialiser serialiser = factory.Create(ReflectorMember.Create(typeof(ArrayTestClass).GetProperty("Elements")), attribute);

            Assert.AreEqual(typeof(XmlArraySerialiser), serialiser.GetType());
        }
コード例 #18
0
 public ReflectorPropertyUsedPropertyInfo(PropertyInfo prop)
 {
     PropertyInfo     = prop;
     MemberSerialiser = GetMemberSerialiser(prop);
 }
コード例 #19
0
 public FileCache(IFileDownloader fileDownloader, IXmlSerialiser serialiser)
 {
     _fileDownloader = fileDownloader;
     _serialiser     = serialiser;
 }
コード例 #20
0
 public AuthnRequestSerialiser(IXmlSerialiser serialiser, IMessageEncoding messageEncoding, ILogProvider logProvider)
 {
     this._serialiser      = serialiser;
     this._messageEncoding = messageEncoding;
     this._logProvider     = logProvider;
 }
コード例 #21
0
 public SeiyuuFileSpec(IXmlSerialiser xmlSerialiser, string rootPath)
 {
     this.xmlSerialiser = xmlSerialiser;
     this.rootPath      = rootPath;
 }
コード例 #22
0
 public SeiyuuFileSpec(IXmlSerialiser xmlSerialiser, string rootPath)
 {
     _xmlSerialiser = xmlSerialiser;
     _rootPath      = rootPath;
 }