Beispiel #1
0
        public async Task <HttpResponseMessage> GetDevices(string CompanyName, string SiteName)
        {
            MonitorDevices objMonitorDevice = null;

            //Check the Parameter search or not,if it then add in the QueryParams,else keep as it is
            if (!string.IsNullOrEmpty(CompanyName) && !string.IsNullOrEmpty(SiteName))
            {
                queryParams = new FormUrlEncodedContent(new Dictionary <string, string>()
                {
                    { "sn", /*model.CompanyName*/ ConfigurationManager.AppSettings["sn"] },
                    { "bn", /* model.SiteName*/ ConfigurationManager.AppSettings["bn"] },
                }).ReadAsStringAsync().Result;
                completeFatiAPI = completeFatiAPI + "?" + queryParams;
            }

            try
            {
                var result = await httpClient.GetAsync(completeFatiAPI);

                if (result.IsSuccessStatusCode)
                {
                    string resultContent = result.Content.ReadAsAsync <string>().Result;
                    objMonitorDevice = JsonConvert.DeserializeObject <MonitorDevices>(resultContent);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objMonitorDevice), Encoding.UTF8, "application/json")
            });
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> GetDevices(RequestLocationDataVM model)
        {
            MonitorDevices objMonitorDevice = new MonitorDevices();

            //Notification objNotifications = new Notification();
            using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
            {
                Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId, model.SiteName);
                CommonHeaderInitializeHttpClient(objSite.RtlsConfiguration.EngageBaseAddressUri);

                ////Check the Parameter search or not,if it then add in the QueryParams,else keep as it is
                queryParams = new FormUrlEncodedContent(new Dictionary <string, string>()
                {
                    { "sn", objSite.RtlsConfiguration.EngageSiteName },
                    { "bn", objSite.RtlsConfiguration.EngageBuildingName }
                    //,
                    //{"device_ids",String.Join(",",model.MacAddresses) }
                }).ReadAsStringAsync().Result;

                try
                {
                    //var result = await httpClient.GetAsync(completeFatiAPI, new StringContent(queryParams, Encoding.UTF8, "application/x-www-form-urlencoded"));
                    var result = await httpClient.GetAsync(completeFatiAPI);

                    if (result.IsSuccessStatusCode)
                    {
                        String msg = "";

                        string resultContent = await result.Content.ReadAsStringAsync();

                        objMonitorDevice = JsonConvert.DeserializeObject <MonitorDevices>(resultContent);
                        using (MacAddressRepository objMacRepo = new MacAddressRepository())
                        {
                            msg = objMacRepo.CheckDeviceRegisted(objMonitorDevice, model.SiteId);
                        }
                        objMonitorDevice.result.errmsg = msg;
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objMonitorDevice), Encoding.UTF8, "application/json")
                          //Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Beispiel #3
0
        public string CheckDeviceRegisted(MonitorDevices model, int siteid)
        {
            string adminMessage = "";

            try
            {
                foreach (var rec in model.records)
                {
                    //If MacAddress already exist with None status then
                    if (db.Device.Any(m => m.MacAddress == rec.device_id))
                    {
                        var objMac = db.Device.FirstOrDefault(m => m.MacAddress == rec.device_id);
                        if (db.DeviceAssociateSite.Any(m => m.DeviceId == objMac.DeviceId))
                        {
                            var objDevice = db.DeviceAssociateSite.FirstOrDefault(m => m.DeviceId == objMac.DeviceId);
                            if (objDevice.status != DeviceStatus.Registered)
                            {
                                objDevice.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                                objDevice.status          = DeviceStatus.Registered;
                                db.Entry(objDevice).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                                adminMessage += "[ " + rec.device_id + " ] Change Device Status to Registered." +
                                                Environment.NewLine;
                            }
                        }
                        else
                        {
                            DeviceAssociateSite objDeviceAssociate = new DeviceAssociateSite();
                            objDeviceAssociate.SiteId          = siteid;
                            objDeviceAssociate.DeviceId        = objMac.DeviceId;
                            objDeviceAssociate.CreatedDateTime = DateTime.Now;
                            objDeviceAssociate.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                            //objDeviceAssociate.IsDeviceRegisterInRtls = true;
                            db.DeviceAssociateSite.Add(objDeviceAssociate);
                            db.SaveChanges();
                            adminMessage += "[ " + rec.device_id + " ]  Added to Associate Site Mapping." +
                                            Environment.NewLine;
                        }
                    }
                    else
                    {
                        Device objMac = new Device();
                        objMac.MacAddress = rec.device_id;
                        db.Device.Add(objMac);
                        db.SaveChanges();
                        DeviceAssociateSite objDeviceAssociate = new DeviceAssociateSite();
                        objDeviceAssociate.SiteId          = siteid;
                        objDeviceAssociate.DeviceId        = objMac.DeviceId;
                        objDeviceAssociate.CreatedDateTime = DateTime.Now;
                        //change
                        //objDeviceAssociate.IsDeviceRegisterInRtls = true;
                        objDeviceAssociate.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                        objDeviceAssociate.status = DeviceStatus.Registered;
                        db.DeviceAssociateSite.Add(objDeviceAssociate);
                        db.SaveChanges();
                        adminMessage += "[ " + rec.device_id + " ]  Added to Device & Associate Site Mapping." +
                                        Environment.NewLine;
                    }
                }
                if (string.IsNullOrEmpty(adminMessage))
                {
                    adminMessage += "All Device Validated for Registration . Status OK ." +
                                    Environment.NewLine;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(adminMessage);
        }