static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: TestCallback <uri>"); return; } Gnome.Vfs.Vfs.Initialize(); Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri(args[0]); Handle handle; // Test 1: Attempt to access a URI requiring authentication w/o a callback registered. try { handle = Sync.Open(uri, OpenMode.Read); Sync.Close(handle); Console.WriteLine("Uri '{0}' doesn't require authentication", uri); return; } catch (VfsException ex) { if (ex.Result != Result.ErrorAccessDenied) { throw ex; } } // Test 2: Attempt an open that requires authentication. ModuleCallbackFullAuthentication cb = new ModuleCallbackFullAuthentication(); cb.Callback += new ModuleCallbackHandler(OnAuthenticate); cb.SetDefault(); handle = Sync.Open(uri, OpenMode.Read); Sync.Close(handle); // Test 3: This call should not require any new authentication. Console.WriteLine("File info: \n{0}", uri.GetFileInfo()); // Test 4: Attempt a call to the parent uri. FileInfo[] entries = Directory.GetEntries(uri.Parent); Console.WriteLine("Directory '{0}' has {1} entries", uri.Parent, entries.Length); // Test 5: Pop the authentication callback and try again. cb.Pop(); try { handle = Sync.Open(uri, OpenMode.Read); } catch (VfsException ex) { if (ex.Result != Result.ErrorAccessDenied) { throw ex; } } Gnome.Vfs.Vfs.Shutdown(); }
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(); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: TestSync <uri>"); return; } Gnome.Vfs.Vfs.Initialize(); Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri(args[0]); Handle handle = Sync.Open(uri, OpenMode.Read); UTF8Encoding utf8 = new UTF8Encoding(); byte[] buffer = new byte[1024]; Result result = Result.Ok; while (result == Result.Ok) { ulong bytesRead; result = Sync.Read(handle, out buffer[0], (ulong)buffer.Length, out bytesRead); Console.WriteLine("result read '{0}' = {1}", uri, result); if (bytesRead == 0) { break; } Console.WriteLine("read ({0} bytes) : '{1}'", bytesRead, utf8.GetString(buffer, 0, (int)bytesRead)); } string test; result = Sync.FileControl(handle, "file:test", out test); Console.WriteLine("result filecontrol '{0}' = {1}", uri, result); Console.WriteLine("result file:test = {0}", test); result = Sync.Close(handle); Console.WriteLine("result close '{0}' = {1}", uri, result); Gnome.Vfs.Vfs.Shutdown(); }