当前位置: 首页>>代码示例>>C#>>正文


C# IFile.GetContent方法代码示例

本文整理汇总了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;
            });
        }
开发者ID:kmcginnes,项目名称:SpicyTaco.ChaseTheTail,代码行数:58,代码来源:TailService.cs

示例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);
		}
开发者ID:Euphrates-Media,项目名称:Platform.VirtualFileSystem,代码行数:54,代码来源:ZipFileSystem.cs

示例3: ServiceModelCodeGenerator

 protected ServiceModelCodeGenerator(IFile file, CodeGenerationOptions options)
     : this(file.GetContent().GetWriter(), options)
 {
 }
开发者ID:techpub,项目名称:Fickle,代码行数:4,代码来源:ServiceModelCodeGenerator.cs

示例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);
		}
开发者ID:Euphrates-Media,项目名称:Platform.VirtualFileSystem,代码行数:15,代码来源:ShadowNodeContent.cs


注:本文中的IFile.GetContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。