コード例 #1
0
        public static void PrepareForCall(this HierarchicalVariableScope scope, ICommandSpecification command, RoomieCommandInterpreter interpreter)
        {
            var givenValues      = scope.Local.FindGivenValues();
            var missingArguments = scope.FindMissingArguments(command.Arguments);

            if (missingArguments.Length > 0)
            {
                throw new MissingArgumentsException(missingArguments);
            }

            var defaultedValues = scope.ApplyDefaults(command.Arguments);

            if (interpreter.Engine.PrintCommandCalls)
            {
                var call = BuilCommandCall(command.Group + "." + command.Name, givenValues, defaultedValues);
                interpreter.WriteEvent(call);
            }

            var mistypedArguments = scope.FindMistypedArguments(command.Arguments);

            if (mistypedArguments.Any())
            {
                foreach (var argument in mistypedArguments)
                {
                    interpreter.WriteEvent(argument.Type.ValidationMessage(argument.Name));
                }

                throw new MistypedArgumentException(mistypedArguments);
            }
        }
コード例 #2
0
        public static void PrepareForCall(this HierarchicalVariableScope scope, ICommandSpecification command, RoomieCommandInterpreter interpreter)
        {
            var givenValues = scope.Local.FindGivenValues();
            var missingArguments = scope.FindMissingArguments(command.Arguments);

            if (missingArguments.Length > 0)
            {
                throw new MissingArgumentsException(missingArguments);
            }

            var defaultedValues = scope.ApplyDefaults(command.Arguments);

            if (interpreter.Engine.PrintCommandCalls)
            {
                var call = BuilCommandCall(command.Group + "." + command.Name, givenValues, defaultedValues);
                interpreter.WriteEvent(call);
            }

            var mistypedArguments = scope.FindMistypedArguments(command.Arguments);

            if (mistypedArguments.Any())
            {
                foreach (var argument in mistypedArguments)
                {
                    interpreter.WriteEvent(argument.Type.ValidationMessage(argument.Name));
                }

                throw new MistypedArgumentException(mistypedArguments);
            }
        }
コード例 #3
0
ファイル: RoomieCommand.cs プロジェクト: Mavtak/roomie
        protected internal RoomieCommand(ICommandSpecification specificationOverrides = null)
        {
            var type = GetType();

            var specification = new CompositeCommandSpecification(
                specificationOverrides ?? new ReadOnlyCommandSpecification(),
                new AttributeBasedCommandSpecification(type),
                new NamespaceBasedCommandSpecification(type)
                );

            Name             = specification.Name;
            Group            = specification.Group;
            Description      = specification.Description;
            Source           = specification.Source;
            ExtensionName    = specification.ExtensionName;
            ExtensionVersion = specification.ExtensionVersion;
            Arguments        = specification.Arguments;

            if (Group == null)
            {
                throw new Exception("Command " + Name + "'s is not set");
            }

            Finalized = true;

            if (GetType().GetCustomAttributes(typeof(NotFinishedAttribute), true).Any())
            {
                Finalized = false;
            }
        }
コード例 #4
0
ファイル: RoomieCommand.cs プロジェクト: Mavtak/roomie
        protected internal RoomieCommand(ICommandSpecification specificationOverrides = null)
        {
            var type = GetType();

            var specification = new CompositeCommandSpecification(
                specificationOverrides ?? new ReadOnlyCommandSpecification(),
                new AttributeBasedCommandSpecification(type),
                new NamespaceBasedCommandSpecification(type)
                );

            Name = specification.Name;
            Group = specification.Group;
            Description = specification.Description;
            Source = specification.Source;
            ExtensionName = specification.ExtensionName;
            ExtensionVersion = specification.ExtensionVersion;
            Arguments = specification.Arguments;

            if (Group == null)
            {
                throw new Exception("Command " + Name + "'s is not set");
            }

            Finalized = true;

            if (GetType().GetCustomAttributes(typeof (NotFinishedAttribute), true).Any())
            {
                Finalized = false;
            }
        }
コード例 #5
0
 public ImmutableDeviceConfiguration(string name, CalendarType uptimeCalendarType, string calendarProviderSettingsName,
     string uptimeCalendarName, TimeSpan uptimeBufferInterval, ICommandSpecification isRunningCommand, ICommandSpecification startCommand,
     ICommandSpecification stopCommand)
 {
     this.Name = name;
     this.UptimeCalendarType = uptimeCalendarType;
     this.CalendarProviderSettingsDirectory = calendarProviderSettingsName;
     this.UptimeCalendarName = uptimeCalendarName;
     this.UptimeBufferInterval = uptimeBufferInterval;
     this.IsRunningCommand = isRunningCommand;
     this.StartCommand = startCommand;
     this.StopCommand = stopCommand;
 }
コード例 #6
0
        public static string ToConsoleFriendlyString(this ICommandSpecification command, bool isDynamic)
        {
            var builder = new StringBuilder();

            builder.Append("Command: ");
            builder.Append(command.Group + "." + command.Name);
            builder.AppendLine();

            if (!isDynamic)
            {
                builder.Append("Source: ");
                builder.Append(command.Source);
                builder.AppendLine();

                builder.Append("Version: ");
                builder.Append(command.ExtensionVersion);
                builder.AppendLine();
            }
            else
            {
                builder.Append("Dynamic Command");
                builder.AppendLine();
            }

            builder.Append("Description: ");
            builder.Append(command.Description);
            builder.AppendLine();

            builder.Append("Arguments:");

            if (!command.Arguments.Any())
            {
                builder.Append(" (none)");
            }
            else
            {
                foreach (var argument in command.Arguments)
                {
                    builder.AppendLine();
                    builder.Append("\t");
                    builder.Append(argument);
                }
            }
            builder.AppendLine();

            return(builder.ToString());
        }
コード例 #7
0
        public static void WriteToXml(this ICommandSpecification command, XmlWriter writer)
        {
            writer.WriteStartElement("Command");
            {
                writer.WriteAttributeString("PluginName", command.ExtensionName);
                writer.WriteAttributeString("Group", command.Group);
                writer.WriteAttributeString("Name", command.Name);

                if (!String.IsNullOrEmpty(command.Description))
                {
                    writer.WriteAttributeString("Description", command.Description);
                }

                foreach (RoomieCommandArgument argument in command.Arguments)
                {
                    argument.WriteToXml(writer);
                }
            }
            writer.WriteEndElement();
        }