Пример #1
0
        private static Stream TryGetStream(ResourceType resourceType, string resource, IEnvironment environment)
        {
            /*
             *      This function attempts to get files embedded in the callers assembly.
             *      Unity.VersionControl.Git which tends to contain logos
             *      Git.Api which tends to contain application resources
             *
             *      Each file's name is their physical path in the project.
             *
             *      When running tests, we assume the tests are looking for application resources, and default to returning Git.Api
             *
             *      First check for the resource in the calling assembly.
             *      If the resource cannot be found, fallback to looking in Git.Api's assembly.
             *      If the resource is still not found, it attempts to find it in the file system
             */

            (string type, string os) = ParseResourceType(resourceType, environment);

            var stream = TryGetResource(resourceType, type, os, resource);

            if (stream != null)
            {
                return(stream);
            }

            SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);

            if (possiblePath.FileExists())
            {
                return(new MemoryStream(possiblePath.ReadAllBytes()));
            }
            return(null);
        }