/// <summary>
        ///     Resolves the alias.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        private EntityAlias ResolveAlias(Guid id, bool reverseAlias)
        {
            EntityAlias entityAlias;
            var         key = new Tuple <Guid, bool>(id, reverseAlias);

            if (_upgradeIdToAliasMap.TryGetValue(key, out entityAlias))
            {
                return(entityAlias);
            }

            if (reverseAlias)
            {
                if (PackageData.Metadata.RelationshipTypeCallback == null)
                {
                    return(null);
                }
                RelationshipTypeEntry relType = PackageData.Metadata.RelationshipTypeCallback(id);
                if (relType?.ReverseAlias == null)
                {
                    return(null);
                }
                entityAlias = new EntityAlias(relType.ReverseAlias);
            }
            else
            {
                entityAlias = NameResolver?.Resolve(id);
            }

            _upgradeIdToAliasMap[key] = entityAlias;

            return(entityAlias);
        }
        public void TestEntityAlias_Equality( )
        {
            var alias1 = new EntityAlias("abc123");
            var alias2 = new EntityAlias("abc123");

            Assert.AreEqual(alias1, alias2);
            Assert.IsTrue(alias1.Equals(alias2));
            Assert.IsTrue(alias1 == alias2);
            Assert.IsFalse(alias1 != alias2);

            alias1 = new EntityAlias("xyz789:abc123");
            alias2 = new EntityAlias("xyz789:abc123");

            Assert.AreEqual(alias1, alias2);
            Assert.IsTrue(alias1.Equals(alias2));
            Assert.IsTrue(alias1 == alias2);
            Assert.IsFalse(alias1 != alias2);

            alias1 = new EntityAlias("xyz789", "abc123");

            Assert.AreEqual(alias1, alias2);
            Assert.IsTrue(alias1.Equals(alias2));
            Assert.IsTrue(alias1 == alias2);
            Assert.IsFalse(alias1 != alias2);
        }
        /// <summary>
        ///     Resolves the specified upgrade identifier.
        /// </summary>
        /// <param name="upgradeId">The upgrade identifier.</param>
        /// <returns></returns>
        public EntityAlias Resolve(Guid upgradeId)
        {
            EntityAlias alias;

            if (!_cache.TryGetValue(upgradeId, out alias))
            {
                using (DatabaseContext ctx = DatabaseContext.GetContext( ))
                {
                    using (var command = ctx.CreateCommand("spResolveTenantAppAlias", CommandType.StoredProcedure))
                    {
                        ctx.AddParameter(command, "@upgradeId", DbType.Guid, upgradeId);
                        ctx.AddParameter(command, "@tenantId", DbType.Int64, _tenantId);

                        var result = command.ExecuteScalar( );

                        if (result != null && result != DBNull.Value)
                        {
                            alias = new EntityAlias(result.ToString( ));

                            _cache[upgradeId] = alias;
                        }
                        else
                        {
                            _cache[upgradeId] = null;
                        }
                    }
                }
            }

            return(alias);
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>();

            //Create an Organization Service
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        orgService     = serviceFactory.CreateOrganizationService(context.InitiatingUserId);

            //Registered Step Guid
            var pluginStepGuid = Guid.Empty;

            var message = Message.Get(executionContext);

            //Plugin Image object
            CrmPluginImage pluginImage = new CrmPluginImage();

            //pluginImage.AssemblyId = new Guid("");
            //pluginImage.PluginId = new Guid("");
            pluginImage.StepId              = new Guid(PluginStepId.Get <string>(executionContext));
            pluginImage.Attributes          = Attributes.Get <string>(executionContext);
            pluginImage.ImageType           = (CrmPluginImageType)ImageType.Get <int>(executionContext);
            pluginImage.EntityAlias         = EntityAlias.Get <string>(executionContext);
            pluginImage.MessagePropertyName = message.Equals("Create") ? "Id" : "Target";
            pluginImage.Name = Name.Get <string>(executionContext);
            pluginImage.CustomizationLevel = CustomizationLevel.Get <int>(executionContext);

            var imageId = pluginImage.CreatePluginImage(ref orgService);

            ImageId.Set(executionContext, imageId.ToString());
        }
Beispiel #5
0
        /// <summary>
        ///     Tests the get application dependents source.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <TestCaseData> TestGetApplicationDependentsSource( )
        {
            long coreSolutionId;

            using (new TenantAdministratorContext("EDC"))
            {
                EntityAlias testSolutionAlias = new EntityAlias("core", "coreSolution");
                coreSolutionId = testSolutionAlias.ToEntityId( );
            }

            yield return(new TestCaseData(-1, false, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(0, false, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(1, false, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(-1, true, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(0, true, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(1, true, 0, null).Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(coreSolutionId, false, 4, new[]
            {
                Applications.SharedApplicationId,
                Applications.CoreDataApplicationId,
                Applications.ConsoleApplicationId,
                Applications.TestApplicationId
            }));

            yield return(new TestCaseData(coreSolutionId, true, 1, new[]
            {
                Applications.ConsoleApplicationId
            }));
        }
        public void TestEntityAlias_Constructor_StringString_EmptyNamespace( )
        {
            const string aliasString = "abc123";

            var alias = new EntityAlias(string.Empty, aliasString);

            Assert.AreEqual(CoreNamespace, alias.Namespace);
            Assert.AreEqual(aliasString, alias.Alias);
        }
        public void TestEntityAlias_ToString( )
        {
            var alias1 = new EntityAlias("xyz789:abc123");
            var alias2 = new EntityAlias("xyz789", "abc123");

            Assert.IsTrue(alias1.ToString( ) == alias2.ToString( ));
            Assert.IsTrue(alias1.ToString( ) == "xyz789:abc123");
            Assert.IsTrue(alias2.ToString( ) == "xyz789:abc123");
        }
        public void TestEntityAlias_Constructor_StringString_RandomNamespace( )
        {
            const string namespaceString = "xyz789";
            const string aliasString     = "abc123";

            var alias = new EntityAlias(namespaceString, aliasString);

            Assert.AreEqual(namespaceString, alias.Namespace);
            Assert.AreEqual(aliasString, alias.Alias);
        }
Beispiel #9
0
 public override int GetHashCode()
 {
     return(Id.GetHashCode() ^
            AssemblyId.GetHashCode() ^
            PluginId.GetHashCode() ^
            StepId.GetHashCode() ^
            Attributes.GetHashCode() ^
            Name.GetHashCode() ^
            RelatedAttribute.GetHashCode() ^
            EntityAlias.GetHashCode() ^
            ImageType.GetHashCode() ^
            MessagePropertyName.GetHashCode());
 }
        public async Task EntityAlias_Delete_Success()
        {
            // Ensure Alias Pre-Conditions are defined.
            await SetupAliasTestConditions();

            // Now create an entity.
            string name   = _uniqueKey.GetKey("EntityD");
            Entity entity = new Entity(name);

            entity.Policies.Add("polTest2");
            entity.Metadata.Add("Company", "ACME");
            entity.Metadata.Add("Products", "Dynamite");

            // Now save entity
            Entity savedEntity = await _idEngine.SaveEntity(entity);

            Assert.IsNotNull(savedEntity, "A10:  Expected to receive an Entity object");

            // Write out some values
            TestContext.WriteLine("Entity Name:      {0}", savedEntity.Name);
            TestContext.WriteLine("Entity ID:        {0}", savedEntity.Id);

            // Now we need to create an AppRole and store it off.
            string  roleName = _uniqueKey.GetKey("aRoleD");
            AppRole theRole  = new AppRole(roleName);

            theRole = await _appRoleAuthEngine.SaveRoleAndReturnRoleObject(theRole);

            Assert.IsNotNull(theRole, "The application role must be a valid role object in order for the Entity-Alias tests to work.");

            // Now lets create an alias.
            Guid aliasGuid = await _idEngine.SaveAlias(savedEntity.Id, _appRoleAccessor, theRole.Name);

            Assert.AreNotEqual(aliasGuid.ToString(), Guid.Empty.ToString());

            TestContext.WriteLine("Alias ID:         {0}", aliasGuid);
            TestContext.WriteLine("Alias Name:       {0}", theRole.Name);

            // Now lets read the alias back.
            EntityAlias alias = await _idEngine.ReadAlias(aliasGuid);

            Assert.AreEqual(theRole.Name, alias.Name, "A30:  Alias Name was incorrect.");
            Assert.AreEqual(_appRoleAccessor, alias.MountAccessor, "A40:  Mount Accessors were not the same.");
            Assert.AreEqual(savedEntity.Id, alias.CanonicalId, "A50:  Auth backend ID's were not the same.");

            // Now Delete it.
            Assert.True(await _idEngine.DeleteAlias(alias.Id));

            // Validate it is gone.
            Assert.ThrowsAsync <VaultInvalidPathException>(async() => await _idEngine.ReadAlias(aliasGuid));
        }
        public void TestEntityAlias_Constructor_String_RandomNamespace( )
        {
            const string aliasString = "xyz789:abc123";

            string[] parts = aliasString.Split(new[]
            {
                ':'
            }, StringSplitOptions.RemoveEmptyEntries);

            var alias = new EntityAlias(aliasString);

            Assert.AreEqual(parts[1], alias.Alias);
            Assert.AreEqual(parts[0], alias.Namespace);
        }
        public void TestEntityAlias_HashCode( )
        {
            var alias1 = new EntityAlias("abc123");
            var alias2 = new EntityAlias("abc123");

            Assert.AreEqual(alias1.GetHashCode( ), alias2.GetHashCode( ));

            alias1 = new EntityAlias("xyz789:abc123");
            alias2 = new EntityAlias("xyz789:abc123");

            Assert.AreEqual(alias1.GetHashCode( ), alias2.GetHashCode( ));

            alias1 = new EntityAlias("xyz789", "abc123");

            Assert.AreEqual(alias1.GetHashCode( ), alias2.GetHashCode( ));
        }
Beispiel #13
0
        /// <summary>
        ///     Gets the data.
        /// </summary>
        /// <value>
        ///     The data.
        /// </value>
        private void ProcessField(Member member, Guid entityId, Guid memberId, string memberType)
        {
            string xmlText = member.Data;
            string type    = null;
            bool   ok      = false;

            DataEntry entry = new DataEntry
            {
                EntityId      = entityId,
                FieldId       = memberId,
                AliasMarkerId = memberId == Guids.ReverseAlias ? 1 : 0
            };

            // Process field types
            switch (memberType)
            {
            case XmlConstants.FieldConstants.TextField:
                type       = Helpers.NVarCharName;
                ok         = true;
                entry.Data = xmlText;
                break;

            case XmlConstants.FieldConstants.IntField:
                int intValue;
                type       = Helpers.IntName;
                ok         = int.TryParse(xmlText, out intValue);
                entry.Data = intValue;
                break;

            case XmlConstants.FieldConstants.AliasField:
                type = Helpers.AliasName;
                EntityAlias alias = new EntityAlias(xmlText);
                entry.Data      = alias.Alias;
                entry.Namespace = alias.Namespace;
                ok = true;
                break;

            case XmlConstants.FieldConstants.BoolField:
                bool boolValue;
                type       = Helpers.BitName;
                ok         = bool.TryParse(xmlText, out boolValue);
                entry.Data = boolValue;
                break;

            case XmlConstants.FieldConstants.DateTimeField:
                DateTime dateTimeValue;
                type       = Helpers.DateTimeName;
                ok         = DateTime.TryParse(xmlText, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out dateTimeValue);
                entry.Data = dateTimeValue;
                break;

            case XmlConstants.FieldConstants.DecimalField:
                decimal decimalValue;
                type       = Helpers.DecimalName;
                ok         = decimal.TryParse(xmlText, out decimalValue);
                entry.Data = decimalValue;
                break;

            case XmlConstants.FieldConstants.GuidField:
                Guid guidValue;
                type       = Helpers.GuidName;
                ok         = Guid.TryParse(xmlText, out guidValue);
                entry.Data = guidValue;
                break;

            case XmlConstants.FieldConstants.XmlField:
                type       = Helpers.XmlName;
                ok         = true;
                entry.Data = xmlText;
                break;
            }

            // Lookup Field type table
            if (string.IsNullOrEmpty(type))
            {
                throw new InvalidOperationException($"Entity '{member.EntityId}' field '{memberId}' has no known type '{memberType}'");
            }

            IList <DataEntry> dataEntries;

            if (!_fieldData.TryGetValue(type, out dataEntries))
            {
                dataEntries      = new List <DataEntry>( );
                _fieldData[type] = dataEntries;
            }

            // Store entry
            if (!ok)
            {
                Context.WriteWarning($"Detected invalid {memberType} value. Field '{memberId}' on entity '{entityId}'");
            }
            else
            {
                dataEntries.Add(entry);
            }
        }