本文整理汇总了C#中System.IO.Compression.ZipArchiveEntry.Open方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchiveEntry.Open方法的具体用法?C# ZipArchiveEntry.Open怎么用?C# ZipArchiveEntry.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUpdateDeleteInventories
private static void AddUpdateDeleteInventories(ZipArchiveEntry inventoriesEntry)
{
Console.WriteLine("inventories.csv is {0} bytes", inventoriesEntry.Length);
IEnumerable<Inventory> inventories = null;
using (var entryStream = inventoriesEntry.Open())
{
Console.WriteLine("Starting inventories at {0:hh:mm:ss.fff}", DateTime.Now);
var stopwatch = new Stopwatch();
stopwatch.Start();
var reader = new StreamReader(entryStream);
var csv = new CsvReader(reader);
csv.Configuration.RegisterClassMap(new InventoryMap());
StringBuilder invForImport = new StringBuilder();
inventories = csv.GetRecords<Inventory>().Where(i => !i.IsDead);
var inventoryCollection = new InventoryCollection();
inventoryCollection.SetItems(inventories);
var importer = new NpgsqlBulkImporter(ConfigurationManager.ConnectionStrings["spurious"].ConnectionString, stopwatch);
importer.BulkImport("inventories", inventoryCollection);
stopwatch.Stop();
Console.WriteLine("Finished inventories at {0:hh:mm:ss.fff}, taking {1}", DateTime.Now, stopwatch.Elapsed);
}
}
示例2: Process
internal static string Process(ZipArchiveEntry packageFile, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem)
{
using (var stream = packageFile.Open())
{
return Process(stream, msBuildNuGetProjectSystem, throwIfNotFound: false);
}
}
示例3: WriteZipArchiveEntry
static void WriteZipArchiveEntry(ZipArchiveEntry entry, string toWrite)
{
using (StreamWriter writer = new StreamWriter(entry.Open()))
{
writer.Write(toWrite);
}
}
示例4: ParseRouteCSV
/// <summary>
/// Reads a ZipArchive entry as the routes CSV and extracts the route colors.
/// </summary>
private static List<GoogleRoute> ParseRouteCSV(ZipArchiveEntry entry)
{
var routes = new List<GoogleRoute>();
using (var reader = new StreamReader(entry.Open()))
{
// Ignore the format line
reader.ReadLine();
while (!reader.EndOfStream)
{
var parts = reader.ReadLine().Split(',');
// Ignore all routes which aren't part of CTS and thus don't have any real-time data.
if (parts[0].Contains("ATS") || parts[0].Contains("PC") || parts[0].Contains("LBL"))
{
continue;
}
routes.Add(new GoogleRoute(parts));
}
}
return routes;
}
示例5: AreHashEqual
private static bool AreHashEqual(FileInfo existing, ZipArchiveEntry duplicate)
{
byte[] originalHash;
byte[] otherHash;
try
{
using (FileStream original = File.Open(existing.FullName, FileMode.Open, FileAccess.Read))
{
if (null == (originalHash = HashFile(original))) { return false; }
}
using (Stream other = duplicate.Open())
{
if (null == (otherHash = HashFile(other))) { return false; }
}
if (originalHash.Length == otherHash.Length)
{
for (int index = 0; index < originalHash.Length; index++)
{
if (originalHash[index] != otherHash[index])
{
WriteError("Hashes don't match.");
return false;
}
}
return true;
}
return false;
}
catch (Exception e)
{
WriteError("Error while trying to compare hash. Error {0}",
e.Message);
return false;
}
}
示例6: AddUpdateDeleteStores
private static void AddUpdateDeleteStores(ZipArchiveEntry entry)
{
IEnumerable<Store> stores = null;
using (var entryStream = entry.Open())
{
Console.WriteLine("stores.csv is {0} bytes", entry.Length);
Console.WriteLine("Starting stores at {0:hh:mm:ss.fff}", DateTime.Now);
var storeTimer = new Stopwatch();
storeTimer.Start();
var reader = new StreamReader(entryStream);
var csv = new CsvReader(reader);
csv.Configuration.RegisterClassMap(new StoreMap());
stores = csv.GetRecords<Store>().Where(s => !s.IsDead);
var storesCollection = new StoreCollection();
storesCollection.SetItems(stores);
var importer = new NpgsqlBulkImporter(ConfigurationManager.ConnectionStrings["spurious"].ConnectionString, storeTimer);
importer.BulkImport("stores", storesCollection);
using (var wrapper = new NpgsqlConnectionWrapper(ConfigurationManager.ConnectionStrings["spurious"].ConnectionString))
{
wrapper.Connection.Open();
var rowsGeoUpdated = wrapper.ExecuteNonQuery("update stores s set (location) = ((select ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) from stores ss where s.id = ss.id))");
Console.WriteLine($"Updated {rowsGeoUpdated} rows geo data from lat/long data");
}
storeTimer.Stop();
Console.WriteLine("Finished stores at {0:hh:mm:ss.fff}, taking {1}", DateTime.Now, storeTimer.Elapsed);
}
}
示例7: Extract
private async Task Extract(ZipArchiveEntry entry, string basePath)
{
var fn = Path.Combine(basePath, entry.FullName);
using (var fstream = File.Create(fn))
{
await entry.Open().CopyToAsync(fstream);
}
}
示例8: UnzipZipArchiveEntryAsync
/// <summary>
/// Unzips ZipArchiveEntry asynchronously.
/// </summary>
/// <param name="entry">The entry which needs to be unzipped</param>
/// <param name="filePath">The entry's full name</param>
/// <param name="unzipFolder">The unzip folder</param>
/// <returns></returns>
public static async Task UnzipZipArchiveEntryAsync(ZipArchiveEntry entry, string filePath, StorageFolder unzipFolder)
{
if (IfPathContainDirectory(filePath))
{
// Create sub folder
string subFolderName = Path.GetDirectoryName(filePath);
bool isSubFolderExist = await IfFolderExistsAsync(unzipFolder, subFolderName);
StorageFolder subFolder;
if (!isSubFolderExist)
{
// Create the sub folder.
subFolder =
await unzipFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.ReplaceExisting);
}
else
{
// Just get the folder.
subFolder =
await unzipFolder.GetFolderAsync(subFolderName);
}
// All sub folders have been created. Just pass the file name to the Unzip function.
string newFilePath = Path.GetFileName(filePath);
if (!string.IsNullOrEmpty(newFilePath))
{
// Unzip file iteratively.
await UnzipZipArchiveEntryAsync(entry, newFilePath, subFolder);
}
}
else
{
// Read uncompressed contents
using (Stream entryStream = entry.Open())
{
byte[] buffer = new byte[entry.Length];
entryStream.Read(buffer, 0, buffer.Length);
// Create a file to store the contents
StorageFile uncompressedFile = await unzipFolder.CreateFileAsync
(entry.Name, CreationCollisionOption.ReplaceExisting);
// Store the contents
using (IRandomAccessStream uncompressedFileStream =
await uncompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
{
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
}
}
示例9: _TryGetPackageManifest
private PackageManifest _TryGetPackageManifest(ZipArchiveEntry manifestEntry)
{
using (var reader = manifestEntry.Open())
using (var xmlReader = XmlReader.Create(reader, new XmlReaderSettings
{
Schemas = SchemaSets.PackageManifest
}))
{
if (!mPackageManifestSerializer.CanDeserialize(xmlReader))
{
return null;
}
return (PackageManifest)mPackageManifestSerializer.Deserialize(xmlReader);
}
}
示例10: InflateEntryAsync
private static async Task InflateEntryAsync(ZipArchiveEntry entry, StorageFolder destFolder, bool createSub = false)
{
string filePath = entry.FullName;
if (!string.IsNullOrEmpty(filePath) && filePath.Contains("/") && !createSub)
{
// Create sub folder
string subFolderName = Path.GetDirectoryName(filePath);
StorageFolder subFolder;
// Create or return the sub folder.
subFolder = await destFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.OpenIfExists);
string newFilePath = Path.GetFileName(filePath);
if (!string.IsNullOrEmpty(newFilePath))
{
// Unzip file iteratively.
await InflateEntryAsync(entry, subFolder, true);
}
}
else
{
// Read uncompressed contents
using (Stream entryStream = entry.Open())
{
byte[] buffer = new byte[entry.Length];
entryStream.Read(buffer, 0, buffer.Length);
// Create a file to store the contents
StorageFile uncompressedFile = await destFolder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);
// Store the contents
using (IRandomAccessStream uncompressedFileStream =
await uncompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
{
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
}
}
示例11: AddUpdateDeleteProducts
private static void AddUpdateDeleteProducts(ZipArchiveEntry entry)
{
IEnumerable<Product> products = null;
using (var entryStream = entry.Open())
{
Console.WriteLine("products.csv is {0} bytes", entry.Length);
Console.WriteLine("Starting products at {0:hh:mm:ss.fff}", DateTime.Now);
var stopwatch = new Stopwatch();
stopwatch.Start();
var reader = new StreamReader(entryStream);
var csv = new CsvReader(reader);
csv.Configuration.RegisterClassMap(new ProductMap());
products = csv.GetRecords<Product>().Where(p => !p.IsDead);
var productCollection = new ProductCollection();
productCollection.SetItems(products);
var importer = new NpgsqlBulkImporter(ConfigurationManager.ConnectionStrings["spurious"].ConnectionString, stopwatch);
importer.BulkImport("products", productCollection);
stopwatch.Stop();
Console.WriteLine("Finished products at {0:hh:mm:ss.fff}, taking {1}", DateTime.Now, stopwatch.Elapsed);
}
}
示例12: Load
public static StockDetails Load(ZipArchiveEntry ze)
{
string symbol = Path.GetFileNameWithoutExtension(ze.Name);
string ext = Path.GetExtension(ze.Name);
if (ext.Equals(".csv", StringComparison.InvariantCultureIgnoreCase))
{
return LoadFromTextStream(symbol, ze.Open());
}
else if (ext.Equals(".tic", StringComparison.InvariantCultureIgnoreCase))
{
return LoadFromBinaryStream(symbol, ze.Open());
}
else
{
throw new ApplicationException("Unsupported file extension");
}
}
示例13: Open
public Stream Open(ZipArchiveEntry zipArchiveEntry, FileMode streamFileMode, FileAccess streamFileAccess)
{
bool canRead = true;
bool canWrite = true;
switch (_packageFileAccess)
{
case FileAccess.Read:
switch (streamFileAccess)
{
case FileAccess.Read:
canRead = true;
canWrite = false;
break;
case FileAccess.Write:
canRead = false;
canWrite = false;
break;
case FileAccess.ReadWrite:
canRead = true;
canWrite = false;
break;
}
break;
case FileAccess.Write:
switch (streamFileAccess)
{
case FileAccess.Read:
canRead = false;
canWrite = false;
break;
case FileAccess.Write:
canRead = false;
canWrite = true;
break;
case FileAccess.ReadWrite:
canRead = false;
canWrite = true;
break;
}
break;
case FileAccess.ReadWrite:
switch (streamFileAccess)
{
case FileAccess.Read:
canRead = true;
canWrite = false;
break;
case FileAccess.Write:
canRead = false;
canWrite = true;
break;
case FileAccess.ReadWrite:
canRead = true;
canWrite = true;
break;
}
break;
}
Stream ns = zipArchiveEntry.Open();
return new ZipWrappingStream(zipArchiveEntry, ns, _packageFileMode, _packageFileAccess, canRead, canWrite);
}
示例14: ReadSheetData
private async Task<List<Dictionary<String, String>>> ReadSheetData(ZipArchiveEntry worksheet)
{
List<Dictionary<String, String>> sheetDataSet = null;
await Task.Run(() =>
{
try
{
if (worksheet != null)
{
try{
excelReader.headers.Clear();
}
catch { }
try{
excelReader.rowIdentifierList.Clear();
}
catch { }
sheetDataSet = new List<Dictionary<string, string>>();
using (var sr = worksheet.Open())
{
XDocument xdoc = XDocument.Load(sr);
//get element to first sheet data
XNamespace xmlns = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
XElement sheetData = xdoc.Root.Element(xmlns + "sheetData");
//build header and row defintion list
var firstRow = sheetData.Elements().First();
foreach (var c in firstRow.Elements())
{
//the c element, if have attribute t, will need to consult sharedStrings
string val = c.Elements().First().Value;
if (c.Attribute("t") != null)
{
excelReader.headers.Add(_sharedStrings[Convert.ToInt32(val)]);
}
else
{
excelReader.headers.Add(val);
}
// Row Identifiers will helpfull in tracking the empty cells
var rowAttribute = c.Attribute("r");
if (rowAttribute != null)
{
String rowAttributeValue = rowAttribute.Value;
int pos = Regex.Match(rowAttributeValue, "[0-9]").Index;
rowAttributeValue = rowAttributeValue.Substring(0, pos);
excelReader.rowIdentifierList.Add(rowAttributeValue);
}
}
foreach (var row in sheetData.Elements())
{
//skip row 1
if (row.Attribute("r").Value == "1")
continue;
Dictionary<string, string> rowData = new Dictionary<string, string>();
int i = 0;
var elementsToLookup = row.Elements();
for (int rowResolverIndex = 0; rowResolverIndex < elementsToLookup.Count(); rowResolverIndex++)
{
var c = elementsToLookup.ElementAt(rowResolverIndex);
// Get the row number of the cell to check whether we are missing out any entry
// due to empty data
var rowAttribute = c.Attribute("r");
if (rowAttribute != null)
{
String actualRowIdentifier = rowAttribute.Value;
int pos = Regex.Match(actualRowIdentifier, "[0-9]").Index;
actualRowIdentifier = actualRowIdentifier.Substring(0, pos);
// Get the element from rowIdentifierList for the index
for (int lookupIndex = i; lookupIndex < excelReader.rowIdentifierList.Count(); lookupIndex++)
{
String expectedRowIdentifier = excelReader.rowIdentifierList.ElementAt(lookupIndex);
if (expectedRowIdentifier.Equals(actualRowIdentifier))
{
break;
}
else
{
String keyToIndex = headers[lookupIndex];
if (!rowData.ContainsKey(keyToIndex))
{
rowData.Add(keyToIndex, ""); // Placing an empty data for the particular header
i++;
}
}
//.........这里部分代码省略.........
示例15: ExtractZipEntryAsync
// Extract a single zip archive entry to the given folder
private async Task ExtractZipEntryAsync(ZipArchiveEntry entry, StorageFolder folder)
{
try
{
using (Stream entryStream = entry.Open())
{
byte[] buffer = new byte[entry.Length];
entryStream.Read(buffer, 0, buffer.Length);
string filePath = entry.FullName.Replace('/', '\\');
StorageFile uncompressedFile = await folder.CreateFileAsync(filePath, CreationCollisionOption.ReplaceExisting);
using (var uncompressedFileStream = await uncompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
{
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
}
catch (Exception ex)
{
DownloadErrors.Add(ex.ToString());
RaisePropertyChanged("HasDownloadErrors");
}
}