Пример #1
0
        private bool IsRoleAssignedToUser(Guid sytemUserId, Guid roleId)
        {
            try
            {
                // Establish a SystemUser link for a query.
                LinkEntity systemUserLink = new LinkEntity()
                {
                    LinkFromEntityName    = "systemuserroles",
                    LinkFromAttributeName = "systemuserid",
                    LinkToEntityName      = "systemuserroles",
                    LinkToAttributeName   = "systemuserid",
                    LinkCriteria          =
                    {
                        Conditions =
                        {
                            new ConditionExpression(
                                "systemuserid", ConditionOperator.Equal, sytemUserId)
                        }
                    }
                };

                // Build the query.
                QueryExpression linkQuery = new QueryExpression()
                {
                    EntityName   = "role",
                    ColumnSet    = new ColumnSet("roleid"),
                    LinkEntities =
                    {
                        new LinkEntity()
                        {
                            LinkFromEntityName    = "role",
                            LinkFromAttributeName = "roleid",
                            LinkToEntityName      = "systemuserroles",
                            LinkToAttributeName   = "roleid",
                            LinkEntities          = { systemUserLink }
                        }
                    },
                    Criteria =
                    {
                        Conditions =
                        {
                            new ConditionExpression("roleid", ConditionOperator.Equal, roleId)
                        }
                    }
                };

                // Retrieve matching roles.
                EntityCollection matchEntities = CrmSvc.RetrieveMultiple(linkQuery);

                return(matchEntities.Entities.Count > 0);
            }
            catch
            {
                return(false);
            }
        }
Пример #2
0
        private bool BulkDeleteJobExists()
        {
            QueryExpression bulkExpression = new QueryExpression()
            {
                EntityName = "asyncoperation",
                ColumnSet  = new ColumnSet(new string[] { "asyncoperationid", "name" }),
                Criteria   =
                {
                    Conditions =
                    {
                        new ConditionExpression("operationtype", ConditionOperator.Equal,      13),
                        new ConditionExpression("name",          ConditionOperator.Equal, jobName),
                    }
                }
            };

            return(CrmSvc.RetrieveMultiple(bulkExpression).Entities.Count > 0);
        }
Пример #3
0
        /// <summary>
        /// Returns the version of specified solution if present.
        /// </summary>
        private int[] GetSolutionVersion(string solutionName)
        {
            FilterExpression filter = new FilterExpression(LogicalOperator.And);

            filter.AddCondition(new ConditionExpression("uniquename", ConditionOperator.Equal, solutionName));
            QueryExpression query = new QueryExpression
            {
                EntityName = "solution",
                ColumnSet  = new ColumnSet("uniquename", "version"),
                Criteria   = filter,
                PageInfo   = new PagingInfo()
                {
                    ReturnTotalRecordCount = true
                }
            };
            EntityCollection stuff = CrmSvc.RetrieveMultiple(query);

            foreach (var i in stuff.Entities)
            {
                PackageLog.Log($"Name: {i.GetAttributeValue<string>("uniquename").ToString()} Version: {i.GetAttributeValue<string>("version")}");
            }
            if (stuff.TotalRecordCount < 1)
            {
                return(null);
            }
            string version = stuff.Entities.First().GetAttributeValue <string>("version");

            if (string.IsNullOrEmpty(version))
            {
                return(null);
            }
            string[] versions = version.Split('.');

            PackageLog.Log($"NonprofitCore - Major:{versions[0]} Minor:{versions[1]} Build:{versions[2]} Revision:{versions[3]}");
            int[] versionNumbers = new int[4];
            int.TryParse(versions[0], out versionNumbers[0]);
            int.TryParse(versions[1], out versionNumbers[1]);
            int.TryParse(versions[2], out versionNumbers[2]);
            int.TryParse(versions[3], out versionNumbers[3]);

            return(versionNumbers);
        }
Пример #4
0
        private Guid CreateUser(ApplicationUser appUser)
        {
            QueryExpression businessUnitQuery = new QueryExpression
            {
                EntityName = "businessunit",
                ColumnSet  = new ColumnSet("businessunitid"),
                Criteria   =
                {
                    Conditions =
                    {
                        new ConditionExpression("parentbusinessunitid",
                                                ConditionOperator.Null)
                    }
                }
            };


            EntityCollection defaultBusinessUnits = CrmSvc.RetrieveMultiple(businessUnitQuery);
            var defaultBusinessUnit = defaultBusinessUnits.Entities[0] ?? null;

            if (defaultBusinessUnit != null)
            {
                Entity systemUser = new Entity("systemuser");
                systemUser["firstname"]            = appUser.FirstName;
                systemUser["lastname"]             = appUser.LastName;
                systemUser["internalemailaddress"] = appUser.InternalEmailAddress;
                systemUser["applicationid"]        = appUser.Id;
                systemUser["businessunitid"]       = new EntityReference
                {
                    LogicalName = "businessunit",
                    Name        = "businessunit",
                    Id          = defaultBusinessUnit.Id
                };

                return(CrmSvc.Create(systemUser));
            }

            return(Guid.Empty);
        }
        /// <summary>
        /// Called after Import completes.
        /// </summary>
        /// <returns></returns>
        public override bool AfterPrimaryImport()
        {
            var version = CrmSvc.ConnectedOrgVersion;

            //Enable all the steps in the plugin assembly
            if (CrmSvc != null && CrmSvc.IsReady)
            {
                var assemblyname = "CrmAsyncRequestResponseSample.Plugins";

                // Create the QueryExpression object to retrieve plug-in type
                var query = new QueryExpression();
                query.EntityName = "plugintype";
                query.Criteria.AddCondition("assemblyname", ConditionOperator.Equal, assemblyname);
                var retrievedPluginType = CrmSvc.RetrieveMultiple(query)[0];

                var pluginTypeId = (Guid)retrievedPluginType.Attributes["plugintypeid"];

                query = new QueryExpression();

                // Set the properties of the QueryExpression object.
                query.EntityName = "sdkmessageprocessingstep";
                query.ColumnSet  = new ColumnSet(new[] { "sdkmessageprocessingstepid", "statecode" });
                query.Criteria.AddCondition(new ConditionExpression("plugintypeid", ConditionOperator.Equal, pluginTypeId));
                var retrievedSteps = CrmSvc.RetrieveMultiple(query);

                foreach (var step in retrievedSteps.Entities)
                {
                    // Enable the step by setting it's state code
                    step.Attributes["statecode"]  = new OptionSetValue(0); // 0 = Enabled
                    step.Attributes["statuscode"] = new OptionSetValue(1); // 1 = Enabled
                    CrmSvc.Update(step);
                }

                return(true); // Do nothing here/
            }

            return(false);
        }
Пример #6
0
        private Guid CreateOrGetApplicationUser(ApplicationUser appUser)
        {
            QueryExpression appUserQuery = new QueryExpression
            {
                EntityName = "systemuser",
                ColumnSet  = new ColumnSet("systemuserid"),
                Criteria   =
                {
                    Conditions =
                    {
                        new ConditionExpression("applicationid", ConditionOperator.Equal, appUser.Id)
                    }
                }
            };

            EntityCollection appUsers = CrmSvc.RetrieveMultiple(appUserQuery);

            if (appUsers != null && appUsers.Entities.Count > 0)
            {
                return(appUsers.Entities[0].Id);
            }

            return(CreateUser(appUser));
        }
Пример #7
0
        private void EnablePluginSteps()
        {
            LogStart("EnablePluginSteps");

            var assemblyname = "FedBizApps.RequestManagement.Plugins";

            // Create the QueryExpression object to retrieve plug-in type
            var query = new QueryExpression {
                EntityName = "plugintype"
            };

            query.Criteria.AddCondition("assemblyname", ConditionOperator.Equal, assemblyname);
            var retrievedPluginType = CrmSvc.RetrieveMultiple(query)[0];

            var pluginTypeId = (Guid)retrievedPluginType.Attributes["plugintypeid"];

            query = new QueryExpression
            {
                EntityName = "sdkmessageprocessingstep",
                ColumnSet  = new ColumnSet(new[] { "sdkmessageprocessingstepid", "statecode" })
            };

            // Set the properties of the QueryExpression object.
            query.Criteria.AddCondition(new ConditionExpression("plugintypeid", ConditionOperator.Equal, pluginTypeId));
            var retrievedSteps = CrmSvc.RetrieveMultiple(query);

            foreach (var step in retrievedSteps.Entities)
            {
                // Enable the step by setting it's state code
                step.Attributes["statecode"]  = new OptionSetValue(0); // 0 = Enabled
                step.Attributes["statuscode"] = new OptionSetValue(1); // 1 = Enabled
                CrmSvc.Update(step);
            }

            LogEnd("EnablePluginSteps");
        }