Ejemplo n.º 1
0
        static void GerarCidades()
        {
            Console.WriteLine("### GERAÇÃO JSON CITIES INICIADA - " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss") + " ### \n\n");
            Console.WriteLine(@" Os arquivos estarão no diretório C:\JsonGeneration\API\Cities");

            if (!Directory.Exists(@"C:\JsonGeneration\API\Cities"))
            {
                Directory.CreateDirectory(@"C:\JsonGeneration\API\Cities");
            }

            var cities = new List <OiWeb.Entity.City>();

            cities.AddRange(OiWeb.Business.City.GetCities());

            Console.WriteLine("{0} - Construindo arquivos...", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));

            Parallel.ForEach(cities, (city) =>
            {
                VMLtWebClient wc = new VMLtWebClient();
                wc.Encoding      = Encoding.UTF8;

                string json = wc.DownloadString("http://back2.tempsite.ws/API/City/" + city.idCity).Replace(@"\u0027", "'").Replace(@"\u0026", "&");

                TextWriter sw = new StreamWriter(@"C:\JsonGeneration\API\Cities\" + city.idCity + ".json");
                sw.Write(json);
                sw.Close();
            });

            Console.WriteLine("{0} - Geração de Cities concluída.", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));
        }
Ejemplo n.º 2
0
        private static void GerarCatalogo()
        {
            Console.WriteLine("### GERAÇÃO JSON CATALOGO ### \n\n");
            Console.WriteLine(@" Os arquivos estarão no diretório C:\JsonGeneration\API\Catalog");

            if (!Directory.Exists(@"C:\JsonGeneration\API\Catalog"))
            {
                Directory.CreateDirectory(@"C:\JsonGeneration\API\Catalog");
            }

            var prideGroups = new List <OiWeb.Entity.PriceGroup>();

            prideGroups.AddRange(OiWeb.Business.Groups.GetPriceGroups());

            Console.WriteLine("{0} - Construindo arquivos...", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));

            Parallel.ForEach(prideGroups, (prideGroup) =>
            {
                VMLtWebClient wc = new VMLtWebClient();
                wc.Encoding      = Encoding.UTF8;

                string json = wc.DownloadString("http://back2.tempsite.ws/API/Product/Catalog/" + prideGroup.idPriceGroup).Replace(@"\u0027", "'").Replace(@"\u0026", "&");

                if (!Directory.Exists(@"C:\JsonGeneration\API\Catalog\" + prideGroup.Product.name))
                {
                    Directory.CreateDirectory(@"C:\JsonGeneration\API\Catalog\" + prideGroup.Product.name);
                }

                if (!Directory.Exists(@"C:\JsonGeneration\API\Catalog\" + prideGroup.Product.name + "\\" + prideGroup.idPriceGroup))
                {
                    Directory.CreateDirectory(@"C:\JsonGeneration\API\Catalog\" + prideGroup.Product.name + "\\" + prideGroup.idPriceGroup);
                }

                TextWriter sw = new StreamWriter(@"C:\JsonGeneration\API\Catalog\" + prideGroup.Product.name + "\\" + prideGroup.idPriceGroup + "\\" + prideGroup.Product.name + ".json");
                sw.Write(json);
                sw.Close();
            });
            Console.WriteLine("{0} - Geração de Catalogo concluída.", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));
            _timer.Enabled = true;
        }