// Recv-6.11: “Forwarding”
        private OM2MResponsePrimitive Fowarding(OM2MRequestPrimitive request)
        {
            // Check timeout
            if (OM2MTimeStamp.IsTimeout((string)request.RequestExpirationTimestamp))
            {
                throw new OM2MRequestTimeoutException();
            }

            if (OM2MTimeStamp.IsTimeout((string)request.ResultExpirationTimestamp))
            {
                throw new OM2MRequestTimeoutException();
            }

            if (OM2MTimeStamp.IsTimeout((string)request.OperationExecutionTime))
            {
                throw new OM2MRequestTimeoutException();
            }

            // Get remote CSE Id
            string remoteCseId;

            var parts = request.TargetId.Split('/');

            if (parts.Length < 2)
            {
                throw new OM2MNotFoundException("Remote CSE not found");
            }

            remoteCseId = parts[1];

            // ToDo:...

            return(null);
        }
        // 7.3.2.1 Check the validity of received request primitive
        // ToDo:
        private void ValidateRequest(OM2MRequestPrimitive request)
        {
            // Relative timestamp to absoule
            if (request.RequestExpirationTimestamp != null)
            {
                try
                {
                    request.RequestExpirationTimestamp = OM2MTimeStamp.GetTimeStamp(request.RequestExpirationTimestamp);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                    throw new OM2MBadRequestException($"Request expiration timestamp is illegal format: {request.RequestExpirationTimestamp}");
                }
            }
            if (request.ResultExpirationTimestamp != null)
            {
                try
                {
                    request.ResultExpirationTimestamp = OM2MTimeStamp.GetTimeStamp(request.ResultExpirationTimestamp);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                    throw new OM2MBadRequestException($"Result expiration timestamp is illegal format: {request.ResultExpirationTimestamp}");
                }
            }

            if (request.RequestExpirationTimestamp != null)
            {
                bool isTimeOut;

                try
                {
                    isTimeOut = OM2MTimeStamp.IsTimeout((string)request.RequestExpirationTimestamp);
                }
                catch (FormatException ex)
                {
                    Console.Error.WriteLine(ex);
                    throw new OM2MBadRequestException($"Request expiration timestamp is illegal format: {request.RequestExpirationTimestamp}");
                }

                if (isTimeOut)
                {
                    throw new OM2MRequestTimeoutException();
                }
            }
        }
        public void DoRequest(OM2MRequestPrimitive request, IOM2MOriginator originator)
        {
            if (!IsInitalized)
            {
                throw new InvalidOperationException("CseService is not initialized.");
            }

            try
            {
                ValidateRequest(request);
            }
            catch (OM2MException ex)
            {
                var response = HandleOM2MException(ex, request);
                originator.SendResponse(response);
                return;
            }
            catch (Exception ex)
            {
                var response = HandleOtherException(ex, request);
                originator.SendResponse(response);
                return;
            }

            var responseType = OM2MResponseType.BlockingRequest;

            if (request.ResponseType != null && request.ResponseType.ResponseTypeValue != null)
            {
                responseType = request.ResponseType.ResponseTypeValue.Value;
            }

            if (responseType == OM2MResponseType.NonBlockingRequestAsynch ||
                responseType == OM2MResponseType.NonBlockingRequestSynch)
            {
                // ToDo:
                // Recv-3.0: Create <request> resource locally
                OM2MRequest req = new OM2MRequest();

                req.ResourceType     = OM2MResourceType.Request;
                req.ExpirationTime   = OM2MTimeStamp.GetTimeStamp(request.RequestExpirationTimestamp);
                req.CreationTime     = OM2MTimeStamp.NowTimeStamp;
                req.LastModifiedTime = req.CreationTime;
                // ToDo:request.AccessControlPolicyIDs
                // ToDo:req.Labels
                req.StateTag = 0;

                req.Operation  = request.Operation;
                req.Target     = request.To;
                req.Originator = request.From;
                req.RequestID  = request.RequestIdentifier;
                // ToDo:request.MetaInformation =
                req.PrimitiveContent = request.PrimitiveContent;
                req.RequestStatus    = OM2MRequestStatus.Pending;
                req.OperationResult  = null;

                // Recv-4.0: Create a success Response
                var response = new OM2MResponsePrimitive(CseConfig, request);
                response.ResponseStatusCode   = OM2MResponseStatusCode.Accepted;
                response.OriginatingTimestamp = OM2MTimeStamp.NowTimeStamp;

                // Recv-5.0: Send Response primitive
                originator.SendResponse(response);

                // Recv-6.0: Resource handling procedures
                response = DoBlockingRequest(request);

                // Recv-7.0: “Update <request> resource”
                req.LastModifiedTime = OM2MTimeStamp.NowTimeStamp;
                req.StateTag++;
                req.RequestStatus = OM2MRequestStatus.Forwarded;

                if (responseType == OM2MResponseType.NonBlockingRequestAsynch)
                {
                    // Recv-8.0: “Send Notification”
                    var notify = new OM2MRequestPrimitive();
                    notify.RequestIdentifier = Guid.NewGuid().ToString();
                    notify.Operation         = OM2MOperation.Notify;
                    notify.From             = request.TargetId;
                    notify.To               = request.From;
                    notify.PrimitiveContent = new OM2MPrimitiveContent();
                    notify.Content          = response.Content;

                    var notifyResponse = originator.SendRequest(notify);

                    // Recv-9.0: “Wait for Response primitive”
                }
            }
            else
            {
                var response = DoRequestCore(request);
                originator.SendResponse(response);
            }
        }