Сегодня пол-дня дебажил код, но не могу найти ошибку
public static TwitchVod ParseVodInfo(JObject json)
{
try
{
ulong vodId = json.Value<ulong>("id");
JToken jt = json.Value<JToken>("stream_id");
ulong streamId = jt != null && jt.Type != JTokenType.Null ? jt.Value<ulong>() : 0U;
string userLogin = json.Value<string>("user_login");
string title = json.Value<string>("title");
string description = json.Value<string>("description");
string dateCreated = json.Value<string>("created_at");
if (!DateTime.TryParseExact(dateCreated, "MM/dd/yyyy HH:mm:ss",
null, System.Globalization.DateTimeStyles.None, out DateTime creationDate))
{
creationDate = DateTime.MaxValue;
}
string datePublished = json.Value<string>("published_at");
if (!DateTime.TryParseExact(datePublished, "MM/dd/yyyy HH:mm:ss",
null, System.Globalization.DateTimeStyles.None, out DateTime publishedDate))
{
publishedDate = DateTime.MaxValue;
}
string url = json.Value<string>("url");
string thumbnailTemplateUrl = json.Value<string>("thumbnail_url");
string viewable = json.Value<string>("viewable");
ulong viewCount = json.Value<ulong>("view_count");
string language = json.Value<string>("language");
string vodTypeString = json.Value<string>("type");
TwitchVodType vodType = GetVodType(vodTypeString);
TimeSpan duration = TimeSpan.Zero;
TwitchUserResult twitchUserResult = TwitchUser.Get(userLogin);
DateTime deletionDeletion = DateTime.MaxValue;
if (vodType == TwitchVodType.Archive && twitchUserResult.ErrorCode == 200 && twitchUserResult.User != null)
{
bool isPartner = twitchUserResult.User.BroadcasterType == TwitchBroadcasterType.Partner;
deletionDeletion = creationDate.AddDays(isPartner ? 60d : 14d);
}
TwitchGame game;
VideoMetadataResult videoMetadataResult = TwitchApiGql.GetVodMetadata(vodId.ToString(), userLogin);
if (videoMetadataResult.ErrorCode == 200)
{
int seconds = videoMetadataResult.Metadata.GetVideoLengthSeconds();
if (seconds > 0)
{
duration = TimeSpan.FromSeconds(seconds);
}
game = videoMetadataResult.Metadata.GetGameInfo();
}
else
{
game = TwitchGame.CreateUnknownGame();
}
return new TwitchVod(vodId, title, description, duration, game, creationDate,
publishedDate, deletionDeletion, url, thumbnailTemplateUrl, viewable, viewCount,
language, vodType, streamId, twitchUserResult.User,
json.ToString(), videoMetadataResult.Metadata);
}
catch (Exception ex)
{
//сюда не заходит
System.Diagnostics.Debug.WriteLine(ex.Message);
return null;
}
}
public List<TwitchVod> GetVideosMultiThreaded(uint maxVideos,
int millisecondsTimeout, CancellationToken cancellationToken = default)
{
List<TwitchVod> resultList = new List<TwitchVod>();
if (maxVideos == 0U) { return resultList; }
JArray jaRawVods = GetVideosRaw(maxVideos);
System.Diagnostics.Debug.WriteLine(jaRawVods.ToString()); //здесь все элементы не-null
if (jaRawVods.Count > 0)
{
var tasks = jaRawVods.Select((j) => Task.Run(() =>
{
TwitchVod vod = Utils.ParseVodInfo(j as JObject);
if (vod == null)
{
//сюда тоже не заходит
System.Diagnostics.Debug.WriteLine(j);
}
resultList.Add(vod);
}));
if (millisecondsTimeout > 0)
{
Task.WhenAll(tasks).Wait(millisecondsTimeout, cancellationToken);
}
else
{
Task.WhenAll(tasks).Wait(cancellationToken);
}
}
return resultList;
}
Вызывается так:
List<TwitchVod> vods = twitchUserResult.User.GetVideosMultiThreaded(10U, 0);
Иногда в коллекцию попадает null
. Не могу понять, каким образом