Example #1
0
        private async Task LSLOpenStream()
        {
            bool sendSecondaryTimestamp = TimestampFormat2.GetType() != typeof(DummyTimestampFormat);

            var channelsInfo = new List <LSLBridgeChannelInfo>();

            foreach (var c in channelLabels)
            {
                channelsInfo.Add(new LSLBridgeChannelInfo {
                    Label = c, Type = Constants.EEG_STREAM_TYPE, Unit = Constants.EEG_UNITS
                });
            }

            streamInfo = new LSLBridgeStreamInfo()
            {
                BufferLength           = Constants.MUSE_LSL_BUFFER_LENGTH,
                Channels               = channelsInfo,
                ChannelCount           = channelCount,
                ChannelDataType        = ChannelDataType.DataType,
                ChunkSize              = Constants.MUSE_SAMPLE_COUNT,
                DeviceManufacturer     = deviceInfoManufacturer,
                DeviceName             = deviceInfoName,
                NominalSRate           = Constants.MUSE_SAMPLE_RATE,
                StreamType             = Constants.EEG_STREAM_TYPE,
                SendSecondaryTimestamp = sendSecondaryTimestamp,
                StreamName             = EEGStreamName
            };

            ValueSet message = new ValueSet
            {
                { LSLBridge.Constants.LSL_MESSAGE_STREAM_INFO, JsonConvert.SerializeObject(streamInfo) }
            };
            await AppServiceManager.SendMessageAsync(LSLBridge.Constants.LSL_MESSAGE_TYPE_OPEN_STREAM, message);
        }
Example #2
0
        private Azure(RestClient restClient, string subscriptionId, string tenantId, IAuthenticated authenticated)
        {
            resourceManager          = ResourceManager.Fluent.ResourceManager.Authenticate(restClient).WithSubscription(subscriptionId);
            storageManager           = StorageManager.Authenticate(restClient, subscriptionId);
            computeManager           = ComputeManager.Authenticate(restClient, subscriptionId);
            networkManager           = NetworkManager.Authenticate(restClient, subscriptionId);
            batchManager             = BatchManager.Authenticate(restClient, subscriptionId);
            keyVaultManager          = KeyVaultManager.Authenticate(restClient, subscriptionId, tenantId);
            trafficManager           = TrafficManager.Fluent.TrafficManager.Authenticate(restClient, subscriptionId);
            dnsZoneManager           = DnsZoneManager.Authenticate(restClient, subscriptionId);
            sqlManager               = SqlManager.Authenticate(restClient, subscriptionId);
            redisManager             = RedisManager.Authenticate(restClient, subscriptionId);
            cdnManager               = CdnManager.Authenticate(restClient, subscriptionId);
            appServiceManager        = AppServiceManager.Authenticate(restClient, subscriptionId, tenantId);
            searchManager            = SearchManager.Authenticate(restClient, subscriptionId);
            serviceBusManager        = ServiceBusManager.Authenticate(restClient, subscriptionId);
            containerInstanceManager = ContainerInstanceManager.Authenticate(restClient, subscriptionId);
            registryManager          = RegistryManager.Authenticate(restClient, subscriptionId);
            containerServiceManager  = ContainerServiceManager.Authenticate(restClient, subscriptionId);
            cosmosDBManager          = CosmosDBManager.Authenticate(restClient, subscriptionId);
            authorizationManager     = AuthorizationManager.Authenticate(restClient, subscriptionId);
            msiManager               = MsiManager.Authenticate(restClient, subscriptionId);
            batchAIManager           = BatchAIManager.Authenticate(restClient, subscriptionId);
            monitorManager           = MonitorManager.Authenticate(restClient, subscriptionId);
            eventHubManager          = EventHubManager.Authenticate(restClient, subscriptionId);

            SubscriptionId     = subscriptionId;
            this.authenticated = authenticated;
        }
Example #3
0
 public static IAppServiceManager CreateAppServiceManager()
 {
     return(CreateMockedManager(c => AppServiceManager
                                .Configure()
                                .WithDelegatingHandlers(GetHandlers())
                                .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                                .Authenticate(c, c.DefaultSubscriptionId)));
 }
Example #4
0
 private async Task LSLCloseStream()
 {
     ValueSet message = new ValueSet
     {
         { LSLBridge.Constants.LSL_MESSAGE_STREAM_NAME, EEGStreamName }
     };
     await AppServiceManager.SendMessageAsync(LSLBridge.Constants.LSL_MESSAGE_TYPE_CLOSE_STREAM, message);
 }
Example #5
0
        /// <summary>
        /// Gets the app service manager.
        /// </summary>
        /// <param name="authenticationOptions">Authenticate settings.</param>
        /// <param name="subscriptionId">The subscription to manage.</param>
        /// <returns>The app service manager.</returns>
        public static IAppServiceManager Get(
            AuthenticationOptions authenticationOptions,
            string subscriptionId)
        {
            AzureCredentials credentials = authenticationOptions.GetAzureCredentials();

            return(AppServiceManager.Authenticate(credentials, subscriptionId));
        }
        private async Task <IFunctionApp> CreateFunctionAppsAsync(IResourceGroup resourceGroup)
        {
            var storageAccount = await StorageManager
                                 .Authenticate(_azureCredentials, _configuration.SubscriptionId)
                                 .StorageAccounts
                                 .Define(_configuration.ResourceNamePrefix.ToLowerInvariant() + "storage")
                                 .WithRegion(_configuration.RegionName)
                                 .WithExistingResourceGroup(resourceGroup)
                                 .WithSku(StorageAccountSkuType.Standard_LRS)
                                 .CreateAsync();

            Console.WriteLine($"Successfully created or updated storage account '{storageAccount.Name}'");

            var appServiceManager = AppServiceManager.Authenticate(_azureCredentials, _configuration.SubscriptionId);
            var appServicePlan    = await appServiceManager
                                    .AppServicePlans
                                    .Define(_configuration.ResourceNamePrefix + "Plan")
                                    .WithRegion(_configuration.RegionName)
                                    .WithExistingResourceGroup(resourceGroup)
                                    .WithPricingTier(PricingTier.FromSkuDescription(new SkuDescription("Y1", "Dynamic", "Y1", "Y", 0)))
                                    .WithOperatingSystem(OperatingSystem.Windows)
                                    .CreateAsync();

            Console.WriteLine($"Successfully created or updated app service plan '{appServicePlan.Name}'");

            var functionApp = await appServiceManager
                              .FunctionApps
                              .Define(_configuration.ResourceNamePrefix + "Api")
                              .WithExistingAppServicePlan(appServicePlan)
                              .WithExistingResourceGroup(resourceGroup)
                              .WithExistingStorageAccount(storageAccount)
                              .WithSystemAssignedManagedServiceIdentity()
                              .DefineAuthentication()
                              .WithDefaultAuthenticationProvider(BuiltInAuthenticationProvider.AzureActiveDirectory)
                              .WithActiveDirectory(_configuration.CertificateAuthorityClientId, $"https://login.microsoftonline.com/{_configuration.TenantId}/v2.0")
                              .Attach()
                              .WithAppSetting("StorageConnectionString", await BuildStorageConnectionString())
                              .WithAppSetting("StorageContainerName", _configuration.FunctionStorageContainerName)
                              .WithAppSetting("RootCertificateId", BuildRootCertificateId())
                              .CreateAsync();

            Console.WriteLine($"Successfully created or updated function app '{functionApp.Name}'");
            return(functionApp);

            async Task <string> BuildStorageConnectionString()
            {
                var storageAccountKeys = await storageAccount.GetKeysAsync();

                var storageAccountKeyValue = storageAccountKeys[0].Value;

                return($"DefaultEndpointsProtocol=https;AccountName={storageAccount.Name};AccountKey={storageAccountKeyValue};EndpointSuffix=core.windows.net");
            }

            string BuildRootCertificateId() => $"https://{_configuration.ResourceNamePrefix.ToLowerInvariant()}vault.vault.azure.net/certificates/{_configuration.RootCertificateName.ToLowerInvariant()}";
        }
Example #7
0
        private async Task LSLPushChunk(MuseSample sample)
        {
            ValueSet message = new ValueSet
            {
                { LSLBridge.Constants.LSL_MESSAGE_STREAM_NAME, EEGStreamName }
            };

            // Can only send 1D array with garbage AppService :S - inlined as channel1sample1,channel1sample2,channel1sample3...channel2sample1,channel2sample2...
            if (streamInfo.ChannelDataType == LSLBridgeDataType.DOUBLE)
            {
                double[] data = new double[Constants.MUSE_SAMPLE_COUNT * channelCount];
                for (int i = 0; i < channelCount; i++)
                {
                    var channelData = sample.ChannelData[channelUUIDs[i]]; // Maintains muse-lsl.py ordering.
                    for (int j = 0; j < Constants.MUSE_SAMPLE_COUNT; j++)
                    {
                        data[(i * Constants.MUSE_SAMPLE_COUNT) + j] = channelData[j];
                    }
                }
                message.Add(LSLBridge.Constants.LSL_MESSAGE_CHUNK_DATA, data);
            }

            // Default to float.
            else if (streamInfo.ChannelDataType == LSLBridgeDataType.FLOAT)
            {
                float[] data = new float[Constants.MUSE_SAMPLE_COUNT * channelCount];
                for (int i = 0; i < channelCount; i++)
                {
                    var channelData = sample.ChannelData[channelUUIDs[i]]; // Maintains muse-lsl.py ordering.
                    for (int j = 0; j < Constants.MUSE_SAMPLE_COUNT; j++)
                    {
                        data[(i * Constants.MUSE_SAMPLE_COUNT) + j] = (float)channelData[j];
                    }
                }
                message.Add(LSLBridge.Constants.LSL_MESSAGE_CHUNK_DATA, data);
            }

            else
            {
                throw new InvalidOperationException("Can't push LSL chunk - unsupported stream data type. Must use float32 or double64.");
            }

            message.Add(LSLBridge.Constants.LSL_MESSAGE_CHUNK_TIMESTAMPS, sample.Timestamps);
            message.Add(LSLBridge.Constants.LSL_MESSAGE_CHUNK_TIMESTAMPS2, sample.Timestamps2);

            await AppServiceManager.SendMessageAsync(LSLBridge.Constants.LSL_MESSAGE_TYPE_SEND_CHUNK, message);
        }
 private static IAppServiceManager GetAppServiceManager(AzureWebAppSettings settings)
 {
     return(AppServiceManager.Authenticate(
                AzureHelper.GetAzureCredentials(settings.AzureServicePrincipal, settings.AzureSubscription),
                settings.AzureSubscription.SubscriptionId));
 }
Example #9
0
 protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
 {
     await AppServiceManager.HandleIncomingConnectionAsync(args.TaskInstance);
 }