Class exposes properties for data storage
Exemplo n.º 1
0
 /// <summary>
 /// Method to read group config
 /// </summary>
 /// <param name="sheetValues">collection object</param>
 /// <param name="listval">dictionary object</param>
 /// <returns>list object</returns>
 private static List<DataStorage> ReadGroupConfig(Collection<Collection<string>> sheetValues, Dictionary<string, string> listval)
 {
     List<DataStorage> groupsData = new List<DataStorage>();
     int counter = 0;
     try
     {
         foreach (var row in sheetValues)
         {
             if (counter == 0)
             {
                 counter = 1;
                 continue;
             }
             DataStorage termInfoTuple = new DataStorage();
             termInfoTuple.SiteUrl = Convert.ToString(listval["CatalogSiteURL"], CultureInfo.InvariantCulture);
             termInfoTuple.GroupName = Convert.ToString(row[0], CultureInfo.InvariantCulture);
             termInfoTuple.GroupDesc = Convert.ToString(row[1], CultureInfo.InvariantCulture);
             termInfoTuple.Permissions = Convert.ToString(row[2], CultureInfo.InvariantCulture);
             termInfoTuple.Members = Convert.ToString(row[3], CultureInfo.InvariantCulture);
             groupsData.Add(termInfoTuple);
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine("Exception Details: " + exception.Message);
         ErrorLogger.LogErrorToTextFile(errorFilePath, "Exception Details: " + exception.Message);
     }
     return groupsData;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Method to add users to current group
        /// </summary>
        /// <param name="clientContext">client context</param>
        /// <param name="site">site object</param>
        /// <param name="currentGrp">group object</param>
        /// <param name="item">data storage</param>
        private static void AddUsersToCurrentGroup(ClientContext clientContext, Web site, Group currentGrp, DataStorage item)
        {
            string[] allUserEmail = item.Members.Split(new char[] { ';' });

            Console.WriteLine("Adding users to this group");
            List<User> allUsers = new List<User>();
            foreach (string userEmail in allUserEmail)
            {
                if (!string.IsNullOrEmpty(userEmail))
                {
                    User user = clientContext.Web.EnsureUser(userEmail.Trim());
                    clientContext.Load(user);
                    clientContext.ExecuteQuery();
                    allUsers.Add(user);
                }
            }
            foreach (User user in allUsers)
            {
                currentGrp.Users.AddUser(user);
            }
            site.Update();
            clientContext.Load(currentGrp);
            clientContext.ExecuteQuery();
            Console.WriteLine("Successfully added users to group " + currentGrp.Title);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method to check if a group exists and create a new one
        /// </summary>
        /// <param name="collGroup">group collection</param>
        /// <param name="item">data storage</param>
        /// <param name="site">site object</param>
        /// <param name="clientContext">client context</param>
        /// <returns>returns group object</returns>
        private static Group CheckAndCreateGroup(GroupCollection collGroup, DataStorage item, Web site, ClientContext clientContext)
        {
            Group currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
            if (currentGrp != null)
            {
                Console.WriteLine("Deleting group " + item.GroupName + " as it is already present");
                collGroup.Remove(currentGrp);
            }

            //Creating group
            Console.WriteLine("Creating group " + item.GroupName);
            GroupCreationInformation grpInfo = new GroupCreationInformation();
            grpInfo.Title = item.GroupName;
            grpInfo.Description = item.GroupDesc;
            collGroup.Add(grpInfo);
            site.Update();
            clientContext.Load(collGroup);
            clientContext.ExecuteQuery();
            Console.WriteLine("Successfully created group " + item.GroupName);
            currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
            return currentGrp;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Method to assign permissions
 /// </summary>
 /// <param name="item">data storage object</param>
 /// <param name="clientContext">client context</param>
 /// <param name="site">site object</param>
 /// <param name="currentGrp">group object</param>
 private static void AssignPermission(DataStorage item, ClientContext clientContext, Web site, Group currentGrp)
 {
     Console.WriteLine("Assigning " + item.Permissions + " permission to group " + item.GroupName);
     RoleDefinitionBindingCollection grpRole = new RoleDefinitionBindingCollection(clientContext);
     RoleDefinition grpRoleDef = null;
     switch (item.Permissions.ToLower(new CultureInfo("en-US", false)))
     {
         case "contribute":
             grpRoleDef = site.RoleDefinitions.GetByType(RoleType.Contributor);
             break;
         case "fullcontrol":
         case "full control":
             grpRoleDef = site.RoleDefinitions.GetByType(RoleType.Administrator);
             break;
         case "read":
         default:
             grpRoleDef = site.RoleDefinitions.GetByType(RoleType.Reader);
             break;
     }
     grpRole.Add(grpRoleDef);
     site.RoleAssignments.Add(currentGrp, grpRole);
     clientContext.Load(currentGrp);
     clientContext.Load(grpRole);
     clientContext.ExecuteQuery();
     Console.WriteLine("Successfully assigned " + item.Permissions + " to group " + item.GroupName);
 }