StatLight.Core.WebServer.ResponseFactory.Get C# (CSharp) Method

Get() public method

public Get ( string localPath ) : ResponseFile
localPath string
return ResponseFile
        public ResponseFile Get(string localPath)
        {
            if (IsKnown(localPath, StatLightServiceRestApi.CrossDomain))
                return new ResponseFile { FileData = Resources.CrossDomain.ToByteArray(), ContentType = "text/xml" };

            if (IsKnown(localPath, StatLightServiceRestApi.ClientAccessPolicy))
                return new ResponseFile { FileData = Resources.ClientAccessPolicy.ToByteArray(), ContentType = "text/xml" };

            if (IsKnown(localPath, StatLightServiceRestApi.GetHtmlTestPage))
            {
                return GetTestHtmlPage();
            }

            if (IsKnown(localPath, StatLightServiceRestApi.GetTestPageHostXap))
                return new ResponseFile { FileData = _currentStatLightConfiguration.Current.Server.HostXap(), ContentType = "application/x-silverlight-app" };

            if (IsKnown(localPath, StatLightServiceRestApi.GetTestRunConfiguration))
                return new ResponseFile { FileData = _currentStatLightConfiguration.Current.Client.Serialize().ToByteArray(), ContentType = "text/xml" };

            throw new NotImplementedException();
        }

Usage Example

        private void ProcessGetRequest(HttpListenerRequest request, HttpListenerResponse response)
        {
            try
            {
                var localPath = GetLocalPath(request);
                if (_responseFactory.IsKnownFile(localPath))
                {
                    var responseFile = _responseFactory.Get(localPath);

                    SetHttpStatus(response, HttpStatusCode.OK);
                    SetContentType(response, responseFile.ContentType);
                    ServeString(response, responseFile.FileData);
                }
                else
                {
                    HandleUnknownRequest(request, response);
                }
            }
            catch (Exception exception)
            {
                _logger.Debug(exception.ToString());
            }
        }