/// <summary>
        /// Initializes a new instance of the <see cref="BeaconSettingsPage"/> class.
        /// </summary>
        public BeaconSettingsPage()
        {
            _oSelectedBeaconCommand = null;
            InitializeComponent();

            App.ShowToast(AppResources.title_add_beacon);
            swEnableBeacon.IsToggled = App.AppSettings.BeaconEnabled;
            swEnableBeacon.Toggled  += (sender, args) =>
            {
                App.AppSettings.BeaconEnabled = swEnableBeacon.IsToggled;
            };

            swEnableBeaconNotifications.IsToggled = App.AppSettings.BeaconNotificationsEnabled;
            swEnableBeaconNotifications.Toggled  += (sender, args) =>
            {
                App.AppSettings.BeaconNotificationsEnabled = swEnableBeaconNotifications.IsToggled;
            };

            _oListSource = App.AppSettings.Beacons;
            if (_oListSource == null)
            {
                _oListSource = new List <BeaconModel>();
            }
            listView.ItemsSource = _oListSource;
        }
Ejemplo n.º 2
0
        private async Task <BeaconModel> QueryPair(BeaconModel input)
        {
            // pair
            var queryPair = new QueryDefinition
                                ($"SELECT * FROM {Cosmos.ContainerNameBeacon} b"
                                + " WHERE b.UserMajor = @UserMajor"
                                + " AND b.UserMinor = @UserMinor"
                                + " AND b.KeyTime = @KeyTime"
                                + " AND b.Major = @Major"
                                + " AND b.Minor = @Minor")
                            .WithParameter("@UserMajor", input.Major)
                            .WithParameter("@UserMinor", input.Minor)
                            .WithParameter("@KeyTime", input.KeyTime)
                            .WithParameter("@Major", input.UserMajor)
                            .WithParameter("@Minor", input.UserMinor);
            var option = new QueryRequestOptions();

            option.PartitionKey = new PartitionKey($"{input.Major}.{input.Minor}");
            try
            {
                var pair = await Cosmos.Beacon.GetItemQueryIterator <BeaconModel>(queryPair, null, option).ReadNextAsync();

                return(pair.FirstOrDefault());
            }
            catch (CosmosException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    Logger.LogInformation($"{nameof(ContactFunction)} Not Found Major:{input.Major} Minor:{input.Major}");
                    return(null);
                }
                Logger.LogError(ex, $"{nameof(ContactFunction)} Throw from QueryPair Major:{input.Major} Minor:{input.Major}");
            }
            return(null);
        }
Ejemplo n.º 3
0
        protected void HandleFoundBeacon(string beaconId, ushort major, ushort minor)
        {
            var beaconModel = new BeaconModel
            {
                UUID  = beaconId,
                Major = major,
                Minor = minor
            };

            var activity = new BeaconActivity
            {
                BeaconModel  = beaconModel,
                CreationDate = DateTime.Now
            };

            //If we registered a beacon in lesser period than threshold we should ignore this event
            var lastActivity = _beaconsActivity.LastOrDefault(x => x.BeaconModel.Equals(activity.BeaconModel) && DateTime.Now - x.CreationDate < _threshold);

            if (lastActivity != null)
            {
                return;
            }

            _beaconsActivity.RemoveAll(s => s.BeaconModel.Equals(activity.BeaconModel));
            _beaconsActivity.Add(activity);

            Debug.WriteLine("Found beacon: {0}.{1} - {2}", major, minor, beaconId);

            BeaconFound?.Invoke(null, beaconModel);
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> UpdateBeacon(int clientId, [FromBody] BeaconModel model)
        {
            var userId = GetUserId();
            var beacon = await _beaconManager.UpdateAsync(model, clientId, userId);

            return(Ok(beacon));
        }
Ejemplo n.º 5
0
        private async Task <IActionResult> Add(BeaconParameter param)
        {
            var data = new BeaconModel();

            data.id              = $"{param.UserUuid}.{param.Id}";
            data.UserUuid        = param.UserUuid;
            data.UserMajor       = param.UserMajor;
            data.UserMinor       = param.UserMinor;
            data.BeaconUuid      = param.BeaconUuid;
            data.Count           = param.Count;
            data.Distance        = param.Distance;
            data.ElaspedTime     = param.ElaspedTime;
            data.FirstDetectTime = param.FirstDetectTime;
            data.LastDetectTime  = param.LastDetectTime;
            data.Major           = param.Major;
            data.Minor           = param.Minor;
            data.Rssi            = param.Rssi;
            data.TXPower         = param.TXPower;
            data.KeyTime         = param.KeyTime;
            data.TimeStamp       = DateTime.UtcNow;
            data.PartitionKey    = param.KeyTime;
            var result = await Cosmos.Beacon.UpsertItemAsync <BeaconModel>(data, new PartitionKey(param.KeyTime));

            return(new StatusCodeResult(201));
        }
Ejemplo n.º 6
0
        public void PropertiesTest()
        {
            // preparation
            var model = new BeaconModel();

            // model property access
            Helper.ModelTestHelper.PropetiesTest(model);
        }
        /// <summary>
        /// Connect device to Beacon Command
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/></param>
        /// <param name="e">The e<see cref="EventArgs"/></param>
        private async void btnConnect_Clicked(object sender, EventArgs e)
        {
            _oSelectedBeaconCommand = (Models.BeaconModel)((TintedCachedImage)sender).BindingContext;
            var oSwitchPopup = new SwitchPopup();

            oSwitchPopup.DeviceSelectedMethod += DelegateMethod;
            await Navigation.PushAsync(oSwitchPopup);
        }
        /// <summary>
        /// On beacon configed
        /// </summary>
        private void OnBeaconConfigged(BeaconModel newBeacon)
        {
            if (newBeacon == null)
            {
                return;
            }

            _oListSource.Add(newBeacon);
            App.ShowToast(AppResources.noswitchselected_explanation_beacons);
            SaveAndRefresh();
        }
        public async Task <Place> GetPlaceByBeaconAsync(BeaconModel beaconModel)
        {
            var parameters = new Dictionary <string, string>
            {
                ["beaconId"] = beaconModel.UUID,
                ["major"]    = beaconModel.Major.ToString(),
                ["minor"]    = beaconModel.Minor.ToString()
            };
            var result = await MobileService.InvokeApiAsync <Place>("PlaceItemCustom", HttpMethod.Get, parameters);

            return(result);
        }
Ejemplo n.º 10
0
        public ActionResult EditPlan(BeaconModel bm)
        {
            var beacons = new List <BeaconModel>();
            var tracks  = new List <BeaconModel>();

            string[] seperator    = { " " };
            string[] posSeperator = { "," };


            try
            {
                string[] beaconIdList = bm.beaconIDString.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

                string[] beaconPosList = bm.beaconPosString.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
                string[] officeids     = bm.OfficeIDString.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

                string[] trackPosList = bm.trackPosString.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < beaconPosList.Length; i++)
                {
                    string[] xyPos  = beaconPosList[i].Split(posSeperator, StringSplitOptions.RemoveEmptyEntries);
                    float    floatx = float.Parse(xyPos[0]);
                    float    floaty = float.Parse(xyPos[1]);
                    beacons.Add(new BeaconModel {
                        OfficeID = int.Parse(officeids[i]), beaconId = beaconIdList[i], xPos = floatx, yPos = floaty
                    });
                }
                for (int i = 0; i < trackPosList.Length; i++)
                {
                    string[] xyPos  = trackPosList[i].Split(posSeperator, StringSplitOptions.RemoveEmptyEntries);
                    float    floatx = float.Parse(xyPos[0]);
                    float    floaty = float.Parse(xyPos[1]);
                    tracks.Add(new BeaconModel {
                        FloorID = bm.FloorID, xPos = floatx, yPos = floaty
                    });
                }

                foreach (var beacon in beacons)
                {
                    dbmapper.AddBeacon(beacon);
                }
                foreach (var track in tracks)
                {
                    dbmapper.AddTrack(track);
                }
            }
            catch (Exception)
            {
            }

            ViewBag.bString = bm.beaconPosString;

            return(RedirectToAction("EditPlan", new { id = bm.FloorID }));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// save the beacon
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ToolbarItem_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUUID.Text))
            {
                UserDialogs.Instance.Toast(AppResources.txt_beacon_UUID_error);
            }
            bool isValid = Guid.TryParse(txtUUID.Text, out Guid uuID);

            if (!isValid)
            {
                UserDialogs.Instance.Toast(AppResources.txt_beacon_UUID_error2);
            }
            else
            {
                if (string.IsNullOrEmpty(txtMajor.Text))
                {
                    txtMajor.Text = "0";
                }
                if (string.IsNullOrEmpty(txtMinor.Text))
                {
                    txtMinor.Text = "0";
                }
                if (ushort.TryParse(txtMinor.Text, out ushort minor))
                {
                    if (ushort.TryParse(txtMajor.Text, out ushort major))
                    {
                        var name = await GetNameAsync();

                        if (!string.IsNullOrEmpty(name))
                        {
                            var beacon = new BeaconModel()
                            {
                                UUID    = uuID,
                                Id      = uuID.ToString(),
                                Name    = name,
                                Enabled = true,
                                Minor   = minor,
                                Major   = major
                            };
                            _Callback.Invoke(beacon);
                            await Navigation.PopAsync();
                        }
                    }
                    await Navigation.PopAsync();
                }
            }
        }
Ejemplo n.º 12
0
        private async void OnBeaconFound(object sender, BeaconModel beaconModel)
        {
            try
            {
                _placeService = _placeService ?? ServiceLocator.Instance.Resolve <IPlaceService>();
                var place = await _placeService.GetPlaceByBeaconAsync(beaconModel);

                var feedbackPage = _rootPage.CurrentPage as FeedbackPage;
                if (feedbackPage == null || feedbackPage.ViewModel?.PlaceId != place.Id)
                {
                    await _rootPage.PushAsync(new FeedbackPage(place.Id, place.Name));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Ejemplo n.º 13
0
        public async Task <BeaconModel> UpdateAsync(BeaconModel model, int clientId, int userId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanEditBeacon))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var beacon = _beaconMapper.ConvertToDataModel(model);

            beacon.UpdatedOn = DateTime.UtcNow;

            beacon = await _beaconRepository.UpdateAsync(beacon);

            return(_beaconMapper.ConvertToModel(beacon));
        }
Ejemplo n.º 14
0
        private async Task <IActionResult> Add(BeaconParameter param)
        {
            var data = new BeaconModel();

            data.id             = Guid.NewGuid().ToString("N") + DateTime.UtcNow.Ticks;
            data.UserUuid       = param.UserUuid;
            data.UserMajor      = param.UserMajor;
            data.UserMinor      = param.UserMinor;
            data.BeaconUuid     = param.BeaconUuid;
            data.Count          = param.Count;
            data.Distance       = param.Distance;
            data.ElaspedTime    = param.ElaspedTime;
            data.LastDetectTime = param.LastDetectTime;
            data.Major          = param.Major;
            data.Minor          = param.Minor;
            data.Rssi           = param.Rssi;
            data.TXPower        = param.TXPower;
            var result = await Cosmos.Beacon.CreateItemAsync(data);

            return(new StatusCodeResult(201));
        }
Ejemplo n.º 15
0
        private async Task Upsert(BeaconModel b1, BeaconModel b2)
        {
            var item = new ContactModel();
            var pk   = $"{b1.UserMajor}.{b1.UserMinor}-{b2.UserMajor}.{b2.UserMinor}";

            item.id           = $"{b1.UserMajor}.{b1.UserMinor}-{b1.KeyTime}-{b2.UserMajor}.{b2.UserMinor}";
            item.KeyTime      = b1.KeyTime;
            item.PartitionKey = pk;
            item.Beacon1      = b1;
            item.Beacon2      = b2;
            Logger.LogInformation($"{nameof(ContactFunction)} Upsert id:{item.id}");
            try
            {
                var result = await Store.Contact.UpsertItemAsync(item, new PartitionKey(pk));

                Logger.LogInformation($"{nameof(ContactFunction)} Complete Upsert id:{item.id}");
            }
            catch (CosmosException ex)
            {
                Logger.LogError(ex, $"{nameof(ContactFunction)} Throw from Upsert id:{item.id}");
            }
        }
Ejemplo n.º 16
0
        public async Task OnBeaconEvent(BeaconEventArgs eventArgs)
        {
            try
            {
                Beacon beacon = eventArgs.Beacon;

                if (eventArgs.EventType != BeaconEventType.None)
                {
                    Logger.Debug("MainPage.OnBeaconEventAsync: '" + eventArgs.EventType + "' event from " + beacon);
                }

                bool isExistingBeacon = false;

                if (BeaconModel.Contains(beacon))
                {
                    if (eventArgs.EventType == BeaconEventType.Exit)
                    {
                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => BeaconModel.Remove(beacon));
                    }
                    else
                    {
                        BeaconModel.AddOrReplace(beacon);
                    }

                    isExistingBeacon = true;
                }

                if (!isExistingBeacon)
                {
                    BeaconModel.AddOrReplace(beacon);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while add/update beacon", e);
            }
        }
Ejemplo n.º 17
0
        private async void OnBeaconFound(object sender, BeaconModel beaconModel)
        {
            try
            {
                var place = await PlaceService.GetPlaceByBeaconAsync(beaconModel);

                if (place != null)
                {
                    if (!_feedbackWasShown)
                    {
                        _feedbackWasShown = true;
                        ShowViewModel <FeedbackViewModel>(new { id = place.Id, name = place.Name });
                    }
                    else
                    {
                        Mvx.Resolve <IMvxMessenger>().Publish(new BeaconFoundMessage(this, place.Id, place.Name));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"{ex}\n{beaconModel.ToString()}");
            }
        }
 public Task Upsert(BeaconModel beacon)
 {
     return(_db.Beacon.UpsertItemAsync <BeaconModel>(beacon, new PartitionKey(beacon.PartitionKey)));
 }
Ejemplo n.º 19
0
 public void CreateMethod()
 {
     // action
     var model = new BeaconModel();
 }