private void GetBeaconById(int id) { BeaconDao beaconDao = new BeaconDao(); Beacon beacon = beaconDao.GetBeaconById(id); if (beacon == null) { ServiceClient.Send(NOT_FOUND_ERROR); return; } string json = Newtonsoft.Json.JsonConvert.SerializeObject(beacon); ServiceClient.Send(json); }
/* Updates the beacon that is provided as json */ private void SetMode(string[] dataItems) { /* Check data */ if (dataItems.Length < 3) { ServiceClient.Send(CreateError_SetMode()); return; } string mode = dataItems[2]; /* If mode string is invalid */ if (!ServerSettings.Modes.ContainsKey(mode)) { ServiceClient.Send(CreateError_SetMode()); return; } /* If fingerprinting mode is being tried to set */ if (ServerSettings.Modes[mode] == Enums.ServerModes.Fingerprinting) { /* Check the command whether it is valid for the fingerprinting */ if (dataItems.Length < 11) { ServiceClient.Send(CreateError_SetMode()); return; } /* Check the parameters */ int envIndex = GetIndex(dataItems, "-env"); if (envIndex == -1) { ServiceClient.Send(CreateError_SetMode()); return; } int beaconIndex = GetIndex(dataItems, "-beacon"); if (beaconIndex == -1) { ServiceClient.Send(CreateError_SetMode()); return; } int xIndex = GetIndex(dataItems, "-x"); if (xIndex == -1) { ServiceClient.Send(CreateError_SetMode()); return; } int yIndex = GetIndex(dataItems, "-y"); if (yIndex == -1) { ServiceClient.Send(CreateError_SetMode()); return; } /* Exceptions will be handled by ServiceClient */ int env = int.Parse(dataItems[envIndex + 1]); int beaconId = int.Parse(dataItems[beaconIndex + 1]); int x = int.Parse(dataItems[xIndex + 1]); int y = int.Parse(dataItems[yIndex + 1]); /* Get the mac address of the beacon provided! */ BeaconDao dao = new BeaconDao(); Beacon beacon = dao.GetBeaconById(beaconId); /*Set coordinates*/ FingerprintingSettings.Fingerprinting_EnvironmentId = env; FingerprintingSettings.Fingerprinting_BeaconId = beaconId; FingerprintingSettings.Fingerprinting_BeaconMacAddress = beacon.MACAddress; FingerprintingSettings.Fingerprinting_X = x; FingerprintingSettings.Fingerprinting_Y = y; } else if (ServerSettings.Modes[mode] == Enums.ServerModes.Positioning) { /* Check the command whether it is valid for positioning */ if (dataItems.Length < 5) { ServiceClient.Send(CreateError_SetMode()); return; } /* Check the parameters */ int beaconIndex = GetIndex(dataItems, "-beacon"); if (beaconIndex == -1) { ServiceClient.Send(CreateError_SetMode()); return; } int beaconId = int.Parse(dataItems[beaconIndex + 1]); /* Get the mac address of the beacon provided! */ BeaconDao dao = new BeaconDao(); Beacon beacon = dao.GetBeaconById(beaconId); /* Set the beacon to be positioned */ PositioningParams.Positioning_BeaconId = beaconId; PositioningParams.Positioning_BeaconMacAddress = beacon.MACAddress; } /* Set mode */ ServerSettings.ServerMode = ServerSettings.Modes[mode]; ServiceClient.Send(OK); }