Example #1
0
        protected string GetSourceTemplate(string path)
        {
            path = _templatesRoot + "/" + path;

            string sourceTemplate = null;

            UnityMainThreadDispatcher.Instance().EnqueueAndWait(() =>
            {
                try
                {
                    sourceTemplate = ResourceLoader.GetTextFileContent(path);
                }
                catch (ResourceNotFoundException)
                {
                    MiddlewareServer.LogWarning("View not found : " + path);
                }
            });

            if (sourceTemplate == null)
            {
                throw new ViewNotFoundException(path);
            }

            return(sourceTemplate);
        }
        public bool HandleRequest(HttpListenerRequest request, HttpListenerResponse response, string relativePath)
        {
            if (request.HttpMethod != "GET")
            {
                return(false);
            }

            if (relativePath == "/")
            {
                return(false);
            }

            var path = _root + relativePath;

            var contentType = GuessContentTypeForPath(path);

            byte[] content = null;

            UnityMainThreadDispatcher.Instance().EnqueueAndWait(() =>
            {
                try
                {
                    content = ResourceLoader.GetBinaryFileContent(path);
                }
                catch (ResourceNotFoundException)
                {
                    MiddlewareServer.LogWarning("Resource not found : " + path);
                }
            });

            if (content == null)
            {
                return(false);
            }

            response.Send(content, contentType);
            return(true);
        }