private static async Task SaveDisList(Hashtable newList, Hashtable oldList, DocumentCollection origin, DocumentCollection oldDc, DocumentCollection newDc) { var allow = new DcAllocate { Type = "DisList", DcName = newDc.Id, DcSelfLink = newDc.SelfLink, District = new List<string>() }; foreach (DictionaryEntry i in newList) { allow.District.Add(i.Key.ToString()); } await RetryService.ExecuteWithRetries(() => _client.CreateDocumentAsync(origin.DocumentsLink, allow)); var ds = from d in _client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink) where d.Type == "DisList" && d.DcName == oldDc.Id select d; DcAllocate l = ds.AsEnumerable().FirstOrDefault(); List<string> disList = (from DictionaryEntry i in oldList select i.Key.ToString()).ToList(); if (l != null) { l.District = disList; await RetryService.ExecuteWithRetries(() => _client.ReplaceDocumentAsync(l)); } else { var allow2 = new DcAllocate { Type = "DisList", DcName = oldDc.Id, DcSelfLink = oldDc.SelfLink, District = disList }; await RetryService.ExecuteWithRetries(() => _client.CreateDocumentAsync(origin.DocumentsLink, allow2)); } }
private static async Task SaveDisList(Hashtable newList, Hashtable oldList, DocumentCollection origin, DocumentCollection oldDc, DocumentCollection newDc, DocumentClient client) { var t = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds; var allow = new DcAllocate { Type = "DisList", DcName = newDc.Id, DcSelfLink = newDc.SelfLink, District = new List<string>() }; foreach (DictionaryEntry i in newList) { allow.District.Add(i.Key.ToString()); } await client.CreateDocumentAsync(origin.DocumentsLink, allow); var ds = from d in client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink) where d.Type == "DisList" && d.DcName == oldDc.Id select d; var l = ds.ToList().FirstOrDefault(); if (l != null) await client.DeleteDocumentAsync(l._self); var allow2 = new DcAllocate { Type = "DisList", DcName = oldDc.Id, DcSelfLink = oldDc.SelfLink, District = new List<string>(), }; foreach (DictionaryEntry i in oldList) { allow2.District.Add(i.Key.ToString()); } await client.CreateDocumentAsync(origin.DocumentsLink, allow2); }