Inheritance: System.Data.Linq.DataContext
Example #1
0
        void Run()
        {
            ChatterService.IChatterService service = new ChatterService.ChatterService(_url);
            service.AllowUntrustedConnection();
            service.Login(_username, _password, _token);

            ProfilesDataContext dc = new ProfilesDataContext();

            List<user> rs =(from p in dc.GetTable<user>() where (p.InternalUserName != null && p.PersonID != null) select p).ToList<user>();

            StreamWriter errors = new StreamWriter("errors.csv", false);
            errors.WriteLine("Name, Person Id, Employee Id, Error");

            StreamWriter processed = new StreamWriter("processed.csv", false);
            processed.WriteLine("Name, Person Id, Employee Id");

            int count = 0;
            try
            {
                foreach (user u in rs)
                {
                    try
                    {
                        service.CreateResearchProfile(u.InternalUserName);
                        processed.WriteLine(u.FirstName + " " + u.LastName + "," + u.PersonID + "," + u.InternalUserName);
                    }
                    catch (Exception ex)
                    {
                        errors.WriteLine(u.FirstName + " " + u.LastName + "," + u.PersonID + "," + u.InternalUserName + ",\"" + ex.Message + "\"");
                    }
                    count++;
                    if (count % 100 == 0)
                    {
                        Console.Out.WriteLine("Processed " + count + " Research Profiles");
                    }
                }
            }
            finally
            {
                processed.Close();
                errors.Close();
                Console.Out.WriteLine("Processed " + count + " Research Profiles");
            }
        }