本文整理汇总了C#中System.IO类的典型用法代码示例。如果您正苦于以下问题:C# IO类的具体用法?C# IO怎么用?C# IO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IO类属于System命名空间,在下文中一共展示了IO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Notify
public void Notify(object sender, IO.FileSystemEventArgs args)
{
char separator = IO.Path.DirectorySeparatorChar;
string relative_path = args.FullPath.Substring (Path.Length);
relative_path = relative_path.Trim (new char [] {' ', separator});
// Ignore changes that happened in the parent path
if (!relative_path.Contains (separator.ToString ()))
return;
string repo_name = relative_path.Substring (0, relative_path.IndexOf (separator));
foreach (SparkleRepoBase repo in ReposToNotify) {
if (repo.Name.Equals (repo_name) && !repo.IsBuffering &&
(repo.Status != SyncStatus.SyncUp && repo.Status != SyncStatus.SyncDown)) {
Thread thread = new Thread (
new ThreadStart (delegate {
repo.OnFileActivity (args);
})
);
thread.Start ();
}
}
}
示例2: ReadShape
public override ShapeBase ReadShape(IO.TextReader TReader)
{
var Reader = new IO.TextReaderWE(TReader);
var Shapes = new ShapeCollection() { Name = "Parts" };
var Lines = new List<Line>();
while (!Reader.IsFinished)
{
Line L;
PointF P1, P2;
if (Reader.ReadLine().Trim() != "zone")
{
throw new Exception("Invalid output");
}
var t = new String[] { " " };
var PS = Reader.ReadLine().Split(t, StringSplitOptions.RemoveEmptyEntries);
P1 = new PointF(Single.Parse(PS[0]), Single.Parse(PS[1]));
PS = Reader.ReadLine().Split(t, StringSplitOptions.RemoveEmptyEntries);
P2 = new PointF(Single.Parse(PS[0]), Single.Parse(PS[1]));
L = new Line(P1, P2);
Lines.Add(L);
}
Shapes.Shapes.Add(new LinesShape(Lines) { Name = "Part 1" });
return Shapes;
}
示例3: EnumerateFiles
public IEnumerable<string> EnumerateFiles(string directoryPath, string searchPattern, IO.SearchOption searchOption)
{
if (directoryPath == null)
throw new ArgumentNullException("directoryPath");
if (searchPattern == null)
throw new ArgumentNullException("searchPattern");
if (HaveFile(directoryPath))
throw new IO.IOException("ファイル名は指定できません");
if (searchPattern.Contains(IO.Path.AltDirectorySeparatorChar) || searchPattern.Contains(IO.Path.DirectorySeparatorChar))
throw new ArgumentException("searchPattern");
string lowerDirectoryPath = directoryPath.ToLower();
var regex = new System.Text.RegularExpressions.Regex(searchPattern.TrimEnd(TrimEndChars).Replace("?", @".").Replace("*", @".*") + "$");
switch (searchOption)
{
case System.IO.SearchOption.AllDirectories:
return InternalHeader.Keys
.Where(key => key.StartsWith(lowerDirectoryPath))
.Where(key => regex.IsMatch(IO.Path.GetFileName(key)));
case System.IO.SearchOption.TopDirectoryOnly:
return InternalHeader.Keys
.Where(key => key.StartsWith(lowerDirectoryPath))
.Where(key => !key.Substring(lowerDirectoryPath.Length).Contains(IO.Path.PathSeparator))
.Where(key => regex.IsMatch(IO.Path.GetFileName(key)));
default:
throw new ArgumentException("searchOption");
}
}
示例4: Dispose
public static void Dispose(IO::FileStream aThis, bool disposing,
[FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
{
if (disposing)
{
innerStream.Dispose();
}
}
示例5: StreamWriter
/// <summary>
/// Constructor.
/// </summary>
/// <param name="stream">The stream </param>
public StreamWriter(IO.Stream stream)
{
if (stream == null)
throw new ArgumentNullException("stream", "The given stream must not be null.");
if (!stream.CanWrite)
throw new ArgumentException("The given stream must be writable.", "stream");
this.stream = new IO.StreamWriter(stream);
}
示例6: EnumerateFileSystemEntries
private static IEnumerable<string> EnumerateFileSystemEntries(string path, IO::SearchOption option, CancellationToken token, IProgress<double> iprogress, bool isEnumFiles, bool isEnumDirs, double progress, double step)
{
if(iprogress != null) {
iprogress.Report(progress);
}
if(isEnumFiles){
IEnumerable<string> files = null;
try{
files = IO::Directory.EnumerateFiles(path);
}catch(IO::IOException){
}catch(UnauthorizedAccessException){
}
if(files != null){
foreach(var file in files) {
yield return file;
}
}
}
if(option == IO::SearchOption.AllDirectories){
string[] dirs = null;
try{
dirs = IO::Directory.EnumerateDirectories(path).ToArray();
}catch(IO::IOException){
}catch(UnauthorizedAccessException){
}
if(dirs != null){
if(isEnumDirs){
foreach(var dir in dirs) {
yield return dir;
}
}
var stepE = step / dirs.Length;
for(int i = 0; i < dirs.Length; i++){
var prog = progress + (step * i * stepE);
foreach(var subfiles in EnumerateFileSystemEntries(dirs[i], option, token, iprogress, isEnumFiles, isEnumDirs, prog, stepE)){
yield return subfiles;
}
}
}
}else if(isEnumDirs){
IEnumerable<string> dirsQ = null;
try{
dirsQ = IO::Directory.EnumerateDirectories(path);
}catch(IO::IOException){
}catch(UnauthorizedAccessException){
}
if(dirsQ != null){
if(iprogress != null){
iprogress.Report(progress + step);
}
foreach(var dir in dirsQ) {
yield return dir;
}
}
}
}
示例7: GetFileMode
private static FileMode GetFileMode(IO.FileMode mode)
{
if (mode != IO.FileMode.Append)
{
return (FileMode)(int)mode;
}
else
{
return (FileMode)(int)IO.FileMode.OpenOrCreate;
}
}
示例8: WriteShape
public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
{
var Dic = new Dictionary<PointF, Int32>();
var Sz = 0;
ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Sz++; });
Writer.WriteLine(Sz);
ShapeWalker.Instance.TypedWalk<LinesShape>(Shape, S => { Writer.WriteLine(S.Lines.Count); });
Sz = 0;
ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
S =>
{
foreach (var L in S.Lines)
{
if (!Dic.ContainsKey(L.P1))
{
Dic.Add(L.P1, Sz++);
}
if (!Dic.ContainsKey(L.P2))
{
Dic.Add(L.P2, Sz++);
}
}
});
Writer.WriteLine(Sz);
foreach (var KV in Dic.OrderBy(KV => KV.Value))
{
Writer.Write(KV.Key.X);
Writer.Write(" ");
Writer.Write(KV.Key.Y);
Writer.WriteLine();
}
ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
S =>
{
Writer.WriteLine();
foreach (var l in S.Lines)
{
Writer.Write(Dic[l.P1]);
Writer.Write(" ");
Writer.Write(Dic[l.P2]);
Writer.WriteLine();
}
});
}
示例9: Seek
/// <summary>Seeks to the specified offset. Origin is always Current, Begin and End are ignored.</summary>
/// <param name="offset">Offset to seek to</param>
/// <param name="origin">Origin. Always System.IO.SeekOrigin.Current</param>
/// <returns>New position, meaningless in a circularbuffer</returns>
public override long Seek(long offset, IO.SeekOrigin origin)
{
lock (this.buffer)
{
if (this.buffer.readPosition + offset >= this.buffer.internalData.Length)
{
this.buffer.readPosition = (this.buffer.readPosition + offset) % this.buffer.internalData.Length;
}
else if (this.buffer.readPosition + offset < 0)
{
this.buffer.readPosition = this.buffer.internalData.Length + this.buffer.readPosition + offset;
}
else
this.buffer.readPosition += offset;
return this.buffer.readPosition;
}
}
示例10: Open
internal static IO.FileStream Open(string path, IO.FileAccess access, IO.FileMode mode, IO.FileShare share = IO.FileShare.None, bool throwException = true)
{
var fileHandle = CreateFile(path, GetFileAccess(access), GetFileShare(share), default(IntPtr), GetFileMode(mode));
if (fileHandle.IsInvalid)
{
if (throwException)
{
HandleCOMError(Marshal.GetLastWin32Error());
}
else
{
return null;
}
}
return new IO.FileStream(fileHandle, access);
}
示例11: WriteShape
public override void WriteShape(ShapeBase Shape, IO.TextWriter Writer)
{
ShapeWalker.Instance.TypedWalk<LinesShape>(Shape,
S =>
{
foreach (var l in S.Lines)
{
Writer.WriteLine(" zone");
Writer.Write(l.P1.X);
Writer.Write(" ");
Writer.Write(l.P1.Y);
Writer.WriteLine();
Writer.Write(l.P2.X);
Writer.Write(" ");
Writer.Write(l.P2.Y);
Writer.WriteLine();
}
});
}
示例12: ReadShape
public override ShapeBase ReadShape(IO.TextReader Reader)
{
int n = int.Parse(Reader.ReadLine().Trim());
var ar = new int[n];
for (int i = 0; i < n; i++)
{
ar[i] = int.Parse(Reader.ReadLine().Trim());
}
int m = int.Parse(Reader.ReadLine().Trim());
var Points = new PointF[m];
for (int i = 0; i < m; i++)
{
var L = Reader.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Points[i] = new PointF(Single.Parse(L[0]), Single.Parse(L[1]));
}
var Collection = new ShapeCollection() { Name = "Parts" };
var MyColors = new Color[] { Color.Red, Color.Blue, Color.Magenta, Color.Green, Color.Teal };
for (int i = 0; i < n; i++)
{
m = ar[i];
var S = new List<Line>();
for (int j = 0; j < m; j++)
{
var L = Reader.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
S.Add(new Line(Points[int.Parse(L[0]) - 1], Points[int.Parse(L[1]) - 1]));
}
Collection.Shapes.Add(new LinesShape(S) { Color = MyColors[i], Name = "Part " + (i + 1).ToString() });
}
return Collection;
}
示例13: SetLength
public static void SetLength(IO::FileStream aThis, long aLength,
[FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
{
innerStream.SetLength(aLength);
}
示例14: get_Length
public static long get_Length(IO::FileStream aThis,
[FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
{
return innerStream.Length;
}
示例15: Write
public static void Write(IO::FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
[FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream)
{
innerStream.Write(aBuffer, aOffset, aCount);
}