コード例 #1
0
        public static Device fromAPIDevice(APIDevice sourceAPIDevice)
        {
            Device result = new Device();
            result.ID = sourceAPIDevice.ID;
            result.GUID = System.Guid.Parse(sourceAPIDevice.Guid.ToString());
            result.KeyPass = System.Guid.Parse(sourceAPIDevice.KeyPass.ToString());
            result.Title = sourceAPIDevice.Title;
            result.PinCode = sourceAPIDevice.PinCode;
            result.StatusID = (long)sourceAPIDevice.StatusID;

            List<Endpoint> ens = new List<Endpoint>();
            foreach (APIEndPoint end in sourceAPIDevice.APIEndPoints)
            {
                Endpoint End = new Endpoint();
                End.ID = end.ID;
                End.GUID = end.GUID;
                End.KeyPass = end.KeyPass;
                End.PinCode = end.PinCode;
                End.Title = end.Title;
                End.TypeID = end.TypeID;
                End.DeviceID = end.DeviceID;

                ens.Add(End);
            }

            result.Endpoints = ens;
            return result;
        }
コード例 #2
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;

            List<APIEndPoint> ens = new List<APIEndPoint>();
            foreach (Endpoint end in sourceDevice.Endpoints)
            {
                APIEndPoint apiEnd = new APIEndPoint();
                apiEnd.ID = end.ID;
                apiEnd.GUID = end.GUID;
                apiEnd.KeyPass = end.KeyPass;
                apiEnd.PinCode = end.PinCode;
                apiEnd.Title = end.Title;
                apiEnd.TypeID = end.TypeID;
                apiEnd.DeviceID = end.DeviceID;

                ens.Add(apiEnd);
            }

            result.APIEndPoints = ens;
            return result;
        }
コード例 #3
0
 /// <summary>
 /// Find Device by Device ID
 /// </summary>
 /// <param name="id">Device ID</param>
 /// <returns>Device object</returns>
 public Device Find(long id)
 {
     Device dev = new Device();
     List<Device> devs = db.Devices.Where(l => l.ID == id).ToList();
     if (devs.Count == 1)
     {
         dev = devs[0];
     }
     else
     {
         throw new Exception("Not Found");
     }
     return dev;
 }
コード例 #4
0
 /// <summary>
 /// Add new Device
 /// </summary>
 /// <param name="title">Device's Title</param>
 /// <returns>Result : Ok or Failed</returns>
 public ResultInfo.Result Add(string title,int utc_Diff,int IsConnectedDelay)
 {
     Device dev = new Device();
     try
     {
         dev.GUID = Guid.NewGuid();
         dev.KeyPass = Guid.NewGuid();
         dev.StatusID = 1;
         dev.Title = title;
         dev.PinCode = "0000";
         dev.UTC_Diff = utc_Diff;
         dev.IsConnected = false;
         dev.IsConnectedDelay = IsConnectedDelay;
         db.Devices.Add(dev);
         db.SaveChanges();
     }
     catch(Exception ex)
     {
         return ResultInfo.GenerateErrorResult(ex.InnerException.ToString());
     }
     return ResultInfo.GenerateOKResult("Saved", dev.ID);
 }
コード例 #5
0
        public ApiResponse SubmitDeviceLog(Models.SubmissionDeviceIO deviceInput)
        {
            ApiResponse oApiResponse = new ApiResponse();

            //Validate KeyPass
            try
            {
                if (string.IsNullOrEmpty(deviceInput.KeyPass))
                {
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);

                    return(oApiResponse);
                }

                //Parse KeyPass
                Guid deviceGuid;
                if (Guid.TryParse(deviceInput.KeyPass, out deviceGuid))
                {
                    //Device keyPass Validation
                    DynThings.Data.Models.Device device = uof_repos.repoDevices.FindByKeyPass(deviceGuid);
                    if (device != null)
                    {
                        //Try Parse ExecutionTimeStamp to DateTime
                        DateTime execTime;
                        if (DateTime.TryParse(deviceInput.ExectionTimeStamp, out execTime))
                        {
                        }
                        else
                        {//DateTime Parse Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return(oApiResponse);
                        }

                        //Submit Data to Database
                        ResultInfo.Result repoResult = uof_repos.repoDeviceIOs.Add(device.ID, deviceInput.Value.ToString(), DeviceIOsRepository.deviceIOType.Log, execTime);

                        //Validate Result
                        if (repoResult.ResultType == ResultInfo.ResultType.Ok)
                        {//Submited
                            ResultInfo.Result result = ResultInfo.GenerateOKResult();
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return(oApiResponse);
                        }
                        else
                        {//Submition Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return(oApiResponse);
                        }
                    }
                }
                else
                {// KeyPass Parse Failed
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return(oApiResponse);
                }
            }
            catch (Exception)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return(oApiResponse);
        }