Ejemplo n.º 1
0
        /// <summary>
        /// This is called by the Find dialog to locate the next name
        /// </summary>
        /// <param name="finder"></param>
        private void OnFindNext(FindSearchViewModel finder)
        {
            Debug.Assert(finder == _finder);
            IEnumerable <int> searchRange;

            if (finder.SearchBackward)
            {
                int spos = (FocusedRow != null) ? FocusedRow.Position : TotalRows;
                searchRange = Enumerable.Range(0, spos).Reverse();
            }
            else
            {
                int spos = (FocusedRow != null) ? FocusedRow.Position : -1;
                searchRange = Enumerable.Range(spos + 1, TotalRows - (spos + 1));
            }

            int foundAt = searchRange.Where(i => VisibleData[i].IsSequence).FirstOrDefault(
                i => finder.Match(VisibleData[i].Header));

            if (foundAt == 0 && !finder.Match(VisibleData[0].Header))
            {
                IErrorVisualizer errorVisualizer = Resolve <IErrorVisualizer>();
                if (errorVisualizer != null)
                {
                    errorVisualizer.Show("No Match", "No matches were found.");
                }
            }
            else
            {
                FocusedRow = VisibleData[foundAt];
                TopRow     = foundAt;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This retrieves a list of databases for this connection
        /// </summary>
        /// <returns></returns>
        public List <string> GetDatabaseList(bool showError)
        {
            if (_dbNames.Count == 0 && IsValid)
            {
                DbProviderFactory dbFac = DbProviderFactories.GetFactory(Provider);
                using (DbConnection dbConn = dbFac.CreateConnection())
                {
                    dbConn.ConnectionString = BuildConnectionString();

                    DbCommand cmd = dbConn.CreateCommand();
                    cmd.CommandText = "sp_databases";
                    cmd.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        dbConn.Open();
                        using (var reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                _dbNames.Add(reader[0].ToString());
                            }
                        }
                    }
                    catch (DbException ex)
                    {
                        if (showError == true)
                        {
                            IErrorVisualizer errorVisualizer = ViewModel.ServiceProvider.Resolve <IErrorVisualizer>();
                            if (errorVisualizer != null)
                            {
                                errorVisualizer.Show("Error connecting to database", ex.Message);
                            }
                        }
                    }
                }
            }

            return(_dbNames);
        }
Ejemplo n.º 3
0
        public int Load()
        {
            string dbConnectionString = _dbConnection.Connection.BuildConnectionString();

            try
            {
                _dc = CreateDbContext(dbConnectionString);

                // Retrieve all the TAXIDs we want.  We essentially want all taxonomy IDs
                // which are parented by the selected id.  The easiest way to do this is with a
                // CTE using SQL2005+.  Unfortunately, LINQ doesn't support that so we drop to straight
                // T-SQL for this.
                const string sqlQuery = @"with cte as (select TaxID from Taxonomy where TaxID={0} " +
                                        @"union all select t.TaxID from Taxonomy t join cte tp on t.ParentTaxID = tp.TaxID) " +
                                        @"select * from cte";

                var results = _dc
                              .ExecuteQuery <Taxonomy>(sqlQuery, _dbConnection.ParentTaxId)
                              .Select(tax => tax.TaxID).ToList();

                // BUGBUG: if the # of sequences is > 2100 then we cannot generate the proper
                // query here since T-SQL doesn't support that many parameters.  So, here we'll group
                // it in batches of 2000.

                var queryGroups = results.Select((id, index) => new { GroupID = index / 2000, id }).GroupBy(x => x.GroupID);

                // Now, grab all the sequences from this group of TaxIds.
                // select distinct seqid from dbo.sequence where alnid = @alignment_id
                //KJD (10/21/2009) - Change query to use vAlignmentGridUngapped which takes into account column indirection supported by the rCAD schema
                //instead of querying the Sequence table directly
                var allSequences = new List <int>();
                foreach (var singleGroup in queryGroups)
                {
                    var thisGroup = singleGroup;
                    var query     = from seq in _dc.SequenceMains
                                    where thisGroup.Select(x => x.id).Contains(seq.TaxID) &&
                                    _dc.vAlignmentGridUngappeds.Where(s => ((s.SeqID == seq.SeqID) && (s.AlnID == _dbConnection.AlignmentId))).FirstOrDefault() != null &&
                                    seq.TaxID > 0 &&
                                    seq.SeqLength > 0 &&
                                    (_dbConnection.LocationId == 0 || seq.LocationID == _dbConnection.LocationId) &&
                                    (seq.SeqTypeID == _dbConnection.SequenceTypeId)
                                    select seq.SeqID;
                    allSequences.AddRange(query.Cast <int>());
                }

                // Now get the sequence headers based on the above collection
                queryGroups = allSequences.Distinct().Select((id, index) => new { GroupID = index / 1000, id }).GroupBy(x => x.GroupID);
                _entities   = new List <IAlignedBioEntity>();

                // 2 minute timeout
                _dc.CommandTimeout = 60 * 2 * 1000;

                // Now execute the queries
                //KJD (10/21/2009) - Change query to use vAlignmentGridUngapped which takes into account column indirection supported by the rCAD schema
                //instead of querying the Sequence table directly
                foreach (var singleGroup in queryGroups)
                {
                    var thisGroup = singleGroup;
                    var query     = from smd in _dc.SequenceMains
                                    from tax in _dc.TaxonomyNamesOrdereds
                                    let maxColumnNumber = _dc.vAlignmentGridUngappeds.Where(s => ((s.SeqID == smd.SeqID) && (s.AlnID == _dbConnection.AlignmentId))).Max(s => s.LogicalColumnNumber)
                                                          where thisGroup.Select(x => x.id).Contains(smd.SeqID) &&
                                                          tax.TaxID == smd.TaxID
                                                          select new DbAlignedBioEntity(_dc, dbConnectionString, smd.SeqID, _dbConnection.AlignmentId, maxColumnNumber)
                    {
                        ScientificName = tax.ScientificName,
                        TaxonomyId     = tax.LineageName,
                        Validator      = BioValidator.rRNAValidator
                    };

                    // Add the results to our list.
                    _entities.AddRange(query.Cast <IAlignedBioEntity>());
                }
                return(_entities.Count);
            }
            catch (Exception ex)
            {
                IErrorVisualizer errorVisualizer = ViewModel.ServiceProvider.Resolve <IErrorVisualizer>();
                if (errorVisualizer != null)
                {
                    errorVisualizer.Show("Encountered error loading data", ex.Message);
                }

                _dc.Dispose();
                _dc = null;
            }

            return(0);
        }