Пример #1
0
        ////////////////
        // Validation //
        ////////////////
        public static bool IsValid(RawProduct p)
        {
            if (p.Name == null || String.IsNullOrEmpty(p.Name.Trim()))
            {
                return(false);
            }

            if (p.Image == null || String.IsNullOrEmpty(p.Image.Trim()))
            {
                return(false);
            }

            if (p.Url == null || String.IsNullOrEmpty(p.Url.Trim()))
            {
                return(false);
            }

            if (p.Price == null || String.IsNullOrEmpty(p.Price.Trim()))
            {
                return(false);
            }

            if (p.Store == null || String.IsNullOrEmpty(p.Store.Trim()))
            {
                return(false);
            }

            if (p.StoreId == null || p.StoreId == Guid.Empty)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public override void ParseFile(string filename)
        {
            Console.Write("Found " + _name + " Catalog: " + filename + "...");

            using (XmlSanitizingStream clean = new XmlSanitizingStream(File.OpenRead(filename)))
            {
                using (XmlReader reader = XmlReader.Create(clean, new XmlReaderSettings {
                    DtdProcessing = DtdProcessing.Ignore
                }))
                {
                    Parallel.ForEach(reader.Products(), node =>
                    {
                        RawProduct p = Parse(node);
                        AddProduct(p);
                    });

                    Console.WriteLine("done.");
                }
            }

            try
            {
                File.Move(filename, filename.Replace(".xml", ".done"));
            }
            catch { }
        }
Пример #3
0
        public override void ParseFile(string filename)
        {
            Console.Write("Found " + _name + " Catalog: " + filename + "...");

            using (CsvReader csv = new CsvReader(new StreamReader(filename), true, ',')
            {
                MissingFieldAction = MissingFieldAction.ReplaceByNull, SkipEmptyLines = true
            })
            {
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();

                while (csv.ReadNextRecord())
                {
                    RawProduct p = Parse(csv);
                    AddProduct(p);
                }

                Console.WriteLine("done.");
            }

            try
            {
                File.Move(filename, filename.Replace(_format, _doneFormat));
            }
            catch { }
        }
Пример #4
0
        protected internal bool AddProduct(RawProduct p)
        {
            try
            {
                dynamic json = JsonConvert.SerializeObject(p);

                Redis.PushJSON(json);

                return(true);
            }
            catch { return(false); }
        }