/// <summary> /// Build the elements retrieving as required from the specified elements instance. /// </summary> public async void Build(Elements elements) { if (GetElement == null) { elements.Get(Key, new Act <Element, Elements, IAction <Element> >(OnRootLoaded, null, elements, null)); } else { OnRootLoaded(await GetElement.RunAsync(), elements, null); } }
/// <summary> /// Asynchronously fetch the item. /// </summary> public async Task <T> Fetch() { T reference; if (_set && _item.TryGetTarget(out reference)) { return(reference); } reference = await GetItem.RunAsync(); if (reference != null) { if (_set) { _item.SetTarget(reference); } else { _set = true; _item = new WeakReference <T>(reference); } } return(reference); }
/// <summary> /// Get the element asynchronously. /// </summary> public async Task <Element> GetAsync() { Element result = null; _lock.Take(); if (_processing) { if (_element == null) { _lock.Release(); if (_path == null) { result = await _getElement.RunAsync(); } else { var parser = new ElementParser(_path).RunSync(); if (parser.Error == null) { result = parser.Root; } else { Log.Error("Element parser error. " + parser.Error); } } if (result == null) { return(null); } if (_onBuild != null) { _onBuild.ArgA = result; _onBuild.Run(); } } else { result = _element.Clone(); _lock.Release(); } return(result); } // check if the link has or should be updated if (_element == null) { if (_path == null) { result = await _getElement.RunAsync(); } else { var parser = new ElementParser(_path).RunSync(); if (parser.Error == null) { result = parser.Root; } else { _lock.Release(); Log.Error("Element parser error. " + parser.Error); return(null); } } _element = result; if (_onBuild != null) { _onBuild.ArgA = _element; _onBuild.Run(); } if (_cacheTime > 0) { _nextUpdate = Time.Milliseconds + _cacheTime; } else { _nextUpdate = long.MaxValue; } } else { if (_nextUpdate < Time.Milliseconds) { if (_path == null) { result = await _getElement.RunAsync(); if (result == null) { _lock.Release(); return(null); } } else { var parser = new ElementParser(_path).RunSync(); if (parser.Error != null) { _lock.Release(); Log.Error("Element parser error. " + parser.Error); return(null); } result = parser.Root; } _element = result; if (_onBuild != null) { _onBuild.ArgA = _element; _onBuild.Run(); } if (_cacheTime > 0) { _nextUpdate = Time.Milliseconds + _cacheTime; } else { _nextUpdate = long.MaxValue; } } } // iterate and run the callbacks foreach (var callback in _callbacks) { callback.ArgA = _element.Clone(); ManagerUpdate.Control.AddSingle(callback); } _callbacks.Clear(); result = _element.Clone(); _lock.Release(); return(result); }