本文整理汇总了C#中IFileInfo.Open方法的典型用法代码示例。如果您正苦于以下问题:C# IFileInfo.Open方法的具体用法?C# IFileInfo.Open怎么用?C# IFileInfo.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileInfo
的用法示例。
在下文中一共展示了IFileInfo.Open方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllResources
private static Dictionary<string, object> GetAllResources(IFileInfo resxFile)
{
using (var stream = resxFile.Open(FileMode.Open, FileAccess.Read))
{
return ReadAllResxEntries(stream);
}
}
示例2: GetModelItemIdFromFile
private Guid GetModelItemIdFromFile(IFileInfo file)
{
using (var stream = file.Open(FileMode.Open, FileAccess.Read))
{
return GetModelItemIdFromStream(stream);
}
}
示例3: MergeChangesIntoResx
public static void MergeChangesIntoResx(ResxDifferences changes, IFileInfo targetResxFile)
{
Dictionary<string, object> currentEntries;
using (var stream = targetResxFile.Open(FileMode.Open, FileAccess.Read))
{
currentEntries = ReadAllResxEntries(stream);
}
using (var newStream = targetResxFile.Open(FileMode.Truncate, FileAccess.Write))
{
MergeChangesIntoResx(changes, currentEntries, newStream);
}
}
示例4: ExportFile
private void ExportFile(IFileInfo file)
{
using (var dialog = new SaveFileDialog {FileName = file.Name, Filter = string.Format("{0}|*{0}", file.Extension)})
{
if (dialog.ShowDialog(this) == DialogResult.OK)
{
using (var input = file.Open(FileMode.Open, FileAccess.Read))
using (var output = File.OpenWrite(dialog.FileName))
{
input.CopyTo(output);
}
}
}
}
示例5: GetFileStream
private Stream GetFileStream (IFileInfo fileInfo)
{
bool onErrorRetry;
do
{
try
{
return fileInfo.Open (FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch (FileNotFoundException ex)
{
onErrorRetry = OnFileOpenError (this, new FileOpenExceptionEventArgs (fileInfo.FullName, ex));
}
catch (DirectoryNotFoundException ex)
{
onErrorRetry = OnFileOpenError (this, new FileOpenExceptionEventArgs (fileInfo.FullName, ex));
}
catch (IOException ex)
{
onErrorRetry = OnFileOpenError (this, new FileOpenExceptionEventArgs (fileInfo.FullName, ex));
}
catch (UnauthorizedAccessException ex)
{
onErrorRetry = OnFileOpenError (this, new FileOpenExceptionEventArgs (fileInfo.FullName, ex));
}
} while (onErrorRetry);
return null;
}
示例6: MergeExistingFileWithRemoteFile
private bool MergeExistingFileWithRemoteFile(IFileInfo file, IDocument remoteDoc, Guid guid, out byte[] localHash) {
byte[] remoteHash = remoteDoc.ContentStreamHash();
localHash = null;
if (file.Length.Equals(remoteDoc.ContentStreamLength)) {
using (var f = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) {
localHash = SHA1Managed.Create().ComputeHash(f);
}
if (remoteHash != null) {
if (localHash != null && localHash.SequenceEqual(remoteHash)) {
if (remoteDoc.LastModificationDate != null) {
try {
file.LastWriteTimeUtc = (DateTime)remoteDoc.LastModificationDate;
} catch(IOException e) {
Logger.Debug("Cannot set last modification date", e);
}
}
file.Uuid = guid;
MappedObject mappedObject = new MappedObject(
file.Name,
remoteDoc.Id,
MappedObjectType.File,
remoteDoc.Parents[0].Id,
remoteDoc.ChangeToken,
remoteDoc.ContentStreamLength ?? file.Length)
{
Guid = guid,
LastLocalWriteTimeUtc = file.LastWriteTimeUtc,
LastRemoteWriteTimeUtc = remoteDoc.LastModificationDate,
LastChecksum = localHash,
ChecksumAlgorithmName = "SHA-1"
};
this.Storage.SaveMappedObject(mappedObject);
return true;
}
}
}
return false;
}
示例7: GetBytesFromFile
private byte[] GetBytesFromFile (IFileInfo fileInfo)
{
using (var stream = fileInfo.Open (FileMode.Open, FileAccess.Read, FileShare.None))
{
using (BinaryReader binaryReader = new BinaryReader (stream))
{
return binaryReader.ReadBytes ((int) fileInfo.Length);
}
}
}
示例8: UploadFileWithPWC
/// <summary>
/// Uploads the file content to the remote document.
/// </summary>
/// <returns>The SHA-1 hash of the uploaded file content.</returns>
/// <param name="localFile">Local file.</param>
/// <param name="doc">Remote document.</param>
/// <param name="transmissionManager">Transmission manager.</param>
/// <param name="transmissionEvent">File Transmission event.</param>
/// <param name="mappedObject">Mapped object saved in <c>Storage</c></param>
protected byte[] UploadFileWithPWC(IFileInfo localFile, ref IDocument doc, Transmission transmission, IMappedObject mappedObject = null) {
byte[] checksum = null;
var docPWC = this.LoadRemotePWCDocument(doc, ref checksum);
using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) {
if (checksum != null) {
// check PWC checksum for integration
using (var hashAlg = new SHA1Managed()) {
int bufsize = 8 * 1024;
byte[] buffer = new byte[bufsize];
for (long offset = 0; offset < docPWC.ContentStreamLength.GetValueOrDefault();) {
int readsize = bufsize;
if (readsize + offset > docPWC.ContentStreamLength.GetValueOrDefault()) {
readsize = (int)(docPWC.ContentStreamLength.GetValueOrDefault() - offset);
}
readsize = file.Read(buffer, 0, readsize);
hashAlg.TransformBlock(buffer, 0, readsize, buffer, 0);
offset += readsize;
if (readsize == 0) {
break;
}
}
hashAlg.TransformFinalBlock(new byte[0], 0, 0);
if (!hashAlg.Hash.SequenceEqual(checksum)) {
docPWC.DeleteContentStream();
}
file.Seek(0, SeekOrigin.Begin);
}
}
byte[] hash = null;
var uploader = FileTransmission.ContentTaskUtils.CreateUploader(this.TransmissionStorage.ChunkSize);
using (var hashAlg = new SHA1Reuse()) {
try {
using (var hashstream = new NonClosingHashStream(file, hashAlg, CryptoStreamMode.Read)) {
int bufsize = 8 * 1024;
byte[] buffer = new byte[bufsize];
for (long offset = 0; offset < docPWC.ContentStreamLength.GetValueOrDefault();) {
int readsize = bufsize;
if (readsize + offset > docPWC.ContentStreamLength.GetValueOrDefault()) {
readsize = (int)(docPWC.ContentStreamLength.GetValueOrDefault() - offset);
}
readsize = hashstream.Read(buffer, 0, readsize);
offset += readsize;
if (readsize == 0) {
break;
}
}
}
var document = doc;
uploader.UploadFile(docPWC, file, transmission, hashAlg, false, (byte[] checksumUpdate, long length) => this.SaveRemotePWCDocument(localFile, document, docPWC, checksumUpdate, transmission));
hash = hashAlg.Hash;
} catch (Exception ex) {
transmission.FailedException = ex;
throw;
}
}
this.TransmissionStorage.RemoveObjectByRemoteObjectId(doc.Id);
var properties = new Dictionary<string, object>();
properties.Add(PropertyIds.LastModificationDate, localFile.LastWriteTimeUtc);
doc = this.Session.GetObject(docPWC.CheckIn(true, properties, null, string.Empty)) as IDocument;
// Refresh is required, or DotCMIS will use cached one only
doc.Refresh();
transmission.Status = TransmissionStatus.FINISHED;
return hash;
}
}
示例9: UploadFile
/// <summary>
/// Uploads the file content to the remote document.
/// </summary>
/// <returns>The SHA-1 hash of the uploaded file content.</returns>
/// <param name="localFile">Local file.</param>
/// <param name="doc">Remote document.</param>
/// <param name="transmissionManager">Transmission manager.</param>
/// <param name="transmissionEvent">File Transmission event.</param>
protected byte[] UploadFile(IFileInfo localFile, IDocument doc, Transmission transmission) {
using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) {
byte[] hash = null;
IFileUploader uploader = FileTransmission.ContentTaskUtils.CreateUploader();
using (var hashAlg = new SHA1Managed()) {
try {
uploader.UploadFile(doc, file, transmission, hashAlg);
hash = hashAlg.Hash;
} catch (Exception ex) {
transmission.FailedException = ex;
throw;
}
}
transmission.Status = TransmissionStatus.FINISHED;
return hash;
}
}
示例10: DownloadCacheFile
protected byte[] DownloadCacheFile(IFileInfo target, IDocument remoteDocument, Transmission transmission, IFileSystemInfoFactory fsFactory) {
if (!this.LoadCacheFile(target, remoteDocument, fsFactory)) {
if (target.Exists) {
target.Delete();
}
}
using (var hashAlg = new SHA1Reuse()) {
using (var filestream = target.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
using (var downloader = ContentTaskUtils.CreateDownloader()) {
try {
downloader.DownloadFile(remoteDocument, filestream, transmission, hashAlg, (byte[] checksumUpdate, long length) => this.SaveCacheFile(target, remoteDocument, checksumUpdate, length, transmission));
if (this.TransmissionStorage != null) {
this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id);
}
} catch (Exception ex) {
transmission.FailedException = ex;
throw;
}
}
target.Refresh();
return hashAlg.Hash;
}
}
示例11: CalculateHashCode
internal virtual byte[] CalculateHashCode(IFileInfo file)
{
using (Stream stream = file.Open(FileMode.Open, FileAccess.Read))
{
var hashProvider = SHA1.Create();
return hashProvider.ComputeHash(stream);
}
}
示例12: CalculateChecksum
/// <summary>
/// Calculates the checksum over the given stream with a former created hashAlgorithm
/// </summary>
/// <returns>The checksum.</returns>
/// <param name="hashAlgorithm">Hash algorithm.</param>
/// <param name="file">File to be hashed.</param>
public static byte[] CalculateChecksum(string hashAlgorithm, IFileInfo file) {
using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) {
return CalculateChecksum(hashAlgorithm, stream);
}
}