public IReadOnlyList <T> LoadFromTemplate <T>(TemplateType templateType) { _buildingBlockTypeString = _objectTypeResolver.TypeFor <T>(); _view.Caption = PKSimConstants.UI.LoadBuildingBlockFromTemplate(_buildingBlockTypeString); _shouldAddItemIcons = !_templateTaskQuery.IsPrimitiveType(templateType); updateIcon(templateType); _availableBuildingBlocks = _templateTaskQuery.AllTemplatesFor(templateType); if (!_availableBuildingBlocks.Any()) { throw new NoBuildingBlockTemplateAvailableException(_buildingBlockTypeString); } var userTemplateNode = _treeNodeFactory.CreateFor(PKSimRootNodeTypes.UserTemplates); var systemTemplateNode = _treeNodeFactory.CreateFor(PKSimRootNodeTypes.SystemTemplates); addTemplatesTo(userTemplateNode, TemplateDatabaseType.User); addTemplatesTo(systemTemplateNode, TemplateDatabaseType.System); updateView(); _view.Display(); if (_view.Canceled) { return(new List <T>()); } return(shouldLoadTemplateWithReferences() ? loadMultipleTemplate <T>() : loadSingleTemplate <T>()); }
public Task <IReadOnlyList <T> > LoadFromTemplateAsync <T>(TemplateType templateType) { _templateTypeDisplay = templateType.ToString(); _view.Caption = PKSimConstants.UI.LoadItemFromTemplate(_templateTypeDisplay); _shouldAddItemIcons = !_templateTaskQuery.IsPrimitiveType(templateType); updateIcon(templateType); _availableTemplates.AddRange(_templateTaskQuery.AllTemplatesFor(templateType) .Where(x => x.IsSupportedByCurrentVersion(_configuration.Version)) .OrderBy(x => x.Name)); if (!_availableTemplates.Any()) { throw new NoTemplateAvailableException(_templateTypeDisplay); } updateView(); _view.Display(); if (_view.Canceled) { return(Task.FromResult <IReadOnlyList <T> >(Array.Empty <T>())); } return(shouldLoadTemplateWithReferences(templateType) ? loadMultipleTemplate <T>() : loadSingleTemplate <T>()); }
public IReadOnlyList <T> LoadFromTemplate <T>(TemplateType templateType) { var allTemplates = new List <T>(); string buildingBlockTypeString = _objectTypeResolver.TypeFor <T>(); _view.Caption = PKSimConstants.UI.LoadBuildingBlockFromTemplate(buildingBlockTypeString); _shouldAddItemIcons = !_templateTaskQuery.IsPrimitiveType(templateType); updateIcon(templateType); _availableBuildingBlocks = _templateTaskQuery.AllTemplatesFor(templateType); if (!_availableBuildingBlocks.Any()) { throw new NoBuildingBlockTemplateAvailableException(buildingBlockTypeString); } var userTemplateNode = _treeNodeFactory.CreateFor(PKSimRootNodeTypes.UserTemplates); var systemTemplateNode = _treeNodeFactory.CreateFor(PKSimRootNodeTypes.SystemTemplates); addTemplatesTo(userTemplateNode, TemplateDatabaseType.User); addTemplatesTo(systemTemplateNode, TemplateDatabaseType.System); updateView(); _view.Display(); if (_view.Canceled) { return(allTemplates); } if (_selectedTemplate.HasReferences) { if (_dialogCreator.MessageBoxYesNo(PKSimConstants.UI.DoYouWantToLoadReferencedTemplateAsWell) == ViewResult.Yes) { return(loadMultipleTemplate <T>()); } } allTemplates.Add(loadSingleTemplate <T>()); return(allTemplates); }