GetDeviceDefinitions returns all of the available device configurations that Jetstream® supports. A device definition is a unique definition for a specific device manufacturer, name of the device and its firmware version. Request object for Jetstream GetDeviceDefinitions.
Наследование: JetstreamRequest
        /// <summary>
        /// Displays view to add new device
        /// </summary>
        /// <returns></returns>
        public ActionResult AddDevice()
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    // construct a Jetstream service client
                    JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey);

                    // create the GetDeviceDefinitions request
                    GetDeviceDefinitionsRequest request = new GetDeviceDefinitionsRequest();

                    // call the Jetstream GetDeviceDefinitions ReST endpoint
                    GetDeviceDefinitionsResponse response = client.GetDeviceDefinitions(request);

                    if (response.Body != null)
                    {
                        //Get the device definations for binding to model dropdown
                        List<Models> modelList = response.DeviceDefinitionList.Select(model => new Models
                        {
                            ModelId = model.Id,
                            Name = model.Name
                        }).ToList();

                        ViewBag.ModelList = new SelectList(modelList.OrderBy(x => x.Name), "ModelId", "Name");
                    }
                    return View("AddDevice");
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : AddDevice() :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : AddDevice() :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Redirect to add device screen
        /// </summary>
        /// <param name="deviceMl"></param>
        /// <returns></returns>
        public ActionResult RedirectToAddDevice(DeviceModel deviceMl)
        {
            // construct a Jetstream service client
            JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey);

            // create the GetDeviceDefinitions request
            GetDeviceDefinitionsRequest request = new GetDeviceDefinitionsRequest();

            // call the Jetstream GetDeviceDefinitions ReST endpoint
            GetDeviceDefinitionsResponse response = client.GetDeviceDefinitions(request);

            if (response.Body != null)
            {
                //Get the device defination for binding to model dropdown
                List<Models> modelList = response.DeviceDefinitionList.Select(model => new Models
                {
                    ModelId = model.Id,
                    Name = model.Name
                }).ToList();

                ViewBag.ModelList = new SelectList(modelList.OrderBy(x => x.Name), "ModelId", "Name");
            }

            return View("AddDevice", deviceMl);
        }
        /// <summary>
        /// Edit current Device
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public ActionResult EditCurrentDevice(int deviceId)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                DeviceModel deviceMl;
                using (JetstreamClient objMainServiceClient = new JetstreamClient())
                {
                    deviceMl = objMainServiceClient.GetDeviceByDeviceId(deviceId);
                }

                // construct a Jetstream service client
                JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey);

                // create the GetDeviceDefinitions request
                GetDeviceDefinitionsRequest request = new GetDeviceDefinitionsRequest();

                // call the Jetstream GetDeviceDefinitions ReST endpoint
                GetDeviceDefinitionsResponse response = client.GetDeviceDefinitions(request);

                if (!string.IsNullOrEmpty(response.Body))
                {
                    //Get the device definations for binding to model dropdown
                    var modelList = response.DeviceDefinitionList.Select(model => new Models
                    {
                        ModelId = model.Id,
                        Name = model.Name
                    }).ToList();

                    ViewBag.ModelList = new SelectList(modelList.OrderBy(x => x.Name), "ModelId", "Name", deviceMl.DeviceGuid);
                }

                return View("EditCurrentDevice", deviceMl);
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : EditCurrentDevice(int deviceId) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : EditCurrentDevice(int deviceId) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Method to update passes to all the device
        /// </summary>
        /// <param name="userMl"></param>
        private static void UpdatePasses(UsersModel userMl)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (!string.IsNullOrEmpty(userMl.PassRFID))
                {
                    // construct a Jetstream service client
                    JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url,
                        JetstreamConfiguration.ApplicationAccessKey);

                    // create the GetDeviceDefinitions request
                    GetDeviceDefinitionsRequest deviceRequest = new GetDeviceDefinitionsRequest();

                    // call the Jetstream GetDeviceDefinitions ReST endpoint
                    GetDeviceDefinitionsResponse deviceResponse = client.GetDeviceDefinitions(deviceRequest);

                    //List the user passRFId
                    List<string> passes = new List<string> { userMl.PassRFID.ToUpper() };

                    //Get the list of Devices from local database
                    IEnumerable<DeviceModel> devices;
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        devices = objMainServiceClient.GetDeviceList();
                    }

                    //Itterate through the list of devices
                    foreach (var device in devices)
                    {
                        //get the device defination list for checking if device allow pass update
                        var deviceModel =
                            deviceResponse.DeviceDefinitionList.Where(x => x.Id == device.DeviceGuid).ToList();

                        if (deviceModel.Count > 0)
                        {
                            //Check if device allow pass update
                            var jetstreamGetDeviceDefinitionsResponseDeviceDefinition = deviceModel.FirstOrDefault();
                            bool updatePass = jetstreamGetDeviceDefinitionsResponseDeviceDefinition != null &&
                                              jetstreamGetDeviceDefinitionsResponseDeviceDefinition.CommandList
                                                  .DeviceSpecificCommandList.DeviceSpecificCommand.ToList()
                                                  .Select(x => x.CommandName)
                                                  .Contains("UpdatePasses");

                            if (updatePass)
                            {
                                //Update Pass to device
                                UpdatePassesRequest updateRequest = new UpdatePassesRequest
                                {
                                    LogicalDeviceId = device.LogicalDeviceId
                                };
                                if (userMl.Status != null && userMl.Status.Value)
                                {
                                    updateRequest.Add = passes;
                                }
                                else
                                {
                                    updateRequest.Remove = passes;
                                }

                                client.DeviceSpecificCommand(updateRequest);
                            }
                        }
                    }
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : UpdatePasses(UsersModel userMl) :: UserController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);
                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : UpdatePasses(UsersModel userMl) :: UserController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
            }
        }
        /// <summary>
        /// Method to process the pass syncronization event
        /// </summary>
        private void ProcessPassSynchronizationEvent()
        {
            try
            {
                StringBuilder sb = new StringBuilder();

                // construct a Jetstream service client
                JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.URL, JetstreamConfiguration.ApplicationAccessKey);

                // create the GetDeviceDefinitions request
                GetDeviceDefinitionsRequest deviceRequest = new GetDeviceDefinitionsRequest();

                // call the Jetstream GetDeviceDefinitions ReST endpoint
                GetDeviceDefinitionsResponse deviceResponse = client.GetDeviceDefinitions(deviceRequest);

                List<Device> devices = JetstreamEventRepository.GetDevices();

                //Get the passrfids to be added or updated
                List<User> users = JetstreamEventRepository.GetUser();
                List<string> passesAdd = users.Where(x => x.StatusId == 1).Select(x => x.PassRFID).Distinct().ToList();
                List<string> passesRemove = users.Where(x => x.StatusId == 0).Select(x => x.PassRFID).Distinct().ToList();

                foreach (var device in devices)
                {
                    var deviceModel = deviceResponse.DeviceDefinitionList.Where(x => x.Id == device.DeviceGuid).ToList();

                    if (deviceModel.Count > 0)
                    {
                        var jetstreamGetDeviceDefinitionsResponseDeviceDefinition = deviceModel.FirstOrDefault();
                        bool updatePass = jetstreamGetDeviceDefinitionsResponseDeviceDefinition != null && jetstreamGetDeviceDefinitionsResponseDeviceDefinition.CommandList.DeviceSpecificCommandList.DeviceSpecificCommand.ToList().Select(x => x.CommandName).Contains("UpdatePasses");

                        if (updatePass)
                        {
                            GetPassesRequest getPassRequest = new GetPassesRequest
                            {
                                LogicalDeviceId = device.LogicalDeviceId
                            };
                            DeviceSpecificCommandResponse getPassResponse = client.DeviceSpecificCommand(getPassRequest);

                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.LoadXml(getPassResponse.Body);

                            string xpath = System.Configuration.ConfigurationManager.AppSettings["xpath"];
                            var nodes = xmlDoc.SelectNodes(xpath);

                            if (nodes != null)
                                foreach (XmlNode childrenNode in nodes)
                                {
                                    var user = users.FirstOrDefault(x => x.PassRFID == childrenNode.Value);
                                    if (user == null)
                                    {
                                        passesRemove.Add(childrenNode.Value);
                                    }
                                    else
                                    {
                                        passesAdd.Remove(childrenNode.Value);
                                    }
                                }

                            UpdatePassesRequest updateRequest = new UpdatePassesRequest
                            {
                                LogicalDeviceId = device.LogicalDeviceId,
                                Add = passesAdd,
                                Remove = passesRemove
                            };

                            // call the Jetstream ResT endpoint 
                            client.DeviceSpecificCommand(updateRequest);
                        }
                    }
                    sb.AppendLine("ProcessPassSynchronizationEvent for Logical Device " + device.LogicalDeviceId);
                }

                // write the collected data to the event log
                EventLog.WriteEntry("JetstreamSDK ", sb.ToString());
            }
            catch (Exception)
            {
                // ignored
            }
        }
        public void GetDeviceDefinitionsTest()
        {
            try
            {   // construct a Jetstream service client
                JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey);

                // create the GetDeviceDefinitions request
                GetDeviceDefinitionsRequest request = new GetDeviceDefinitionsRequest();

                // call the Jetstream GetDeviceDefinitions ReST endpoint
                GetDeviceDefinitionsResponse response = client.GetDeviceDefinitions(request);

                if (response.Body != null)
                {
                    //contain data
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }