예제 #1
0
        public void ReadFile(string filename)
        {
#if DEBUG
            Console.WriteLine("Reading LCBO inventory update");
#endif
            if (_storeProductPair == null)
            {
                _storeProductPair = new Dictionary <int, Dictionary <int, ProductEntry> >();
            }
            if (_products == null || _products.Count < 1)
            {
                throw new InvalidDataException(
                          "No products were specified to be searched for, did you forget to call ReadProducts?");
            }
            using (TextReader textReader = new StreamReader(filename, false))
            {
                string line;
                while ((line = textReader.ReadLine()) != null)
                {
                    int pID;
                    if (!int.TryParse(line.Substring(8, 7), out pID))
                    {
                        throw new InvalidDataException(string.Format("Unable to parse Product ID '{0}'",
                                                                     line.Substring(8, 7)));
                    }

                    //Console.WriteLine(line.Substring(0, 8));
                    //Console.WriteLine(line.Substring(8, 7));

                    if (!_products.ContainsKey(pID))
                    {
                        continue;
                    }

                    //if (!_products.Contains()) continue;

                    ProductEntry pEnt = new ProductEntry();
                    pEnt.SetInfoFromRaw(line);

                    if (!_storeProductPair.ContainsKey(pEnt.StoreID))
                    {
                        _storeProductPair.Add(pEnt.StoreID, new Dictionary <int, ProductEntry>());
                    }
                    _storeProductPair[pEnt.StoreID].Add(pEnt.ProductID, pEnt);
                }
            }
#if DEBUG
            int i = 0;
            foreach (var spp in _storeProductPair)
            {
                if (spp.Value.Count > i)
                {
                    i = spp.Value.Count;
                }
            }
            Console.WriteLine("Found {0} products in {1} store{2}", i, _storeProductPair.Count, _storeProductPair.Count != 1 ? "s": "");
#endif
        }
예제 #2
0
        public void ReadFile(string filename)
        {
            #if DEBUG
            Console.WriteLine("Reading LCBO inventory update");
            #endif
            if (_storeProductPair == null)
            {
                _storeProductPair = new Dictionary<int, Dictionary<int, ProductEntry>>();
            }
            if (_products == null || _products.Count < 1)
            {
                throw new InvalidDataException(
                    "No products were specified to be searched for, did you forget to call ReadProducts?");
            }
            using (TextReader textReader = new StreamReader(filename, false))
            {
                string line;
                while ((line = textReader.ReadLine()) != null)
                {
                    int pID;
                    if (!int.TryParse(line.Substring(8, 7), out pID))
                    {
                        throw new InvalidDataException(string.Format("Unable to parse Product ID '{0}'",
                                                                     line.Substring(8, 7)));
                    }

                    //Console.WriteLine(line.Substring(0, 8));
                    //Console.WriteLine(line.Substring(8, 7));

                    if (!_products.ContainsKey(pID)) continue;

                    //if (!_products.Contains()) continue;

                    ProductEntry pEnt = new ProductEntry();
                    pEnt.SetInfoFromRaw(line);

                    if (!_storeProductPair.ContainsKey(pEnt.StoreID))
                    {
                        _storeProductPair.Add(pEnt.StoreID, new Dictionary<int, ProductEntry>());
                    }
                    _storeProductPair[pEnt.StoreID].Add(pEnt.ProductID, pEnt);
                }
            }
            #if DEBUG
            int i = 0;
            foreach (var spp in _storeProductPair)
            {
                if (spp.Value.Count > i)
                {
                    i = spp.Value.Count;
                }
            }
            Console.WriteLine("Found {0} products in {1} store{2}", i, _storeProductPair.Count, _storeProductPair.Count != 1 ? "s": "");
            #endif
        }