Created
March 21, 2017 05:00
-
-
Save supreettare/a1c88c9ac158dbd5a67d3cc30b3e2fae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> DownloadPayload(string userId) | |
{ | |
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); | |
ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null; | |
try | |
{ | |
//string unique = DateTime.Now.Ticks.ToString() + DateTime.UtcNow.TimeOfDay.ToString(); | |
// Download all user Departments | |
//await userDepartmentsTable.PurgeAsync(); | |
await userDepartmentsTable.PullAsync( | |
"Departments", | |
userDepartmentsTable.Where(x => x.UserId == userId), false, new System.Threading.CancellationToken(), null); | |
var allDepartments = await userDepartmentsTable.Where(x => x.UserId == userId).ToListAsync(); | |
List<Task> TaskList = new List<Task>(); | |
// Download all categories for all user departments | |
foreach (var department in allDepartments) | |
{ | |
var departmentId = department.DepartmentId; | |
TaskList.Add(reportCategoryTable.PullAsync("Category"+departmentId, reportCategoryTable.Where(x => x.DepartmentId == departmentId && x.IsDeleted == false))); | |
//await reportCategoryTable.PullAsync( | |
// "Category", | |
// reportCategoryTable.Where(x => x.DepartmentId == departmentId && x.IsDeleted == false ), false, new System.Threading.CancellationToken(), null); | |
var allCategories = await reportCategoryTable.Where(x => x.DepartmentId == departmentId && x.IsDeleted == false).OrderBy(x => x.Name).ToListAsync(); | |
// download all report templates for all categories | |
foreach (var category in allCategories) | |
{ | |
var categoryId = category.Id; | |
await reportTemplateTable.PullAsync( | |
"ReportTemplate", | |
reportTemplateTable.Where(x => x.ReportCategoryId == categoryId), false, new System.Threading.CancellationToken(), null); | |
var allTemplates = await reportTemplateTable.Where(x => x.ReportCategoryId == categoryId && x.IsDeleted== false).OrderByDescending(x => x.Title).ToListAsync(); | |
// download all report template details for all report templates | |
foreach (var template in allTemplates) | |
{ | |
var templateId = template.Id; | |
await reportTemplateDetailTable.PullAsync( | |
"ReportTemplateDetail", | |
reportTemplateDetailTable.Where(x => x.ReportTemplateId == templateId), false, new System.Threading.CancellationToken(), null); | |
//var data = await reportTemplateDetailTable.ToListAsync(); | |
// download all reports for this template filled by this user | |
await reportTable.PullAsync("Report", reportTable.Where(x => x.ReportCreatedById == userId && x.TemplateId == templateId), false, new System.Threading.CancellationToken(), null); | |
} | |
} | |
} | |
await Task.WhenAll(TaskList); | |
tcs.SetResult(true); | |
} | |
catch (MobileServicePushFailedException exc) | |
{ | |
if (exc.PushResult != null) | |
{ | |
syncErrors = exc.PushResult.Errors; | |
} | |
} | |
return tcs.Task.Result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment