public virtual async Task Search(TNDTargetModel targetModel, TNDSearchItem searchItem) { if (searchItem == null) { // //this._ApplicationBuis.GetDataAccess().InitalSearch() } else { // targetModel.StartSearch(); try { // var entityItems = targetModel.EntityItems; var checkedItems = targetModel.CheckedItems; searchItem.ParseSearch(); var taskSearchResult = this._ApplicationBuis.GetDataAccess().SearchTerm( searchItem.MetaEntity, searchItem.SearchTerm, searchItem.Emails, searchItem.EmailDomains); TNDEntityItem[] arrSearchResults = null; try { arrSearchResults = await taskSearchResult.ConfigureAwait(true); } catch (Exception exception) { throw; #warning exception } replaceEntityItems(entityItems, checkedItems, arrSearchResults); } finally { targetModel.FinishSearch(); } } }
private void RemoveTarget(TNDTargetModel selectedTarget) { if (ReferenceEquals(this._SearchModel.SelectedTarget, selectedTarget)) { this._SearchModel.SelectedTarget = this._SearchModel.Targets.FirstOrDefault(t => !ReferenceEquals(t, selectedTarget)); } this._SearchModel.Targets.Remove(selectedTarget); if (this._SearchModel.Targets.Count == 0) { this._ApplicationBuis.ShowDropWindow(); } }
public override void ShowSearchWindow(TNDTargetModel[] lst) { try { base.ShowSearchWindow(lst); #if false if (lst == null) { return; } if (!lst.Any()) { return; } #else if (lst == null) { lst = new TNDTargetModel[0]; } #endif // var app = (App)System.Windows.Application.Current; var dropWindow = getDropWindow(app); var searchWindow = getSearchWindow(app); // if (searchWindow == null) { searchWindow = new SearchWindow(); searchWindow.Init(); } if (searchWindow != null) { TNDSearchModel model = (TNDSearchModel)searchWindow.DataContext; if (model != null) { model.AddTargets(lst); } if (dropWindow != null) { dropWindow.Hide(); } searchWindow.Show(); } // } catch (Exception exception) { App.ApplicationBuis.OnFatalException("TNDApplicationBuis2.ShowSearch", exception); } }
private TNDStoreItem GetOrCreateStoreItem(TNDTargetModel selectedTarget, TNDDropItem dropItem, TNDEntityItem checkedItem) { TNDStoreItem storeItem = null; var storeItems = selectedTarget.StoreItems; lock (storeItems) { storeItem = storeItems.FirstOrDefault(si => ReferenceEquals(si.CheckedItem, checkedItem)); if (storeItem == null) { var metaStorage = checkedItem.MetaEntity.MetaStorage; storeItem = new TNDStoreItem(); storeItem.DropItem = dropItem; storeItem.CheckedItem = checkedItem; storeItems.Add(storeItem); } } return(storeItem); }
public void HandleDrops(TNDFavorite favorite, TNDDropItem[] drops) { this._DropModel.Drops.AddRange(drops); var lst = new List <TNDTargetModel>(); foreach (var dropItem in drops) { if (dropItem.Content != null && dropItem.LastException == null) { TNDTargetModel targetModel = new TNDTargetModel(); targetModel.DropItem = dropItem; targetModel.Favorite = favorite; targetModel.Init(this._DataAccess, this._ApplicationBuis); lst.Add(targetModel); targetModel.PrepareSearch(); //this._DataAccess.InitalSearch(favorite, dropItem); } } this._ApplicationBuis.ShowSearchWindow(lst.ToArray()); }
/// <summary>Query for entities by id</summary> /// <param name="targetModel">the taget</param> /// <param name="metaEntity">default metaEntity.</param> /// <param name="addOrReplace">true to add; false to replace</param> /// <param name="ids">the ids</param> /// <param name="returnParent">true to return also parent.</param> /// <param name="returnThis">true to return this entity type.</param> /// <param name="returnChildren">true to return children.</param> /// <returns>the search result</returns> public virtual async Task Query(TNDTargetModel targetModel, TNDMetaEntity metaEntity, bool addOrReplace, System.Collections.IEnumerable ids, bool returnParent, bool returnThis, bool returnChildren) { string idsText = getIds(ids); idsText = idsText.Trim(); var entityItems = targetModel.EntityItems; var checkedItems = targetModel.CheckedItems; var taskSearchResult = this._ApplicationBuis.GetDataAccess().Query( metaEntity, idsText, true, true, true); TNDEntityItem[] arrSearchResults = null; try { arrSearchResults = await taskSearchResult; } catch (Exception exception) { throw; #warning exception } if (addOrReplace) { addEntityItems(entityItems, checkedItems, arrSearchResults); } else { replaceEntityItems(entityItems, checkedItems, arrSearchResults); } #if false if (arrSearchResults == null || !arrSearchResults.Any()) { entityItems.Clear(); } else { entityItems.Clear(); var dictCheckedItems = checkedItems.ToDictionary(_ => _); // var newCheckedItems = new List <TNDEntityItem>(); // add the found ones - uses the found. foreach (var searchResult in arrSearchResults) { if (dictCheckedItems.Remove(searchResult)) { searchResult.IsChecked = true; newCheckedItems.Add(searchResult); } } // add the not found ones - reuse the old. newCheckedItems.AddRange(dictCheckedItems.Keys); // var sortedNewCheckedItems = newCheckedItems .OrderBy(_ => _.MetaEntity.MetaEntityLevel) .ThenBy(_ => _.MetaEntityName) .ThenBy(_ => _.Name) .ToArray(); checkedItems.Replace(newCheckedItems); entityItems.Replace(arrSearchResults); } #endif }
public ITNDTargetBuis Init(TNDTargetModel targetModel, ITNDDataAccess dataAccess, ITNDApplicationBuis applicationBuis) { this._ApplicationBuis = applicationBuis; this._DataAccess = dataAccess; return(this); }