コード例 #1
0
 private async Task <bool> UpdateAnimeDetails(IAnimeDetails details, string username, string password, bool canCache = true, bool isupdate = false)
 {
     try
     {
         var updateRequest = _webHttpWebRequestFactory.Create();
         updateRequest.CreateRequest(isupdate
             ? string.Format(EditShowUrl, details.AnimeId)
             : string.Format(AddShowUrl, details.AnimeId));
         updateRequest.UserAgent = _userAgent;
         updateRequest.SetCredentials(username, password);
         updateRequest.Method      = WebRequestMethods.Http.Post;
         updateRequest.ContentType = "application/x-www-form-urlencoded";
         var requestStream = updateRequest.GetRequestStream();
         var requestWriter = new StreamWriter(requestStream);
         requestWriter.Write($"data={_jsonMapper.ConvertAnimeDetailsToXml(details)}");
         requestWriter.Close();
         var response = GetResponse(updateRequest);
         if (response.Contains("Error"))
         {
             Log.Warning("Failed to update {AnimeId} for {username}. Response received was {Response}", details.AnimeId, username, response);
             return(false);
         }
         Log.Information("Successfully completed the update of {AnimeId} for {username}", details.AnimeId, username);
         return(true);
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Error occured while trying to update {AnimeId} for {username}", details.AnimeId, username);
         return(false);
     }
 }