Example #1
0
        void Finding(object sender, FindingWidgetEventArgs e)
        {
            if ((!e.Id.HasValue || e.Id <= 0) && String.IsNullOrEmpty(e.Name))
            {
                return;
            }

            if (e.Id.HasValue && e.Id > 0)
            {
                AsyncManager.RegisterAsyncTask(
                    (asyncSender, ea, callback, state) => // Begin
                    widgetRepository.BeginFind(e.Id.Value, callback, state),
                    result =>                             // End
                {
                    var widget = widgetRepository.EndFind(result);
                    if (widget != null)
                    {
                        View.Model.Widgets.Add(widget);
                    }
                },
                    result => { }, // Timeout
                    null, false);
            }
            else
            {
                AsyncManager.RegisterAsyncTask(
                    (asyncSender, ea, callback, state) => // Begin
                    widgetRepository.BeginFindByName(e.Name, callback, state),
                    result =>                             // End
                {
                    var widget = widgetRepository.EndFindByName(result);
                    if (widget != null)
                    {
                        View.Model.Widgets.Add(widget);
                    }
                },
                    result => { }, // Timeout
                    null, false);
            }
            AsyncManager.ExecuteRegisteredAsyncTasks();
            View.Model.ShowResults = true;
        }