コード例 #1
0
        private List <System.Web.Mvc.SelectListItem> LoadRoles(long?roleId = null, User user = null)
        {
            RoleConfiguration rc    = new RoleConfiguration();
            List <Role>       roles = rc.GetAllRoles();
            List <System.Web.Mvc.SelectListItem> result = new List <SelectListItem>();

            foreach (var item in roles)
            {
                bool isSelected = false;
                if (user != null && roleId.HasValue)
                {
                    isSelected = (user.RoleId == roleId);
                }

                SelectListItem sl = new SelectListItem()
                {
                    Value    = item.RoleId.ToString(),
                    Text     = item.Name,
                    Selected = isSelected
                };

                result.Add(sl);
            }

            return(result);
        }
コード例 #2
0
 protected override void Seed(ngSecurity.Server.Data.DbContext context)
 {
     context.Database.Delete();
     context.Database.CreateIfNotExists();
     RoleConfiguration.Seed(context);
     UserConfiguration.Seed(context);
 }
コード例 #3
0
 public Role(RoleConfiguration role)
 {
     Config      = role;
     State       = Config.EnabledOnStartup ? new AutoStarting(this) : (IState) new Stopped(this);
     _dispatcher = Dispatcher.CurrentDispatcher;
     _logs       = new ObservableCollection <FifoLog>();
 }
コード例 #4
0
 public static void Initialize(IDblDipDbContext context, IEventStore store, IConfiguration configuration)
 {
     RoleConfiguration.Seed(store);
     SystemLocationConfiguration.Seed(store, configuration);
     CardConfiguration.Seed(store, context);
     UserConfiguration.Seed(context, store);
     DashboardConfiguration.Seed(context, store);
 }
コード例 #5
0
ファイル: DbInitializer.cs プロジェクト: lulzzz/DblDip
 public static void Initialize(IAppDbContext context, IConfiguration configuration)
 {
     RoleConfiguration.Seed(context, configuration);
     SystemLocationConfiguration.Seed(context, configuration);
     CardConfiguration.Seed(context, configuration);
     UserConfiguration.Seed(context, configuration);
     DashboardConfiguration.Seed(context, configuration);
 }
コード例 #6
0
 protected override void Seed(ECommerceAppContext context)
 {
     TenantConfiguration.Seed(context);
     CategoryConfiguration.Seed(context);
     RoleConfiguration.Seed(context);
     UserConfiguration.Seed(context);
     ProductConfiguration.Seed(context);
 }
コード例 #7
0
 public static void Seed(AppDbContext context)
 {
     ProfileTypeConfiguration.Seed(context);
     RoleConfiguration.Seed(context);
     UserConfiguration.Seed(context);
     OrderStatusesConfiguration.Seed(context);
     ProductConfiguration.Seed(context);
     context.SaveChanges();
 }
コード例 #8
0
    /// <summary>
    ///   Runs all of the roles designated for this scenario. If this is a single-role instance, only one role is run, otherwise all roles
    ///   are run in parallel.
    /// </summary>
    ///
    /// <param name="roleList">The list of roles needed for the scenario being run.</param>
    /// <param name="testConfiguration">The <see cref="TestConfiguration" /> instance used to configure this test scenario run.</param>
    /// <param name="roleConfiguration">The <see cref="RoleConfiguration" /> instance used to configure the role being run.</param>
    /// <param name="metrics">The <see cref="Metrics" /> instance used by this role to send metrics to application insights.</param>
    /// <param name="testName">The name of the test scenario that is being run, for metrics purposes.</param>
    /// <param name="cancellationToken">The <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
    ///
    private static async Task RunScenario(List <string> roleList,
                                          TestConfiguration testConfiguration,
                                          RoleConfiguration roleConfiguration,
                                          Metrics metrics,
                                          string roleString,
                                          string testName,
                                          CancellationToken cancellationToken)
    {
        var scenarioTasks = new List <Task>();

        try
        {
            // This means the job index environment variable was not set, so run all roles for this scenario in parallel.
            if (string.IsNullOrEmpty(roleString))
            {
                foreach (var role in roleList)
                {
                    scenarioTasks.Add(RunRole(role, testConfiguration, roleConfiguration, metrics, testName, cancellationToken));
                }
            }
            else
            {
                scenarioTasks.Add(RunRole(roleList[int.Parse(roleString)], testConfiguration, roleConfiguration, metrics, testName, cancellationToken));
            }

            while (!cancellationToken.IsCancellationRequested)
            {
                UpdateEnvironmentStatistics(metrics);

                await Task.Delay(TimeSpan.FromMinutes(5), cancellationToken).ConfigureAwait(false);
            }

            await Task.WhenAll(scenarioTasks).ConfigureAwait(false);
        }
        catch (TaskCanceledException)
        {
            // Run is complete
        }
        catch (Exception ex) when
            (ex is OutOfMemoryException ||
            ex is StackOverflowException ||
            ex is ThreadAbortException)
        {
            throw;
        }
        catch (Exception ex)
        {
            metrics.Client.TrackException(ex);
        }
        finally
        {
            metrics.Client.Flush();
            await Task.Delay(60000).ConfigureAwait(false);
        }
    }
コード例 #9
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            ExaminationConfiguration.Configure(builder);
            UserConfiguration.Configure(builder);
            RoleConfiguration.Configure(builder);
            ExaminationDetailsDetailsConfiguration.Configure(builder);
            QuestionUserAnswerConfiguration.Configure(builder);
            PossibleAnswerSelectedConfiguration.Configure(builder);

            BuildQuestion(builder);
            BuildTest(builder);

            base.OnModelCreating(builder);
        }
コード例 #10
0
        public DTO.RoleConfiguration Execute(RoleConfiguration roleConfiguration)
        {
            var roleConfigurationDto = TypeAdapter.Adapt <DTO.RoleConfiguration>(roleConfiguration);
            var role = _roleRepository.FindBy(roleConfiguration.RoleId);

            roleConfigurationDto.Role = TypeAdapter.Adapt <DTO.Role>(role);
            var permission = _permissionRepository.FindBy(roleConfiguration.PermissionId);

            roleConfigurationDto.Permission = TypeAdapter.Adapt <DTO.Permission>(permission);
            var accessLevel = _accessLevelRepository.FindBy(roleConfiguration.AccessLevelId);

            roleConfigurationDto.AccessLevel = TypeAdapter.Adapt <DTO.AccessLevel>(accessLevel);
            return(roleConfigurationDto);
        }
コード例 #11
0
ファイル: WebConfigHelper.cs プロジェクト: sycomix/LightBlue
        public static WebHostArgs Create(RoleConfiguration config)
        {
            var assembly = config.Assembly;
            var args     = new WebHostArgs
            {
                Assembly          = assembly,
                Port              = int.Parse(config.Port),
                RoleName          = config.RoleName,
                Title             = config.Title,
                ConfigurationPath = ConfigurationLocator.LocateConfigurationFile(config.ConfigurationPath),
                UseSsl            = bool.Parse(config.UseSsl),
                Hostname          = config.Hostname,
                UseHostedStorage  = false,
                Use64Bit          = false,
            };

            return(args);
        }
コード例 #12
0
        private static void AddRoleConfigurations(
            Dictionary <string, RoleConfiguration> roleNameToPropertiesMapping,
            List <ServiceConfigurationRole> roles,
            List <ServiceConfigurationRoleCertificate> certificates,
            ServiceConfigurationRoleSecurityConfigurations securityConfigurations,
            List <ServiceConfigurationNetworkConfigurationAddressAssignmentsInstanceAddress> roleInstanceAddresses,
            string subnetName)
        {
            foreach (string roleName in roleNameToPropertiesMapping.Keys)
            {
                RoleConfiguration roleConfiguration             = roleNameToPropertiesMapping[roleName];
                ServiceConfigurationRoleSetting[] settingsArray = roleConfiguration.Settings.Keys.Select(key => new ServiceConfigurationRoleSetting {
                    name = key, value = roleConfiguration.Settings[key]
                }).ToArray();

                // Add Configuration for each role
                roles.Add(new ServiceConfigurationRole()
                {
                    name      = roleName,
                    Instances = new ServiceConfigurationRoleInstances()
                    {
                        count = roleConfiguration.InstanceCount.ToString()
                    },
                    // Note: For now these settings and certificates are same for all roles.
                    // They can be handled later as we add support for other scenarios.
                    ConfigurationSettings  = settingsArray,
                    Certificates           = certificates?.ToArray(),
                    SecurityConfigurations = securityConfigurations
                });

                // Add the required subnet for each role
                roleInstanceAddresses.Add(new ServiceConfigurationNetworkConfigurationAddressAssignmentsInstanceAddress()
                {
                    roleName = roleName,
                    Subnets  = new ServiceConfigurationNetworkConfigurationAddressAssignmentsInstanceAddressSubnets()
                    {
                        Subnet = new ServiceConfigurationNetworkConfigurationAddressAssignmentsInstanceAddressSubnetsSubnet()
                        {
                            name = subnetName
                        }
                    }
                });
            }
        }
コード例 #13
0
    /// <summary>
    ///   Starts a background task for each test that needs to be run, and waits for all
    ///   test runs to completed before returning.
    /// </summary>
    ///
    /// <param name="roleList">The list of roles needed for the scenario being run.</param>
    /// <param name="testConfiguration">The <see cref="TestConfiguration" /> instance used to configure this test scenario run.</param>
    /// <param name="roleConfiguration">The <see cref="RoleConfiguration" /> instance used to configure the role being run.</param>
    /// <param name="metrics">The <see cref="Metrics" /> instance used by this role to send metrics to application insights.</param>
    /// <param name="testName">The name of the test scenario that is being run, for metrics purposes.</param>
    /// <param name="cancellationToken">The <see cref="CancellationToke"/> instance to signal the request to cancel the operation.</param>
    ///
    private static async Task RunRole(string role,
                                      TestConfiguration testConfiguration,
                                      RoleConfiguration roleConfiguration,
                                      Metrics metrics,
                                      string testName,
                                      CancellationToken cancellationToken)
    {
        if (role == RoleConfiguration.Publisher)
        {
            var publisherConfiguration = new PublisherConfiguration();
            var publisher = new Publisher(publisherConfiguration, testConfiguration, metrics, testName);
            await publisher.Start(cancellationToken);
        }

        if (role == RoleConfiguration.BufferedPublisher)
        {
            var publisherConfiguration = new BufferedPublisherConfiguration();
            var publisher = new BufferedPublisher(testConfiguration, publisherConfiguration, metrics, testName);
            await publisher.Start(cancellationToken);
        }

        if (role == RoleConfiguration.Processor)
        {
            var partitionCount = _getPartitionCount(testConfiguration.EventHubsConnectionString, testConfiguration.EventHub);
            await partitionCount.ConfigureAwait(false);

            var processConfiguration = new ProcessorConfiguration();
            var processor            = new Processor(testConfiguration, processConfiguration, metrics, partitionCount.Result, testName);
            await processor.Start(cancellationToken);
        }

        if (role == RoleConfiguration.BurstBufferedPublisher)
        {
            var publisherConfiguration = new BufferedPublisherConfiguration();
            publisherConfiguration.ProducerPublishingDelay = TimeSpan.FromMinutes(25);
            var publisher = new BufferedPublisher(testConfiguration, publisherConfiguration, metrics, testName);
            await publisher.Start(cancellationToken);
        }

        //return Task.CompletedTask;
        await Task.Delay(TimeSpan.FromSeconds(1));
    }
コード例 #14
0
 private static string LoadExpectedApiKey()
 {
     RoleConfiguration.ThrowIfUnavailable();
     return(RoleEnvironment.GetConfigurationSettingValue("ApiKey"));
 }
コード例 #15
0
 public static void Seed(PhysicianLookupDbContext context, IConfiguration configuration)
 {
     RoleConfiguration.Seed(context);
     PhysicianConfiguration.Seed(context);
     UserConfiguration.Seed(context, configuration);
 }
コード例 #16
0
 public void Add(RoleConfiguration item)
 {
     _auditEventListener.OnPreInsert(item);
     _dataBaseSqlServerOrmLite.Insert(item);
 }
コード例 #17
0
 public void Update(RoleConfiguration item)
 {
     _auditEventListener.OnPreUpdate(item);
     _dataBaseSqlServerOrmLite.Update(item);
 }
コード例 #18
0
 public void Remove(RoleConfiguration item)
 {
     _dataBaseSqlServerOrmLite.Remove(item);
 }
コード例 #19
0
    /// <summary>
    ///   Starts a background task for each test and role that needs to be run in this process, and waits for all
    ///   test runs to completed before finishing the run.
    /// </summary>
    ///
    /// <param name="opts">The parsed command line inputs.</param>
    ///
    private static async Task RunOptions(Options opts)
    {
        // See if there are environment variables available to use in the .env file
        var environment               = new Dictionary <string, string>();
        var appInsightsKey            = String.Empty;
        var eventHubsConnectionString = String.Empty;

        var environmentFile = Environment.GetEnvironmentVariable("ENV_FILE");

        if (!(string.IsNullOrEmpty(environmentFile)))
        {
            environment = EnvironmentReader.LoadFromFile(environmentFile);
        }

        environment.TryGetValue(EnvironmentVariables.ApplicationInsightsKey, out appInsightsKey);
        environment.TryGetValue(EnvironmentVariables.EventHubsConnectionString, out eventHubsConnectionString);

        // If not, and this is an interactive run, try and get them from the user.

        eventHubsConnectionString = PromptForResources("Event Hubs Connection String", "all test runs", eventHubsConnectionString, opts.Interactive);
        appInsightsKey            = PromptForResources("Application Insights Instrumentation Key", "all test runs", appInsightsKey, opts.Interactive);

        // If a job index is provided, a single role is started, otherwise, all specified roles within the
        // test scenario runs are run in parallel.

        var roleConfiguration = new RoleConfiguration();
        var testScenarioTasks = new List <Task>();
        var metrics           = new Metrics(appInsightsKey);

        var testConfiguration = new TestConfiguration();

        testConfiguration.EventHubsConnectionString = eventHubsConnectionString;

        var cancellationSource = new CancellationTokenSource();
        var runDuration        = TimeSpan.FromHours(testConfiguration.DurationInHours);

        cancellationSource.CancelAfter(runDuration);

        using var azureEventListener = new AzureEventSourceListener((args, level) => metrics.Client.TrackTrace($"EventWritten: {args.ToString()} Level: {level}."), EventLevel.Warning);

        // If running the Event Producer Test scenario, gather resources and add a scenario run to the task list.
        if (opts.Test == RoleConfiguration.EventProducerTest || opts.Test == RoleConfiguration.EventProducerTestShort || opts.All)
        {
            // Get the needed resources for the event producer test: an event hub
            var eventHubName = String.Empty;
            environment.TryGetValue(EnvironmentVariables.EventHubEventProducerTest, out eventHubName);
            eventHubName = PromptForResources("Event Hub", RoleConfiguration.EventProducerTest, eventHubName, opts.Interactive);
            testConfiguration.EventHub = eventHubName;

            roleConfiguration.TestScenarioRoles.TryGetValue(RoleConfiguration.EventProducerTest, out var roleList);
            testScenarioTasks.Add(RunScenario(roleList, testConfiguration, roleConfiguration, metrics, opts.Role, RoleConfiguration.EventProducerTest, cancellationSource.Token));
        }

        // If running the Buffered Producer Test scenario, gather resources and add a scenario run to the task list.
        if (opts.Test == RoleConfiguration.BufferedProducerTest || opts.Test == RoleConfiguration.BufferedProducerTestShort || opts.All)
        {
            // Get the needed resources for the buffered producer test: an event hub
            var eventHubName = String.Empty;
            environment.TryGetValue(EnvironmentVariables.EventHubBufferedProducerTest, out eventHubName);
            eventHubName = PromptForResources("Event Hub", RoleConfiguration.BufferedProducerTest, eventHubName, opts.Interactive);
            testConfiguration.EventHub = eventHubName;

            roleConfiguration.TestScenarioRoles.TryGetValue(RoleConfiguration.BufferedProducerTest, out var roleList);
            testScenarioTasks.Add(RunScenario(roleList, testConfiguration, roleConfiguration, metrics, opts.Role, RoleConfiguration.BufferedProducerTest, cancellationSource.Token));
        }

        // If running the Burst Buffered Producer Test scenario, gather resources and add a scenario run to the task list.
        if (opts.Test == RoleConfiguration.BurstBufferedProducerTest || opts.Test == RoleConfiguration.BurstBufferedProducerTestShort || opts.All)
        {
            // Get the needed resources for the buffered producer test: an event hub
            var eventHubName = String.Empty;
            environment.TryGetValue(EnvironmentVariables.EventHubBurstBufferedProducerTest, out eventHubName);
            eventHubName = PromptForResources("Event Hub", "Burst Buffered Producer Test", eventHubName, opts.Interactive);
            testConfiguration.EventHub = eventHubName;

            roleConfiguration.TestScenarioRoles.TryGetValue(RoleConfiguration.BurstBufferedProducerTest, out var roleList);
            testScenarioTasks.Add(RunScenario(roleList, testConfiguration, roleConfiguration, metrics, opts.Role, RoleConfiguration.BurstBufferedProducerTest, cancellationSource.Token));
        }

        // If running the Processor Test scenario, gather resources and add a scenario run to the task list.
        if (opts.Test == RoleConfiguration.EventProcessorTest || opts.Test == RoleConfiguration.EventProcessorTestShort || opts.All)
        {
            // Get the needed resources for the processor test: an event hub, storage account, and blob container name
            var eventHubName            = String.Empty;
            var storageBlob             = String.Empty;
            var storageConnectionString = String.Empty;
            environment.TryGetValue(EnvironmentVariables.EventHubProcessorTest, out eventHubName);
            eventHubName = PromptForResources("Event Hub", RoleConfiguration.EventProcessorTest, eventHubName, opts.Interactive);
            testConfiguration.EventHub = eventHubName;

            environment.TryGetValue(EnvironmentVariables.StorageBlobProcessorTest, out storageBlob);
            storageBlob = PromptForResources("Storage Blob Name", RoleConfiguration.EventProcessorTest, storageBlob, opts.Interactive);
            testConfiguration.BlobContainer = storageBlob;

            environment.TryGetValue(EnvironmentVariables.StorageAccountProcessorTest, out storageConnectionString);
            storageConnectionString = PromptForResources("Storage Account Connection String", RoleConfiguration.EventProcessorTest, storageConnectionString, opts.Interactive);
            testConfiguration.StorageConnectionString = storageConnectionString;

            roleConfiguration.TestScenarioRoles.TryGetValue(RoleConfiguration.EventProcessorTest, out var roleList);
            testScenarioTasks.Add(RunScenario(roleList, testConfiguration, roleConfiguration, metrics, opts.Role, RoleConfiguration.BurstBufferedProducerTest, cancellationSource.Token));
        }

        // Wait for all scenario runs to finish before returning.
        await Task.WhenAll(testScenarioTasks).ConfigureAwait(false);
    }