예제 #1
0
    private void SetupJob()
    {
        _input                = new TextBox();
        _input.Multiline      = true;
        _input.AcceptsReturn  = true;
        _input.AcceptsTab     = true;
        _input.ScrollBars     = System.Windows.Forms.ScrollBars.Both;
        _input.Dock           = DockStyle.Fill;
        _input.SelectionStart = 0; //Work-around for the AppendText bug.
        _input.TextChanged   += new EventHandler(_input_TextChanged);

        _log                = new TextBox();
        _log.Font           = new System.Drawing.Font("Courier New", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
        _log.Multiline      = true;
        _log.AcceptsReturn  = true;
        _log.AcceptsTab     = true;
        _log.ScrollBars     = System.Windows.Forms.ScrollBars.Vertical;
        _log.Dock           = DockStyle.Fill;
        _log.SelectionStart = 0; //Work-around for the AppendText bug.
        _log.ReadOnly       = true;

        SetSubItem(Display.name, FileName);
        SetSubItem(Display.dir, DirectoryName);

        _buf              = new Byte[512];
        asyncCallback     = new AsyncCallback(AsyncRead);
        asyncReadCallback = new AsyncReadCallback(InvokedAsyncRead);

        SetStatus(Status.idle);
        timerCallback     = new System.Threading.TimerCallback(TimerTick);
        timerTickCallback = new TimerTickCallback(InvokedTimerTick);
        timer             = new System.Threading.Timer(timerCallback, this, 0, 2000);
    }
예제 #2
0
 public override void BeginRead(AsyncReadCallback callback)
 {
     EndRead();
     (readthread = new Thread(
                       () => {
                           string msg;
                           while ((msg = Read()) != null) {
                               callback(this, msg);
                           }
                       })).Start();
 }
예제 #3
0
 public override void BeginRead(AsyncReadCallback callback) {
     if (asyncread != null && asyncread.IsAlive) {
         CancelAsync();
     }
     (asyncread = new Thread(
         () => {
             while (true) {
                 try {
                     var br = UnderlyingStream.Read(b, 0, 4096);
                     lock (_readLock) {
                         if (br < 1) connected = false;
                         callback.BeginInvoke(this, br < 1 ? null : Encoding.GetString(b, 0, br), null, null);
                     }
                 } catch (Exception e) {
                     LastError = e;
                     connected = false;
                     return;
                 }
             }
         })).Start();
 }
예제 #4
0
 public AsyncReadCallbackWrapper(AsyncReadCallback managed, object o) : base(o)
 {
     NativeDelegate = new AsyncReadCallbackNative(NativeCallback);
     _managed       = managed;
 }
예제 #5
0
 /// <summary>
 /// When overridden in a derived class, begins asyncronous reading and will invoke
 /// the callback each time there is a new message. The message will return as null
 /// when the stream is closed, and no further callbacks will occur.
 /// </summary>
 /// <param name="callback">The method to invoke each time a message is recieved</param>
 public abstract void BeginRead(AsyncReadCallback callback);
예제 #6
0
		public static void Read (Handle handle, out byte buffer, uint bytes, AsyncReadCallback callback)
		{
			AsyncReadCallbackWrapper wrapper = new AsyncReadCallbackWrapper (callback, null);
			gnome_vfs_async_read (handle.Handle, out buffer, bytes, wrapper.NativeDelegate, IntPtr.Zero);
		}
예제 #7
0
        public VfsStream(string text_uri, FileMode mode, bool async)
        {
            if (text_uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (text_uri == "")
            {
                throw new ArgumentNullException("Uri is empty");
            }

            if (mode < FileMode.CreateNew || mode > FileMode.Append)
            {
                throw new ArgumentOutOfRangeException("mode");
            }

            if (text_uri.IndexOfAny(Path.InvalidPathChars) != -1)
            {
                throw new ArgumentException("Uri has invalid chars");
            }

            uri = new Gnome.Vfs.Uri(text_uri);

            if (mode == FileMode.Open && !uri.Exists)
            {
                throw new FileNotFoundException("Could not find uri \"" + text_uri + "\".");
            }

            if (mode == FileMode.CreateNew)
            {
                string dname = uri.ExtractDirname();
                if (dname != "" && !new Uri(dname).Exists)
                {
                    throw new DirectoryNotFoundException("Could not find a part of " +
                                                         "the path \"" + dname + "\".");
                }
            }

            if (async)
            {
                callback      = new AsyncCallback(OnAsyncCallback);
                readCallback  = new AsyncReadCallback(OnAsyncReadCallback);
                writeCallback = new AsyncWriteCallback(OnAsyncWriteCallback);
            }

            OpenMode om = OpenMode.None;

            switch (mode)
            {
            case FileMode.CreateNew:
            case FileMode.Create:
            case FileMode.Truncate:
            case FileMode.Append:
                om     = OpenMode.Write;
                access = FileAccess.Write;
                break;

            case FileMode.OpenOrCreate:
                if (uri.Exists)
                {
                    om     = OpenMode.Read;
                    access = FileAccess.Read;
                }
                else
                {
                    om     = OpenMode.Write;
                    access = FileAccess.Write;
                }
                break;

            case FileMode.Open:
                om     = OpenMode.Read;
                access = FileAccess.Read;
                break;
            }

            /* 644 */
            FilePermissions perms = FilePermissions.UserRead |
                                    FilePermissions.UserWrite |
                                    FilePermissions.GroupRead |
                                    FilePermissions.OtherRead;

            Result result;

            handle = null;
            switch (mode)
            {
            case FileMode.Append:
                if (uri.Exists)
                {
                    if (async)
                    {
                        handle = Async.Open(uri, om,
                                            (int)Async.Priority.Default,
                                            callback);
                        Wait();
                        Async.Seek(handle, SeekPosition.End, 0, callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Open(uri, om);
                        result = Sync.Seek(handle, SeekPosition.End, 0);
                        Vfs.ThrowException(uri, result);
                    }
                }
                else
                {
                    if (async)
                    {
                        handle = Async.Create(uri, om, true, perms,
                                              (int)Async.Priority.Default,
                                              callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Create(uri, om, true, perms);
                    }
                }
                break;

            case FileMode.Create:
                if (uri.Exists)
                {
                    if (async)
                    {
                        handle = Async.Open(uri, om,
                                            (int)Async.Priority.Default,
                                            callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Open(uri, om);
                        result = uri.Truncate(0);
                        Vfs.ThrowException(uri, result);
                    }
                }
                else
                {
                    handle = Sync.Create(uri, om, true, perms);
                }
                break;

            case FileMode.CreateNew:
                if (uri.Exists)
                {
                    throw new IOException("Uri \"" + text_uri + "\" already exists.");
                }
                else
                {
                    if (async)
                    {
                        handle = Async.Create(uri, om, true, perms,
                                              (int)Async.Priority.Default,
                                              callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Create(uri, om, true, perms);
                    }
                }
                break;

            case FileMode.Open:
                if (uri.Exists)
                {
                    if (async)
                    {
                        handle = Async.Open(uri, om,
                                            (int)Async.Priority.Default,
                                            callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Open(uri, om);
                    }
                }
                else
                {
                    throw new FileNotFoundException(text_uri);
                }
                break;

            case FileMode.OpenOrCreate:
                if (uri.Exists)
                {
                    if (async)
                    {
                        handle = Async.Open(uri, om,
                                            (int)Async.Priority.Default,
                                            callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Open(uri, om);
                    }
                }
                else
                {
                    if (async)
                    {
                        handle = Async.Create(uri, om, true, perms,
                                              (int)Async.Priority.Default,
                                              callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Create(uri, om, true, perms);
                    }
                }
                break;

            case FileMode.Truncate:
                if (uri.Exists)
                {
                    result = uri.Truncate(0);
                    if (async)
                    {
                        handle = Async.Open(uri, om,
                                            (int)Async.Priority.Default,
                                            callback);
                        Wait();
                    }
                    else
                    {
                        handle = Sync.Open(uri, om);
                        Vfs.ThrowException(uri, result);
                    }
                }
                else
                {
                    throw new FileNotFoundException(text_uri);
                }
                break;
            }

            this.mode    = mode;
            this.canseek = true;
            this.async   = async;
        }
		public AsyncReadCallbackWrapper (AsyncReadCallback managed, object o) : base (o)
		{
			NativeDelegate = new AsyncReadCallbackNative (NativeCallback);
			_managed = managed;
		}
예제 #9
0
        public static void Read(Handle handle, out byte buffer, uint bytes, AsyncReadCallback callback)
        {
            AsyncReadCallbackWrapper wrapper = new AsyncReadCallbackWrapper(callback, null);

            gnome_vfs_async_read(handle.Handle, out buffer, bytes, wrapper.NativeDelegate, IntPtr.Zero);
        }
예제 #10
0
		public VfsStream (string text_uri, FileMode mode, bool async)
		{
			if (text_uri == null)
				throw new ArgumentNullException ("uri");
				
			if (text_uri == "")
				throw new ArgumentNullException ("Uri is empty");
			
			if (mode < FileMode.CreateNew || mode > FileMode.Append)
				throw new ArgumentOutOfRangeException ("mode");

			if (text_uri.IndexOfAny (Path.InvalidPathChars) != -1)
				throw new ArgumentException ("Uri has invalid chars");
			
			uri = new Gnome.Vfs.Uri (text_uri);

			if (mode == FileMode.Open && !uri.Exists)
				throw new FileNotFoundException ("Could not find uri \"" + text_uri + "\".");

			if (mode == FileMode.CreateNew) {
				string dname = uri.ExtractDirname ();
				if (dname != "" && !new Uri (dname).Exists)
					throw new DirectoryNotFoundException ("Could not find a part of " +
									      "the path \"" + dname + "\".");
			}
			
			if (async) {
				callback = new AsyncCallback (OnAsyncCallback);
				readCallback = new AsyncReadCallback (OnAsyncReadCallback);
				writeCallback = new AsyncWriteCallback (OnAsyncWriteCallback);
			}
			
			OpenMode om = OpenMode.None;
			switch (mode) {
				case FileMode.CreateNew:
				case FileMode.Create:
				case FileMode.Truncate:
				case FileMode.Append:
					om = OpenMode.Write;
					access = FileAccess.Write;
					break;
				case FileMode.OpenOrCreate:
					if (uri.Exists) {
						om = OpenMode.Read;
						access = FileAccess.Read;
					} else {
						om = OpenMode.Write;
						access = FileAccess.Write;
					}
					break;
				case FileMode.Open:
					om = OpenMode.Read;
					access = FileAccess.Read;
					break;
			}
			
			/* 644 */
			FilePermissions perms = FilePermissions.UserRead |
						FilePermissions.UserWrite |
						FilePermissions.GroupRead |
						FilePermissions.OtherRead;
			
			Result result;
			handle = null;
			switch (mode) {
				case FileMode.Append:
					if (uri.Exists) {
						if (async) {
							handle = Async.Open (uri, om,
									     (int)Async.Priority.Default,
									     callback);
							Wait ();
							Async.Seek (handle, SeekPosition.End, 0, callback);
							Wait ();
						} else {
							handle = Sync.Open (uri, om);
							result = Sync.Seek (handle, SeekPosition.End, 0);
							Vfs.ThrowException (uri, result);
						}
					} else {
						if (async) {
							handle = Async.Create (uri, om, true, perms,
									       (int)Async.Priority.Default,
									       callback);
							Wait ();
						} else {
							handle = Sync.Create (uri, om, true, perms);
						}
					}
					break;
				case FileMode.Create:
					if (uri.Exists) {
						if (async) {
							handle =  Async.Open (uri, om,
									      (int)Async.Priority.Default,
									      callback);
							Wait ();
						} else {
							handle = Sync.Open (uri, om);
							result = uri.Truncate (0);
							Vfs.ThrowException (uri, result);
						}
					} else {
						handle = Sync.Create (uri, om, true, perms);
					}
					break;
				case FileMode.CreateNew:
					if (uri.Exists) {
						throw new IOException ("Uri \"" + text_uri + "\" already exists.");
					} else {
						if (async) {
							handle = Async.Create (uri, om, true, perms,
									       (int)Async.Priority.Default,
									       callback);
							Wait ();
						} else {
							handle = Sync.Create (uri, om, true, perms);
						}
					}
					break;
				case FileMode.Open:
					if (uri.Exists) {
						if (async) {
							handle = Async.Open (uri, om,
									     (int)Async.Priority.Default,
									     callback);
							Wait ();
						} else {
							handle = Sync.Open (uri, om);
						}
					} else {
						throw new FileNotFoundException (text_uri);
					}
					break;
				case FileMode.OpenOrCreate:
					if (uri.Exists) {
						if (async) {
							handle = Async.Open (uri, om,
									     (int)Async.Priority.Default,
									     callback);
							Wait ();
						} else {
							handle = Sync.Open (uri, om);
						}
					} else {
						if (async) {
							handle = Async.Create (uri, om, true, perms,
									       (int)Async.Priority.Default,
									       callback);
							Wait ();
						} else {
							handle = Sync.Create (uri, om, true, perms);
						}
					}
					break;
				case FileMode.Truncate:
					if (uri.Exists) {
						result = uri.Truncate (0);
						if (async) {
							handle = Async.Open (uri, om,
									     (int)Async.Priority.Default,
									     callback);
							Wait ();
						} else {
							handle = Sync.Open (uri, om);
							Vfs.ThrowException (uri, result);
						}
					} else {
						throw new FileNotFoundException (text_uri);
					}
					break;
			}
			
			this.mode = mode;
			this.canseek = true;
			this.async = async;
		}
예제 #11
0
 public override void BeginRead(AsyncReadCallback callback) {
     if (asyncread != null && asyncread.IsAlive) asyncread.Abort();
     asyncread = new Thread(
         () => {
             while (true) {
                 callback(this, Read());
             }
             // ReSharper disable FunctionNeverReturns
         });
     // ReSharper restore FunctionNeverReturns
     asyncread.Start();
 }