コード例 #1
0
        private async void InitAndroidPushNotifier()
        {
            Common.AndroidPushNotifier = new AndroidPushNotifier(await MSAAuthenticator.GetUserUniqueIdAsync());

            Common.AndroidPushNotifier.Devices.CollectionChanged += DevicesCollectionChanged;

            await Common.AndroidPushNotifier.DiscoverAndroidDevices(ServiceFunctions.GetDeviceUniqueId());
        }
コード例 #2
0
        private async void SendCarrier(string deviceId)
        {
            RemoteSystem rs = null;

            Android.Util.Log.Debug(TAG, "3 " + deviceId);

            MessageReceiveHelper.InitProgressNotifier();

            //try finding remote system for 15 seconds
            for (int i = 0; i < 30; i++)
            {
                rs = Common.MessageCarrierPackageManager.RemoteSystems.FirstOrDefault(x => x.Id == deviceId);
                RemoteSystem rs2;
                try
                {
                    rs2 = Common.PackageManager.RemoteSystems.FirstOrDefault(x => x.Id == deviceId);
                }
                catch
                {
                }


                if (rs != null)
                {
                    break;
                }

                await Task.Delay(TimeSpan.FromSeconds(0.5));
            }

            Android.Util.Log.Debug(TAG, "4");

            if (rs == null)
            {
                System.Diagnostics.Debug.WriteLine($"Couldn't find device {deviceId}");
                StopSelf();
                return;
            }

            Android.Util.Log.Debug(TAG, "5");

            string thisDeviceUniqueId = ServiceFunctions.GetDeviceUniqueId();

            Android.Util.Log.Debug(TAG, "6 " + thisDeviceUniqueId);

            try
            {
                while (true)
                {
                    lastActiveTime = DateTime.UtcNow;

                    Android.Util.Log.Debug(TAG, "Connecting to message carrier service...");
                    var c = await Common.MessageCarrierPackageManager.Connect(rs, false);

                    if (c != RomeAppServiceConnectionStatus.Success)
                    {
                        Android.Util.Log.Debug(TAG, $"Connection failed. {c.ToString()}");
                        throw new Exception($"Connection failed. {c.ToString()}");
                    }

                    Android.Util.Log.Debug(TAG, "Connected.");
                    Android.Util.Log.Debug(TAG, "Sending message carrier...");

                    var data = new Dictionary <string, object>()
                    {
                        { "SenderId", thisDeviceUniqueId },
                    };

                    var response = await Common.MessageCarrierPackageManager.Send(data);

                    Android.Util.Log.Debug(TAG, $"Response received. ({response.Status.ToString()})");

                    if ((response.Message == null) || (response.Message.Count == 0))
                    {
                        Android.Util.Log.Debug(TAG, "Response is empty.");
                        await Task.Delay(TimeSpan.FromSeconds(1));

                        continue;
                    }

                    var isFinished = await MessageReceiveHelper.ProcessReceivedMessage(response.Message);

                    Android.Util.Log.Debug(TAG, "Finished.");

                    if (isFinished)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug(TAG, "Exception in SendCarrier()");
                Log.Debug(TAG, ex.Message);
                Log.Debug(TAG, ex.ToString());
            }
            finally
            {
                Common.MessageCarrierPackageManager.CloseAppService();
            }

            //StopSelf();
        }