public void SaveAsTemplate(ICache <IPKSimBuildingBlock, IReadOnlyList <IPKSimBuildingBlock> > buildingBlocksWithReferenceToSave, TemplateDatabaseType templateDatabaseType) { var templates = new Cache <IPKSimBuildingBlock, Template>(); var allBuildingBlocksToSave = buildingBlocksWithReferenceToSave.Keys.Union(buildingBlocksWithReferenceToSave.SelectMany(x => x)).ToList(); //First pass. Save the template item corresponding to the specific building blocks foreach (var buildingBlockToSave in allBuildingBlocksToSave) { var templateItem = templateItemFor(buildingBlockToSave, templateDatabaseType); //user cancels saving action for one building block. Cancel the whole process if (templateItem == null) { return; } templates.Add(buildingBlockToSave, templateItem); } //then update the template references that will be save to the template database foreach (var keyValue in buildingBlocksWithReferenceToSave.KeyValues) { var templateItem = templates[keyValue.Key]; keyValue.Value.Each(reference => templateItem.References.Add(templates[reference])); } _templateTaskQuery.SaveToTemplate(templates.ToList()); _dialogCreator.MessageBoxInfo(PKSimConstants.UI.TemplatesSuccessfullySaved(templates.Select(x => x.Name).ToList())); }
public void SaveToTemplate <T>(T objectToSave, TemplateType templateType, string defaultName) where T : class { using (var namePresenter = _applicationController.Start <INameTemplatePresenter>()) { if (!namePresenter.NewName(defaultName, templateType)) { return; } var templateItem = new LocalTemplate { Name = namePresenter.Name, Description = namePresenter.Description, Type = templateType, Object = objectToSave, DatabaseType = TemplateDatabaseType.User, }; _templateTaskQuery.SaveToTemplate(templateItem); _dialogCreator.MessageBoxInfo(PKSimConstants.UI.TemplateSuccessfullySaved(templateItem.Name, _objectTypeResolver.TypeFor(objectToSave))); } }