/// <summary>
        /// Get static content
        /// </summary>
        public Stream StaticContent(string content)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(content))
                {
                    content = "index.html";
                }

                string filename = content.Contains("?")
                    ? content.Substring(0, content.IndexOf("?", StringComparison.Ordinal))
                    : content;

                if (filename == "config.json")
                {
                    return(typeof(DataSandboxTool).Assembly.GetManifestResourceStream($"{typeof(DataSandboxService).Namespace}.sandbox.config.json"));
                }
                else
                {
                    // Get the query tool stream

                    var contentPath = $"{typeof(DataSandboxService).Namespace}.Resources.{filename.Replace("/", ".")}";

                    if (!typeof(DataSandboxTool).Assembly.GetManifestResourceNames().Contains(contentPath))
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode = 404;
                        return(null);
                    }
                    else
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode = 200; /// HttpStatusCode.OK;
                        //RestOperationContext.Current.OutgoingResponse.ContentLength = new FileInfo(contentPath).Length;
                        RestOperationContext.Current.OutgoingResponse.ContentType = DefaultContentTypeMapper.GetContentType(contentPath);

                        return(typeof(DataSandboxTool).Assembly.GetManifestResourceStream(contentPath));
                    }
                }
            }
            catch (Exception e)
            {
                RestOperationContext.Current.OutgoingResponse.StatusCode = (int)HttpStatusCode.InternalServerError;

                this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString());
                return(null);
            }
        }
        /// <summary>
        /// Get the specified embedded resource
        /// </summary>
        public Stream Index(String content)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(content))
                {
                    var requestUrl = RestOperationContext.Current.IncomingRequest.Url;
                    RestOperationContext.Current.OutgoingResponse.Redirect($"{requestUrl.Scheme}://{requestUrl.Host}:{requestUrl.Port}{requestUrl.AbsolutePath}/index.html");
                    return(new MemoryStream());
                }

                string filename = content.Contains("?")
                    ? content.Substring(0, content.IndexOf("?", StringComparison.Ordinal))
                    : content;


                var contentPath = $"SanteDB.Messaging.Metadata.Docs.{filename.Replace("/", ".")}";

                if (!typeof(MetadataServiceBehavior).Assembly.GetManifestResourceNames().Contains(contentPath))
                {
                    RestOperationContext.Current.OutgoingResponse.StatusCode = 404;
                    return(null);
                }
                else
                {
                    RestOperationContext.Current.OutgoingResponse.StatusCode = 200; /// HttpStatusCode.OK;
                    //RestOperationContext.Current.OutgoingResponse.ContentLength = new FileInfo(contentPath).Length;
                    RestOperationContext.Current.OutgoingResponse.ContentType = DefaultContentTypeMapper.GetContentType(contentPath);
                    return(typeof(MetadataServiceBehavior).Assembly.GetManifestResourceStream(contentPath));
                }
            }
            catch (Exception e)
            {
                RestOperationContext.Current.OutgoingResponse.StatusCode = 500;

                this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString());
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get static content
        /// </summary>
        public Stream StaticContent(string content)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(content))
                {
                    content = "index.html";
                }

                string filename = content.Contains("?")
                    ? content.Substring(0, content.IndexOf("?", StringComparison.Ordinal))
                    : content;

                if (filename == "config.json")
                {
                    var cpath = Path.Combine(Path.GetDirectoryName(typeof(DataSandboxTool).Assembly.Location), "sandbox.config.json");
                    RestOperationContext.Current.OutgoingResponse.ContentType = DefaultContentTypeMapper.GetContentType(cpath);
                    return(File.OpenRead(cpath));
                }
                else
                {
                    // Get the query tool stream
#if DEBUG
                    var contentPath = Path.Combine(Path.GetDirectoryName(typeof(DataSandboxTool).Assembly.Location), "SandboxTool", filename);

                    if (!File.Exists(contentPath))
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode = (int)HttpStatusCode.NotFound;
                        return(null);
                    }
                    else
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode      = (int)HttpStatusCode.OK;
                        RestOperationContext.Current.OutgoingResponse.ContentLength64 = new FileInfo(contentPath).Length;
                        RestOperationContext.Current.OutgoingResponse.ContentType     = DefaultContentTypeMapper.GetContentType(contentPath);

                        return(File.OpenRead(contentPath));
                    }
#else
                    var contentPath = $"SanteDB.Tools.DataSandbox.Resources.{filename.Replace("/", ".")}";

                    if (!typeof(DataSandboxTool).Assembly.GetManifestResourceNames().Contains(contentPath))
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode = 404;
                        return(null);
                    }
                    else
                    {
                        RestOperationContext.Current.OutgoingResponse.StatusCode = 200; /// HttpStatusCode.OK;
                        //RestOperationContext.Current.OutgoingResponse.ContentLength = new FileInfo(contentPath).Length;
                        RestOperationContext.Current.OutgoingResponse.ContentType = DefaultContentTypeMapper.GetContentType(contentPath);

                        return(typeof(DataSandboxTool).Assembly.GetManifestResourceStream(contentPath));
                    }
#endif
                }
            }
            catch (Exception e)
            {
                RestOperationContext.Current.OutgoingResponse.StatusCode = (int)HttpStatusCode.InternalServerError;

                this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString());
                return(null);
            }
        }