File: TestSyncCreate.cs

package info (click to toggle)
gtk-sharp2 2.8.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 21,208 kB
  • ctags: 5,843
  • sloc: xml: 245,420; cs: 24,183; sh: 8,547; ansic: 2,739; makefile: 1,582; perl: 1,177
file content (47 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Gnome.Vfs;
using System;
using System.Text;

namespace TestGnomeVfs {
	public class TestSyncCreate {
		static void Main (string[] args)
		{
			if (args.Length != 1) {
				Console.WriteLine ("Usage: TestSyncCreate <uri>");
				return;
			}
		
			Gnome.Vfs.Vfs.Initialize ();

			Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri (args[0]);
			
			FilePermissions perms = FilePermissions.UserRead |
						FilePermissions.UserWrite |
						FilePermissions.GroupRead |
						FilePermissions.OtherRead;
			Console.WriteLine (perms);
			Handle handle = Sync.Create (uri, OpenMode.Write, false, perms);

			UTF8Encoding utf8 = new UTF8Encoding ();
			Result result = Result.Ok;
			Console.WriteLine ("Enter text and end with Ctrl-D");
			while (result == Result.Ok) {
				string line = Console.ReadLine ();
				if (line == null)
					break;
				byte[] buffer = utf8.GetBytes (line);

				ulong bytesWritten;
				result = Sync.Write (handle, out buffer[0],
						     (ulong)buffer.Length, out bytesWritten);
				Console.WriteLine ("result write '{0}' = {1}", uri, result);
				Console.WriteLine ("{0} bytes written", bytesWritten);
			}
			
			result = Sync.Close (handle);
			Console.WriteLine ("result close '{0}' = {1}", uri, result);
			
			Gnome.Vfs.Vfs.Shutdown ();
		}
	}
}