예제 #1
0
 static void InitUsers(SPServiceContext context) {
     UserProfileManager manager = new UserProfileManager(context);
     using (var db = new CMSMIPEntities()) {
         var users = db.CMS_SA_USER_INFO_V;
         foreach (var user in users) {
             if (!manager.UserExists(user.SP账号)) {
                 UserProfile userProfile = manager.CreateUserProfile(user.SP账号);
             }
         }
     }
 }
예제 #2
0
 static void InitOrganizations(SPServiceContext context, SPSite site) {
     ProfileSubtypeManager subtypeManager = ProfileSubtypeManager.Get(context);
     string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization);
     ProfileSubtype subtype = subtypeManager.GetProfileSubtype(subtypeName);
     OrganizationProfileManager manager = new OrganizationProfileManager(context);
     OrganizationProfile rootProfile = manager.RootOrganization;
     using (var db = new CMSMIPEntities()) {
         var root = db.CMS_BA_IN_DEPT_INFO_V.Where(o => o.组织机构上级ID == 0).FirstOrDefault();
         CreateOrganization(root.组织机构名称, root.机构ID, rootProfile, subtype, manager, site);
     }
 }
예제 #3
0
 static OrganizationProfile CreateOrganization(string displayName, long id, OrganizationProfile parentProfile, ProfileSubtype subtype, OrganizationProfileManager manager, SPSite site) {
     OrganizationProfile profile = manager.CreateOrganizationProfile(subtype, parentProfile);
     profile.DisplayName = displayName;
     using (var db = new CMSMIPEntities()) {
         IEnumerable<string> accountNames = db.CMS_SA_USER_INFO_V.Where(u => u.所属部门ID == id).Select(u => u.SP账号);
         foreach (var accountName in accountNames) {
             profile.AddMember(accountName, OrganizationMembershipType.Member);
         }
         profile.Commit();
         CreateSiteGroup(profile, accountNames, site);
         var subOrganizations = db.CMS_BA_IN_DEPT_INFO_V.Where(o => o.组织机构上级ID == id);
         foreach (var subOrganization in subOrganizations) {
             CreateOrganization(subOrganization.组织机构名称, subOrganization.机构ID, profile, subtype, manager, site);
         }
         return profile;
     }
     Console.WriteLine(displayName + id);
 }