public IReadOnlyList <Template> AllTemplatesFor(TemplateDatabaseType templateDatabaseType, TemplateType templateType) { if (templateDatabaseType == TemplateDatabaseType.Remote) { return(_remoteTemplateRepository.AllTemplatesFor(templateType)); } var allTemplates = new List <Template>(); using (establishConnection(templateDatabaseType)) { var connection = databaseConnection(); var sqlQuery = $"SELECT t.{TemplateTable.Columns.TEMPLATE_TYPE}, t.{TemplateTable.Columns.NAME} FROM " + $"{TemplateTable.NAME} t WHERE t.{TemplateTable.Columns.TEMPLATE_TYPE} IN ({typeFrom(templateType)})"; foreach (DASDataRow row in connection.ExecuteQueryForDataTable(sqlQuery)) { var template = loadTemplateBy(templateDatabaseType, row.StringAt(TemplateTable.Columns.NAME), row.StringAt(TemplateTable.Columns.TEMPLATE_TYPE), connection); addReferencesToTemplate(template, connection); allTemplates.Add(template); } } return(allTemplates); }
private Template loadTemplateBy(TemplateDatabaseType templateDatabaseType, string templateName, string templateType, DAS connection) { try { addTemplateNameParameter(templateName, connection); var sqlQuery = string.Format("SELECT t.{2} FROM {3} t WHERE t.{0} = '{4}' AND t.{1}={5}", TemplateTable.Columns.TEMPLATE_TYPE, TemplateTable.Columns.NAME, TemplateTable.Columns.DESCRIPTION, TemplateTable.NAME, templateType, _pName); var row = connection.ExecuteQueryForSingleRow(sqlQuery); return(new Template { DatabaseType = templateDatabaseType, TemplateType = EnumHelper.ParseValue <TemplateType>(templateType), Name = templateName, Description = row.StringAt(TemplateTable.Columns.DESCRIPTION) }); } finally { removeNameParameter(connection); } }
protected override void SaveAsTemplate(IReadOnlyList <Compound> compounds, TemplateDatabaseType templateDatabaseType) { var possibleMetabolites = new HashSet <Compound>(); compounds.SelectMany(retrieveAllMetabolitesFor).Each(x => possibleMetabolites.Add(x)); bool saveMetabolites = false; if (possibleMetabolites.Any()) { saveMetabolites = _dialogCreator.MessageBoxYesNo(PKSimConstants.UI.DoYouWantToSaveCompoundMetaboliteAsTemplate) == ViewResult.Yes; } if (!saveMetabolites) { base.SaveAsTemplate(compounds, templateDatabaseType); return; } //cache of compound and their possible references var cache = new Cache <IPKSimBuildingBlock, IReadOnlyList <IPKSimBuildingBlock> >(); compounds.Each(compound => addMetaboliteForCompoundTo(compound, cache)); _buildingBlockTask.SaveAsTemplate(cache, templateDatabaseType); }
public bool Exists(TemplateDatabaseType templateDatabaseType, string name, TemplateType templateType) { using (establishConnection(templateDatabaseType)) { var newTemplate = createTemplateRow(templateType, name); return(newTemplate.ExistsInDB()); } }
private IDisposable establishConnection(TemplateDatabaseType templateDatabaseType) { var database = templateDatabaseType == TemplateDatabaseType.User ? new DatabaseDisposer(_templateDatabase, _userSettings.TemplateDatabasePath) : new DatabaseDisposer(_templateDatabase, _pkSimConfiguration.TemplateSystemDatabasePath); _templateDatabaseConverter.Convert(_templateDatabase); return(database); }
private void addTemplatesTo(ITreeNode rootNode, TemplateDatabaseType templateDatabaseType) { foreach (var bb in _availableBuildingBlocks.Where(x => x.DatabaseType == templateDatabaseType).OrderBy(x => x.Name)) { var node = _treeNodeFactory.CreateFor(bb).Under(rootNode); if (_shouldAddItemIcons) { node.WithIcon(ApplicationIcons.IconByName(bb.TemplateType.ToString())); } } _view.AddNode(rootNode); }
public IEnumerable <Template> AllTemplatesFor(TemplateDatabaseType templateDatabaseType, TemplateType templateType) { var allTemplates = new List <Template>(); using (establishConnection(templateDatabaseType)) { var connection = databaseConnection(); var sqlQuery = string.Format("SELECT t.{0}, t.{1} FROM {2} t WHERE t.{0} IN ({3})", TemplateTable.Columns.TEMPLATE_TYPE, TemplateTable.Columns.NAME, TemplateTable.NAME, typeFrom(templateType)); foreach (DASDataRow row in connection.ExecuteQueryForDataTable(sqlQuery)) { var template = loadTemplateBy(templateDatabaseType, row.StringAt(TemplateTable.Columns.NAME), row.StringAt(TemplateTable.Columns.TEMPLATE_TYPE), connection); addReferencesToTemplate(template, connection); allTemplates.Add(template); } } return(allTemplates); }
private Template templateItemFor(IPKSimBuildingBlock buildingBlockToSave, TemplateDatabaseType templateDatabaseType) { string buildingBlockName = buildingBlockToSave.Name; string buildingBlockType = TypeFor(buildingBlockToSave); var templateType = buildingBlockToSave.BuildingBlockType.AsTemplateType(); if (_templateTaskQuery.Exists(templateDatabaseType, buildingBlockName, templateType)) { var result = _dialogCreator.MessageBoxYesNoCancel(PKSimConstants.UI.TemplateWithNameAlreadyExistsInTheDatabase(buildingBlockToSave.Name, buildingBlockType), PKSimConstants.UI.Override, PKSimConstants.UI.SaveAs, PKSimConstants.UI.CancelButton); //user does not want to override if (result == ViewResult.Cancel) { return(null); } //retrieve a new name if (result == ViewResult.No) { var allTemplateNames = _templateTaskQuery.AllTemplatesFor(templateDatabaseType, templateType).Select(x => x.Name); buildingBlockName = _entityTask.NewNameFor(buildingBlockToSave, allTemplateNames); if (string.IsNullOrEmpty(buildingBlockName)) { return(null); } } } Load(buildingBlockToSave); return(new Template { Name = buildingBlockName, Description = buildingBlockToSave.Description, Object = buildingBlockToSave, TemplateType = templateType, DatabaseType = templateDatabaseType }); }
protected override void SaveAsTemplate(Compound compound, TemplateDatabaseType templateDatabaseType) { var allMetabolitesForCompound = retrieveAllMetabolitesFor(compound); bool saveMetabolites = false; if (allMetabolitesForCompound.Any()) { saveMetabolites = _dialogCreator.MessageBoxYesNo(PKSimConstants.UI.DoYouWantToSaveCompoundMetaboliteAsTemplate) == ViewResult.Yes; } if (!saveMetabolites) { base.SaveAsTemplate(compound, templateDatabaseType); return; } //cache of compound and their possible references var cache = new Cache <IPKSimBuildingBlock, IReadOnlyList <IPKSimBuildingBlock> >(); addMetaboliteForCompoundTo(compound, cache); _buildingBlockTask.SaveAsTemplate(cache, templateDatabaseType); }
protected override void SaveAsTemplate(IReadOnlyList <Individual> individuals, TemplateDatabaseType templateDatabaseType) { //We need to save expression profiles for individuals var cache = new Cache <IPKSimBuildingBlock, IReadOnlyList <IPKSimBuildingBlock> >(); individuals.Each(x => cache[x] = x.AllExpressionProfiles()); _buildingBlockTask.SaveAsTemplate(cache, templateDatabaseType); }
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 SaveAsTemplate(IReadOnlyList <IPKSimBuildingBlock> buildingBlocks, TemplateDatabaseType templateDatabaseType) { var cache = new Cache <IPKSimBuildingBlock, IReadOnlyList <IPKSimBuildingBlock> >(); buildingBlocks.Each(buildingBlock => cache[buildingBlock] = new List <IPKSimBuildingBlock>()); SaveAsTemplate(cache, templateDatabaseType); }