当前位置: 首页>>代码示例>>C#>>正文


C# IOrganizationService.Associate方法代码示例

本文整理汇总了C#中IOrganizationService.Associate方法的典型用法代码示例。如果您正苦于以下问题:C# IOrganizationService.Associate方法的具体用法?C# IOrganizationService.Associate怎么用?C# IOrganizationService.Associate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOrganizationService的用法示例。


在下文中一共展示了IOrganizationService.Associate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssignAdminRole

        private void AssignAdminRole(IOrganizationService service, Guid id)
        {
            string adminRoleName = "System Administrator";
            try
            {
                QueryExpression query = new QueryExpression
                {
                    EntityName = "role",
                    ColumnSet = new ColumnSet("name"),
                    Criteria = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression
                        {
                                AttributeName = "name",
                                Operator = ConditionOperator.Equal,
                                Values = {adminRoleName}
                        }
                    }
                }
                };
                EntityCollection roles = service.RetrieveMultiple(query);
                EntityReferenceCollection entityRefCln = new EntityReferenceCollection();
                foreach (Entity entity in roles.Entities)
                {
                        entityRefCln.Add(entity.ToEntityReference());
                }
                service.Associate("team", id, new Relationship("teamroles_association"), entityRefCln);
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:Sujith88,项目名称:Sujith-MS-CRM-Sample-code,代码行数:35,代码来源:Sujith+Plug-in.cs

示例2: Run

        /// <summary>
        /// Create and configure the organization service proxy.
        /// Create a team, a queue and a role.
        /// Add read queue privileges to the role.
        /// Assign the role to the team so that they can read the queue.
        /// Assign the queue to the team.
        /// Optionally delete any entity records that were created for this sample.
        // </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptForDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {

                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
                                                                     serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    _service = (IOrganizationService)_serviceProxy;

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetAssociateDisassociate1>
                    // Associate the accounts to the contact record.

                    // Create a collection of the entities that will be 
                    // associated to the contact.
                    EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account1Id));
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account2Id));
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account3Id));

                    // Create an object that defines the relationship between the contact and account.
                    Relationship relationship = new Relationship("account_primary_contact");


                    //Associate the contact with the 3 accounts.
                    _service.Associate(Contact.EntityLogicalName, _contactId, relationship,
                        relatedEntities);

                    Console.WriteLine("The entities have been associated.");

                    //Disassociate the records.
                    _service.Disassociate(Contact.EntityLogicalName, _contactId, relationship,
                        relatedEntities);

                    //</snippetAssociateDisassociate1>

                    Console.WriteLine("The entities have been disassociated.");

                    DeleteRequiredRecords(promptForDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
开发者ID:cesugden,项目名称:Scripts,代码行数:68,代码来源:AssociateDisassociate.cs

示例3: Run

        /// <summary>
        /// Retrieve a role from CRM.
        /// Assign that role to a team.
        /// <param name="organizationFriendlyName">The friendly name of 
        /// the target organization.</param>
        /// <param name="discoveryServer">The name of the discovery server.</param>
        /// <param name="promptForDelete">Indicates whether to prompt the user 
        /// to delete the records created in this sample.</param>
        /// </summary>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {
                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
                                                                     serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    _service = (IOrganizationService)_serviceProxy;

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetAssignSecurityRoleToTeam1>

                    // Retrieve a role from CRM.
                    QueryExpression query = new QueryExpression
                    {
                        EntityName = Role.EntityLogicalName,
                        ColumnSet = new ColumnSet("roleid"),
                        Criteria = new FilterExpression
                        {
                            Conditions =
                        {
                            // You would replace the condition below with an actual role
                            // name, or skip this query if you had a role id.
                            new ConditionExpression
                            {
                                AttributeName = "name",
                                Operator = ConditionOperator.Equal,
                                Values = {_roleName}
                            }
                        }
                        }
                    };

                    Role role = _service.RetrieveMultiple(query).Entities.
                        Cast<Role>().First();


                    // Add the role to the team.
                    _service.Associate(
                           Team.EntityLogicalName,
                           _teamId,
                           new Relationship("teamroles_association"),
                           new EntityReferenceCollection() { new EntityReference(Role.EntityLogicalName, _roleId) });

                    Console.WriteLine("Assigned role to team");
                    //</snippetAssignSecurityRoleToTeam1>

                    DeleteRequiredRecords(promptForDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
开发者ID:cesugden,项目名称:Scripts,代码行数:74,代码来源:AssignSecurityRoleToTeam.cs

示例4: AssociateDissassociateSecurityRoles

        /// <summary>
        ///     Associates the dissassociate security roles.
        /// </summary>
        /// <param name="crmService">The CRM service.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="associateRecords">if set to <c>true</c> [associate records].</param>
        public static void AssociateDissassociateSecurityRoles(IOrganizationService crmService, string roleName,
            bool associateRecords)
        {
            var roles = RetrieveMultipleByEntityName(crmService, EntityName.role, true);
            var systemUserRoles = RetrieveMultipleByEntityName(crmService, EntityName.systemuserroles);

            var systemUsers = RetrieveMultipleByEntityName(crmService, EntityName.systemuser, true);

            foreach (var user in systemUsers)
            {
                var tempRoleId =
                    roles.FirstOrDefault(
                        r =>
                            string.Compare((string) r.Value[role.name], roleName, StringComparison.OrdinalIgnoreCase) ==
                            0
                            && ((EntityReference) r.Value[role.businessunitid]).Id ==
                            ((EntityReference) user.Value[systemuser.businessunitid]).Id).Key;
                try
                {
                    var isExists = systemUserRoles.Any(c => (Guid) c.Value[systemuserroles.roleid] == tempRoleId
                                                            &&
                                                            (Guid) c.Value[systemuserroles.systemuserid] == user.Key);
                    if (associateRecords && !isExists)
                    {
                        "associating role {0} with user {1}".TraceVerbose(tempRoleId, user.Key);
                        crmService.Associate(
                            EntityName.systemuser,
                            user.Key,
                            new Relationship("systemuserroles_association"),
                            new EntityReferenceCollection
                            {
                                new EntityReference(EntityName.role, tempRoleId)
                            }
                            );
                        "association successful".TraceSuccess();
                    }
                    else if (!associateRecords && isExists)
                    {
                        "Disassociating role {0} with user {1}".TraceVerbose(tempRoleId, user.Key);
                        crmService.Disassociate(
                            EntityName.systemuser,
                            user.Key,
                            new Relationship("systemuserroles_association"),
                            new EntityReferenceCollection
                            {
                                new EntityReference(EntityName.role, tempRoleId)
                            }
                            );
                        "Disassociation successful".TraceSuccess();
                    }
                }
                catch (FaultException<OrganizationServiceFault> orgex)
                {
                    orgex.Message.TraceError(orgex);
                }
            }
        }
开发者ID:asifulm,项目名称:xrmdiff,代码行数:63,代码来源:XrmHelperAndUtilityFunctions.cs

示例5: Invoke_Associate

 public void Invoke_Associate(IOrganizationService service)
 {
     // Act
     service.Associate(string.Empty, Guid.Empty, new Relationship(), new EntityReferenceCollection());
 }
开发者ID:Innofactor,项目名称:CUTE,代码行数:5,代码来源:ServiceTestCases.cs


注:本文中的IOrganizationService.Associate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。