Exemple #1
0
        public async Task <HttpResponseMessage> DeRegisterDevices(RequestLocationDataVM model)
        {
            Notification objNotifications = new Notification();

            try
            {
                HttpRequestMessage message = new HttpRequestMessage(new HttpMethod("DELETE"), "/api/engage/v1/device_monitors/");
                var queryParams            = new Dictionary <string, string>()
                {
                    { "sn", ConfigurationManager.AppSettings["sn"] },
                    { "bn", ConfigurationManager.AppSettings["bn"] },
                    { "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> 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")
            });
        }