예제 #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
        private ApiResponse CoreSubmitEndPointInput(Models.SubmissionEndPointIO oEndPointInput)
        {
            ApiResponse oApiResponse = new ApiResponse();

            try
            {
                //Validate KeyPass
                if (string.IsNullOrEmpty(oEndPointInput.KeyPass))
                {
                    ResultInfo.Result result = ResultInfo.GenerateErrorResult("Keypass is missing");
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return(oApiResponse);
                }

                Guid endPointKeyPass;
                if (Guid.TryParse(oEndPointInput.KeyPass, out endPointKeyPass))
                {
                    //endPoint keyPass Validation
                    DynThings.Data.Models.Endpoint oEndpoint = uof_repos.repoEndpoints.FindByKeyPass(endPointKeyPass);

                    if (oEndpoint != null)
                    {
                        //Try Parse ExecutionTimeStamp to DateTime
                        DateTime execTime;
                        if (oEndPointInput.ExectionTimeStamp == "")
                        {
                            oEndPointInput.ExectionTimeStamp = DateTime.UtcNow.AddHours(int.Parse(oEndpoint.Device.UTC_Diff.ToString())).ToString();
                        }
                        if (DateTime.TryParse(oEndPointInput.ExectionTimeStamp, out execTime))
                        {
                        }
                        else
                        {//DateTime Parse Failed
                            ResultInfo.Result result = ResultInfo.GenerateErrorResult("DateTime is not in correct format");
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return(oApiResponse);
                        }

                        //Submit Data to Database
                        ResultInfo.Result repoResult = uof_repos.repoEndpointIOs.SubmitInput(endPointKeyPass, oEndPointInput.Value.ToString(), execTime);

                        oApiResponse = ApiResponseAdapter.fromResult(repoResult);
                    }
                }
                else
                {// KeyPass Parse Failed
                    ResultInfo.Result result = ResultInfo.GenerateErrorResult("Keypass is not valid");
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return(oApiResponse);
                }
            }
            catch (Exception ex)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return(oApiResponse);
        }
예제 #3
0
 public List<Endpoint> GetList(bool EnableUnspecified)
 {
     List<Endpoint> ends = new List<Endpoint>();
     if (EnableUnspecified == true)
     {
         Endpoint end0 = new Endpoint();
         end0.ID = 0;
         end0.Title = "-Select All-";
         ends.Add(end0);
         ends.AddRange(db.Endpoints.OrderBy(e => e.Title).ToList());
     }
     return ends;
 }
예제 #4
0
 /// <summary>
 /// Find Endpoint by EndPoint ID
 /// </summary>
 /// <param name="id">Endpoint ID</param>
 /// <returns>Endpoint object</returns>
 public Endpoint Find(long id)
 {
     Endpoint end = new Endpoint();
     List<Endpoint> ends = db.Endpoints.Where(l => l.ID == id).ToList();
     if (ends.Count == 1)
     {
         end = ends[0];
     }
     else
     {
         throw new Exception("Not Found");
     }
     return end;
 }
예제 #5
0
        private ApiResponse CoreSubmitEndPointInput(Models.SubmissionEndPointIO oEndPointInput)
        {
            ApiResponse oApiResponse = new ApiResponse();

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

                Guid endPointKeyPass;
                if (Guid.TryParse(oEndPointInput.KeyPass, out endPointKeyPass))
                {
                    //endPoint keyPass Validation
                    DynThings.Data.Models.Endpoint oEndpoint = UnitOfWork_Repositories.repoEndpoints.FindByKeyPass(endPointKeyPass);

                    if (oEndpoint != null)
                    {
                        //Try Parse ExecutionTimeStamp to DateTime
                        DateTime execTime;
                        if (oEndPointInput.ExectionTimeStamp == "")
                        {
                            oEndPointInput.ExectionTimeStamp = DateTime.UtcNow.AddHours(int.Parse(oEndpoint.Device.UTC_Diff.ToString())).ToString();
                        }
                        if (DateTime.TryParse(oEndPointInput.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 = UnitOfWork_Repositories.repoEndpointIOs.Add(oEndpoint.ID, oEndPointInput.Value.ToString(), EndpointIOsRepository.EndPointIOType.Input, 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 ex)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return(oApiResponse);
        }
예제 #6
0
 public ResultInfo.Result Add(string title, long typeID, long deviceID,long thingID)
 {
     Endpoint end = new Endpoint();
     try
     {
         end.GUID = Guid.NewGuid();
         end.KeyPass = Guid.NewGuid();
         end.PinCode = "0000";
         end.Title = title;
         end.DeviceID = deviceID;
         end.TypeID = typeID;
         end.ThingID = thingID;
         db.Endpoints.Add(end);
         db.SaveChanges();
         return ResultInfo.GenerateOKResult("Saved", end.ID);
     }
     catch
     {
         return ResultInfo.GetResultByID(1);
     }
 }