<commit_before>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

using System;
using System.Collections.Generic;
using NDesk.DBus;
using org.freedesktop.DBus;

public class ManagedDBusTest
{
	public static void Main (string[] args)
	{
		string addr = Address.SessionBus;

		if (args.Length == 1) {
			string arg = args[0];

			switch (arg)
			{
				case "--system":
					addr = Address.SystemBus;
					break;
				case "--session":
					addr = Address.SessionBus;
					break;
				default:
					Console.Error.WriteLine ("Usage: monitor.exe [--system | --session]");
					return;
			}
		}

		Connection conn = new Connection (false);
		conn.Open (addr);
		conn.Authenticate ();

		ObjectPath opath = new ObjectPath ("/org/freedesktop/DBus");
		string name = "org.freedesktop.DBus";

		Bus bus = conn.GetObject<Bus> (name, opath);

		bus.NameAcquired += delegate (string acquired_name) {
			Console.WriteLine ("NameAcquired: " + acquired_name);
		};

		bus.Hello ();

		//hack to process the NameAcquired signal synchronously
		conn.HandleSignal (conn.ReadMessage ());

		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.Signal));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.MethodCall));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.MethodReturn));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.Error));

		while (true) {
			Message msg = conn.ReadMessage ();
			Console.WriteLine ("Message:");
			Console.WriteLine ("\t" + "Type: " + msg.Header.MessageType);
			//foreach (HeaderField hf in msg.HeaderFields)
			//	Console.WriteLine ("\t" + hf.Code + ": " + hf.Value);
			foreach (KeyValuePair<FieldCode,object> field in msg.Header.Fields)
				Console.WriteLine ("\t" + field.Key + ": " + field.Value);

			if (msg.Body != null) {
				Console.WriteLine ("\tBody:");
				MessageReader reader = new MessageReader (msg);

				//TODO: this needs to be done more intelligently
				try {
					foreach (DType dtype in msg.Signature.Data) {
						if (dtype == DType.Invalid)
							continue;<commit_msg>monitor.exe: Support for custom watch expressions<commit_after>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

using System;
using System.Collections.Generic;
using NDesk.DBus;
using org.freedesktop.DBus;

public class ManagedDBusTest
{
	public static void Main (string[] args)
	{
		string addr = Address.SessionBus;

		if (args.Length == 1) {
			string arg = args[0];

			switch (arg)
			{
				case "--system":
					addr = Address.SystemBus;
					break;
				case "--session":
					addr = Address.SessionBus;
					break;
				default:
					Console.Error.WriteLine ("Usage: monitor.exe [--system | --session] [watch expressions]");
					return;
			}
		}

		Connection conn = new Connection (false);
		conn.Open (addr);
		conn.Authenticate ();

		ObjectPath opath = new ObjectPath ("/org/freedesktop/DBus");
		string name = "org.freedesktop.DBus";

		Bus bus = conn.GetObject<Bus> (name, opath);

		bus.NameAcquired += delegate (string acquired_name) {
			Console.WriteLine ("NameAcquired: " + acquired_name);
		};

		bus.Hello ();

		//hack to process the NameAcquired signal synchronously
		conn.HandleSignal (conn.ReadMessage ());

		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.Signal));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.MethodCall));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.MethodReturn));
		bus.AddMatch (MessageFilter.CreateMatchRule (MessageType.Error));

		//custom match rules
		if (args.Length > 1)
			for (int i = 1 ; i != args.Length ; i++)
				bus.AddMatch (args[i]);

		while (true) {
			Message msg = conn.ReadMessage ();
			Console.WriteLine ("Message:");
			Console.WriteLine ("\t" + "Type: " + msg.Header.MessageType);
			//foreach (HeaderField hf in msg.HeaderFields)
			//	Console.WriteLine ("\t" + hf.Code + ": " + hf.Value);
			foreach (KeyValuePair<FieldCode,object> field in msg.Header.Fields)
				Console.WriteLine ("\t" + field.Key + ": " + field.Value);

			if (msg.Body != null) {
				Console.WriteLine ("\tBody:");
				MessageReader reader = new MessageReader (msg);

				//TODO: this needs to be done more intelligently
				try {
					foreach (DType dtype in msg.Signature.Data) {
						if (dtype == DType.Invalid)
							continue;
{'fraction_non_alphanumeric': 0.1358782094978414, 'fraction_numerical': 0.003181095205635083, 'mean_word_length': 3.464503042596349, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1594949', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1345, 'n_words': 361}