本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.OfType方法的具体用法?C# ZipFile.OfType怎么用?C# ZipFile.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.OfType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute()
{
var tempFileName = Path.GetTempFileName();
File.Delete(tempFileName);
try
{
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(testPort);
using (var ravenDbServer = new RavenDbServer(new RavenConfiguration
{
DataDirectory = tempFileName,
Port = testPort,
AnonymousUserAccessMode = AnonymousUserAccessMode.All,
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
}))
{
using (var zipFile = new ZipFile(file))
{
var zipEntries = zipFile.OfType<ZipEntry>()
.Where(x => x.Name.StartsWith("raw/"))
.Where(x => Path.GetExtension(x.Name) == ".txt")
.GroupBy(x => x.Name.Split('_').First())
.Select(x => new { Request = x.First(), Response = x.Last() })
.ToArray();
foreach (var pair in zipEntries)
{
// wait until we are finished executing
// make scenario executing predictable
while (ravenDbServer.Database.HasTasks)
Thread.Sleep(50);
TestSingleRequest(
new StreamReader(zipFile.GetInputStream(pair.Request)).ReadToEnd(),
zipFile.GetInputStream(pair.Response).ReadData()
);
}
}
}
}
finally
{
if (Directory.Exists(tempFileName))
Directory.Delete(tempFileName, true);
}
}
示例2: Execute
public void Execute()
{
var tempFileName = Path.GetTempFileName();
File.Delete(tempFileName);
try
{
RavenDbServer.EnsureCanListenToWhenInNonAdminContext(testPort);
using (new RavenDbServer(new RavenConfiguration
{
DataDirectory = tempFileName,
Port = testPort,
AnonymousUserAccessMode = AnonymousUserAccessMode.All,
ShouldCreateDefaultsWhenBuildingNewDatabaseFromScratch = false
}))
{
using (var zipFile = new ZipFile(file))
{
var zipEntries = zipFile.OfType<ZipEntry>()
.Where(x => x.Name.StartsWith("raw/"))
.Where(x => Path.GetExtension(x.Name) == ".txt")
.GroupBy(x => x.Name.Split('_').First())
.Select(x => new {Request = x.First(), Response = x.Last()})
.ToArray();
foreach (var pair in zipEntries)
{
TestSingleRequest(
new StreamReader(zipFile.GetInputStream(pair.Request)).ReadToEnd(),
zipFile.GetInputStream(pair.Response).ReadData()
);
}
}
}
}
finally
{
Directory.Delete(tempFileName, true);
}
}
示例3: ExtractZipForInstall
public static async Task ExtractZipForInstall(string zipFilePath, string outFolder)
{
var zf = new ZipFile(zipFilePath);
var entries = zf.OfType<ZipEntry>().ToArray();
var re = new Regex(@"lib[\\\/][^\\\/]*[\\\/]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
try {
await Utility.ForEachAsync(entries, (zipEntry) => {
if (!zipEntry.IsFile) return;
var entryFileName = Uri.UnescapeDataString(zipEntry.Name);
if (!re.Match(entryFileName).Success) return;
var fullZipToPath = Path.Combine(outFolder, re.Replace(entryFileName, "", 1));
var directoryName = Path.GetDirectoryName(fullZipToPath);
var buffer = new byte[64*1024];
if (directoryName.Length > 0) {
Utility.Retry(() => Directory.CreateDirectory(directoryName), 2);
}
Utility.Retry(() => {
using (var zipStream = zf.GetInputStream(zipEntry))
using (FileStream streamWriter = File.Create(fullZipToPath)) {
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}, 5);
}, 4);
} finally {
zf.Close();
}
}