Exemplo n.º 1
0
        static void UpdateProjectCollectionWithData()
        {
            #region Aaron's Code
            //ListItemCollection spItems = GetLatestSharePointMRPData();
            //List<SPdataObj> spDataList = new List<SPdataObj>();

            //foreach (Microsoft.SharePoint.Client.ListItem listItem in spItems)
            //{
            //    SPdataObj spData = new SPdataObj();
            //    spData.ProjectId = listItem["ID"] != null ? Convert.ToInt32(listItem["ID"]) : -1,
            //    spData.Title = listItem["Title"] !=null ? listItem["Title"].ToString(): "",
            //    spData.ProjectType = ((string[])listItem["Project_x0020_Type"])[0].ToString();
            //    spData.Date = (DateTime)listItem["Date"];
            //    spData.Month = ((DateTime)listItem["Date"]).Month.ToString();
            //    spData.Quarter = listItem["Quarter"].ToString();
            //    spData.Week = int.Parse(listItem["Week"].ToString());
            //    spData.Location = listItem["Location"].ToString();
            //    spData.PlannedHours = listItem["Planned_x0020_Hours"] != null ?
            //                      Convert.ToInt32(listItem["Planned_x0020_Hours"]) : -1,
            //    spData.PM = listItem["PM"] != null ? listItem["PM"].ToString() : "";
            //    spData.Person = listItem["Person"] != null ? ((Microsoft.SharePoint.Client.FieldUserValue)listItem["Person"]).LookupValue : "";
            //    spData.Created = (DateTime)listItem["Created"];
            //    spData.Modified = (DateTime)listItem["Modified"];
            //    spData.Comments = listItem["Comments"] != null ? listItem["Comments"].ToString() : "";

            //    spDataList.Add(spData);


            //}
            #endregion

            //method call to Data Access Layer
            var projectList = CreateProjectCollectionWithData();
            SPtoMongoDB.UpdateProjectsInMongoDB(projectList);
        }
Exemplo n.º 2
0
        static void LDAPUpdate()
        {
            List <Employee> ldapDataList = new List <Employee>();

            using (var context = new PrincipalContext(ContextType.Domain, "STI", spUserName, spPassword))
            {
                using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
                {
                    DirectorySearcher ds = searcher.GetUnderlyingSearcher() as DirectorySearcher;
                    if (ds != null)
                    {
                        ds.PageSize = 10000;
                    }
                    else
                    {
                        Console.WriteLine("ds not null");
                        Console.ReadLine();
                    }

                    foreach (var result in searcher.FindAll())
                    {
                        DirectoryEntry de       = result.GetUnderlyingObject() as DirectoryEntry;
                        Employee       ldapData = new Employee();
                        var            mngr     = objNullCheck(de.Properties["manager"].Value);
                        mngr = mngr != null?mngr.Split(',')[0].Replace("CN=", "") : "";

                        ldapData.EmployeeName      = objNullCheck(de.Properties["name"].Value);
                        ldapData.FirstName         = objNullCheck(de.Properties["givenName"].Value);
                        ldapData.LastName          = objNullCheck(de.Properties["sn"].Value);
                        ldapData.SAMAccountName    = objNullCheck(de.Properties["samAccountName"].Value);
                        ldapData.DistinguishedName = objNullCheck(de.Properties["distinguishedName"].Value);
                        ldapData.UserPrincipalName = objNullCheck(de.Properties["userPrincipalName"].Value);
                        ldapData.Department        = objNullCheck(de.Properties["department"].Value);
                        ldapData.Company           = objNullCheck(de.Properties["company"].Value);
                        ldapData.Title             = objNullCheck(de.Properties["title"].Value);
                        ldapData.ManagerName       = mngr;
                        ldapData.IsDeveloper       = string.IsNullOrEmpty(ldapData.DistinguishedName) ?
                                                     false : ldapData.DistinguishedName.Contains("Development");

                        //ldapData.LdapManagerDistinguishedName = de.Properties["manager"].Value.ToString();

                        //int cnt = de.Properties["memberOf"].Count;
                        //string memberof = "";
                        //for (int idx = 0; idx < cnt; idx++)
                        //{
                        //    memberof += (de.Properties["memberOf"][idx].ToString().Split(',')[0].Replace("CN=", ""));
                        //    if (idx < (cnt - 1))
                        //    {
                        //        memberof += ", ";
                        //    }
                        //}
                        if (ldapData.UserPrincipalName != "")
                        {
                            ldapDataList.Add(ldapData);
                        }
                    }
                }
            }

            //method call to Data Access Layer
            SPtoMongoDB.UpdateEmployeesInMongoDB(ldapDataList);
        }