public async static void DeleteBarrier(Context context, params PendingIntent[] pendingIntents)
        {
            string MethodName = "UpdateBarriers";

            BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
            foreach (PendingIntent pendingIntent in pendingIntents)
            {
                builder.DeleteBarrier(pendingIntent);
            }
            var barrierTask = Awareness.GetBarrierClient(context).UpdateBarriersAsync(builder.Build());

            try
            {
                await barrierTask;

                if (barrierTask.IsCompleted)
                {
                    string logMessage = "Delete barrier success";
                    ShowToast(context, logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    string logMessage = "Delete barrier failed";
                    ShowToast(context, logMessage);
                    Log.Error(MethodName, logMessage, barrierTask.Exception);
                }
            }
            catch (Exception ex)
            {
                string logMessage = "Delete barrier failed";
                ShowToast(context, logMessage);
                Log.Error(MethodName, logMessage, ex);
            }
        }
        public async static void BatchBarrier(Context context, BarrierUpdateRequest.Builder builder)
        {
            string MethodName  = "UpdateBarriers";
            var    barrierTask = Awareness.GetBarrierClient(context).UpdateBarriersAsync(builder.Build());

            try
            {
                await barrierTask;

                if (barrierTask.IsCompleted)
                {
                    string logMessage = "Batch barrier success";
                    ShowToast(context, logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    string logMessage = "Batch barrier failed";
                    ShowToast(context, logMessage);
                    Log.Error(MethodName, logMessage, barrierTask.Exception);
                }
            }
            catch (Exception ex)
            {
                string logMessage = "Batch barrier failed";
                ShowToast(context, logMessage);
                Log.Error(MethodName, logMessage, ex);
            }
        }
        public async static void AddBarrier(Context context, string label, AwarenessBarrier barrier, PendingIntent pendingIntent)
        {
            string MethodName = "UpdateBarriers";

            BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
            // When the status of the registered barrier changes, pendingIntent is triggered.
            // label is used to uniquely identify the barrier. You can query a barrier by label and delete it.
            BarrierUpdateRequest request = builder.AddBarrier(label, barrier, pendingIntent).Build();
            var barrierTask = Awareness.GetBarrierClient(context).UpdateBarriersAsync(request);

            try
            {
                await barrierTask;

                if (barrierTask.IsCompleted)
                {
                    string logMessage = "Add barrier success";
                    ShowToast(context, logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    string logMessage = "Add barrier failed";
                    ShowToast(context, logMessage);
                    Log.Error(MethodName, logMessage, barrierTask.Exception);
                }
            }
            catch (Exception ex)
            {
                string logMessage = "Add barrier failed";
                ShowToast(context, logMessage);
                Log.Error(MethodName, logMessage, ex);
            }
        }
Beispiel #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            InitializeButtons();

            log = new Logger(FindViewById <LinearLayout>(Resource.Id.ll_log), FindViewById <ScrollView>(Resource.Id.sv_log), this);

            Awareness.GetBarrierClient(this).EnableUpdateWindow(true);
            QueryDeviceSupportingCapabilities();
            CheckAndRequestPermissions();
        }
        public async static void QueryBarrier(Context context, params string[] labels)
        {
            string MethodName           = "QueryBarrier";
            BarrierQueryRequest request = BarrierQueryRequest.ForBarriers(labels);
            var barrierTask             = Awareness.GetBarrierClient(context).QueryBarriersAsync(request);

            try
            {
                await barrierTask;

                if (barrierTask.IsCompleted)
                {
                    IBarrierStatusMap statusMap     = barrierTask.Result.BarrierStatusMap;
                    string            barrierLabel  = "target barrier label";
                    BarrierStatus     barrierStatus = statusMap.GetBarrierStatus(barrierLabel);
                    if (barrierStatus != null)
                    {
                        string logMessage = $"Target barrier status is {barrierStatus.PresentStatus}";
                        ShowToast(context, logMessage);
                        Log.Info(MethodName, logMessage);
                    }
                    else
                    {
                        Log.Info(MethodName, $"{MethodName} is success but there is no barrier.");
                    }
                }
                else
                {
                    string logMessage = "Query barrier failed";
                    ShowToast(context, logMessage);
                    Log.Error(MethodName, logMessage, barrierTask.Exception);
                }
            }
            catch (Exception ex)
            {
                string logMessage = "Query barrier failed";
                ShowToast(context, logMessage);
                Log.Error(MethodName, logMessage, ex.Message);
            }
        }