예제 #1
0
        protected override UDPBaseResponse <ResponseAddFile> ParseResponse(UDPReturnCode code, string receivedData)
        {
            switch (code)
            {
            case UDPReturnCode.MYLIST_ENTRY_ADDED:
            {
                /* Response Format
                 * {int4 mylist id of new entry}
                 */
                // parse the MyList ID
                string[] arrResult = receivedData.Split('\n');
                if (arrResult.Length >= 2)
                {
                    int.TryParse(arrResult[1], out int myListID);
                    return(new UDPBaseResponse <ResponseAddFile>
                        {
                            Code = code,
                            Response = new ResponseAddFile
                            {
                                MyListID = myListID,
                                State = State,
                                IsWatched = IsWatched,
                                WatchedDate = WatchedDate
                            }
                        });
                }
                break;
            }

            case UDPReturnCode.FILE_ALREADY_IN_MYLIST:
            {
                /* Response Format
                 * {int4 lid}|{int4 fid}|{int4 eid}|{int4 aid}|{int4 gid}|{int4 date}|{int2 state}|{int4 viewdate}|{str storage}|{str source}|{str other}|{int2 filestate}
                 */
                //file already exists: read 'watched' status
                string[] arrResult = receivedData.Split('\n');
                if (arrResult.Length >= 2)
                {
                    string[] arrStatus   = arrResult[1].Split('|');
                    bool     hasMyListID = int.TryParse(arrStatus[0], out int myListID);
                    if (!hasMyListID)
                    {
                        throw new UnexpectedUDPResponseException
                              {
                                  Message    = "MyListID was not provided. Use AniDBMyList_RequestAddEpisode for generic files.",
                                  Response   = receivedData,
                                  ReturnCode = code
                              }
                    }
                    ;


                    GetFile_State state = (GetFile_State)int.Parse(arrStatus[6]);

                    int  viewdate = int.Parse(arrStatus[7]);
                    bool watched  = viewdate > 0;

                    DateTime?watchedDate = null;
                    if (watched)
                    {
                        DateTime utcDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        utcDate = utcDate.AddSeconds(viewdate);

                        watchedDate = utcDate.ToLocalTime();
                    }

                    return(new UDPBaseResponse <ResponseAddFile>
                        {
                            Code = code,
                            Response = new ResponseAddFile
                            {
                                MyListID = myListID,
                                State = state,
                                IsWatched = watched,
                                WatchedDate = watchedDate
                            }
                        });
                }
                break;
            }
            }
            throw new UnexpectedUDPResponseException(code, receivedData);
        }
    }
예제 #2
0
        protected override UDPBaseResponse <ResponseAddFile> ParseResponse(UDPReturnCode code, string receivedData)
        {
            switch (code)
            {
            case UDPReturnCode.MYLIST_ENTRY_ADDED:
            {
                // We're adding a generic file, so it won't return a MyListID
                return(new UDPBaseResponse <ResponseAddFile>
                    {
                        Code = code,
                        Response = new ResponseAddFile
                        {
                            State = State,
                            IsWatched = IsWatched,
                            WatchedDate = WatchedDate
                        }
                    });
            }

            case UDPReturnCode.FILE_ALREADY_IN_MYLIST:
            {
                /* Response Format
                 * {int4 lid}|{int4 fid}|{int4 eid}|{int4 aid}|{int4 gid}|{int4 date}|{int2 state}|{int4 viewdate}|{str storage}|{str source}|{str other}|{int2 filestate}
                 */
                //file already exists: read 'watched' status
                string[] arrResult = receivedData.Split('\n');
                if (arrResult.Length >= 2)
                {
                    string[] arrStatus = arrResult[1].Split('|');
                    // We expect 0 for a MyListID
                    int.TryParse(arrStatus[0], out int myListID);

                    GetFile_State state = (GetFile_State)int.Parse(arrStatus[6]);

                    int  viewdate = int.Parse(arrStatus[7]);
                    bool watched  = viewdate > 0;

                    DateTime?watchedDate = null;
                    if (watched)
                    {
                        DateTime utcDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        utcDate = utcDate.AddSeconds(viewdate);

                        watchedDate = utcDate.ToLocalTime();
                    }

                    return(new UDPBaseResponse <ResponseAddFile>
                        {
                            Code = code,
                            Response = new ResponseAddFile
                            {
                                MyListID = myListID,
                                State = state,
                                IsWatched = watched,
                                WatchedDate = watchedDate
                            }
                        });
                }
                break;
            }
            }
            throw new UnexpectedUDPResponseException(code, receivedData);
        }