コード例 #1
0
        /// <summary>
        /// Gets a group.
        /// </summary>
        /// <param name="name">A string representing the name of the group to retrieve.</param>
        /// <returns>Returns an IGroup representing the group if the group is found, otherwise returns null.</returns>
        public IGroup GetGroup(string name)
        {
            Group group = null;
            try
            {
                //sample of logging debug output
                _logger.LogDebugMessage(base.GetType().ToString() + ".GetGroup", "Group: " + name);

                //TODO: Get more information from CRM
                group = new Group(this.SecurityLabel, name, "SAMPLE Group1Description", "*****@*****.**");
            }
            catch (Exception ex)
            {
                //sample of logging debug output
                _logger.LogErrorMessage(base.GetType().ToString() + ".GetGroup error", "Group: " + name + " Error: " + ex.Message);
            }

            return group;    
        }
コード例 #2
0
        /// <summary>
        /// Finds and returns the given user's groups.
        /// </summary>
        /// <param name="userName">A string representing the username of the user whose groups should be returned.</param>
        /// <param name="properties">An IDictionary representing the properties used to filter the groups returned.</param>
        /// <returns>An IGroupCollection representing the groups which were found.</returns>
        public IGroupCollection FindGroups(string userName, IDictionary<string, object> properties)
        {
            //the collection that we will populate and finally return
            GroupCollection groups = new GroupCollection();

            #region CRM code

            try
            {
                ServerConnection serverConnect = new ServerConnection(this._crmconfigurations);
                ServerConnection.Configuration config = serverConnect.GetServerConfiguration();
                if (config == null)
                {
                    if (this._logger != null)
                    {
                        this._logger.LogErrorMessage("K2Community.CSP.CRM", "CRM URL not found");
                    }
                }
                else
                {
                    string FetchXml = @"
                    <fetch mapping='logical'>
	                    <entity name='team'>
		                    <attribute name='name' />
	                    </entity>
                    </fetch>";

                    using (_serviceProxy = ServerConnection.GetOrganizationProxy(config))
                    {
                        _serviceProxy.EnableProxyTypes();

                        // Build fetch request and obtain results.
                        Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest efr = new Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest()
                        {
                            Query = new FetchExpression(FetchXml)
                        };
                        Microsoft.Xrm.Sdk.EntityCollection entityResults = ((Microsoft.Xrm.Sdk.Messages.RetrieveMultipleResponse)_serviceProxy.Execute(efr)).EntityCollection;

                        //sample of logging debug output
                        _logger.LogDebugMessage(base.GetType().ToString() + ".FindGroups", "Finding groups for user: "******".FindGroups", "Team Name: {0}", e.Attributes["name"].ToString());
                            Group group1 = new Group(this.SecurityLabel, e.Attributes["name"].ToString(), "", "");

                            //add the group to the collection
                            groups.Add(group1);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (this._logger != null)
                {
                    _logger.LogErrorMessage(base.GetType().ToString() + ".FindGroups error", "User: "******" Error: " + ex.Message + ex.StackTrace);
                }
            }

            #endregion

            //return the collection of groups that the user belongs to
            return groups;
        }