Example #1
0
        public static void Process()
        {
            try
            {
                string hackertxt  = "E:\\excel\\hack" + Guid.NewGuid().ToString() + ".txt";
                string projecttxt = "E:\\excel\\project" + Guid.NewGuid().ToString() + ".txt";

                //GetHackersFromApi();
                DateTime startTime = DateTime.Now;
                Console.WriteLine("Starting Conversion " + startTime);
                tempFileSheet1 = (Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())) + "data1";
                tempFileSheet2 = (Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())) + "data2";

                ExcelToCSVCoversion(@"E:\excel\Input\20180725.xlsx");

                CsvHelper.CsvReader csvReader = new CsvHelper.CsvReader(File.OpenText(tempFileSheet1 + ".csv"));
                csvReader.Read();
                csvReader.ReadHeader();
                List <Hacker> hackers = new List <Hacker>();

                while (csvReader.Read())
                {
                    var hack = new Hacker();
                    hack.alias          = csvReader.GetField("alias");
                    hack.Upn            = csvReader.GetField("email");
                    hack.city           = csvReader.GetField("hb_city");
                    hack.country        = csvReader.GetField("hb_country");
                    hack.name           = csvReader.GetField("PreferredFirstName");
                    hack.officeLocation = csvReader.GetField("Bldg").Replace("N/A", "");
                    hack.Registered_On  = csvReader.GetField <DateTime>("registration_date");
                    hackers.Add(hack);
                }

                csvReader = new CsvHelper.CsvReader(File.OpenText(tempFileSheet2 + ".csv"));
                csvReader.Read();
                csvReader.ReadHeader();
                List <Project> projects = new List <Project>();

                while (csvReader.Read())
                {
                    var hack = new Project();
                    hack.id             = csvReader.GetField <int>("id");
                    hack.hackathon_name = csvReader.GetField("hackathon_name");
                    hack.description    = csvReader.GetField("description");
                    hack.members        = csvReader.GetField("members");
                    hack.tagline        = csvReader.GetField("tagline");
                    hack.title          = csvReader.GetField("title");
                    hack.venue          = csvReader.GetField("venue");
                    projects.Add(hack);
                }

                Console.WriteLine("Conversion Completed " + (DateTime.Now - startTime));
                List <int> pids = new List <int>();
                pids.Add(70766);
                pids.Add(72814);
                pids.Add(72117);
                projects = projects.Where(cc => pids.Contains(cc.id)).ToList();

                //Task addorUpdateusers = Task.Factory.StartNew(() => { AddOrUpdateProject(projects); }); //AddOrUpdateProject(projects);
                //Task addorregisteredusers = Task.Factory.StartNew(() => { AddRegisteredUsers(hacker); }); //AddRegisteredUsers(hacker);

                File.WriteAllText(hackertxt, Newtonsoft.Json.JsonConvert.SerializeObject(hackers));
                File.WriteAllText(projecttxt, Newtonsoft.Json.JsonConvert.SerializeObject(projects));

                UserRegistration.AddRegisteredUsers(hackers);
                ProjectRegistration.AddOrUpdateProject(projects);

                //Task.WaitAll(addorUpdateusers, addorregisteredusers);

                Console.WriteLine("Entire Process Completed " + (DateTime.Now - startTime));

                Console.WriteLine("Start time " + DateTime.Now);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }