在反序列化XML时,Restsharp将myobject返回为null

时间:2014-01-17 15:35:19

标签: c# restsharp

我正在使用plex状态API,我无法加载我的对象。

以下是我的其他客户端方法:

private static List<RestClient> GetRestClients()
    {
        var clientList = new List<RestClient>();

        foreach (PlexUrl pu in DatabaseHelper.GetPlexUrls())
        {
            var client = new RestClient();
            client.AddHandler("application/xml", new DotNetXmlDeserializer());
            client.BaseUrl = pu.Url;
            clientList.Add(client);
        }

        return clientList;
    }

    private static RestRequest GetRequest()
    {
        var request = new RestRequest(Method.GET);
        request.Resource = "status/sessions";
        request.AddHeader(Constants.PLEX_TOKEN_PREFIX, Cache.Get<string>(Constants.PLEX_USER_TOKEN));

        return request;
    }

    public static List<MediaContainer> GetSessions()
    {
        var sessions = new List<MediaContainer>();

        foreach (var client in GetRestClients())
        {
            var response = client.Execute<MediaContainer>(GetRequest());

            if (!string.IsNullOrEmpty(response.ErrorMessage))
            {
                Logger.LogError(response.ErrorMessage);

                if (Properties.Settings.Default.NotifyErrors)
                    MainWindow.TrayIcon.ShowBalloonTip("Error Connecting to PMS", string.Format("There was an error connecting to {0}.", client.BaseUrl), Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Error);
            }
            else
            {
                sessions.Add(response.Data);
            }
        }

        return sessions;
    }

以下是XML的示例,媒体容器可以包含多个视频。

<MediaContainer size="1">
    <Video addedAt="1387660866" art="/library/metadata/696/art/1387660904" contentRating="R" duration="7607858" guid="com.plexapp.agents.themoviedb://87421?lang=en" key="/library/metadata/696" librarySectionID="1" originallyAvailableAt="2013-09-06" rating="6.0999999046325701" ratingKey="696" sessionKey="1" studio="Universal Pictures" summary="Betrayed by his own kind and left for dead on a desolate planet, Riddick fights for survival against alien predators and becomes more powerful and dangerous than ever before. Soon bounty hunters from throughout the galaxy descend on Riddick only to find themselves pawns in his greater scheme for revenge. With his enemies right where he wants them, Riddick unleashes a vicious attack of vengeance before returning to his home planet of Furya to save it from destruction." tagline="Survival Is His Revenge" thumb="/library/metadata/696/thumb/1387660904" title="Riddick" type="movie" updatedAt="1387660904" viewOffset="24922" year="2013">
        <Media aspectRatio="2.35" audioChannels="6" audioCodec="ac3" bitrate="4346" container="mkv" duration="7607858" height="796" id="652" videoCodec="h264" videoFrameRate="24p" videoResolution="1080" width="1916">
            <Part container="mkv" duration="7607858" file="/home/jim/Movies/Riddick (2013).mkv" id="652" key="/library/parts/652/file.mkv" size="4132905434">
                <Stream bitDepth="8" bitrate="3875" cabac="1" chromaSubsampling="4:2:0" codec="h264" codecID="V_MPEG4/ISO/AVC" colorSpace="yuv" duration="7607858" frameRate="23.976" frameRateMode="cfr" hasScalingMatrix="0" height="796" id="3677" index="0" language="English" languageCode="eng" level="40" profile="high" refFrames="5" scanType="progressive" streamType="1" title="" width="1916"/>
                <Stream bitDepth="16" bitrate="384" bitrateMode="cbr" channels="6" codec="ac3" codecID="A_AC3" dialogNorm="-27" duration="7607840" id="3678" index="1" language="English" languageCode="eng" samplingRate="48000" selected="1" streamType="2" title=""/>
            </Part>
        </Media>
        <Genre id="218" tag="Action"/>
        <Genre id="247" tag="Science Fiction"/>
        <Genre id="108" tag="Thriller"/>
        <Writer id="4080" tag="David Twohy"/>
        <Director id="4078" tag="David Twohy"/>
        <Producer id="6820" tag="Ted Field"/>
        <Producer id="4020" tag="Vin Diesel"/>
        <Producer id="6821" tag="Samantha Vincent"/>
        <Country id="71" tag="USA"/>
        <Role id="660" role="Riddick" tag="Vin Diesel" thumb="http://image.tmdb.org/t/p/original/qwyfzMKIhxJ7ols66FgEf7eGdcI.jpg"/>
        <Role id="1054" role="Lord Vaako" tag="Karl Urban" thumb="http://image.tmdb.org/t/p/original/tHYOUO33K7iaDw8nXyqRvDIkVuM.jpg"/>
        <Role id="6811" role="Dahl" tag="Katee Sackhoff" thumb="http://image.tmdb.org/t/p/original/8NcZJxNRSxP2QegcWeX8WDnFlSs.jpg"/>
        <Role id="6812" role="Santana" tag="Jordi Moll&#xE0;" thumb="http://image.tmdb.org/t/p/original/A648UpxxLlgdqziafgSCAVaR0Sc.jpg"/>
        <Role id="6813" role="Moss" tag="Bokeem Woodbine" thumb="http://image.tmdb.org/t/p/original/5jxJLgIsEsKwsHSLVjNvMZzs1Mm.jpg"/>
        <Role id="6814" role="Luna" tag="Nolan Gerard Funk" thumb="http://image.tmdb.org/t/p/original/an3qC0DTKiyzLs76Xw9t9crQfN5.jpg"/>
        <Role id="6815" role="Nunez" tag="Noah Danby" thumb="http://image.tmdb.org/t/p/original/l6soX1Mb6V2QWwxrMjTVEaaaPB2.jpg"/>
        <Role id="6816" role="Rubio" tag="Neil Napier"/>
        <Role id="6817" role="" tag="Keri Hilson" thumb="http://image.tmdb.org/t/p/original/bmrHsGOx35pcYKXjn1aEL7sb5Rd.jpg"/>
        <Role id="6818" role="Diaz" tag="Dave Bautista" thumb="http://image.tmdb.org/t/p/original/gtb1sMCmZjAeF0lSdEWLjFsSvmr.jpg"/>
        <Role id="6819" role="Boss Johns" tag="Matthew Nable"/>
        <Collection id="4093" tag="The Chronicles of Riddick"/>
        <User id="1" thumb="http://www.gravatar.com/avatar/57ddfffd0c28b16997abce76964b5c03?d=404" title="JBurlison@Gmail.com"/>
        <Player machineIdentifier="4f44996d-2fb4-4fcf-9ba4-4b3ab360ed27" platform="Android" state="playing" title="My SM-N900P"/>
        <TranscodeSession key="4f44996d-2fb4-4fcf-9ba4-4b3ab360ed27" throttled="0" progress="0.40000000596046448" speed="0.5" duration="7607000" videoDecision="transcode" audioDecision="transcode" protocol="hls" container="mpegts" videoCodec="h264" audioCodec="aac" audioChannels="2" width="1280" height="532"/>
    </Video>
</MediaContainer>

和我的对象: https://gist.github.com/JBurlison/8469403

我使用其他方法成功地将更简单的XML反序列化为对象。

我通过它进行调试,似乎是尝试使用媒体标记而不是视频标记加载视频对象。我相信这是一个错误,但我想问一下,万一我做了一些明显错误的事情。

0 个答案:

没有答案