protected async void CreateItems()
{
- sections.InitSections();
// add only visible sections to content view in required order
var customization = GetCustomization().OrderBy(c => c.Order);
foreach (var cust in customization)
if (cust.IsVisible && section != null)
{
- if (section.Init != null)
- {
- await section.InitComplete;
- }
+ await section.Init;
await CoreApplication.Post(() =>
{
-using System;
+using SettingCore.TextResources;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
{
public class Sections
{
+ // TODO : remove dictionary after all gadget sections have been changed
private Dictionary<string, View> sections = new Dictionary<string, View>();
private List<Section> sectionList = new List<Section>();
return false;
}
- public void Add(string menuPath, Action action, Action init = null)
+ public void Add(string menuPath, Action action, Task task = null)
{
menuPath = menuPath.ToLowerInvariant();
sectionList.Add(new Section
{
MenuPath = menuPath,
CreateItem = action,
- Init = init
+ Init = task is null ? Task.CompletedTask : InitAsync(task),
});
}
- public Section GetSection(string menuPath)
+ private Task InitAsync(Task task)
{
- return sectionList.Where(a => a.MenuPath == menuPath).FirstOrDefault();
+ return Task.Run(async () =>
+ {
+ await task;
+ return true;
+ });
}
- public void InitSections()
+ public Section GetSection(string menuPath)
{
- var initList = sectionList.Where(a => a.Init != null).ToList();
- foreach (var section in initList)
- {
- section.InitComplete = Task.Run(() => section.Init);
- }
+ return sectionList.Where(a => a.MenuPath == menuPath).FirstOrDefault();
}
public void Clear()
{
public string MenuPath { get; set; }
public Action CreateItem { get; set; }
- public Action Init { get; set; }
- public Task InitComplete { get; set; }
+ public Task Init { get; set; }
}
}
}