public SimpleSearchItem[][][] SimpleSearchCache()
        {
            SimpleSearchItem[][][] r = new SimpleSearchItem[6][][];

            List <int> populatedCountries;

            this.GetPopulatedCountries(out populatedCountries);

            for (int i = 0; i < GENDERTABLESCOUNT; i++)
            {
                //SearchItem[][][] x = new SearchItem[i][][];

                for (int j = 1; j <= MaxCountryId; j++)
                {
                    if (populatedCountries.Contains(j))
                    {
                        r[i][j] = UsersByLastAction((GenderTable)i, j);
                    }
                }
            }
            return(r);
        }
예제 #2
0
        public static int[] results(int agemin, int agemax, int relationship, int sign, int ethnicity, int eyes, int page, out string speed)
        {
            HiPerfTimer t           = new HiPerfTimer();
            int         startRecord = ((page - 1) * 15);
            int         stopRecord  = 15;


            IEnumerable <int> x = null;

            int[] xx = new int[16];

            SimpleSearchItem[][][] elementi;

            if (HttpContext.Current.Cache["SearchItems"] == null)
            {
                elementi = (SimpleSearchItem[][][])HttpContext.Current.Cache["SearchItemsBackup"];
            }
            else
            {
                elementi = (SimpleSearchItem[][][])HttpContext.Current.Cache["SearchItems"];
            }

            t.Start();


            //lock (thisLock)
            //{
            //xx = ((from a in elementi where a.age > agemin && a.age < agemax & a.relationship.Contains(relationship) && (sign == 0 || a.sign == sign) && a.ethnicity == ethnicity && (eyes == 0 || a.eyes == eyes) select a.userId).Skip(startRecord).Take(stopRecord)).ToArray();

            int foundrecords = 0;
            int counter      = 0;
            int z            = elementi.Count();
            int ss           = startRecord + stopRecord;

            for (int i = 0; i < z; i++)
            {
                SimpleSearchItem s = elementi[0][1][i];
                if (s.age > agemin && s.age < agemax)
                {
                    if (s.relationship.Contains(relationship) && (sign == 0 || s.sign == sign) && s.ethnicity == ethnicity)
                    {
                        if (foundrecords >= startRecord)
                        {
                            xx[counter] = s.userId;
                            counter     = counter + 1;
                        }
                        foundrecords = foundrecords + 1;

                        if (foundrecords > ss)
                        {
                            break;
                        }
                    }
                }
            }
            //}
            t.Stop();


            speed = ((t.Duration) * 1000000).ToString();

            return(xx);
        }
        private SimpleSearchItem[] UsersByLastAction(GenderTable x, int countryId)
        {
            string sql = "dbo.Users_GetByLastAction";
            List <SimpleSearchItem> tempResults = new List <SimpleSearchItem>();

            SqlConnection cnn = new SqlConnection(ConnectionStrings.sqlSearch);
            SqlCommand    cmd = new SqlCommand(sql, cnn);

            cmd.Parameters.AddWithValue("@GenderTable", Convert.ToInt32(x)).SqlDbType       = SqlDbType.Int;
            cmd.Parameters.AddWithValue("@Country_ID", Convert.ToByte(countryId)).SqlDbType = SqlDbType.TinyInt;
            SqlDataReader rdr = null;

            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                cnn.Open();
                rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        SimpleSearchItem it = new SimpleSearchItem();
                        it.relationship = new List <int>();

                        it.userId = rdr.GetInt32(0);
                        it.age    = Convert.ToInt32(rdr.GetValue(2));
                        it.relationship.Add(rdr.GetInt16(6));
                        it.sign      = Convert.ToInt32(rdr.GetByte(5));
                        it.ethnicity = Convert.ToInt32(rdr.GetInt16(3));
                        //it.eyes = Convert.ToInt32(rdr.GetInt16(6));

                        tempResults.Add(it);
                    }
                }
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message, e.InnerException);
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (!(rdr == null))
                {
                    rdr.Close();
                    rdr.Dispose();
                }
                cnn.Close();
                cmd.Dispose();
            }

            SimpleSearchItem[] r = new SimpleSearchItem[tempResults.Count];
            r = tempResults.ToArray();

            return(r);
        }