示例#1
0
        private void WriteResourceToOutputDirectory(ResourceReference<XmlTestElement> resourceRef, Type testClass, String outputPath)
        {
            string path = resourceRef.getResourcePath();
            Stream resource = new ResourceFinder(testClass).GetResource(path);
            if (resource == null)
            {
                resource = new ResourceFinder(typeof(MarkupWriter)).GetResource(path);
                if (resource == null)
                {
                    StringBuilder sb = new StringBuilder();
                    string[] resourceNames = typeof(MarkupWriter).Assembly.GetManifestResourceNames();
                    sb.AppendLine("resource count: " + resourceNames.Length);
                    foreach (string s in resourceNames) {
                        sb.AppendLine("resource: " + s);
                    }
                    throw new XcordionBug(sb.ToString() + "Cannot find resource: " + path);
                }
            }

            using (resource)
            {
                path = path.Replace('/', Path.DirectorySeparatorChar);
                while (path[0] == Path.DirectorySeparatorChar)
                {
                    path = path.Substring(1);
                }

                FileInfo outputFile = new FileInfo(outputDirectory.FullName + Path.DirectorySeparatorChar + path);
                if (!outputFile.Directory.Exists)
                {
                    Mkdirs(outputFile.Directory);
                }

                resourceRef.setResourceReferenceUri(FileUtils.relativePath(outputPath, path, false, Path.DirectorySeparatorChar));

                if (outputFile.Exists && outputFile.LastWriteTime < DateTime.Now.AddSeconds(5))
                {
                    return;
                }

                byte[] bytes = new byte[resource.Length];
                resource.Read(bytes, 0, bytes.Length);
                File.WriteAllBytes(outputFile.FullName, bytes);
            }
        }
 private static bool TryResourceName(ResourceFinder finder, string resourceName)
 {
     try
     {
         return finder.ResourceExists(resourceName);
     }
     catch (Exception)
     {
         return false;
     }
 }