public static NSScriptCommandDescription Create(string suiteName, string commandName, NSScriptCommandDescriptionDictionary commandDeclaration)
        {
            if (String.IsNullOrEmpty(suiteName))
            {
                throw new ArgumentException("suiteName cannot be null or empty");
            }
            if (String.IsNullOrEmpty(commandName))
            {
                throw new ArgumentException("commandName cannot be null or empty");
            }
            if (commandDeclaration == null)
            {
                throw new ArgumentNullException("commandDeclaration");
            }

            // ensure that the passed description is well formed
            if (String.IsNullOrEmpty(commandDeclaration.CommandClass))
            {
                throw new ArgumentException("cmdClass");
            }
            if (String.IsNullOrEmpty(commandDeclaration.AppleEventCode))
            {
                throw new ArgumentException("eventCode");
            }
            if (commandDeclaration.AppleEventCode.Length != 4)
            {
                throw new ArgumentException("eventCode must be a four characters string.");
            }
            if (String.IsNullOrEmpty(commandDeclaration.AppleEventClassCode))
            {
                throw new ArgumentException("eventClass");
            }
            if (commandDeclaration.AppleEventClassCode.Length != 4)
            {
                throw new ArgumentException("eventClass must be a four characters string.");
            }
            if (commandDeclaration.ResultAppleEventCode != null && commandDeclaration.ResultAppleEventCode.Length != 4)
            {
                throw new ArgumentException("resultAppleEvent must be a four characters string.");
            }

            using (var nsSuitName = new NSString(suiteName))
                using (var nsCommandName = new NSString(commandName)) {
                    try {
                        var cmd = new NSScriptCommandDescription(nsSuitName, nsCommandName, commandDeclaration.Dictionary);
                        cmd.description = commandDeclaration;
                        return(cmd);
                    } catch (Exception e) {
                        // this exception is raised by the platform because the internal constructor returns a nil
                        // from the docs we know:
                        //
                        // Returns nil if the event constant or class name for the command description is missing; also returns nil
                        // if the return type or argument values are of the wrong type.
                        //
                        // the conclusion is that the user created a wrong description dict, we let him know
                        throw new ArgumentException("commandDeclaration",
                                                    "Wrong description dictionary: Check that the event constant, class name and argument definitions are well formed as per apple documentation.", e);
                    }
                }
        }
Beispiel #2
0
        public static NSScriptCommandDescription Create(string suiteName, string commandName, NSScriptCommandDescriptionDictionary commandDeclaration)
        {
            if (String.IsNullOrEmpty (suiteName))
                throw new ArgumentException ("suiteName cannot be null or empty");
            if (String.IsNullOrEmpty (commandName))
                throw new ArgumentException ("commandName cannot be null or empty");
            if (commandDeclaration == null)
                throw new ArgumentNullException ("commandDeclaration");

            // ensure that the passed description is well formed
            if (String.IsNullOrEmpty (commandDeclaration.CommandClass))
                throw new ArgumentException ("cmdClass");
            if (String.IsNullOrEmpty (commandDeclaration.AppleEventCode))
                throw new ArgumentException ("eventCode");
            if (commandDeclaration.AppleEventCode.Length != 4)
                throw new ArgumentException ("eventCode must be a four characters string.");
            if (String.IsNullOrEmpty (commandDeclaration.AppleEventClassCode))
                throw new ArgumentException ("eventClass");
            if (commandDeclaration.AppleEventClassCode.Length != 4)
                throw new ArgumentException ("eventClass must be a four characters string.");
            if (commandDeclaration.ResultAppleEventCode != null && commandDeclaration.ResultAppleEventCode.Length != 4)
                throw new ArgumentException ("resultAppleEvent must be a four characters string.");

            using (var nsSuitName = new NSString (suiteName))
            using (var nsCommandName = new NSString (commandName)) {
                try {
                    var cmd = new NSScriptCommandDescription (nsSuitName, nsCommandName, commandDeclaration.Dictionary);
                    cmd.description = commandDeclaration;
                    return cmd;
                } catch (Exception e) {
                    // this exception is raised by the platform because the internal constructor returns a nil
                    // from the docs we know:
                    //
                    // Returns nil if the event constant or class name for the command description is missing; also returns nil
                    // if the return type or argument values are of the wrong type.
                    //
                    // the conclusion is that the user created a wrong description dict, we let him know
                    throw new ArgumentException ("commandDeclaration",
                        "Wrong description dictionary: Check that the event constant, class name and argument definitions are well formed as per apple documentation.", e);
                }
            }
        }