Example #1
0
        /// <summary>
        /// Get list of Device's commands.
        /// </summary>
        /// <param name="pageNumber">Page Number.</param>
        /// <param name="pageSize">Items count per page.</param>
        /// <param name="loadParents">Enable or Disable loading the Parents objects.</param>
        /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param>
        /// <param name="searchFor">Search text as per the 'Title' field.</param>
        /// <param name="locationID">Filter by Location ID. You can keep it null or empty to ignore this filter.</param>
        /// <param name="DeviceID">Filter by Device ID. You can keep it null or empty to ignore this filter.</param>
        /// <returns></returns>
        public APIDeviceCommandResponseModels.GetDeviceCommandsList GetDeviceCommandsList(string searchFor, long locationID, long DeviceID, bool loadDevice, int pageNumber, int pageSize)
        {
            APIDeviceCommandResponseModels.GetDeviceCommandsList result = new APIDeviceCommandResponseModels.GetDeviceCommandsList();

            IPagedList <DeviceCommand> cmdsPL = uow_Repositories.repoDeviceCommands.GetPagedList(searchFor, DeviceID, locationID, pageNumber, pageSize);
            List <DeviceCommand>       cmds   = cmdsPL.ToList();

            List <APIDeviceCommand> apiCmds = new List <APIDeviceCommand>();

            foreach (DeviceCommand cmd in cmds)
            {
                APIDeviceCommand apiCmd = TypesMapper.APIDeviceCommandAdapter.fromDeviceCommand(cmd, loadDevice);
                apiCmds.Add(apiCmd);
            }
            result.DeviceCommands = apiCmds;


            PagingInfoResponseModel pagingInfo = new PagingInfoResponseModel();

            pagingInfo.CurrentPage  = cmdsPL.PageNumber;
            pagingInfo.ItemsPerPage = cmdsPL.PageSize;
            pagingInfo.ItemsCount   = cmdsPL.TotalItemCount;
            pagingInfo.PagesCount   = cmdsPL.PageCount;
            result.PagingInfo       = pagingInfo;
            return(result);
        }
Example #2
0
        public static APIDevice fromDevice(Device sourceDevice, bool loadEndPoints, bool loadDeviceCommands)
        {
            APIDevice result = new APIDevice();

            result.ID                      = sourceDevice.ID;
            result.Guid                    = System.Guid.Parse(sourceDevice.GUID.ToString());
            result.KeyPass                 = System.Guid.Parse(sourceDevice.KeyPass.ToString());
            result.Title                   = sourceDevice.Title;
            result.IsConnected             = sourceDevice.IsConnected0;
            result.IsConnectedDelay        = sourceDevice.IsConnectedDelay;
            result.LastConnectionTimeStamp = sourceDevice.LastConnectionTimeStamp;
            result.UTC_Diff                = sourceDevice.UTC_Diff;

            #region Load Master Types
            result.DeviceStatus = TypesMapper.APIDeviceStatusAdapter.fromDeviceStatus(sourceDevice.DeviceStatu);
            #endregion

            #region Load Parents

            #endregion

            #region Load Childs
            #region Load Endpoints
            if (loadEndPoints)
            {
                #region EndPoints
                List <APIEndPoint> ens = new List <APIEndPoint>();
                foreach (Endpoint end in sourceDevice.Endpoints)
                {
                    APIEndPoint apiEnd = APIEndPointAdapter.fromEndpoint(end, false, false);
                    ens.Add(apiEnd);
                }
                result.EndPoints = ens;
                #endregion
            }
            #endregion

            #region Load DeviceCommands
            if (loadDeviceCommands)
            {
                #region Device Commands
                List <APIDeviceCommand> cmds = new List <APIDeviceCommand>();
                foreach (DeviceCommand cmd in sourceDevice.DeviceCommands)
                {
                    APIDeviceCommand apiCmd = APIDeviceCommandAdapter.fromDeviceCommand(cmd, false);
                    cmds.Add(apiCmd);
                }
                result.DeviceCommands = cmds;
                #endregion
            }
            #endregion
            #endregion


            return(result);
        }
        public static APIDeviceCommand fromDeviceCommand(DeviceCommand sourceDeviceCommand)
        {
            APIDeviceCommand apiCmd = new APIDeviceCommand();

            apiCmd.ID          = sourceDeviceCommand.ID;
            apiCmd.Title       = sourceDeviceCommand.Title;
            apiCmd.Description = sourceDeviceCommand.Description;
            apiCmd.CommandCode = sourceDeviceCommand.CommandCode;
            apiCmd.DeviceID    = sourceDeviceCommand.DeviceID;
            apiCmd.OwnerID     = sourceDeviceCommand.OwnerID;
            return(apiCmd);
        }
        public static APIDeviceCommand fromDeviceCommand(DeviceCommand sourceDeviceCommand, bool loadParents, bool loadChilds)
        {
            APIDeviceCommand apiCmd = new APIDeviceCommand();

            apiCmd.ID          = sourceDeviceCommand.ID;
            apiCmd.Title       = sourceDeviceCommand.Title;
            apiCmd.Description = sourceDeviceCommand.Description;
            apiCmd.CommandCode = sourceDeviceCommand.CommandCode;

            #region Parents
            if (loadParents)
            {
                #region Device
                apiCmd.Device = TypesMapper.APIDeviceAdapter.fromDevice(sourceDeviceCommand.Device, false, false);

                #endregion
            }
            #endregion
            return(apiCmd);
        }
Example #5
0
        /// <summary>
        /// Get list of Device's commands.
        /// </summary>
        /// <param name="pageNumber">Page Number.</param>
        /// <param name="pageSize">Items count per page.</param>
        /// <param name="loadParents">Enable or Disable loading the Parents objects.</param>
        /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param>
        /// <param name="searchFor">Search text as per the 'Title' field.</param>
        /// <param name="locationID">Filter by Location ID. You can keep it null or empty to ignore this filter.</param>
        /// <param name="DeviceID">Filter by Device ID. You can keep it null or empty to ignore this filter.</param>
        /// <returns></returns>
        public List <APIDeviceCommand> GetDeviceCommands(int pageNumber, int pageSize, bool loadParents, bool loadChilds, string searchFor, long locationID, long DeviceID)
        {
            List <APIDeviceCommand> result = new List <APIDeviceCommand>();
            List <DeviceCommand>    cmds   = db.DeviceCommands
                                             .Where(e =>
                                                    (e.Title.Contains(searchFor) || (searchFor == null || searchFor == "")) &&//Filter by Search "Title"
                                                    ((DeviceID == null || DeviceID == 0) || (e.DeviceID == DeviceID)) &&
                                                    ((e.Device.LinkDevicesLocations.Any(l => l.LocationID == locationID)) || (locationID == null || locationID == 0))//Filter by locationID
                                                    ).OrderBy(e => e.Title)
                                             .Skip(pageSize * (pageNumber - 1))
                                             .Take(pageSize).ToList();

            foreach (DeviceCommand cmd in cmds)
            {
                APIDeviceCommand apiCmd = new APIDeviceCommand();
                apiCmd = TypesMapper.APIDeviceCommandAdapter.fromDeviceCommand(cmd, loadParents, loadChilds);
                result.Add(apiCmd);
            }
            return(result);
        }
Example #6
0
        public static APIDevice fromDevice(Device sourceDevice)
        {
            APIDevice result = new APIDevice();

            result.ID                      = sourceDevice.ID;
            result.Guid                    = System.Guid.Parse(sourceDevice.GUID.ToString());
            result.KeyPass                 = System.Guid.Parse(sourceDevice.KeyPass.ToString());
            result.Title                   = sourceDevice.Title;
            result.PinCode                 = sourceDevice.PinCode;
            result.StatusID                = (long)sourceDevice.StatusID;
            result.StatusTitle             = sourceDevice.DeviceStatu.Title;
            result.IsConnected             = sourceDevice.IsConnected0;
            result.IsConnectedDelay        = sourceDevice.IsConnectedDelay;
            result.LastConnectionTimeStamp = sourceDevice.LastConnectionTimeStamp;
            result.UTC_Diff                = sourceDevice.UTC_Diff;
            //Get Endpoints
            List <APIEndPoint> ens = new List <APIEndPoint>();

            foreach (Endpoint end in sourceDevice.Endpoints)
            {
                APIEndPoint apiEnd = APIEndPointAdapter.fromEndpoint(end);
                ens.Add(apiEnd);
            }
            result.EndPoints = ens;

            //Get Commands
            List <APIDeviceCommand> cmds = new List <APIDeviceCommand>();

            foreach (DeviceCommand cmd in sourceDevice.DeviceCommands)
            {
                APIDeviceCommand apiCmd = APIDeviceCommandAdapter.fromDeviceCommand(cmd);
                cmds.Add(apiCmd);
            }
            result.DeviceCommands = cmds;

            return(result);
        }