Пример #1
0
        public byte[] GetContent(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            if (!path.StartsWith("/"))
            {
                throw new ArgumentException("Must be an absolute path.", "path");
            }

            if (!PathUtility.IsFullFileName(path))
            {
                throw new ArgumentException("Invalid path.", "path");
            }

            // actual file
            if (ContentSearch == ContentSearch.FileAndAssembly || ContentSearch == ContentSearch.File)
            {
                var filePath = PathUtility.WorkingDirectory + path;

                if (File.Exists(filePath))
                {
                    return(File.ReadAllBytes(filePath));
                }
            }

            // assembly file
            if (ContentSearch == ContentSearch.FileAndAssembly || ContentSearch == ContentSearch.Assembly)
            {
                var assembly     = Assembly.GetEntryAssembly();
                var resourceName = assembly.GetName().Name + path.Replace('/', '.');

                if (assembly.GetManifestResourceNames().Contains(resourceName))
                {
                    using (var stream = assembly.GetManifestResourceStream(resourceName))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            stream.CopyTo(memoryStream);

                            return(memoryStream.ToArray());
                        }
                    }
                }
            }

            // HtmlUi resource
            if (ResourceUtility.ResourceExists(path))
            {
                return(ResourceUtility.GetResourceAsBytes(path));
            }

            throw new ContentNotFoundException(path);
        }