/// <summary>
        ///   Loads the collection's values from file.
        /// </summary>
        void Load()
        {
            Clear();

            if (!File.Exists(_dataFile))
            {
                return;
            }

            try
            {
                var reader       = XmlValueReader.CreateFromFile(_dataFile, _rootNodeName);
                var loadedHashes = reader.ReadManyNodes(_rootNodeName, Read);

                foreach (var hash in loadedHashes)
                {
                    this[hash.Key] = hash.Value;
                }
            }
            catch (Exception ex)
            {
                Clear();

                const string errmsg = "Failed to load TextureHashCollection from file `{0}`.";
                if (log.IsErrorEnabled)
                {
                    log.Error(string.Format(errmsg, _dataFile), ex);
                }
                Debug.Fail(string.Format(errmsg, _dataFile));
            }
        }
        /// <summary>
        /// Loads the quest descriptions from file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
        void Load(ContentPaths contentPath)
        {
            var filePath = GetFilePath(contentPath);
            var reader   = XmlValueReader.CreateFromFile(filePath, _rootFileNodeName);

            ReadState(reader);
        }
Example #3
0
        /// <summary>
        /// Reads a <see cref="ActionDisplayCollection"/> from file. If the file at the given <paramref name="path"/> does not
        /// exist, then an empty <see cref="ActionDisplayCollection"/> will be used.
        /// </summary>
        /// <param name="path">The path of the file to read from.</param>
        /// <returns>The loaded <see cref="ActionDisplayCollection"/>.</returns>
        public static ActionDisplayCollection Read(string path)
        {
            if (!File.Exists(path))
            {
                return(new ActionDisplayCollection());
            }

            var reader = XmlValueReader.CreateFromFile(path, _fileRootName);

            return(new ActionDisplayCollection(reader));
        }
Example #4
0
        public void CreateXmlReaderInsideNodeTest()
        {
            // Create the reader at the MyInt node (first value node)
            var xmlReader = GetTestXmlValueReaderReader();

            MoveXmlReaderToNode(xmlReader, "MyInt");

            var r = XmlValueReader.Create(xmlReader, "Values");

            TestXmlValueReader(r);
        }
Example #5
0
        public void CreateXmlReaderAtNodeTest()
        {
            // Create the reader at the Values node
            var xmlReader = GetTestXmlValueReaderReader();

            MoveXmlReaderToNode(xmlReader, "Values");

            var r = XmlValueReader.Create(xmlReader, "Values");

            TestXmlValueReader(r);
        }
Example #6
0
        public void RunTest(string expected)
        {
            var stringReader = new StringReader(expected);
            var reader       = XmlReader.Create(stringReader);

            reader.Read();
            reader.Read();
            var valueReader = new XmlValueReader(reader);
            var content     = valueReader.ReadToEnd();
            var actual      = "<value>" + content + "</value>";

            Assert.AreEqual(expected, actual.Replace("\n", "\r\n"));
        }
Example #7
0
        /// <summary>
        /// Loads a <see cref="List{T}"/> containing the <see cref="CacheItemInfo"/> values in the cache file.
        /// </summary>
        /// <returns>The <see cref="List{T}"/> containing the <see cref="CacheItemInfo"/> values in the cache file.</returns>
        protected virtual IEnumerable <CacheItemInfo> Load()
        {
            var ret = new List <CacheItemInfo>();

            // Make sure the cache file exists
            if (!File.Exists(CacheFile))
            {
                return(ret);
            }

            // Load the items
            var r           = XmlValueReader.CreateFromFile(CacheFile, _rootNodeName);
            var loadedItems = r.ReadManyNodes("Item", x => new CacheItemInfo(x));

            ret.AddRange(loadedItems);

            return(ret);
        }
Example #8
0
        public void Load(ContentPaths contentPath, CreateWallEntityFromReaderHandler createWall)
        {
            var filePath = GetFilePath(contentPath);

            // Clear the old walls in case this isn't the first load
            _walls.Clear();

            if (!File.Exists(filePath))
            {
                return;
            }

            // Read the values
            var reader      = XmlValueReader.CreateFromFile(filePath, _rootNodeName);
            var loadedWalls = reader.ReadManyNodes(_rootNodeName, x => ReadWalls(x, createWall));

            foreach (var wall in loadedWalls)
            {
                _walls[(int)wall.Key] = wall.Value;
            }
        }
        public override System.Collections.Generic.IEnumerable<List<Product>> ReadFromDir(string dir)
        {
            if (!Directory.Exists(dir))
            {
                Console.WriteLine("Directory not found: " + dir);
                yield break;
            }

            Console.WriteLine("Started reading from: " + dir);

            List<Product> products = new List<Product>();
            string[] filePaths = Util.ConcatArrays(Directory.GetFiles(dir, "*.xml"), Directory.GetFiles(dir, "*.csv"));

            // Initialize XmlValueReader and its keys
            XmlValueReader xvr = new XmlValueReader();
            xvr.ProductEnd = "product";
            xvr.AddKeys("sku", XmlNodeType.Element);
            xvr.AddKeys("advertisercategory", XmlNodeType.Element);
            xvr.AddKeys("name", XmlNodeType.Element);
            xvr.AddKeys("manufacturer", XmlNodeType.Element);
            xvr.AddKeys("saleprice", XmlNodeType.Element);
            xvr.AddKeys("currency", XmlNodeType.Element);
            xvr.AddKeys("buyurl", XmlNodeType.Element);
            xvr.AddKeys("imageurl", XmlNodeType.Element);
            xvr.AddKeys("description", XmlNodeType.Element);
            xvr.AddKeys("lastupdated", XmlNodeType.Element);
            xvr.AddKeys("instock", XmlNodeType.Element);

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = DtdProcessing.Ignore;
            Product p = new Product();

            foreach (string file in filePaths)
            {
                string fileUrl = Path.GetFileNameWithoutExtension(file).Split(null)[0].Replace('$', '/');
                xvr.CreateReader(file, settings);
                foreach (DualKeyDictionary<string, XmlNodeType, string> dkd in xvr.ReadProducts())
                {
                    p.SKU = dkd["sku"][XmlNodeType.Element];
                    p.Title = dkd["name"][XmlNodeType.Element];
                    p.Brand = dkd["manufacturer"][XmlNodeType.Element];
                    p.Price = dkd["saleprice"][XmlNodeType.Element];
                    p.Currency = dkd["currency"][XmlNodeType.Element];
                    p.Category = dkd["advertisercategory"][XmlNodeType.Element];
                    p.Url = dkd["buyurl"][XmlNodeType.Element];
                    p.Image_Loc = dkd["imageurl"][XmlNodeType.Element];
                    p.Description = dkd["description"][XmlNodeType.Element];
                    p.LastModified = dkd["lastupdated"][XmlNodeType.Element];
                    p.Stock = dkd["instock"][XmlNodeType.Element];
                    p.Affiliate = "CommissionJunction";
                    p.FileName = file;
                    p.Webshop = fileUrl;

                    // Hash the title and the webshop into a unique ID, because CommissionJunctionReader didn't provide any
                    p.AffiliateProdID = (p.Title + p.Webshop).ToSHA256();

                    products.Add(p);
                    p = new Product();

                    if (products.Count > PackageSize)
                    {
                        yield return products;
                        products.Clear();
                    }
                }
                yield return products;
                products.Clear();
            }
        }
        public override IEnumerable<List<Product>> ReadFromFile(string file)
        {
            // Initialize XmlValueReader and its keys
            using (XmlValueReader xvr = new XmlValueReader())
            {
                List<Product> products = new List<Product>();
                string fileUrl = Path.GetFileNameWithoutExtension(file).Split(null)[0].Replace('$', '/');

                xvr.ProductEnd = "product";
                xvr.AddKeys("sku", XmlNodeType.Element);
                xvr.AddKeys("advertisercategory", XmlNodeType.Element);
                xvr.AddKeys("name", XmlNodeType.Element);
                xvr.AddKeys("manufacturer", XmlNodeType.Element);
                xvr.AddKeys("saleprice", XmlNodeType.Element);
                xvr.AddKeys("currency", XmlNodeType.Element);
                xvr.AddKeys("buyurl", XmlNodeType.Element);
                xvr.AddKeys("imageurl", XmlNodeType.Element);
                xvr.AddKeys("description", XmlNodeType.Element);
                xvr.AddKeys("lastupdated", XmlNodeType.Element);
                xvr.AddKeys("instock", XmlNodeType.Element);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Ignore;
                settings.CloseInput = true;
                Product p = new Product();

                xvr.CreateReader(file, settings);
                foreach (DualKeyDictionary<string, XmlNodeType, string> dkd in xvr.ReadProducts())
                {
                    p.SKU = dkd["sku"][XmlNodeType.Element];
                    p.Title = dkd["name"][XmlNodeType.Element];
                    p.Brand = dkd["manufacturer"][XmlNodeType.Element];
                    p.Price = dkd["saleprice"][XmlNodeType.Element];
                    p.Currency = dkd["currency"][XmlNodeType.Element];
                    p.Category = dkd["advertisercategory"][XmlNodeType.Element];
                    p.Url = dkd["buyurl"][XmlNodeType.Element];
                    p.Image_Loc = dkd["imageurl"][XmlNodeType.Element];
                    p.Description = dkd["description"][XmlNodeType.Element];
                    p.LastModified = dkd["lastupdated"][XmlNodeType.Element];
                    p.Stock = dkd["instock"][XmlNodeType.Element];
                    p.Affiliate = "CommissionJunction";
                    p.FileName = file;
                    p.Webshop = fileUrl;

                    // Hash the title and the webshop into a unique ID, because CommissionJunctionReader didn't provide any
                    p.AffiliateProdID = (p.Title + p.Webshop).ToSHA256();

                    products.Add(p);
                    p = new Product();

                    if (products.Count >= PackageSize)
                    {
                        yield return products;
                        products.Clear();
                    }
                }
                yield return products;
            }
        }
Example #11
0
        public override System.Collections.Generic.IEnumerable<List<Product>> ReadFromDir(string dir)
        {
            if (!Directory.Exists(dir))
            {
                Console.WriteLine("Directory not found: " + dir);
                yield break;
            }

            Console.WriteLine("Started reading from: " + dir);

            List<Product> products = new List<Product>();
            string[] filePaths = Util.ConcatArrays(Directory.GetFiles(dir, "*.xml"), Directory.GetFiles(dir, "*.csv"));

            // Initialize XmlValueReader and its keys
            XmlValueReader xvr = new XmlValueReader();
            xvr.ProductEnd = "product";
            xvr.AddKeys("european_article_number", XmlNodeType.Element);
            xvr.AddKeys("product_name", XmlNodeType.Element);
            xvr.AddKeys("brand", XmlNodeType.Element);
            xvr.AddKeys("price", XmlNodeType.Element);
            xvr.AddKeys("currency", XmlNodeType.Element);
            xvr.AddKeys("deeplink", XmlNodeType.Element);
            xvr.AddKeys("image_url", XmlNodeType.Element);
            xvr.AddKeys("category", XmlNodeType.Element);
            xvr.AddKeys("description", XmlNodeType.Element);
            xvr.AddKeys("delivery_cost", XmlNodeType.Element);
            xvr.AddKeys("product_id", XmlNodeType.Element);
            xvr.AddKeys("delivery_period", XmlNodeType.Element);
            xvr.AddKeys("program_id", XmlNodeType.Element);
            xvr.AddKeys("validuntil", XmlNodeType.Element);
            xvr.AddKeys("last_updated", XmlNodeType.Element);

            Product p = new Product();

            foreach (string file in filePaths)
            {
                string fileUrl = Path.GetFileNameWithoutExtension(file).Split(null)[0].Replace('$', '/');

                xvr.CreateReader(file);
                foreach (DualKeyDictionary<string, XmlNodeType, string> dkd in xvr.ReadProducts())
                {
                    // Fill the product with fields
                    p.EAN = dkd["european_article_number"][XmlNodeType.Element];
                    p.Title = dkd["product_name"][XmlNodeType.Element];
                    p.Brand = dkd["brand"][XmlNodeType.Element];
                    p.Price = dkd["price"][XmlNodeType.Element];
                    p.Url = dkd["deeplink"][XmlNodeType.Element];
                    p.Image_Loc = dkd["image_url"][XmlNodeType.Element];
                    p.Category = dkd["category"][XmlNodeType.Element];
                    p.Description = dkd["description"][XmlNodeType.Element];
                    p.DeliveryCost = dkd["delivery_cost"][XmlNodeType.Element];
                    p.DeliveryTime = dkd["delivery_period"][XmlNodeType.Element];
                    p.AffiliateProdID = dkd["product_id"][XmlNodeType.Element] + dkd["program_id"][XmlNodeType.Element];
                    p.Currency = dkd["currency"][XmlNodeType.Element];
                    p.Affiliate = "Webgains";
                    p.FileName = file;
                    p.Webshop = fileUrl;
                    products.Add(p);
                    p = new Product();

                    if (products.Count > PackageSize)
                    {
                        yield return products;
                        products.Clear();
                    }
                }
                yield return products;
                products.Clear();
            }
        }
Example #12
0
        public override IEnumerable<List<Product>> ReadFromFile(string file)
        {
            // Initialize XmlValueReader and its keys
            using (XmlValueReader xvr = new XmlValueReader())
            {
                List<Product> products = new List<Product>();
                string fileUrl = Path.GetFileNameWithoutExtension(file).Split(null)[0].Replace('$', '/');
                xvr.ProductEnd = "product";
                xvr.AddKeys("european_article_number", XmlNodeType.Element);
                xvr.AddKeys("product_name", XmlNodeType.Element);
                xvr.AddKeys("brand", XmlNodeType.Element);
                xvr.AddKeys("price", XmlNodeType.Element);
                xvr.AddKeys("currency", XmlNodeType.Element);
                xvr.AddKeys("deeplink", XmlNodeType.Element);
                xvr.AddKeys("image_url", XmlNodeType.Element);
                xvr.AddKeys("category", XmlNodeType.Element);
                xvr.AddKeys("description", XmlNodeType.Element);
                xvr.AddKeys("delivery_cost", XmlNodeType.Element);
                xvr.AddKeys("product_id", XmlNodeType.Element);
                xvr.AddKeys("delivery_period", XmlNodeType.Element);
                xvr.AddKeys("program_id", XmlNodeType.Element);
                xvr.AddKeys("validuntil", XmlNodeType.Element);
                xvr.AddKeys("last_updated", XmlNodeType.Element);

                Product p = new Product();

                xvr.CreateReader(file, new XmlReaderSettings { CloseInput = true });
                foreach (DualKeyDictionary<string, XmlNodeType, string> dkd in xvr.ReadProducts())
                {
                    // Fill the product with fields
                    p.EAN = dkd["european_article_number"][XmlNodeType.Element];
                    p.Title = dkd["product_name"][XmlNodeType.Element];
                    p.Brand = dkd["brand"][XmlNodeType.Element];
                    p.Price = dkd["price"][XmlNodeType.Element];
                    p.Url = dkd["deeplink"][XmlNodeType.Element];
                    p.Image_Loc = dkd["image_url"][XmlNodeType.Element];
                    p.Category = dkd["category"][XmlNodeType.Element];
                    p.Description = dkd["description"][XmlNodeType.Element];
                    p.DeliveryCost = dkd["delivery_cost"][XmlNodeType.Element];
                    p.DeliveryTime = dkd["delivery_period"][XmlNodeType.Element];
                    p.AffiliateProdID = dkd["product_id"][XmlNodeType.Element] + dkd["program_id"][XmlNodeType.Element];
                    p.Currency = dkd["currency"][XmlNodeType.Element];
                    p.Affiliate = "Webgains";
                    p.FileName = file;
                    p.Webshop = fileUrl;
                    products.Add(p);
                    p = new Product();

                    if (products.Count >= PackageSize)
                    {
                        yield return products;
                        products.Clear();
                    }
                }
                yield return products;
            }
        }
Example #13
0
        /// <summary>
        /// Loads the <see cref="BodyInfoManager"/> from the specified file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns>
        /// The loaded <see cref="BodyInfoManager"/>.
        /// </returns>
        static BodyInfoManager Load(string filePath)
        {
            var reader = XmlValueReader.CreateFromFile(filePath, _rootNodeName);

            return(new BodyInfoManager(reader));
        }
Example #14
0
        public override IEnumerable<List<Product>> ReadFromFile(string file)
        {
            //  Initialize XmlValueReader and its keys
            using (XmlValueReader xvr = new XmlValueReader())
            {
                List<Product> products = new List<Product>();
                string fileUrl = Path.GetFileNameWithoutExtension(file).Split(null)[0].Replace('$', '/');
                xvr.ProductEnd = "product";
                xvr.AddKeys("ean", XmlNodeType.Element);
                xvr.AddKeys("sku", XmlNodeType.Element);
                xvr.AddKeys("name", XmlNodeType.Element);
                xvr.AddKeys("brand", XmlNodeType.Element);
                xvr.AddKeys("price", XmlNodeType.Element);
                xvr.AddKeys("currency", XmlNodeType.Element);
                xvr.AddKeys("productUrl", XmlNodeType.Element);
                xvr.AddKeys("imageUrl", XmlNodeType.Element);
                xvr.AddKeys("TDCategoryName", XmlNodeType.Element);
                xvr.AddKeys("description", XmlNodeType.Element);
                xvr.AddKeys("shippingCost", XmlNodeType.Element);
                xvr.AddKeys("inStock", XmlNodeType.Element);
                xvr.AddKeys("deliveryTime", XmlNodeType.Element);
                xvr.AddKeys("TDProductId", XmlNodeType.Element);

                Product p = new Product();

                xvr.CreateReader(file, new XmlReaderSettings { CloseInput = true });
                foreach (DualKeyDictionary<string, XmlNodeType, string> dkd in xvr.ReadProducts())
                {
                    //  Fill the product with fields
                    p.EAN = dkd["ean"][XmlNodeType.Element];
                    p.SKU = dkd["sku"][XmlNodeType.Element];
                    p.Title = dkd["name"][XmlNodeType.Element];
                    p.Brand = dkd["brand"][XmlNodeType.Element];
                    p.Price = dkd["price"][XmlNodeType.Element];
                    p.Url = dkd["productUrl"][XmlNodeType.Element];
                    p.Image_Loc = dkd["imageUrl"][XmlNodeType.Element];
                    p.Category = dkd["TDCategoryName"][XmlNodeType.Element];
                    p.Description = dkd["description"][XmlNodeType.Element];
                    p.DeliveryCost = dkd["shippingCost"][XmlNodeType.Element];
                    p.DeliveryTime = dkd["deliveryTime"][XmlNodeType.Element];
                    p.Stock = dkd["inStock"][XmlNodeType.Element];
                    p.AffiliateProdID = dkd["TDProductId"][XmlNodeType.Element];
                    p.Currency = dkd["currency"][XmlNodeType.Element];
                    p.Affiliate = "TradeDoubler";
                    p.FileName = file;
                    p.Webshop = fileUrl;
                    products.Add(p);
                    p = new Product();

                    if (products.Count >= PackageSize)
                    {
                        yield return products;
                        products.Clear();
                    }
                }
                yield return products;
            }
        }
 /// <summary>
 /// When overridden in the derived class, gets the IValueReader instance used to read the values
 /// written by the IValueWriter created with GetWriter().
 /// </summary>
 /// <returns>The IValueWriter instance.</returns>
 public override IValueReader GetReader()
 {
     return(XmlValueReader.CreateFromFile(_filePath, _rootNodeName));
 }
Example #16
0
        public void TestWriteReadManyValuesExtensiveXml()
        {
            const int count = 100;

            var filePath = Path.GetTempFileName();

            try
            {
                var sources = new List <DE>(count);
                using (var writer = XmlValueWriter.Create(filePath, "DynamicEntities"))
                {
                    writer.Write("Count", count);
                    for (var i = 0; i < count; i++)
                    {
                        var src = new DE();
                        sources.Add(src);
                        var key = "Entity" + Parser.Invariant.ToString(i);
                        writer.WriteStartNode(key);
                        _dynamicEntityFactoryBase.Write(writer, src);
                        writer.WriteEndNode(key);
                    }
                }

                var reader = XmlValueReader.CreateFromFile(filePath, "DynamicEntities");
                for (var i = 0; i < count; i++)
                {
                    var key = "Entity" + Parser.Invariant.ToString(i);
                    var r   = reader.ReadNode(key);

                    var src  = sources[i];
                    var dest = (DE)_dynamicEntityFactoryBase.Read(r);

                    Assert.AreEqual(src.Position, dest.Position);
                    Assert.AreEqual(src.Size, dest.Size);
                    Assert.AreEqual(src.Velocity, dest.Velocity);
                    Assert.AreEqual(src.Weight, dest.Weight);
                    Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
                    Assert.AreEqual(src.Center, dest.Center);

                    Assert.AreEqual(src.A, dest.A, "Index: " + i);
                    Assert.AreEqual(src.B, dest.B, "Index: " + i);
                    Assert.AreEqual(src.C, dest.C, "Index: " + i);
                    Assert.AreEqual(src.D, dest.D, "Index: " + i);
                    Assert.AreEqual(src.E, dest.E, "Index: " + i);
                    Assert.AreEqual(src.F, dest.F, "Index: " + i);
                    Assert.AreEqual(src.G, dest.G, "Index: " + i);
                    Assert.AreEqual(Math.Round(src.H), Math.Round(dest.H), "Index: " + i);
                    Assert.AreEqual(src.I, dest.I, "Index: " + i);
                    Assert.AreEqual(src.J, dest.J, "Index: " + i);
                    Assert.AreEqual(Math.Round(src.K), Math.Round(dest.K), "Index: " + i);
                    Assert.AreEqual(src.L.Round(), dest.L.Round(), "Index: " + i);
                    Assert.AreEqual(src.M, dest.M, "Index: " + i);
                    Assert.AreEqual(src.N, dest.N, "Index: " + i);
                    Assert.AreEqual(src.O, dest.O, "Index: " + i);
                    Assert.AreEqual(src.P, dest.P, "Index: " + i);
                    Assert.AreEqual(src.Q.Round(), dest.Q.Round(), "Index: " + i);
                    Assert.AreEqual(src.R.Round(), dest.R.Round(), "Index: " + i);
                }
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }