public void Run(string manifestPath, CdsConnection cdsConnection)
        {
            var manifest = SerialisationWrapper.DeserialiseFromFile <ProcessActivationManifest>(manifestPath);
            var client   = XrmClient.GetCrmServiceClientFromManifestConfiguration(manifest.CdsConnection);

            ValidateManifest(manifest);
            if (!ValidationResult.IsValid)
            {
                // TODO - throw a good error ;)
                return;
            }

            if (manifest.LoggingConfiguration == null)
            {
                manifest.LoggingConfiguration = new LoggingConfiguration()
                {
                    LoggerConfigurationType = LoggerConfigurationType.Console,
                    LogLevelToTrace         = LogLevel.Information
                };
            }

            var processWrapper = new ProcessActivationWrapper();

            processWrapper.SetStatusFromManifest(client, manifest);
        }
Exemple #2
0
        public void Run(string manifestPath, CdsConnection cdsConnection)
        {
            // TODO - throw good errors if manifest can't be found/read/isInvalid
            var manifest = SerialisationWrapper.DeserialiseFromFile <ConfigurationManifest>(manifestPath);
            // TODO - throw good error if XrmClient is unauthorised/etc...
            var client = XrmClient.GetCrmServiceClientFromManifestConfiguration(manifest.CdsConnection);

            ValidateManifest(manifest);
            if (!ValidationResult.IsValid)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Manifest is not valid. Not progressing with registration");
                Console.WriteLine($"\nErrors found in manifest validation:\n{ValidationResult}");
                Console.ResetColor();

                // QUESTION - Do you really want to throw an exception here, if you're already logging the val output?
                throw new InvalidManifestException("Exiting processing with exception - Manifest is not valid");
            }

            if (manifest.LoggingConfiguration == null)
            {
                manifest.LoggingConfiguration = new LoggingConfiguration()
                {
                    LoggerConfigurationType = LoggerConfigurationType.Console,
                    LogLevelToTrace         = LogLevel.Information
                };
            }

            var configWrapper = new ConfigurationWrapper();

            configWrapper.GenerateCustomisations(manifest, client);
        }
Exemple #3
0
        public void GetBaseCurrencyTest()
        {
            var context    = new XrmFakedContext();
            var orgService = context.GetOrganizationService();

            var baseCurrencyId = Guid.NewGuid();
            var baseCurrency   = new Entity("organization")
            {
                Id                 = Guid.NewGuid(),
                ["name"]           = "crm-organisation",
                ["basecurrencyid"] = new EntityReference("transactioncurrency", baseCurrencyId)
            };

            context.Initialize(new List <Entity>()
            {
                baseCurrency
            });

            var retrievedBaseCurrency = XrmClient.GetBaseCurrency(orgService);

            Assert.AreEqual(baseCurrencyId, retrievedBaseCurrency.Id);
        }
        public void GetRootBusinessUnitTest()
        {
            var context    = new XrmFakedContext();
            var orgService = context.GetOrganizationService();

            var rootBusinessUnit = new Entity("businessunit")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "root",
                ["parentbusinessunitid"] = null
            };

            var childBusinessUnit1 = new Entity("businessunit")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "child 1",
                ["parentbusinessunitid"] = rootBusinessUnit.Id
            };

            var childBusinessUnit2 = new Entity("businessunit")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "child 2",
                ["parentbusinessunitid"] = rootBusinessUnit.Id
            };

            context.Initialize(new List <Entity>()
            {
                rootBusinessUnit,
                childBusinessUnit1,
                childBusinessUnit2
            });

            var retrievedRootBusinessUnit = XrmClient.GetRootBusinessUnit(orgService);

            Assert.AreEqual(rootBusinessUnit.Id, retrievedRootBusinessUnit.Id);
        }
        public void Run(string manifestPath, CdsConnection cdsConnection)
        {
            var manifest = SerialisationWrapper.DeserialiseFromFile <PluginManifest>(manifestPath);

            if (cdsConnection != null)
            {
                manifest.CdsConnection = cdsConnection;
            }

            ValidateManifest(manifest);
            if (!ValidationResult.IsValid)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Manifest is not valid. Not progressing with registration");
                Console.WriteLine($"\nErrors found in manifest validation:\n{ValidationResult}");
                Console.ResetColor();

                throw new InvalidManifestException("Exiting processing with exception - Manifest is no valid");
            }

            if (manifest.LoggingConfiguration == null)
            {
                manifest.LoggingConfiguration = new LoggingConfiguration()
                {
                    LoggerConfigurationType = LoggerConfigurationType.Console,
                    LogLevelToTrace         = LogLevel.Information
                };
            }

            var client = XrmClient.GetCrmServiceClientFromManifestConfiguration(manifest.CdsConnection);

            var pluginWrapper = new PluginWrapper();

            pluginWrapper.RegisterPlugins(manifest, client);
            pluginWrapper.RegisterServiceEndpoints(manifest, client);
        }
        /// <summary>
        /// Create entities and attributes from a ConfigurationManifest
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="client"></param>
        /// <param name="t"></param>
        /// <param name="publisherPrefix"></param>
        public void GenerateEntityModel(ConfigurationManifest manifest, IOrganizationService client, TracingHelper t, string publisherPrefix)
        {
            if (manifest.Entities == null)
            {
                t.Debug($"No entities in manifest to be processed");
            }
            else
            {
                foreach (var entity in manifest.Entities)
                {
                    t.Debug($"Processing entity: {entity.DisplayName}");
                    entity.CreateOrUpdate(client, publisherPrefix, manifest);
                    t.Info($"Entity {entity.DisplayName} created or updated");

                    if (entity.Attributes == null)
                    {
                        t.Debug($"No attributes to process for entity {entity.DisplayName}");
                    }
                    else
                    {
                        XmlDocument formXml = null;

                        foreach (var attribute in entity.Attributes)
                        {
                            t.Debug($"Processing attribute: {attribute.DisplayName}");
                            attribute.EntitySchemaName = entity.SchemaName;

                            try
                            {
                                var attributeMetaData = attribute.CreateOrUpdate(client, publisherPrefix, manifest);

                                if (attribute.AddToForm)
                                {
                                    FormHelper.AddAttributeToForm(attributeMetaData, ref formXml);
                                }
                                t.Debug($"Attribute {attribute.DisplayName} added to form");

                                // TODO - add to views
                                if (attribute.AddToViewOrder.HasValue)
                                {
                                    attribute.AddToSystemViews();
                                }
                                t.Debug($"Attribute {attribute.DisplayName} added to views");

                                t.Info($"Attribute {attribute.DisplayName} successfully processed");
                            }
                            catch (NotCustomisableException e)
                            {
                                t.Warning(e.Message);
                            }
                        }

                        if (formXml != null)
                        {
                            FormHelper.UpdateFormXml(client, entity.SchemaName, formXml, "Information");
                        }
                    }

                    if (entity.EntityPermissions == null)
                    {
                        t.Debug($"Entity {entity.DisplayName} has no security permissions to process");
                    }
                    else
                    {
                        // TODO - extract this out into a new method (and refactor the CreateSecurityRoles method too)

                        var rootBusinessUnit = XrmClient.GetRootBusinessUnit(client);

                        foreach (var entityPermission in entity.EntityPermissions)
                        {
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Create", entityPermission.Create, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Read", entityPermission.Read, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Write", entityPermission.Write, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Delete", entityPermission.Delete, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Append", entityPermission.Append, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "AppendTo", entityPermission.AppendTo, rootBusinessUnit, t);
                            UpdateSecurityRoleEntityPermission(client, entity.SchemaName, entityPermission.RoleName,
                                                               "Share", entityPermission.Share, rootBusinessUnit, t);
                        }
                    }

                    t.Info($"Entity {entity.DisplayName} successfully processed");
                }
            }
        }
        /// <summary>
        /// Create or update security roles
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="client"></param>
        /// <param name="t"></param>
        /// <param name="publisherPrefix"></param>
        public void CreateSecurityRoles(ConfigurationManifest manifest, IOrganizationService client, TracingHelper t, string publisherPrefix)
        {
            if (manifest.SecurityRoles == null)
            {
                t.Debug($"No security roles in manifest to be processed");
            }
            else
            {
                var rootBusinessUnit = XrmClient.GetRootBusinessUnit(client);

                foreach (var securityRole in manifest.SecurityRoles)
                {
                    var existingRole = GetExistingSecurityRoleQuery(securityRole.Name, rootBusinessUnit)
                                       .RetrieveSingleRecord(client);

                    var role = new Role()
                    {
                        Name           = securityRole.Name,
                        BusinessUnitId = rootBusinessUnit
                    }.CreateOrUpdate(client, GetExistingSecurityRoleQuery(securityRole.Name, rootBusinessUnit));

                    SolutionWrapper.AddSolutionComponent(client, manifest.SolutionName, role.Id, ComponentType.Role);

                    if (securityRole.Privileges == null)
                    {
                        continue;
                    }
                    foreach (var rolePrivilege in securityRole.Privileges)
                    {
                        var retrievePrivilegesByName = new QueryExpression("privilege")
                        {
                            ColumnSet = new ColumnSet(true),
                            Criteria  = new FilterExpression
                            {
                                Conditions =
                                {
                                    new ConditionExpression("name", ConditionOperator.Equal, rolePrivilege)
                                }
                            }
                        };
                        var privilegeId = retrievePrivilegesByName.RetrieveSingleRecord(client);
                        if (privilegeId == null)
                        {
                            t.Warning($"Privilege with name {rolePrivilege} cannot be found. " +
                                      $"{rolePrivilege} for role {securityRole.Name} has been skipped");
                            continue;
                        }

                        var addedPrivilege = new AddPrivilegesRoleRequest()
                        {
                            RoleId     = role.Id,
                            Privileges = new []
                            {
                                new RolePrivilege()
                                {
                                    PrivilegeId = privilegeId.Id,
                                    Depth       = PrivilegeDepth.Global
                                }
                            }
                        };
                        client.Execute(addedPrivilege);
                    }
                }
            }
        }