Beispiel #1
0
        /// <param name="channelName">Name of the channel.</param>
        /// <param name="tenantName">Name of the tenant.</param>
        /// <param name="filter">The filter.</param>
        public SubscriberRefObject(string channelName, string tenantName, Func <MessageEventArgs <T>, bool> filter)
        {
            Context = new TenantAdministratorContext(tenantName);

            Filter = filter;

            Manager = new RedisManager( );
            Manager.Connect( );

            ReceivedMessages = new List <MessageEventArgs <T> >( );
            MessageReceived  = new AutoResetEvent(false);

            Channel = Manager.GetChannel <T>(channelName);

            Channel.MessageReceived += Handler;
            Channel.Subscribe( );

            /////
            // Allow time for the server to receive the message and process it.
            /////
            Thread.Sleep(1000);
        }
        /// <summary>
        ///     Generates the random load.
        /// </summary>
        /// <param name="state">The state.</param>
        private void GenerateRandomLoad(object state)
        {
            int iterationCount = ( int )state;

            Queue <Tuple <long, long, long> > relationship = new Queue <Tuple <long, long, long> >( );

            Dictionary <string, Queue <Tuple <long, long> > > data = new Dictionary <string, Queue <Tuple <long, long> > >( );

            Random random = new Random(Guid.NewGuid( ).GetHashCode( ));

            using (TenantAdministratorContext.SetContext(RunAsDefaultTenant.DefaultTenantName))
                using (DatabaseContext context = DatabaseContext.GetContext(true))
                {
                    for (int iteration = 0; iteration < iterationCount; iteration++)
                    {
                        int val = random.Next(0, 29);

                        /////
                        // Double the likelyhood of inserts. (Cheap way)
                        /////
                        switch (val)
                        {
                        case 0:
                        case 1:
                            CreateEntity(context);
                            break;

                        case 2:
                        case 3:
                            CreateRelationship(context, relationship);
                            break;

                        case 4:
                            DeleteRelationship(context, relationship);
                            break;

                        case 5:
                        case 6:
                            CreateData(context, "Alias", "'optimus'", data, ", Namespace, AliasMarkerId", ", 'core', 0");
                            break;

                        case 7:
                            DeleteData(context, "Alias", data);
                            break;

                        case 8:
                        case 9:
                            CreateData(context, "Bit", "0", data);
                            break;

                        case 10:
                            DeleteData(context, "Bit", data);
                            break;

                        case 11:
                        case 12:
                            CreateData(context, "DateTime", "'2000-01-01'", data);
                            break;

                        case 13:
                            DeleteData(context, "DateTime", data);
                            break;

                        case 14:
                        case 15:
                            CreateData(context, "Decimal", "123", data);
                            break;

                        case 16:
                            DeleteData(context, "Decimal", data);
                            break;

                        case 17:
                        case 18:
                            CreateData(context, "Guid", $"'{Guid.NewGuid( )}'", data);
                            break;

                        case 19:
                            DeleteData(context, "Guid", data);
                            break;

                        case 20:
                        case 21:
                            CreateData(context, "Int", "0", data);
                            break;

                        case 22:
                            DeleteData(context, "Int, data", data);
                            break;

                        case 23:
                        case 24:
                            CreateData(context, "NVarChar", "'Optimus Prime'", data);
                            break;

                        case 25:
                            DeleteData(context, "NVarChar", data);
                            break;

                        case 26:
                        case 27:
                            CreateData(context, "Xml", "'<a></a>'", data);
                            break;

                        case 28:
                            DeleteData(context, "Xml", data);
                            break;
                        }
                    }
                }
        }
        /// <summary>
        ///     Gets the identity providers for the specified tenant.
        /// </summary>
        /// <returns>TenantIdentityProviderResponse.</returns>
        public TenantIdentityProviderResponse GetIdentityProviders(string tenant)
        {
            if (string.IsNullOrWhiteSpace(tenant))
            {
                throw new ArgumentNullException(nameof(tenant));
            }

            var response = new TenantIdentityProviderResponse {
                IdentityProviders = new List <IdentityProviderResponse>()
            };

            using (new SecurityBypassContext())
            {
                TenantAdministratorContext tenantAdminContext;

                try
                {
                    tenantAdminContext = new TenantAdministratorContext(tenant);
                }
                catch (EntityNotFoundException)
                {
                    return(response);
                }

                try
                {
                    var idProviderId = new EntityRef("core:identityProvider");
                    var isOfTypeId   = new EntityRef("core:isOfType");
                    var nameId       = new EntityRef("core:name");
                    var aliasId      = new EntityRef("core:alias");
                    var isEnabledId  = new EntityRef("core:isProviderEnabled");
                    var ordinalId    = new EntityRef("core:providerOrdinal");

                    // Get the identity providers for the given tenant
                    var entityRequest = new EntityRequest
                    {
                        Entities      = idProviderId.ToEnumerable(),
                        RequestString = "name, isProviderEnabled, providerOrdinal, isOfType.alias",
                        Hint          = "tenant ip providers",
                        QueryType     = QueryType.Instances
                    };

                    // Run the query
                    var instances = BulkRequestRunner.GetEntitiesByType(entityRequest);

                    if (instances == null)
                    {
                        return(response);
                    }

                    foreach (var instance in instances)
                    {
                        var    isEnabled = false;
                        string name      = null;
                        var    ordinal   = 0;
                        var    id        = instance.Id.Id;

                        foreach (var fieldData in instance.Fields)
                        {
                            if (fieldData.FieldId == null || fieldData.Value?.Type == null)
                            {
                                continue;
                            }

                            if (fieldData.FieldId.Id == nameId.Id)
                            {
                                name = fieldData.Value.ValueString;
                            }
                            else if (fieldData.FieldId.Id == ordinalId.Id &&
                                     fieldData.Value.Type.GetRunTimeType() == typeof(int) &&
                                     fieldData.Value.Value != null)
                            {
                                ordinal = (int)fieldData.Value.Value;
                            }
                            else if (fieldData.FieldId.Id == isEnabledId.Id &&
                                     fieldData.Value.Type.GetRunTimeType() == typeof(bool) &&
                                     fieldData.Value.Value != null)
                            {
                                isEnabled = (bool)fieldData.Value.Value;
                            }
                        }

                        if (!isEnabled || string.IsNullOrWhiteSpace(name))
                        {
                            continue;
                        }

                        var singleOrDefault =
                            instance.Relationships.SingleOrDefault(r => r.RelationshipTypeId.Id == isOfTypeId.Id);

                        if (singleOrDefault == null)
                        {
                            continue;
                        }

                        var isOfTypeEntityData = singleOrDefault.Entities;

                        var identityProvider = new IdentityProviderResponse
                        {
                            Id      = id,
                            Name    = name,
                            Ordinal = ordinal
                        };

                        if (isOfTypeEntityData != null)
                        {
                            var typeEntity = isOfTypeEntityData.FirstOrDefault();
                            if (typeEntity == null)
                            {
                                continue;
                            }

                            var typeAliasData = typeEntity.Fields.SingleOrDefault(f => f.FieldId.Id == aliasId.Id);

                            if (typeAliasData?.Value != null)
                            {
                                identityProvider.TypeAlias = typeAliasData.Value.ValueString;
                            }
                        }

                        response.IdentityProviders.Add(identityProvider);
                    }
                }
                finally
                {
                    tenantAdminContext.Dispose();
                }
            }

            return(response);
        }