2016-07-19 8 views
0

Azure TableStorageから大きなデータセットを取得しようとしています。 1回でそれを取得しようといくつかの試みをした後私はあきらめて、現在Deserialized正しく取得されていないTableContinuationトークンを使用しています。オブジェクトは作成されているが、すべてのNext ...値(すなわちNextRowKey、NextPartitionKey、など私が渡していますが、それはして移入されなければならない値を見ることができます作成​​されることstringresponse中...TableContinuationTokenが正しくJSONから逆シリアル化されない

クラスは、オブジェクトのリストが含まれており、トークン

public class FlorDataset 
{ 
    public List<FlorData> Flors { get; set; } 
    public TableContinuationToken Token { get; set; } 
} 

コントローラ際、NULLですコードは正確にロケット科学ではありません....

 [HttpGet, Route("api/list/{token}")] 
    public IHttpActionResult FindAll(string token) 
    { 
     try 
     { 
      TableContinuationToken actualToken = token == "None" 
       ? null 
       : new TableContinuationToken() 
       { 
        NextPartitionKey = NextPartition, 
        NextRowKey = token, 
        NextTableName = NextTableName 
       }; 

      var x = Run(actualToken); 
      Flors = x.Flors; 
      actualToken = x.Token; 
      NextTableName = actualToken.NextTableName; 
      NextPartition = actualToken.NextPartitionKey; 

       return Flors != null 
        ? (IHttpActionResult)new IsoncOkResult<FlorDataset>(x, this) 
        : NotFound(); 

     } 
     catch (Exception ex) 
     { 
      Trace.TraceError(ex.ToString()); 
      return NotFound(); 
     } 
    } 

    private FlorDataset Run(TableContinuationToken token) 
    { 
     return _repo.GetAllByYear("2016", token) as FlorDataset; 
    } 
012 2コントローラがある私のかなり標準的なWeb APIを呼び出す

呼び出しコード:

   do 
      { 
       try 
       { 
        HttpResponseMessage response = null; 
        if (string.IsNullOrEmpty(token.NextRowKey)) 
        { 
         response = await client.GetAsync("api/list/None"); 
        } 
        else 
        { 
         response = await client.GetAsync($"api/list/{token.NextRowKey}"); 
        } 
        if (response.IsSuccessStatusCode) 
        { 
         var stringresponse = await response.Content.ReadAsStringAsync(); 
         var ds = JsonConvert.DeserializeObject<FlorDataset>(stringresponse); 
         token = ds.Token; 
         Flors.AddRange(ds.Flors); 
        } 
        else 
        { 
         token = null; 
        } 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.ToString()); 
        token = null; 
       } 
      } while (token != null); 

答えて

0

わかりましたが、これは最大のソリューションではありませんが、それは他のケースの誰にこれまで働く唯一のものは、同じことをしようとしているのです私の質問に絡みついて....

デシリアライズを行う前に、あなたはひどい文字列置換をしています....私は実際にこれを投稿するだけで気分が悪いので、誰かがより良い答えを共有してください.....

if (response.IsSuccessStatusCode) 
{ 
    var stringresponse = await response.Content.ReadAsStringAsync(); 
    stringresponse = stringresponse.Replace(">k__BackingField", ""); 
    stringresponse = stringresponse.Replace("<", ""); 
    var ds = JsonConvert.DeserializeObject<FlorDataset>(stringresponse); 
    token = ds.Token; 
    Flors.AddRange(ds.Flors);      
} 

いいえ、きれいではありませんが、動作します!!!! :-D今漂白剤で私の指を洗うつもり!

関連する問題