Example #1
0
 protected override RequestResponse HandleGET(string requestPath)
 {
     var response = new RequestResponse();
     responseDocument = new XmlDocument();
     GetResolver getResolver = new GetResolver(new SceneWriter(responseDocument));
     var responseObject = getResolver.WriteSceneOrGetEntity(requestPath.Trim('/').TrimEnd('/'));
     if (responseObject.GetType() == typeof(string))
         response.SetResponseBuffer((string)responseObject);
     else
     {
         responseDocument.AppendChild((XmlElement)responseObject);
         response.SetResponseBuffer(XmlToString(responseDocument));
     }
     response.ReturnCode = 200;
     return response;
 }
Example #2
0
 protected override RequestResponse HandleDELETE(string requestPath)
 {
     RequestResponse response = new RequestResponse();
     try
     {
         bool deleted = new DeleteResolver().DeleteEntity(requestPath.Trim('/').TrimEnd('/'));
         response.ReturnCode = deleted ? 204 : 202;
     }
     catch(InvalidOperationException e)
     {
         response.ReturnCode = 501;
         response.SetResponseBuffer("An error occurred when trying to delete an entity: "
             + e.Message);
     }
     return response;
 }
Example #3
0
        protected override RequestResponse HandleGET(string requestPath)
        {
            var response = new RequestResponse();

            responseDocument = new XmlDocument();
            GetResolver getResolver    = new GetResolver(new SceneWriter(responseDocument));
            var         responseObject = getResolver.WriteSceneOrGetEntity(requestPath.Trim('/').TrimEnd('/'));

            if (responseObject.GetType() == typeof(string))
            {
                response.SetResponseBuffer((string)responseObject);
            }
            else
            {
                responseDocument.AppendChild((XmlElement)responseObject);
                response.SetResponseBuffer(XmlToString(responseDocument));
            }
            response.ReturnCode = 200;
            return(response);
        }
Example #4
0
 private RequestResponse SendErrorResponse()
 {
     RequestResponse errorResponse = new RequestResponse();
     errorResponse.ReturnCode = 404;
     errorResponse.SetResponseBuffer("No service is registered under the specified path");
     return errorResponse;
 }
Example #5
0
        protected override RequestResponse HandlePUT(string requestPath, string content)
        {
            var response = new RequestResponse();
            responseDocument = new XmlDocument();

            try
            {
                responseDocument.AppendChild(
                    new PutPostResolver(responseDocument).UpdateEntity(requestPath.TrimStart('/').TrimEnd('/'), content)
                );
                response.ReturnCode = 200;
                response.SetResponseBuffer(XmlToString(responseDocument));
            }
            catch (EntityNotFoundException)
            {
                response.ReturnCode = 404;
                response.SetResponseBuffer("Entity with given GUID is not present in World");
            }
            catch (FormatException e)
            {
                response.ReturnCode = 400;
                response.SetResponseBuffer(e.Message);
            }

            return response;
        }
Example #6
0
 protected override RequestResponse HandlePOST(string requestPath, string content)
 {
     var response = new RequestResponse();
     responseDocument = new XmlDocument();
     responseDocument.AppendChild(new PutPostResolver(responseDocument).AddEntity(requestPath, content));
     response.SetResponseBuffer(XmlToString(responseDocument));
     response.ReturnCode = 201;
     return response;
 }
Example #7
0
        protected override RequestResponse HandlePOST(string requestPath, string content)
        {
            //Console.WriteLine("handle post");
            RequestResponse response = new RequestResponse();

            //response.ReturnCode = 200;

            //Console.WriteLine(requestPath);

            //Console.WriteLine(content);

            JObject jObject = null;
            if (!content.Equals(""))
            {
                jObject = JsonParser(content);
            }

            if (requestPath.Equals("/StartAnimation"))
            {
                ApplyServiceRequest(jObject, 1); //Start Animation

                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/StopAnimation"))
            {
                ApplyServiceRequest(jObject, 2); //Start Animation
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/UpdatePose"))
            {
                ApplyServiceRequest(jObject, 3); //Start Animation
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/AddMarker"))
            {
                AddMarker(content, 4); //Add marker
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/DeleteMarker"))
            {
                DeleteMarker(content, 5); //Add marker
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/StartAnimationPipeline"))
            {
                StartBVHAnimationPipeline(jObject, 5); //Add marker
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/CreateAnimationEntity"))
            {
                CreateAnimationEntity(content, 6); //Add marker
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/SetAnimationEntity"))
            {
                SetAnimationEntity(content, 7); //Add marker
                response.ReturnCode = 200;
            }
            else if (requestPath.Equals("/SetAnimationConstraints"))
            {
                SetAnimationConstraints(content, 8); //Add marker
                response.ReturnCode = 200;
            }

            return response;
        }
Example #8
0
 protected RequestResponse ConstructServerError()
 {
     RequestResponse errorResponse = new RequestResponse();
     errorResponse.ReturnCode = 500;
     errorResponse.SetResponseBuffer("Some error occured when trying to process request for " + Path);
     return errorResponse;
 }