/// <summary> /// /// </summary> /// <param name="MacAddress"></param> /// <param name="LocationServiceType"></param> /// <returns></returns> public void UpdateLocationServiceTypeforMac(RequestOmniModel objRequestOmniModel, RtlsEngine EngineType) { if (db.Device.Any(m => m.MacAddress == objRequestOmniModel.MacAddress)) { var ObjDeviceAssociateSite = db.DeviceAssociateSite.First(m => m.Device.MacAddress == objRequestOmniModel.MacAddress && m.SiteId == objRequestOmniModel.SiteId); if (objRequestOmniModel.NotificationTypeId == 10) { ObjDeviceAssociateSite.IsTrackByAdmin = true; } else if (objRequestOmniModel.NotificationTypeId == 20) { ObjDeviceAssociateSite.IsEntryNotify = true; } if (EngineType == RtlsEngine.OmniEngine) { ObjDeviceAssociateSite.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.OmniEngine; } else if (EngineType == RtlsEngine.EngageEngine) { ObjDeviceAssociateSite.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine; } ObjDeviceAssociateSite.status = DeviceStatus.Registered; db.Entry(ObjDeviceAssociateSite).State = EntityState.Modified; db.SaveChanges(); } }
public async Task regMacToOmniEngine(RequestOmniModel objRequestOmniModel) { //ReturnData result = new ReturnData(); string retResult = null; SecomRegisterDevice objSecomRegisterDevice = new SecomRegisterDevice(); objSecomRegisterDevice.mac = objRequestOmniModel.MacAddress; objSecomRegisterDevice.station_info.device.id = objRequestOmniModel.MacAddress; objSecomRegisterDevice.station_info.user.label = objRequestOmniModel.UserName; using (var objSecomClient = new SecomClient()) { var jsonToken = await objSecomClient.GetSecomLoginToken(); var token_details = JObject.Parse(jsonToken); var token = token_details["jwt"].ToString(); //Register the Mac retResult = await objSecomClient.RegisterDevice(objSecomRegisterDevice, token); //If the uniqueId is not retured try with GetDevice to get the uniqueId if (string.IsNullOrEmpty(retResult)) { retResult = await objSecomClient.GetDevice(objRequestOmniModel.MacAddress, token); } if (!string.IsNullOrEmpty(retResult)) { await objOmniDeviceMappingRepository.CreateMacUniqueId(objRequestOmniModel.MacAddress, retResult); } } }
public async Task <HttpResponseMessage> AddDevice(RequestOmniModel objRequestOmniModel) { //objRequestOmniModel.MacAddress= "7z:c5:37:c0:83:y3"; //create the RequestModel for secom api string result = null; try { using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository()) { //Get the EngageEngine Base Url as per SiteId Site objSiteConfiguration = objRtlsConfigurationRepository.GetAsPerSite(objRequestOmniModel.SiteId); if (objSiteConfiguration.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine) { OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness(); await objOmniEngineBusiness.regMacToOmniEngine(objRequestOmniModel); using (MacAddressRepository objMacAddressRepository = new MacAddressRepository()) { objMacAddressRepository.UpdateLocationServiceTypeforMac(objRequestOmniModel, objSiteConfiguration.RtlsConfiguration.RtlsEngineType); } //string OmniBaseAddressUri = objSiteConfiguration.RtlsConfiguration.OmniBaseAddressUri; } if (objSiteConfiguration.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine) { EngageEngineBusiness objEngageEngineBusiness = new EngageEngineBusiness(); if (await objEngageEngineBusiness.regMacToEngageEngine(objRequestOmniModel)) { using (MacAddressRepository objMacAddressRepository = new MacAddressRepository()) { objMacAddressRepository.UpdateLocationServiceTypeforMac(objRequestOmniModel, objSiteConfiguration.RtlsConfiguration.RtlsEngineType); } } //string EngageBaseAddressUri = objSiteConfiguration.RtlsConfiguration.EngageBaseAddressUri; } } } catch (Exception ex) { result = ex.Message; log.Error(ex.Message); } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json") }); }
//DeleteDevices in OmniEngiene public async Task <bool> DeleteDevices(RequestOmniModel objRequestOmniModel) { ReturnData result = new ReturnData(); using (var objSecomClient = new SecomClient()) { //Get Token Through login var jsonToken = await objSecomClient.GetSecomLoginToken(); var token_details = JObject.Parse(jsonToken); var token = token_details["jwt"].ToString(); //Get Unique Id from OmniMapping Table var UniqueId = objOmniDeviceMappingRepository.ReregisterGetUniqueId(objRequestOmniModel.MacAddress); //call for Delete device var _deleteDevice = await objSecomClient.DeleteDevice(token, UniqueId); return(true); } }
//Reregister in OmniEngiene public async Task <bool> ReRegister(RequestOmniModel objRequestOmniModel) { ReturnData result = new ReturnData(); SecomRegisterDevice objSecomRegisterDevice = new SecomRegisterDevice(); objSecomRegisterDevice.mac = objRequestOmniModel.MacAddress; objSecomRegisterDevice.station_info.device.id = objRequestOmniModel.MacAddress; using (var objSecomClient = new SecomClient()) { //Get Token Through login var jsonToken = await objSecomClient.GetSecomLoginToken(); var token_details = JObject.Parse(jsonToken); var token = token_details["jwt"].ToString(); //Get Unique Id from OmniMapping Table var UniqueId = objOmniDeviceMappingRepository.ReregisterGetUniqueId(objRequestOmniModel.MacAddress); //call for deregister mac var _reriegister = await objSecomClient.ReRegisterDevice(objSecomRegisterDevice, token, UniqueId); return(true); } }
public async Task <bool> regMacToEngageEngine(RequestOmniModel objRequestOmniModel) { bool result = false; EngageRegisterDevice objEngageRegisterDevice = new EngageRegisterDevice(); using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository()) { var objSite = objRtlsConfigurationRepository.GetAsPerSite(objRequestOmniModel.SiteId); objEngageRegisterDevice.EngageBaseAddressUri = objSite.RtlsConfiguration.EngageBaseAddressUri; objEngageRegisterDevice.EngageSiteName = objSite.RtlsConfiguration.EngageSiteName; objEngageRegisterDevice.EngageBuildingName = objSite.RtlsConfiguration.EngageBuildingName; objEngageRegisterDevice.MacAddress = objRequestOmniModel.MacAddress; EngageEngineClient objEngageEngineClient = new EngageEngineClient(); if (await objEngageEngineClient.RegisterDevice(objEngageRegisterDevice)) { result = true; } else { result = false; } } return(result); }
public async Task <HttpResponseMessage> AddDevices(RequestLocationDataVM model) { Notification objNotifications = new Notification(); DeviceAssociateSite deviceid = null; using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository()) { Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId); foreach (var item in model.MacAddresses) { // When Device is coming for reregister in OmniEngiene int deviceId = _OmniDeviceMappingRepository.GetDeviceId(item); deviceid = objRtlsConfigurationRepository.DeviceAssociateSiteStatus(deviceId); if (deviceid.status == DeviceStatus.DeRegistered) { OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness(); RequestOmniModel objRequestOmniModel = new RequestOmniModel(); objRequestOmniModel.MacAddress = item; await objOmniEngineBusiness.ReRegister(objRequestOmniModel); } } //First time devive will store if (deviceid.status == DeviceStatus.None) { try { if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine) { foreach (var item in model.MacAddresses) { OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness(); RequestOmniModel objRequestOmniModel = new RequestOmniModel(); objRequestOmniModel.MacAddress = item; await objOmniEngineBusiness.regMacToOmniEngine(objRequestOmniModel); objNotifications.result.returncode = Convert.ToInt32(FatiApiResult.Success); using (MacAddressRepository objMacRepository = new MacAddressRepository()) { objMacRepository.RegisterListOfMacAddresses(model); } } } if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine) { foreach (var item in model.MacAddresses) { EngageEngineBusiness objEngageEngineBusiness = new EngageEngineBusiness(); RequestOmniModel objRequestOmniModel = new RequestOmniModel(); objRequestOmniModel.SiteId = model.SiteId; objRequestOmniModel.MacAddress = item; if (await objEngageEngineBusiness.regMacToEngageEngine(objRequestOmniModel)) { objNotifications.result.returncode = Convert.ToInt32(FatiApiResult.Success); using (MacAddressRepository objMacRepository = new MacAddressRepository()) { objMacRepository.RegisterListOfMacAddresses(model); } } } } } catch (Exception ex) { log.Error(ex.InnerException.Message); objNotifications.result.returncode = -1; objNotifications.result.errmsg = ex.InnerException.Message; } } } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json") }); }
public async Task <HttpResponseMessage> DeRegisterDevices(RequestLocationDataVM model) { Notification objNotifications = new Notification(); HttpRequestMessage message = new HttpRequestMessage(); OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness(); RequestOmniModel objRequestOmniModel = new RequestOmniModel(); try { using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository()) { Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId, model.SiteName); if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine) { foreach (var item in model.MacAddresses) { objRequestOmniModel.MacAddress = item; var deregisterData = await objOmniEngineBusiness.DeregisterMacFromOmniEngine(objRequestOmniModel); } } else if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine) { CommonHeaderInitializeHttpClient(objSite.RtlsConfiguration.EngageBaseAddressUri); message = new HttpRequestMessage(new HttpMethod("DELETE"), "/api/engage/v1/device_monitors/"); var queryParams = new Dictionary <string, string>() { { "sn", objSite.RtlsConfiguration.EngageSiteName }, { "bn", objSite.RtlsConfiguration.EngageBuildingName }, { "device_ids", String.Join(",", model.MacAddresses) } }; message.Content = new FormUrlEncodedContent(queryParams); try { HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(message); if (httpResponseMessage.EnsureSuccessStatusCode().IsSuccessStatusCode) { string resultContent = await httpResponseMessage.Content.ReadAsStringAsync(); objNotifications = JsonConvert.DeserializeObject <Notification>(resultContent); if (objNotifications.result.returncode == Convert.ToInt32(FatiApiResult.Success)) { using (MacAddressRepository objMacRepository = new MacAddressRepository()) { objMacRepository.DeRegisterListOfMacs(model.MacAddresses); } } } else { objNotifications.result.returncode = Convert.ToInt32(httpResponseMessage.StatusCode.ToString()); objNotifications.result.errmsg = "Some Problem Occured"; } } catch (Exception ex) { string errorType = ex.GetType().ToString(); string errorMessage = errorType + ": " + ex.Message; throw new Exception(errorMessage, ex.InnerException); } } } } catch (Exception ex) { log.Error(ex.InnerException.Message); objNotifications.result.returncode = -1; objNotifications.result.errmsg = ex.InnerException.Message; } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json") }); }
public async Task <HttpResponseMessage> DeleteDevices(RequestLocationDataVM model) { Notification objNotifications = new Notification(); DeviceAssociateSite deviceStatus = null; using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository()) { Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId); foreach (var item in model.MacAddresses) { // When Device is coming to delete in OmniEngiene int deviceId = _OmniDeviceMappingRepository.GetDeviceId(item); deviceStatus = objRtlsConfigurationRepository.DeviceAssociateSiteStatus(deviceId); if (deviceStatus.status == DeviceStatus.DeRegistered) { OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness(); RequestOmniModel objRequestOmniModel = new RequestOmniModel(); objRequestOmniModel.MacAddress = item; var returnStatus = await objOmniEngineBusiness.DeleteDevices(objRequestOmniModel); if (returnStatus == true) { try { //Delete Device ralated data DeviceAssociateSite _DeviceAssociateSite = db.DeviceAssociateSite.FirstOrDefault(k => k.DeviceId == deviceId); Device _Device = db.Device.FirstOrDefault(p => p.DeviceId == deviceId); NetWorkOfSite _NetworkOfSite = db.NetWorkOfSite.Where(p => p.SiteId == model.SiteId).Where(q => q.LocServiceTypeId != 0).FirstOrDefault(); OmniDeviceMapping _OmniDeviceMapping = db.OmniDeviceMapping.FirstOrDefault(k => k.DeviceId == deviceId); //If User registered from CaptivePortal if (_DeviceAssociateSite.IsRegisterInCaptivePortal == true) { WifiUserLoginCredential _WifiUserLoginCredential = db.WifiUserLoginCredential.Where(p => p.Device.DeviceId == deviceId).Where(q => q.NetWorkOfSiteId == _NetworkOfSite.NetWorkOfSiteId).FirstOrDefault(); WifiUser _WifiUser = db.WifiUser.Where(p => p.UserId == _WifiUserLoginCredential.WifiUserId).FirstOrDefault(); UsersAddress _UsersAddress = db.UsersAddress.Where(p => p.UserId == _WifiUser.UserId).FirstOrDefault(); db.UsersAddress.Remove(_UsersAddress); db.WifiUser.Remove(_WifiUser); db.WifiUserLoginCredential.Remove(_WifiUserLoginCredential); } db.DeviceAssociateSite.Remove(_DeviceAssociateSite); db.OmniDeviceMapping.Remove(_OmniDeviceMapping); db.Device.Remove(_Device); db.SaveChanges(); } catch (Exception ex) { log.Error(ex.Message); } } } } } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json") }); }