public static int Main(string[] args) { Console.WriteLine("Device starting.\n"); string str = System.IO.File.ReadAllText("Settings.json"); Settings._Settings = JsonConvert.DeserializeObject <Settings>(str); source = new CancellationTokenSource(); token = source.Token; int port = int.Parse(Settings._Settings.Port, CultureInfo.InvariantCulture); Microsoft.Azure.Devices.TransportType s_transportType = Microsoft.Azure.Devices.TransportType.Amqp; try { using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(Settings._Settings.connectionString, s_transportType)) { DeviceStreamProxySvc sample = new DeviceStreamProxySvc(serviceClient, Settings._Settings.device_id, port, OnSvcRecvText, OnSvcStatusUpdate); sample.RunSampleAsync().GetAwaiter().GetResult(); } } catch (Exception ex) { OnSvcStatusUpdate(string.Format("Proxy Svc fail {0}", ex.Message)); } Console.WriteLine("Done.\n"); return(0); }
private void ButtonCanceLSvc_Click(object sender, RoutedEventArgs e) { //DeviceStream_Svc.deviceStream_Svc?.Cancel(); //Azure_IoTHub_Telemetry.ReadDeviceToCloudMessages.Cancel(); OnSvcStatusUpdate("Svc Cancelling actioned"); if (!DeviceStreamProxySvc.isRunning) { if (tasks != null) { if (tasks.Count != 0) { source.Cancel(); } } } else { DeviceStreamProxySvc.Cancel(); } }
public static int Main(string[] args) { Console.WriteLine("Device starting.\n"); string str = System.IO.File.ReadAllText("Settings.json"); Settings._Settings = JsonConvert.DeserializeObject <Settings>(str); //if (string.IsNullOrEmpty(s_connectionString) && args.Length > 0) //{ // s_connectionString = args[0]; //} //if (string.IsNullOrEmpty(s_deviceId) && args.Length > 1) //{ // s_deviceId = args[1]; //} //if (string.IsNullOrEmpty(s_port) && args.Length > 2) //{ // s_port = args[2]; //} //if (string.IsNullOrEmpty(s_connectionString) || // string.IsNullOrEmpty(s_deviceId) || // string.IsNullOrEmpty(s_port)) //{ // Console.WriteLine("Please provide a connection string, device ID and local port"); // Console.WriteLine("Usage: ServiceLocalProxyC2DStreamingSample [iotHubConnString] [deviceId] [localPortNumber]"); // return 1; //} //int port = int.Parse(s_port, CultureInfo.InvariantCulture); //using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType)) //{ // var sample = new DeviceStreamSample(serviceClient, s_deviceId, port); // sample.RunSampleAsync().GetAwaiter().GetResult(); //} source = new CancellationTokenSource(); token = source.Token; int port = int.Parse(Settings._Settings.Port, CultureInfo.InvariantCulture); Microsoft.Azure.Devices.TransportType s_transportType = Microsoft.Azure.Devices.TransportType.Amqp; try { using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(Settings._Settings.connectionString, s_transportType)) { DeviceStreamProxySvc sample = new DeviceStreamProxySvc(serviceClient, Settings._Settings.device_id, port, OnSvcRecvText, OnSvcStatusUpdate); sample.RunSampleAsync().GetAwaiter().GetResult(); } } catch (Exception ex) { OnSvcStatusUpdate(string.Format("Proxy Svc fail {0}", ex.Message)); } Console.WriteLine("Done.\n"); return(0); }