On Thu, 2012-02-09 at 07:58 +0000, Ilber Ibrahimi wrote: 
> I have the same problem on MAC OS X. The watcher works only on the
> root folder.
> Just create an empty project with a  filesystemwatcher.

In the attached mess [yea, it is just me hacking together some scrap to
test and idea] commenting and uncommenting the
"watcher.IncludeSubdirectories = true;" fixes/breaks the notifications.
using Gtk;
using Gdk;
using System;
using System.IO;
using System.Net.NetworkInformation;

 
class Network {
    public static bool IsNetworkAvailable()
    {
        return IsNetworkAvailable(0);
    }

    /// <summary>
    /// Indicates whether any network connection is available.
    /// Filter connections below a specified speed, as well as virtual network cards.
    /// </summary>
    /// <param name="minimumSpeed">The minimum speed required. Passing 0 will not filter connection using speed.</param>
    /// <returns>
    ///     <c>true</c> if a network connection is available; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsNetworkAvailable(long minimumSpeed)
    {
        if (!NetworkInterface.GetIsNetworkAvailable())
            return false;

        foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
        {
            // discard because of standard reasons
            if ((ni.OperationalStatus != OperationalStatus.Up) ||
                (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback) ||
                (ni.NetworkInterfaceType == NetworkInterfaceType.Tunnel))
                continue;

            // this allow to filter modems, serial, etc.
            // I use 10000000 as a minimum speed for most cases
            if (ni.Speed < minimumSpeed)
                continue;

            // discard virtual cards (virtual box, virtual pc, etc.)
            if ((ni.Description.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0) ||
                (ni.Name.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0))
                continue;

            return true;
        }
        return false;
    }
}



class CoilsSync {

	// The tray Icon
	private StatusIcon trayIcon;
	// The Window
	private Gtk.Window window;
 
	public CoilsSync()
	{
		trayIcon = new StatusIcon(new Pixbuf ("theIcon.png"));
		trayIcon.Visible = true;
 
		// Show/Hide the window (even from the Panel/Taskbar) when the TrayIcon has been clicked.
		trayIcon.Activate += delegate { window.Visible = !window.Visible; };
		// Show a pop up menu when the icon has been right clicked.
		trayIcon.PopupMenu += OnTrayIconPopup;
 
		// A Tooltip for the Icon
		trayIcon.Tooltip = "Hello World Icon";
 
        Console.WriteLine(Network.IsNetworkAvailable().ToString());
    
        
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = @"/home/awilliam/tmp";
        watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
        watcher.Changed += new FileSystemEventHandler(watcher_Changed);
        watcher.Created += new FileSystemEventHandler(watcher_Created);	
        watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);	
        watcher.EnableRaisingEvents = true;
        //watcher.IncludeSubdirectories = true;
	}
 
    void watcher_Renamed(object sender, RenamedEventArgs e)
    {
        Console.WriteLine("File Renamed: Old Name: " + e.OldName +
            " New Name: " + e.Name);
    }
    
    void watcher_Changed(object sender, FileSystemEventArgs e)
    {
        Console.WriteLine("File Changed: " + e.FullPath);
    }

    void watcher_Created(object sender, FileSystemEventArgs e)
    {
        Console.WriteLine("File Created: " + e.FullPath);
    }
    
    void watcher_Deleted(object sender, FileSystemEventArgs e)
    {
        Console.WriteLine("File Deleted: " + e.FullPath);
    }    
    
 
	// Create the popup menu, on right click.
	void OnTrayIconPopup (object o, EventArgs args) {
		Menu popupMenu = new Menu();
		
		// Quit the application when quit has been clicked.		
		ImageMenuItem menuItem = new ImageMenuItem ("Quit");
    	menuItem.Image = new Gtk.Image(Stock.Quit, IconSize.Menu);;
		popupMenu.Add(menuItem);
		menuItem.Activated += delegate { Application.Quit(); };
		
		menuItem = new ImageMenuItem ("Preferences");
    	menuItem.Image = new Gtk.Image(Stock.Preferences, IconSize.Menu);
		popupMenu.Add(menuItem);
		menuItem.Activated += delegate { Application.Quit(); };
		
		
		menuItem = new ImageMenuItem ("Sync Now");
    	menuItem.Image = new Gtk.Image(Stock.Refresh, IconSize.Menu);
		popupMenu.Add(menuItem);
		menuItem.Activated += delegate { Application.Quit(); };		
		if (!Network.IsNetworkAvailable())
		    menuItem.Sensitive = false;
	
		popupMenu.ShowAll();
		popupMenu.Popup();
	}
}

class App {
    public static CoilsSync x;
    
	static void Main() {
		// Initialize GTK#
		Application.Init ();
        x = new CoilsSync();
		Application.Run ();
	}
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to