public async Task GetMedia()
{
try
{
IReadOnlyList<StorageFile> files =
await GetMediaFromFolder(_location, CommonFileQuery.OrderByName);
if (files.Count > 0)
{
await DispatchHelper.InvokeAsync(() => HasNoMedia = false);
}
else
{
await DispatchHelper.InvokeAsync(() => HasNoMedia = true);
}
int j = 0;
foreach (StorageFile storageFile in files)
{
var mediaVM = new MediaViewModel(storageFile);
await mediaVM.Initialize();
// Get back to UI thread
await DispatchHelper.InvokeAsync(() =>
{
Media.Add(mediaVM);
int i = new Random().Next(0, files.Count - 1);
if (j < 5 && i <= (files.Count - 1) / 2)
{
MediaRandom.Add(mediaVM);
j++;
}
MediaGroupedByAlphabet = Media.OrderBy(x => x.AlphaKey).GroupBy(x => x.AlphaKey);
ExecuteSemanticZoom();
});
}
}
catch
{
}
}