Exemplo n.º 1
0
        /// <summary>
        /// Logs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="message">The message.</param>
        public static void Log(
            object sender,
            SeverityMessage message)
        {
            // Check the listeners outside of a lock. If we have anything, then
            // return as fast as we can.
            if (logged == null)
            {
                return;
            }

            // Get the listeners at the point of reading the log.
            EventHandler <SeverityMessageEventArgs> listeners;

            using (new ReadLock(threadLock))
            {
                listeners = logged;
            }

            // If we don't have listeners, then just break out.
            if (listeners == null)
            {
                return;
            }

            // Create an event handler and invoke it.
            var args = new SeverityMessageEventArgs(message);

            listeners(sender, args);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a severity message with a given message and logs it using
        /// the instance's context.
        /// </summary>
        /// <param name="severity">The severity.</param>
        /// <param name="format">The format.</param>
        /// <param name="arguments">The arguments.</param>
        public void Log(
            Severity severity,
            string format,
            params object[] arguments)
        {
            var message = new SeverityMessage(severity, String.Format(format, arguments));

            Log(message);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SeverityMessageEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 public SeverityMessageEventArgs(SeverityMessage message)
 {
     Message = message;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Logs the specified message to the logging subsystem.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Log(SeverityMessage message)
 {
     LogManager.Log(context, message);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Logs the message to any class listening to the manager.
 /// </summary>
 /// <param name="message">The message.</param>
 public static void Log(SeverityMessage message)
 {
     Log(null, message);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a single action into the manager, automatically connecting
        /// accelerators and groups.
        /// </summary>
        /// <param name="newAction">The action to add.</param>
        public void Add(Action newAction)
        {
            // Make sure we have sane data.
            if (newAction == null)
            {
                throw new ArgumentNullException("action");
            }

            // Check to see if we are going to filter out this action.
            if (!CanAdd(newAction))
            {
                return;
            }

            // Associate the name of the action in the current dictionary. If the
            // name is already registered, then add a message and ignore the
            // request.
            string actionName = newAction.Name;

            if (actions.ContainsKey(actionName))
            {
                // Create a new error message.
                var message = new SeverityMessage(
                    Severity.Error,
                    "Cannot register " + actionName
                        + " action because it was already registered previously.");
                messages.Add(message);

                return;
            }

            actions[actionName] = newAction;

            // Figure out what action group this action is associated with.
            string groupName = "Global";

            if (newAction is IConfigurableAction)
            {
                groupName = ((IConfigurableAction) newAction).GroupName;
            }

            ActionSet group = GetOrCreateGroup(groupName);

            group.Add(newAction);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Scans the specified assembly and looks for all constructible actions
        /// with zero parameter constructors. For every one, it creates a new
        /// instance and adds it to the manager.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        public void Add(Assembly assembly)
        {
            // Make sure we don't have a null since we can't handle that.
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            // Scan through the types of the assembly.
            var emptyTypes = new Type[]
            {
            };
            var emptyObjects = new object[]
            {
            };
            Type actionType = typeof (Action);

            foreach (Type type in assembly.GetTypes())
            {
                // Make sure the type is a concrete instance.
                if (!type.IsClass
                    || type.IsAbstract)
                {
                    // We can't create this type.
                    continue;
                }

                // If we aren't an Action type, then just continue.
                if (!actionType.IsAssignableFrom(type))
                {
                    continue;
                }

                // Make sure we can add it.
                if (!CanAdd(type))
                {
                    continue;
                }

                // Determine if we have a parameterless constructor.
                ConstructorInfo constructor = type.GetConstructor(emptyTypes);

                if (constructor == null)
                {
                    // Add a message to report this.
                    var message = new SeverityMessage(
                        Severity.Alert,
                        "Cannot create an instance of " + type
                            + " because it does not have a parameterless constructor.");
                    messages.Add(message);

                    // We are done with this type.
                    continue;
                }

                // Create the item and add it to the manager.
                var action = (Action) constructor.Invoke(emptyObjects);

                Add(action);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Logs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="message">The message.</param>
        public static void Log(
			object sender,
			SeverityMessage message)
        {
            // Check the listeners outside of a lock. If we have anything, then
            // return as fast as we can.
            if (logged == null)
            {
                return;
            }

            // Get the listeners at the point of reading the log.
            EventHandler<SeverityMessageEventArgs> listeners;

            using (new ReadLock(threadLock))
            {
                listeners = logged;
            }

            // If we don't have listeners, then just break out.
            if (listeners == null)
            {
                return;
            }

            // Create an event handler and invoke it.
            var args = new SeverityMessageEventArgs(message);
            listeners(sender, args);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Logs the message to any class listening to the manager.
 /// </summary>
 /// <param name="message">The message.</param>
 public static void Log(SeverityMessage message)
 {
     Log(null, message);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SeverityMessageEventArgs"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 public SeverityMessageEventArgs(SeverityMessage message)
 {
     Message = message;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Logs the specified message to the logging subsystem.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Log(SeverityMessage message)
 {
     LogManager.Log(context, message);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a severity message with a given message and logs it using
        /// the instance's context.
        /// </summary>
        /// <param name="severity">The severity.</param>
        /// <param name="format">The format.</param>
        /// <param name="arguments">The arguments.</param>
        public void Log(
			Severity severity,
			string format,
			params object[] arguments)
        {
            var message = new SeverityMessage(severity, String.Format(format, arguments));
            Log(message);
        }