static async Task SendEvent(Message eventMessage)
        {
            if (!IotHubSettings.IsSendDataToAzureEnabled)
            {
                return;
            }

            var deviceClient = GetDeviceClient();
            await deviceClient.SendEventAsync(eventMessage).ConfigureAwait(false);

            AppCenterService.TrackEvent("IoT Message Sent");
        }
            static async Task openApp(string appUrl, string webUrl)
            {
                var supportsUri = await Launcher.CanOpenAsync(appUrl);

                if (supportsUri)
                {
                    AppCenterService.TrackEvent("Launched Twitter Profile", "Method", "Twitter App");
                    await Launcher.OpenAsync(appUrl);
                }
                else
                {
                    AppCenterService.TrackEvent("Launched Twitter Profile", "Method", "Browser");
                    await Browser.OpenAsync(webUrl);
                }
            }
        public static async Task SendMessage <T>(T data) where T : class
        {
            if (data is null)
            {
                return;
            }

            try
            {
                var jsonData = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false);

                var eventMessage = new Message(Encoding.UTF8.GetBytes(jsonData));

                await SendEvent(eventMessage).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                AppCenterService.Report(e);
                OnIoTDeviceServiceFailed(e.Message);
            }
        }
Exemple #4
0
        public static Task <Location> GetLocation()
        {
            var tcs = new TaskCompletionSource <Location>();

            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    var location = await Geolocation.GetLocationAsync(GeolocationRequest).ConfigureAwait(false);
                    tcs.SetResult(location);
                }
                catch (Exception e)
                {
                    OnGeolocationFailed(e);
                    AppCenterService.Report(e);

                    tcs.SetException(e);
                }
            });

            return(tcs.Task);
        }
Exemple #5
0
        protected override void OnStart()
        {
            base.OnStart();

            AppCenterService.Start();
        }
 static void OnIoTDeviceServiceFailed(string message)
 {
     AppCenterService.TrackEvent("IoT Device Service Failed", "Message", message);
     IoTDeviceServiceFailed?.Invoke(null, message);
 }