public bool MoveNext()
        {
            if (i >= MAXRESULTS)
            {
                return(false);
            }

            int pos = current.IndexPos;

            do
            {
                pos = database.NextRecordPos(pos);

                //if (pos < 0) { i = MAXRESULTS; return false; }

                int minnext = int.MaxValue;
                for (int cnt = 0; cnt < terms.Length; cnt++)
                {
                    // find the first record that contains at least one of the terms
                    if (termpos[cnt] >= 0 && termpos[cnt] < pos)
                    {
                        termpos[cnt] = database.NextHit(pos, terms[cnt]);
                    }
                    if (termpos[cnt] > 0)
                    {
                        if (termpos[cnt] < minnext)
                        {
                            minnext = termpos[cnt];
                        }
                    }
                }

                if (minnext == int.MaxValue)
                {
                    i = MAXRESULTS; return(false);
                }
                pos = minnext;

                current = database.RecordFromPos(pos);

                bool isPremiumMatch = (includePremium || current.Meal != "P");
                if (isPremiumMatch && searchWorker.IsMatch(current.Name))
                {
                    i++;
                    return(true);
                }
            } while (pos > 0);

            i = MAXRESULTS;
            return(false);
        }
Exemplo n.º 2
0
        public FoodItem ItemFromResourceRecord(ResourceRecord2 record)
        {
            if (record.IndexPos <= 0)
            {
                return(null);
            }
            if (record.DataPos <= 0)
            {
                return(null);
            }

            int endofrecord = Data.IndexOf(RECORDDELIMIT, record.DataPos);

            if (endofrecord <= 0)
            {
                return(null);
            }
            string row = data.Substring(record.DataPos, endofrecord - record.DataPos - 1);

            FoodItem result = new FoodItem(record.Name, false);

            //result.TextDB = record.Name;
            result.DescriptionDB = null;
            result.Culture       = record.DBCulture;
            result.CommonMeal    = record.Meal;

            var values = row.Split(FIELDDELIMIT);

            //Row	ID	AllWeights	AllProperties

            if (Ints.ParseStorage(values[0]) != record.Row)
            {
                throw new ArgumentOutOfRangeException("pos");
            }
            result.SourceID = values[1];
            //result.ServingSizesData = values[2];
            string ss = values[2];
            string pp = values[3];

            result.NutritionDB    = pp;
            result.ServingSizesDB = ss.Replace(",", ".");

            return(result);
        }
 public ResourceSearchResult2VM(ResourceRecord2 record) : base(record.Name)
 {
     this.record = record;
 }
Exemplo n.º 4
0
 public static FoodItem FoodItemFromResourceRecord(ResourceRecord2 record)
 {
     return(FromCulture(record.DBCulture).ItemFromResourceRecord(record));
 }