本文整理汇总了C#中IFile.GetContent方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.GetContent方法的具体用法?C# IFile.GetContent怎么用?C# IFile.GetContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFile
的用法示例。
在下文中一共展示了IFile.GetContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tail
//public IObservable<string> TailV2(IFile file)
//{
// return ObservableFile.WatchLines(file.GetNativePath(), Encoding.Default);
//}
public IObservable<string> Tail(IFile file, IScheduler scheduler = null)
{
return Observable.Create<string>(subj =>
{
var disposable = new CompositeDisposable();
scheduler = scheduler ?? RxApp.TaskpoolScheduler;
var abortSignal = new ManualResetEvent(false);
disposable.Add(Disposable.Create(() => abortSignal.Set()));
disposable.Add(scheduler.Schedule(abortSignal, (sched, state) =>
{
using (var reader = new StreamReader(
file.GetContent().OpenStream(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
long lastOffset = reader.BaseStream.Length;
if (reader.BaseStream.Length > 0)
{
// Send the last 10 kb of text to the reader.
lastOffset = Math.Max(0, reader.BaseStream.Length - (1024 * 10));
}
while (!state.WaitOne(100))
{
// Idle if file hasn't changed.
if (reader.BaseStream.Length <= lastOffset)
{
if (reader.BaseStream.Length < lastOffset)
{
lastOffset = reader.BaseStream.Length;
}
continue;
}
// Read the data.
reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
var delta = reader.BaseStream.Length - lastOffset;
var buffer = new char[delta];
reader.ReadBlock(buffer, 0, buffer.Length);
// Publish the data.
subj.OnNext(new string(buffer));
// Update the offset.
lastOffset = reader.BaseStream.Position;
}
}
return Disposable.Empty;
}));
return disposable;
});
}
示例2: CreateZipFile
public static ZipFileSystem CreateZipFile(IFile zipFile, IEnumerable<IFile> files, Func<IFile, string> fileToFullPath, FileSystemOptions options)
{
var compressionLevel = 9;
var zipCompressionLevel = options.Variables["ZipCompressionLevel"];
if (zipCompressionLevel != null)
{
compressionLevel = Convert.ToInt32(zipCompressionLevel);
if (compressionLevel < 0)
{
compressionLevel = 0;
}
else if (compressionLevel > 9)
{
compressionLevel = 9;
}
}
using (var zipOutputStream = new ZLib.ZipOutputStream(zipFile.GetContent().GetOutputStream()))
{
zipOutputStream.SetLevel(compressionLevel);
zipOutputStream.IsStreamOwner = true;
zipOutputStream.UseZip64 = ZLib.UseZip64.Dynamic;
if (files != null)
{
foreach (var file in files)
{
var entryName = fileToFullPath(file);
entryName = ZLib.ZipEntry.CleanName(entryName);
var entry = new ZLib.ZipEntry(entryName);
using (var stream = file.GetContent().GetInputStream(FileMode.Open, FileShare.Read))
{
if (stream.Length > 0)
{
entry.Size = stream.Length;
}
zipOutputStream.PutNextEntry(entry);
stream.CopyTo(zipOutputStream);
}
zipOutputStream.CloseEntry();
}
}
}
return new ZipFileSystem(zipFile, options);
}
示例3: ServiceModelCodeGenerator
protected ServiceModelCodeGenerator(IFile file, CodeGenerationOptions options)
: this(file.GetContent().GetWriter(), options)
{
}
示例4: DoGetOutputStream
protected override Stream DoGetOutputStream(string encoding, FileMode mode, FileShare sharing)
{
IFile file;
file = this.tempFileSystem.ResolveFile(GenerateName());
switch (mode)
{
case FileMode.Truncate:
file.Create();
break;
}
return new ShadowOutputStream(file.GetContent().GetOutputStream(encoding, sharing), this.shadowFile.ShadowedFile, file);
}