Ejemplo n.º 1
0
        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);
                }
            }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        protected override void OnStart()
        {
            base.OnStart();

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