internal static UdpBindingCollectionElement GetBindingCollectionElement()
 {
     return((UdpBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement(UdpTransportConfigurationStrings.UdpBindingElementName));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Override to add registrations to the container.
        /// </summary>
        /// <param name="builder">The builder through which components can be registered.</param>
        /// <remarks>
        /// Note that the ContainerBuilder parameter is not the same one
        /// that the module is being registered by (i.e. it can have its own defaults).
        /// </remarks>
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            // Register the global application objects
            {
                builder.Register(c => new DependencyInjectionProxy(
                                     c.Resolve <IContainer>()))
                .As <IDependencyInjectionProxy>();

                builder.Register(c => new FeedbackReportCollector(
                                     c.Resolve <IFileSystem>()))
                .As <ICollectFeedbackReports>();

                builder.Register(c => new FeedbackReportTransmitter(
                                     c.Resolve <IReportSender>()))
                .As <ISendFeedbackReports>();

                builder.Register(c => new TimingReportCollection())
                .SingleInstance();

                builder.Register(
                    c =>
                {
                    Func <string, IDisposable> result = description => null;
                    if (ConfigurationHelpers.ShouldBeProfiling())
                    {
                        // Autofac 2.4.5 forces the 'c' variable to disappear. See here:
                        // http://stackoverflow.com/questions/5383888/autofac-registration-issue-in-release-v2-4-5-724
                        var ctx = c.Resolve <IComponentContext>();
                        Func <TimingReport, string> reportBuilder =
                            report =>
                        {
                            var stream = new MemoryStream();
                            Func <Stream> streamFactory = () => stream;
                            var transformer             = ctx.Resolve <TextReporter>(
                                new Autofac.Core.Parameter[]
                            {
                                new TypedParameter(typeof(Func <Stream>), streamFactory)
                            });
                            transformer.Transform(report);

                            // normally you can't touch the stream anymore, but it turns out you
                            // can touch the actual buffer
                            var buffer       = stream.GetBuffer();
                            var outputString = Encoding.Unicode.GetString(buffer, 0, buffer.Length);

                            // Note that the result may have terminating characters, multiple of them
                            // because we don't know the amount of data written to the buffer.
                            return(outputString.Replace("\0", string.Empty));
                        };

                        result =
                            description =>
                            new TimingIntervalHelper(
                                ctx.Resolve <SystemDiagnostics>(),
                                ctx.Resolve <IGenerateTimingReports>(),
                                ctx.Resolve <TimingReportCollection>(),
                                reportBuilder,
                                description);
                    }

                    return(result);
                })
                .SingleInstance();

                builder.Register(c => new FileSystem())
                .As <IFileSystem>();
            }
        }
Exemplo n.º 3
0
        private static ITaskProcessorClientConfiguration GetClientConfiguration(string configFileName)
        {
            string configFilePath = Path.Combine("Configuration", "Client", configFileName + ".config");

            return(ConfigurationHelpers.Load <ClientConfigurationSection>(ClientConfigurationSection.SectionName, configFilePath));
        }
 internal static NetMsmqBindingCollectionElement GetBindingCollectionElement()
 {
     return((NetMsmqBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement("netMsmqBinding"));
 }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            Console.WriteLine("=======================================================================");
            Console.WriteLine(AssemblyInformationHelper.HeaderMessage);
            Console.WriteLine("=======================================================================");
            Console.WriteLine(">> Loading configurations....");

            try
            {
                //Configuration
                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                              .AddJsonFile("devicesettings.json", optional: false, reloadOnChange: true)
                              .AddJsonFile("modulessettings.json", optional: true, reloadOnChange: true)
                              .AddEnvironmentVariables();

                _environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");

                if (string.IsNullOrWhiteSpace(_environmentName))
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("No environment platform has been found. Default setting: Development.");
                    _environmentName = "Development";
                    Console.ResetColor();
                }

                try
                {
                    ConfigurationHelpers.CheckEnvironmentConfigurationFiles(_environmentName);
                }
                catch (MissingEnvironmentConfigurationFileException ex)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(ex.Message);
                    Console.ResetColor();
                    Console.WriteLine("Execution will continue with default settings in appsettings.json, devicesettings.json and modulessettings.json.");
                }

                builder.AddJsonFile($"appsettings.{_environmentName}.json", optional: true, reloadOnChange: true);
                builder.AddJsonFile($"devicesettings.{_environmentName}.json", optional: true, reloadOnChange: true);
                builder.AddJsonFile($"modulessettings.{_environmentName}.json", optional: true, reloadOnChange: true);


                Configuration = builder.Build();

                //Service provider and DI
                IServiceCollection services = new ServiceCollection();

                ConfigureServices(services);

                var deviceSettings = Configuration.Get <DeviceSettings>();
                if (deviceSettings == null)
                {
                    throw new ArgumentException("No device settings have been configured.");
                }

                if (deviceSettings.SimulationSettings == null)
                {
                    throw new ArgumentException("No device simulation settings have been configured.");
                }

                if (deviceSettings.SimulationSettings.EnableDevice || deviceSettings.SimulationSettings.EnableModules)
                {
                    //If any of the simulators is enabled, messaging services will be required to build the messages.
                    RegisterMessagingServices(services);
                }

                if (deviceSettings.SimulationSettings.EnableDevice)
                {
                    RegisterDeviceSimulators(services);
                }

                if (deviceSettings.SimulationSettings.EnableModules)
                {
                    RegisterModuleSimulators(deviceSettings, services);
                }

                IServiceProvider serviceProvider = services.BuildServiceProvider();

                //Logger
                var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger <Program>();
                logger.LogDebug("PROGRAM::Settings, DI and logger configured and ready to use.");

                //Simulators
                if (!deviceSettings.SimulationSettings.EnableDevice && !deviceSettings.SimulationSettings.EnableModules)
                {
                    logger.LogDebug("PROGRAM::No simulator has been configured.");
                }
                else
                {
                    if (deviceSettings.SimulationSettings.EnableDevice)
                    {
                        StartDevicesSimulators(serviceProvider, logger);
                    }

                    if (deviceSettings.SimulationSettings.EnableModules)
                    {
                        StartModulesSimulators(serviceProvider, logger);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
            }
            finally
            {
                Console.ReadLine();
            }
        }
Exemplo n.º 6
0
        public async Task InitiateSimulationAsync()
        {
            string logPrefix = "system".BuildLogPrefix();


            //Connectivity tests
            //Control if a connection string exists (ideally, stored in TPM/HSM or any secured location.
            //If there is no connection string, check if the DPS settings are provided.
            //If so, provision the device and persist the connection string for upcoming boots.
            if (string.IsNullOrEmpty(_deviceSettingsDelegate.CurrentValue.ConnectionString))
            {
                string connectionString = await _provisioningService.ProvisionDevice();

                if (!string.IsNullOrEmpty(connectionString))
                {
                    _deviceSettingsDelegate.CurrentValue.ConnectionString = connectionString;
                }
                else
                {
                    throw new Exception($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::An issue occured during the provisioning process or the connetion string building process.");
                }

                _logger.LogWarning($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Device connection string being persisted.");
                await ConfigurationHelpers.WriteDeviceSettings(_deviceSettingsDelegate.CurrentValue, _environmentName);
            }

            //At this stage, the connection string should be set properly and the device client should be able to communicate with the IoT Hub with no issues.
            try
            {
                IoTTools.CheckDeviceConnectionStringData(_deviceSettingsDelegate.CurrentValue.ConnectionString, _logger);

                // Connect to the IoT hub using the MQTT protocol
                if (_dpsSettings.GroupEnrollment != null)
                {
                    if (_dpsSettings.GroupEnrollment.SecurityType == SecurityType.SymmetricKey)
                    {
                        _deviceClient = DeviceClient.CreateFromConnectionString(
                            _deviceSettingsDelegate.CurrentValue.ConnectionString,
                            _dpsSettings.GroupEnrollment.SymmetricKeySettings.TransportType);
                    }
                    else if (_dpsSettings.GroupEnrollment.SecurityType == SecurityType.X509CA)
                    {
                        string           deviceCertificateFullPath         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _dpsSettings.GroupEnrollment.CAX509Settings.DeviceX509Path);
                        X509Certificate2 deviceLeafProvisioningCertificate = new X509Certificate2(deviceCertificateFullPath, _dpsSettings.GroupEnrollment.CAX509Settings.Password);

                        IAuthenticationMethod auth = new DeviceAuthenticationWithX509Certificate(_deviceSettingsDelegate.CurrentValue.DeviceId, deviceLeafProvisioningCertificate);

                        _deviceClient = DeviceClient.Create(_deviceSettingsDelegate.CurrentValue.HostName, auth, _dpsSettings.GroupEnrollment.CAX509Settings.TransportType);
                    }
                    else
                    {
                        _logger.LogError($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Feature not implemented.");
                    }

                    _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Device client created.");

                    if (_simulationSettings.EnableTwinPropertiesDesiredChangesNotifications)
                    {
                        await _deviceClient.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChange, null);

                        _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Twin Desired Properties update callback handler registered.");
                    }

                    //Configuration
                    if (_simulationSettings.EnableC2DDirectMethods)
                    {
                        //Register C2D Direct methods handlers
                        await RegisterC2DDirectMethodsHandlersAsync();
                    }

                    if (_simulationSettings.EnableC2DMessages)
                    {
                        //Start receiving C2D messages
                        ReceiveC2DMessagesAsync();
                    }

                    //Messages
                    if (_simulationSettings.EnableLatencyTests)
                    {
                        SendDeviceToCloudLatencyTestAsync(_deviceSettingsDelegate.CurrentValue.DeviceId, _simulationSettings.LatencyTestsFrecuency);
                    }

                    if (_simulationSettings.EnableTelemetryMessages)
                    {
                        SendDeviceToCloudMessagesAsync(_deviceSettingsDelegate.CurrentValue.DeviceId); //interval is a global variable changed by processes
                    }
                    if (_simulationSettings.EnableErrorMessages)
                    {
                        SendDeviceToCloudErrorAsync(_deviceSettingsDelegate.CurrentValue.DeviceId, _simulationSettings.ErrorFrecuency);
                    }

                    if (_simulationSettings.EnableCommissioningMessages)
                    {
                        SendDeviceToCloudCommissioningAsync(_deviceSettingsDelegate.CurrentValue.DeviceId, _simulationSettings.CommissioningFrecuency);
                    }

                    if (_simulationSettings.EnableReadingTwinProperties)
                    {
                        //Twins
                        _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::INITIALIZATION::Retrieving twin.");
                        Twin twin = await _deviceClient.GetTwinAsync();

                        if (twin != null)
                        {
                            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::INITIALIZATION::Device twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}.");
                        }
                        else
                        {
                            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::INITIALIZATION::No device twin.");
                        }
                    }

                    if (_simulationSettings.EnableFileUpload)
                    {
                        throw new NotImplementedException("File upload feature has not been implemented yet.");
                    }

                    _deviceClient.SetConnectionStatusChangesHandler(new ConnectionStatusChangesHandler(ConnectionStatusChanged));
                }
                else
                {
                    _logger.LogWarning($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::No enrollment group has been found.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::ERROR::InitiateSimulationAsync:{ex.Message}.");
            }
        }
 internal static BasicHttpBindingCollectionElement GetBindingCollectionElement()
 {
     return((BasicHttpBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement("basicHttpBinding"));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public TestHarness(BuildXLContext context, AbsolutePath configFile)
 {
     m_context     = context;
     Configuration = ConfigurationHelpers.GetDefaultForTesting(context.PathTable, configFile);
 }
Exemplo n.º 9
0
        private static async Task <bool> CreateAndRunPip(
            PipProgram program,
            string tempDirectory,
            string outFile,
            IEnumerable <string> restInstructions,
            bool is64Bit)
        {
            Contract.Requires(restInstructions != null);
            Contract.Requires(tempDirectory != null);
            Contract.Requires(!string.IsNullOrEmpty(outFile));

            BuildXLContext context = BuildXLContext.CreateInstanceForTesting();

            using (var fileAccessListener = new FileAccessListener(Events.Log))
            {
                fileAccessListener.RegisterEventSource(BuildXL.Processes.ETWLogger.Log);

                var loggingContext   = BuildXLTestBase.CreateLoggingContextForTest();
                var fileContentTable = FileContentTable.CreateNew(loggingContext);
                var config           = ConfigurationHelpers.GetDefaultForTesting(context.PathTable, AbsolutePath.Create(context.PathTable, Path.Combine(tempDirectory, "config.dc")));
                config.Sandbox.LogObservedFileAccesses = true;

                Pip pip = null;

                var instructions = restInstructions as string[] ?? restInstructions.ToArray();

                switch (program)
                {
                case PipProgram.Cmd:
                    pip = CreateCmdPip(context, tempDirectory, outFile, is64Bit);
                    break;

                case PipProgram.Self:
                    pip = CreateSelfPip(context, tempDirectory, outFile, instructions, is64Bit);
                    break;
                }

                Contract.Assume(pip != null);

                var isSubstUsed = FileUtilities.TryGetSubstSourceAndTarget(tempDirectory, out var substSource, out var substTarget, out var errorMessage);
                XAssert.IsFalse(!isSubstUsed && errorMessage != null, errorMessage);

                PipResult executeResult = await Execute(
                    context,
                    fileContentTable,
                    config,
                    pip,
                    isSubstUsed
                    ?(substSource, substTarget)
                    : default((string, string)?));

                bool valid = false;

                switch (program)
                {
                case PipProgram.Cmd:
                    valid = ValidateCmd(fileAccessListener.FileAccesses, outFile, is64Bit);
                    break;

                case PipProgram.Self:
                    valid = ValidateSelf(
                        fileAccessListener.FileAccesses,
                        instructions.Length > 0 ? instructions[0] : string.Empty,
                        outFile,
                        is64Bit);
                    break;
                }

                return(executeResult.Status == PipResultStatus.Succeeded && valid);
            }
        }
Exemplo n.º 10
0
 public void Initialize()
 {
     ConfigurationHelpers.ConfigureNet45();
 }
        public async Task InitiateSimulationAsync()
        {
            string logPrefix = "system".BuildLogPrefix();

            try
            {
                //Connectivity tests
                //Control if a connection string exists (ideally, stored in TPM/HSM or any secured location.
                //If there is no connection string, check if the DPS settings are provided.
                //If so, provision the device and persist the connection string for upcoming boots.
                if (string.IsNullOrEmpty(ModuleSettings.ConnectionString))
                {
                    ModuleSettings.ConnectionString = await _provisioningService.AddModuleIdentityToDevice(ModuleSettings.ModuleId);

                    if (string.IsNullOrEmpty(ModuleSettings.ConnectionString))
                    {
                        _logger.LogWarning($"{logPrefix}::{ModuleSettings.ArtifactId}::No module connection string has been created.");
                    }
                    else
                    {
                        _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Module connection string being persisted.");
                        await ConfigurationHelpers.WriteModulesSettings(ModuleSettings, _environmentName);
                    }
                }

                IoTTools.CheckModuleConnectionStringData(ModuleSettings.ConnectionString, _logger);

                // Connect to the IoT hub using the MQTT protocol
                _moduleClient = ModuleClient.CreateFromConnectionString(ModuleSettings.ConnectionString, Microsoft.Azure.Devices.Client.TransportType.Mqtt);
                _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Module client created.");

                if (SimulationSettings.EnableTwinPropertiesDesiredChangesNotifications)
                {
                    await _moduleClient.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChange, null);

                    _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Twin Desired Properties update callback handler registered.");
                }

                //Configuration
                if (SimulationSettings.EnableC2DDirectMethods)
                {
                    //Register C2D Direct methods handlers
                    await RegisterC2DDirectMethodsHandlersAsync(_moduleClient, ModuleSettings, _logger);
                }

                if (SimulationSettings.EnableC2DMessages)
                {
                    //Start receiving C2D messages

                    ReceiveC2DMessagesAsync(_moduleClient, ModuleSettings, _logger);
                }

                //Messages
                if (SimulationSettings.EnableTelemetryMessages)
                {
                    SendDeviceToCloudMessagesAsync(_moduleClient, ModuleSettings.DeviceId, ModuleSettings.ModuleId, _logger); //interval is a global variable changed by processes
                }
                if (SimulationSettings.EnableErrorMessages)
                {
                    SendDeviceToCloudErrorAsync(_moduleClient, ModuleSettings.DeviceId, ModuleSettings.ModuleId, SimulationSettings.ErrorFrecuency, _logger);
                }

                if (SimulationSettings.EnableCommissioningMessages)
                {
                    SendDeviceToCloudCommissioningAsync(_moduleClient, ModuleSettings.DeviceId, ModuleSettings.ModuleId, SimulationSettings.CommissioningFrecuency, _logger);
                }

                if (SimulationSettings.EnableReadingTwinProperties)
                {
                    //Twins
                    _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::INITIALIZATION::Retrieving twin.");
                    Twin twin = await _moduleClient.GetTwinAsync();

                    if (twin != null)
                    {
                        _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::INITIALIZATION::Device twin: {JsonConvert.SerializeObject(twin, Formatting.Indented)}.");
                    }
                    else
                    {
                        _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::INITIALIZATION::No device twin.");
                    }
                }

                _moduleClient.SetConnectionStatusChangesHandler(new ConnectionStatusChangesHandler(ConnectionStatusChanged));
            }
            catch (ConnectionStringException ex)
            {
                _logger.LogError($"{logPrefix}::{ModuleSettings.ArtifactId}::ConnectionStringException:{ex.Message}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"{logPrefix}::{ModuleSettings.ArtifactId}::{ex.Message}");
            }
        }
 internal static NetHttpsBindingCollectionElement GetBindingCollectionElement()
 {
     return((NetHttpsBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement(ConfigurationStrings.NetHttpsBindingCollectionElementName));
 }
Exemplo n.º 13
0
 static ConnectivityModeHelper()
 {
     ConnectivityModeHelper.OverrideInternalConnectivityMode = ConfigurationHelpers.GetOverrideConnectivityMode();
 }
        public async Task <TokenIssueResponse> IssueToken(TokenIssueRequest request)
        {
            // Login to CaaS
            IAccount account = await _computeClient.LoginAsync(
                new NetworkCredential(
                    request.Message.Credentials.UserName,
                    request.Message.Credentials.Password));

            // Get available clouds
            IEnumerable <DatacenterWithMaintenanceStatusType> dataCenters =
                await _computeClient.GetDataCentersWithMaintenanceStatuses();

            string loginToken = request.Message.Credentials.UserName + ":" + request.Message.Credentials.Password;

            byte[] buffer            = new byte[loginToken.Length];
            string loginTokenEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(loginToken));

            List <Endpoint> endPoints = new List <Endpoint>();

            endPoints.Add(new Endpoint()
            {
                Url         = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                Id          = "AU1",                // TODO: Map to cloud id?
                InternalURL = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                PublicURL   = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                Region      = "RegionOne"
            });
            foreach (var dataCenter in dataCenters)
            {
                endPoints.Add(new Endpoint()
                {
                    Url         = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                    Id          = dataCenter.location,            // TODO: Map to cloud id?
                    InternalURL = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                    PublicURL   = ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName),
                    Region      = "Dimension Data " + dataCenter.displayName
                });
            }

            TokenIssueResponse response = new TokenIssueResponse()
            {
                AccessToken = new AccessToken()
                {
                    Token   = new Token(request.Message.TenantName, request.Message.TenantName, loginTokenEncoded),
                    Catalog = new ServiceCatalogEntry[]
                    {
                        new ServiceCatalogEntry()
                        {
                            Endpoints      = endPoints.ToArray(),
                            EndpointsLinks = new string[]
                            {
                                ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName)
                            },
                            Name = "nova",
                            Type = EndpointType.compute
                        },
                        new ServiceCatalogEntry()
                        {
                            Endpoints      = endPoints.ToArray(),
                            EndpointsLinks = new string[]
                            {
                                ConfigurationHelpers.GetTenantUrl(Request.RequestUri.Host, request.Message.TenantName)
                            },
                            Name = "keystone",
                            Type = EndpointType.identity
                        }
                    },
                    User = new User()
                    {
                        Id         = Guid.NewGuid().ToString(),
                        Name       = account.FullName,
                        Roles      = new User.Role[] { },
                        RolesLinks = new string[] {},
                        UserName   = request.Message.Credentials.UserName
                    }
                }
            };

            return(response);
        }
Exemplo n.º 15
0
        private void ConnectionStringProtection(bool protect)
        {
            try
            {
                var oConfiguration = ConfigurationHelpers.GetCurrentConfiguration();

                if (oConfiguration != null)
                {
                    //var blnChanged = false;
                    var oSection = oConfiguration.GetSection("connectionStrings") as ConnectionStringsSection;

                    if (oSection != null)
                    {
                        if ((!(oSection.ElementInformation.IsLocked)) && (!(oSection.SectionInformation.IsLocked)))
                        {
                            if (protect)
                            {
                                if (!(oSection.SectionInformation.IsProtected))
                                {
                                    oSection.SectionInformation.ProtectSection(DATA_PROTECTION_PROVIDER);
                                }
                            }
                            else
                            {
                                if (oSection.SectionInformation.IsProtected)
                                {
                                    oSection.SectionInformation.UnprotectSection();
                                    ConnectionString = oSection.ConnectionStrings["LexyEntities"].ConnectionString;
                                }
                                else
                                {
                                    ConnectionString = oSection.ConnectionStrings["LexyEntities"].ConnectionString;
                                    //oSection.SectionInformation.ProtectSection(DATA_PROTECTION_PROVIDER);
                                    //oSection.SectionInformation.ForceSave = true;
                                    //oConfiguration.Save();

                                    //var isweb = ConfigurationManager.AppSettings["IsWebApps"];
                                    //if (isweb.Equals("0"))
                                    //{
                                    //    oSection.SectionInformation.ProtectSection(DATA_PROTECTION_PROVIDER);
                                    //    oSection.SectionInformation.ForceSave = true;
                                    //    oConfiguration.Save();
                                    //}
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("File Configuration is locked");
                        }

                        //if (blnChanged)
                        //{
                        //    oSection.SectionInformation.ForceSave = true;
                        //    oConfiguration.Save();
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO ERROR User Privilages
                ConnectionString = ConfigurationManager.ConnectionStrings["lexyEntities"].ConnectionString;
            }
        }
 public CaaSAuthenticationMiddleWare(OwinMiddleware next, Func <Uri, IComputeApiClient> apiClient)
     : base(next)
 {
     _apiClient = apiClient(ConfigurationHelpers.GetApiUri());
 }
 public void OneTimeSetup() => _configuration = ConfigurationHelpers.GetMyConfiguration("appsettings.Production.json");
        public void UnescapedStringToCharsArray_NullProvided_ThrowsException()
        {
            Action action = () => ConfigurationHelpers.UnescapedStringToCharsArray(null);

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 19
0
            protected override void ConfigureExternalServices(IServiceCollection services)
            {
                services.AddScoped(provider => Mock.Of <IAmazonCognitoIdentityProvider>());

                ConfigurationHelpers.ConfigureExternalServices(services);
            }
 /// <inheritdoc />
 public ITaskProcessorConfiguration GetTaskProcessorConfiguration()
 {
     return(ConfigurationHelpers.Load <TaskProcessorConfigurationSection>(TaskProcessorConfigurationSection.SectionName));
 }
Exemplo n.º 21
0
        private async Task TestDownloadResolver(DownloadData data, Func <DownloadResolver, Task> performTest, bool useHttpServer = true)
        {
            var dummyConfigFile = Path.Combine(TemporaryDirectory, m_uniqueTestFolder, "config.dsc");

            var statistics       = new Statistics();
            var moduleRegistry   = new ModuleRegistry(FrontEndContext.SymbolTable);
            var workspaceFactory = CreateWorkspaceFactoryForTesting(FrontEndContext, ParseAndEvaluateLogger);
            var configuration    = ConfigurationHelpers.GetDefaultForTesting(FrontEndContext.PathTable, AbsolutePath.Create(FrontEndContext.PathTable, dummyConfigFile));
            var resolverSettings = new ResolverSettings();

            var frontEndFactory = new FrontEndFactory();

            frontEndFactory.AddFrontEnd(new DownloadFrontEnd());
            frontEndFactory.TrySeal(new LoggingContext("UnitTest"));

            using (var host = new FrontEndHostController(
                       frontEndFactory,
                       workspaceFactory,
                       new EvaluationScheduler(degreeOfParallelism: 1),
                       moduleRegistry,
                       new FrontEndStatistics(),
                       global::BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(),
                       collector: null,
                       collectMemoryAsSoonAsPossible: false))
            {
                var frontEndEngineAbstraction = new BasicFrontEndEngineAbstraction(
                    FrontEndContext.PathTable,
                    FrontEndContext.FileSystem,
                    configuration);

                ((IFrontEndController)host).InitializeHost(FrontEndContext, configuration);
                host.SetState(frontEndEngineAbstraction, new TestEnv.TestPipGraph(), configuration);

                var resolver = new DownloadResolver(
                    statistics,
                    host,
                    FrontEndContext,
                    Logger.Log,
                    "TestFrontEnd"
                    );

                var workspaceResolver = new DownloadWorkspaceResolver();
                workspaceResolver.UpdateDataForDownloadData(data, FrontEndContext);
                await resolver.InitResolverAsync(resolverSettings, workspaceResolver);

                if (useHttpServer)
                {
                    using (var listener = new HttpListener())
                    {
                        // This test relies on the mutex in the build engine to only run one unittest at a time and this assembly to be single thread
                        // if any of those assumptions will be broken we will have to either dynamically (remind you globally) get unique ports.
                        // HttpListner doesn't have this built-in so there will always be a race. Just spam the ports utnill one doesn't fail
                        // use a global mutex (This is not honored by qtest since it can run in a different session on cloudbuild).
                        listener.Prefixes.Add(TestServer);
                        listener.Start();

                        StartRequestHandler(listener);

                        await performTest(resolver);

                        listener.Stop();
                        listener.Close();
                    }
                }
                else
                {
                    await performTest(resolver);
                }
            }
        }
 /// <inheritdoc />
 public ITaskProcessorClientConfiguration GetClientConfiguration()
 {
     return(ConfigurationHelpers.Load <ClientConfigurationSection>(ClientConfigurationSection.SectionName));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerController"/> class.
 /// </summary>
 /// <param name="apiClient">The API client.</param>
 public ServerController(Func <Uri, IComputeApiClient> apiClient)
 {
     _computeClient = apiClient(ConfigurationHelpers.GetApiUri());
 }
 /// <inheritdoc />
 public ITaskProcessorSerializationConfiguration GetSerializationConfiguration()
 {
     return(ConfigurationHelpers.Load <SerializationConfigurationSection>(SerializationConfigurationSection.SectionName));
 }
Exemplo n.º 25
0
 internal static WSHttpBindingCollectionElement GetBindingCollectionElement()
 {
     return((WSHttpBindingCollectionElement)ConfigurationHelpers.GetBindingCollectionElement("wsHttpBinding"));
 }
 /// <inheritdoc />
 public ITaskSchedulerConfiguration GetTaskSchedulerConfiguration()
 {
     return(ConfigurationHelpers.Load <TaskSchedulerConfigurationSection>(TaskSchedulerConfigurationSection.SectionName));
 }
Exemplo n.º 27
0
        private static ITaskWorkersConfiguration GetTaskWorkerConfiguration(string configFileName)
        {
            string configFilePath = Path.Combine("Configuration", "TaskWorker", configFileName + ".config");

            return(ConfigurationHelpers.Load <TaskWorkerConfigurationSection>(TaskWorkerConfigurationSection.SectionName, configFilePath));
        }
        internal override void Interpret()
        {
            if (Offset + 1 >= TopInterpreter.Args.Length || IsParameterEqual("help", TopInterpreter.Args[Offset + 1], "?"))
            {
                _root.Load(_typeInfoOfConfiguration);
                HelpGenerators.PrintConfigurationContextHelp(_root, this, true);
                return;
            }

            bool ro = false;

            IncreaseOffset();
            object requiredObject = _referenceToObject;

            (PropertyInfo prop, object[] indexers, PropertyInfo lastNonIndexer) =
                ConfigurationHelpers.ResolvePathRecursive(TopInterpreter.Args[Offset], _typeInfoOfConfiguration, ref requiredObject,
                                                          ref ro);

            IncreaseOffset();
            string Operator = TopInterpreter.Args[Offset];

            if (IsParameterEqual("Help", Operator, allowPrefixFree: true))
            {
                var contextAttribute = lastNonIndexer.PropertyType.GetCustomAttribute <CmdConfigurationNamespaceAttribute>();
                if (contextAttribute is null)
                {
                    var valueAttribute = lastNonIndexer.GetCustomAttribute <CmdConfigurationFieldAttribute>();
                    valueAttribute.Load(new PropertyOrFieldInfo(lastNonIndexer));
                    HelpGenerators.PrintConfigurationFieldHelp(valueAttribute, this);
                    return;
                }
                else
                {
                    HelpGenerators.PrintConfigurationContextHelp(contextAttribute, this);
                }
            }

            if (IsParameterEqual("Get", Operator, allowPrefixFree: true))
            {
                object currentValue;
                try {
                    currentValue = indexers is null?prop.GetValue(requiredObject) : prop.GetValue(requiredObject, indexers);
                }
                catch (Exception e) {
                    throw new CLIUsageException("An error occurred while obtaining the value requested:", e);
                }

                Console.WriteLine(JsonConvert.SerializeObject(currentValue));
                return;
            }

            if (IsParameterEqual("Set", Operator, allowPrefixFree: true))
            {
                var valueAttribute = prop.GetCustomAttribute <CmdConfigurationFieldAttribute>();
                if (ro || !prop.CanWrite)
                {
                    throw new CLIUsageException("The given property is read only");
                }

                if (IncreaseOffset())
                {
                    throw new CLIUsageException("Please supply a value to set the given value to!");
                }

                if (!CommandlineMethods.GetValueFromString(TopInterpreter.Args[Offset], prop.PropertyType, out object newValue))
                {
                    throw new CLIUsageException(
                              $"The given string (TopInterpreter.Args[Offset]) couldn't be parsed to {prop.PropertyType}!");
                }

                try {
                    if (indexers is null)
                    {
                        prop.SetValue(requiredObject, newValue);
                    }
                    else
                    {
                        prop.SetValue(requiredObject, newValue, indexers);
                    }
                }
                catch (Exception e) {
                    throw new CLIUsageException("An error occurred while writing the value:", e);
                }

                if (_referenceToObject is IConfigurationRoot iCfgRoot)
                {
                    iCfgRoot.Save(Enumerable.Repeat(new PropertyOrFieldInfo(lastNonIndexer), 1));
                }

                return;
            }

            if (IsParameterEqual("RemoveAt", Operator, allowPrefixFree: true))
            {
                var valueAttribute = prop.GetCustomAttribute <CmdConfigurationFieldAttribute>();
                if (ro || !prop.CanWrite)
                {
                    throw new CLIUsageException("The given value is not writable");
                }

                if (!typeof(ICollection).IsAssignableFrom(prop.PropertyType))
                {
                    throw new CLIUsageException("The object that you try to remove an element from is no collection.");
                }

                if (IncreaseOffset())
                {
                    throw new CLIUsageException("Please supply a value to set the given value to!");
                }

                if (!CommandlineMethods.GetValueFromString(TopInterpreter.Args[Offset], out int removalIndex))
                {
                    throw new CLIUsageException($"The given string couldn't be parsed to {prop.PropertyType}!");
                }

                try {
                    ((IList)(indexers is null ? prop.GetValue(requiredObject) : prop.GetValue(requiredObject, indexers)))
                    .RemoveAt(removalIndex);                     //Safe due to previous assignability check
                }
                catch (Exception e) {
                    throw new CLIUsageException("An error occurred while removing an object:", e);
                }
            }

            throw new CLIUsageException("Could not resolve the operator provided");
            //TODO Remove and Add missing
            //_root.Interpret(printErrors);
        }
Exemplo n.º 29
0
        private static ITaskProcessorSerializationConfiguration GetSerializationtConfiguration(string configFileName)
        {
            string configFilePath = Path.Combine("Configuration", "Serialization", configFileName + ".config");

            return(ConfigurationHelpers.Load <SerializationConfigurationSection>(SerializationConfigurationSection.SectionName, configFilePath));
        }
Exemplo n.º 30
0
        private void Add(ServiceModelOptions options, IEnumerable endpoints)
        {
            if (endpoints is null)
            {
                return;
            }

            foreach (var endpoint in endpoints.OfType <IEndpoint>())
            {
                options.Services.Add(_mapper.ResolveContract(endpoint.Contract), o =>
                {
                    o.Endpoint = new EndpointAddress(endpoint.Address);

                    if (!string.IsNullOrEmpty(endpoint.Binding) || !string.IsNullOrEmpty(endpoint.BindingConfiguration))
                    {
                        o.Binding = ConfigLoader.LookupBinding(endpoint.Binding, endpoint.BindingConfiguration, ConfigurationHelpers.GetEvaluationContext(endpoint));
                    }
                });
            }
        }