public Task DeployAsync(IotHub iotHub, CancellationToken token) { return(Profiler.Run( () => iotHub.DeployDeviceConfigurationAsync(this.deviceId, this.config, token), "Deployed edge configuration to device with modules:\n {Modules}", string.Join("\n ", this.moduleImages))); }
public Provisioning() { this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.TestRunnerProxy); }
public ManualProvisioningFixture() { this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.Proxy); }
void ProcessQRCode(string code) { code = "My314"; StartCoroutine(IotHub.GetDeviceModelForCode( code, d => { GameObject deviceUI = null; if (instantiatedDevices.ContainsKey(d.DeviceId)) { Debug.Log("Known device: prepare placement"); deviceUI = instantiatedDevices[d.DeviceId].Instance; //WorldAnchorManager.Instance.RemoveAnchor(deviceUI); var distanceInFront = GazeManager.Instance.GazeOrigin + GazeManager.Instance.GazeNormal * 2.0f; deviceUI.transform.position = distanceInFront; } else { Debug.Log("Unknown device: prepare placement"); deviceUI = _controlFactory.CreateControlFromDescriptor(d.DeviceId, d.SubSystems[0].UI); deviceUI.SetActive(true); } _configuringUI = deviceUI; _configuringDevice = d; _configuringControlManager = deviceUI.GetComponent <ControlManager>(); _configuringControlManager.State = ControlManager.ConfigState.PreparePlacement; _finishedScanning = true; })); }
public SetupFixture() { this.daemon = OsPlatform.Current.CreateEdgeDaemon(Context.Current.InstallerPath); this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.Proxy); }
public EdgeRuntime(string deviceId, Option <string> agentImage, Option <string> hubImage, Option <Uri> proxy, Registries registries, bool optimizeForPerformance, IotHub iotHub) { this.agentImage = agentImage; this.deviceId = deviceId; this.hubImage = hubImage; this.iotHub = iotHub; this.optimizeForPerformance = optimizeForPerformance; this.proxy = proxy; this.registries = registries; }
public SetupFixture() { Option <Registry> bootstrapRegistry = Option.Maybe(Context.Current.Registries.First()); this.daemon = OsPlatform.Current.CreateEdgeDaemon(Context.Current.InstallerPath, Context.Current.EdgeAgentBootstrapImage, bootstrapRegistry); this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.Proxy); }
public async Task ModuleToModuleDirectMethod( [Values] Protocol protocol) { if (Platform.IsWindows() && (protocol == Protocol.AmqpWs || protocol == Protocol.MqttWs)) { Assert.Ignore("Module-to-module direct methods don't work over WebSocket on Windows"); } string agentImage = Context.Current.EdgeAgentImage.Expect(() => new ArgumentException()); string hubImage = Context.Current.EdgeHubImage.Expect(() => new ArgumentException()); string senderImage = Context.Current.MethodSenderImage.Expect(() => new ArgumentException()); string receiverImage = Context.Current.MethodReceiverImage.Expect(() => new ArgumentException()); bool optimizeForPerformance = Context.Current.OptimizeForPerformance; Option <Uri> proxy = Context.Current.Proxy; CancellationToken token = this.cts.Token; string name = $"module-to-module direct method ({protocol.ToString()})"; Log.Information("Running test '{Name}'", name); await Profiler.Run( async() => { var iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); EdgeDevice device = (await EdgeDevice.GetIdentityAsync( Context.Current.DeviceId, iotHub, token)).Expect(() => new Exception("Device should have already been created in setup fixture")); string methodSender = $"methodSender-{protocol.ToString()}"; string methodReceiver = $"methodReceiver-{protocol.ToString()}"; string clientTransport = protocol.ToTransportType().ToString(); var builder = new EdgeConfigBuilder(device.Id); foreach ((string address, string username, string password) in Context.Current.Registries) { builder.AddRegistryCredentials(address, username, password); } builder.AddEdgeAgent(agentImage).WithProxy(proxy); builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy); builder.AddModule(methodSender, senderImage) .WithEnvironment( new[] { ("ClientTransportType", clientTransport), ("TargetModuleId", methodReceiver) });
public async Task BeforeAllAsync() { await Profiler.Run( async() => { (string, string, string)rootCa = Context.Current.RootCaKeys.Expect(() => new ArgumentException()); Option <Uri> proxy = Context.Current.Proxy; string deviceId = Context.Current.DeviceId; using (var cts = new CancellationTokenSource(Context.Current.SetupTimeout)) { CancellationToken token = cts.Token; this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); this.ca = await CertificateAuthority.CreateAsync( deviceId, rootCa, Context.Current.CaCertScriptPath, token); this.daemon = OsPlatform.Current.CreateEdgeDaemon(Context.Current.InstallerPath); await this.daemon.ConfigureAsync( config => { config.SetCertificates(this.ca.Certificates); config.Update(); return(Task.FromResult(("with edge certificates", Array.Empty <object>()))); }, token); var runtime = new EdgeRuntime( deviceId, Context.Current.EdgeAgentImage, Context.Current.EdgeHubImage, proxy, Context.Current.Registries, Context.Current.OptimizeForPerformance, this.iotHub); await runtime.DeployConfigurationAsync(token); } }, "Completed custom certificate setup"); }
protected void BeforeEachModuleTest() { this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.Proxy); this.runtime = new EdgeRuntime( Context.Current.DeviceId, Context.Current.EdgeAgentImage, Context.Current.EdgeHubImage, Context.Current.Proxy, Context.Current.Registries, Context.Current.OptimizeForPerformance, this.iotHub); }
public ManualProvisioningFixture(string deviceIdSuffix) { this.daemon = OsPlatform.Current.CreateEdgeDaemon(Context.Current.InstallerPath); this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, Context.Current.Proxy); this.runtime = new EdgeRuntime( Context.Current.DeviceId + deviceIdSuffix, Context.Current.EdgeAgentImage, Context.Current.EdgeHubImage, Context.Current.Proxy, Context.Current.Registries, Context.Current.OptimizeForPerformance, this.iotHub); }
public Task VerifyAsync(IotHub iotHub, CancellationToken token) { EdgeAgent agent = new EdgeAgent(this.deviceId, iotHub); return(agent.WaitForReportedConfigurationAsync(this.expectedConfig, token)); }
private void OnDeselectionHandler() { IotHub.SendMethod(_deviceId, onDeselectionMethod); }
public ManualProvisioningFixture(string connectionString, string eventHubEndpoint) { this.iotHub = new IotHub(connectionString, eventHubEndpoint, Context.Current.Proxy); }
public Task <int> RunAsync(Args args) => Profiler.Run( "Running tempSensor test", async() => { using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) { CancellationToken token = cts.Token; // ** setup var iotHub = new IotHub(args.ConnectionString, args.Endpoint, args.Proxy); var device = await EdgeDevice.GetOrCreateIdentityAsync( args.DeviceId, iotHub, token); var daemon = new EdgeDaemon(args.InstallerPath); await daemon.UninstallAsync(token); await daemon.InstallAsync( device.ConnectionString, args.PackagesPath, args.Proxy, token); await args.Proxy.Match( async p => { await daemon.StopAsync(token); var yaml = new DaemonConfiguration(); yaml.AddHttpsProxy(p); yaml.Update(); await daemon.StartAsync(token); }, () => daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token)); var agent = new EdgeAgent(device.Id, iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); // ** test var config = new EdgeConfiguration(device.Id, args.AgentImage, iotHub); args.Registry.ForEach( r => config.AddRegistryCredentials(r.address, r.username, r.password)); config.AddEdgeHub(args.HubImage); args.Proxy.ForEach(p => config.AddProxy(p)); config.AddTempSensor(args.SensorImage); await config.DeployAsync(token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); // ** teardown await daemon.StopAsync(token); await device.MaybeDeleteIdentityAsync(token); } return(0); }, "Completed tempSensor test");
public async Task <int> RunAsync(Args args) { LogEventLevel consoleLevel = args.Verbose ? LogEventLevel.Verbose : LogEventLevel.Information; var loggerConfig = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console(consoleLevel); args.LogFile.ForEach(f => loggerConfig.WriteTo.File(f)); Log.Logger = loggerConfig.CreateLogger(); try { using (var cts = new CancellationTokenSource(args.Timeout)) { Log.Information("Running tempSensor test"); await Profiler.Run( async() => { CancellationToken token = cts.Token; // ** setup var iotHub = new IotHub(args.ConnectionString, args.Endpoint, args.Proxy); EdgeDevice device = await EdgeDevice.GetOrCreateIdentityAsync( args.DeviceId, iotHub, token); var daemon = Platform.CreateEdgeDaemon(args.InstallerPath); await daemon.UninstallAsync(token); await daemon.InstallAsync( device.ConnectionString, args.PackagesPath, args.Proxy, token); await daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token); var agent = new EdgeAgent(device.Id, iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); // ** test var config = new EdgeConfiguration(device.Id, args.AgentImage, iotHub); args.Registry.ForEach( r => config.AddRegistryCredentials(r.address, r.username, r.password)); config.AddEdgeHub(args.HubImage); args.Proxy.ForEach(p => config.AddProxy(p)); config.AddTempSensor(args.SensorImage); await config.DeployAsync(token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); // ** teardown await daemon.StopAsync(token); await device.MaybeDeleteIdentityAsync(token); }, "Completed tempSensor test"); } } catch (OperationCanceledException e) { Log.Error(e, "Cancelled tempSensor test after {Timeout} minutes", args.Timeout.TotalMinutes); } catch (Exception e) { Log.Error(e, "Failed tempSensor test"); return(1); } finally { Log.CloseAndFlush(); } return(0); }
public async Task TempSensor() { string agentImage = Context.Current.EdgeAgentImage.Expect(() => new ArgumentException()); string hubImage = Context.Current.EdgeHubImage.Expect(() => new ArgumentException()); string sensorImage = Context.Current.TempSensorImage.Expect(() => new ArgumentException()); bool optimizeForPerformance = Context.Current.OptimizeForPerformance; Option <Uri> proxy = Context.Current.Proxy; CancellationToken token = this.cts.Token; string name = "temp sensor"; Log.Information("Running test '{Name}'", name); await Profiler.Run( async() => { var iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); EdgeDevice device = (await EdgeDevice.GetIdentityAsync( Context.Current.DeviceId, iotHub, token)).Expect(() => new Exception("Device should have already been created in setup fixture")); var builder = new EdgeConfigBuilder(device.Id); foreach ((string address, string username, string password) in Context.Current.Registries) { builder.AddRegistryCredentials(address, username, password); } builder.AddEdgeAgent(agentImage).WithProxy(proxy); builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy); builder.AddModule("tempSensor", sensorImage); await builder.Build().DeployAsync(iotHub, token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); }, "Completed test '{Name}'", name); }