Exemple #1
0
        private void ListKinds(IndentingTextWriter writer)
        {
            var sigs = ComponentCatalog.GetAllSignatureTypes()
                       .Select(ComponentCatalog.SignatureToString)
                       .OrderBy(x => x);

            writer.WriteLine("Available component kinds:");
            using (writer.Nest())
            {
                foreach (var sig in sigs)
                {
                    writer.WriteLine(sig);
                }
            }
        }
Exemple #2
0
        private void ShowComponents(IndentingTextWriter writer)
        {
            Type   typeSig;
            Type   typeRes;
            string kind;

            if (_kind == null)
            {
                // Show commands.
                typeSig = typeof(SignatureCommand);
                typeRes = typeof(ICommand);
                kind    = "Command";
                writer.WriteLine("Available commands:");
            }
            else
            {
                kind = _kind.ToLowerInvariant();
                var sigs = ComponentCatalog.GetAllSignatureTypes();
                typeSig = sigs.FirstOrDefault(t => ComponentCatalog.SignatureToString(t).ToLowerInvariant() == kind);
                if (typeSig == null)
                {
                    typeSig = sigs.FirstOrDefault(t => ComponentCatalog.SignatureToString(t).StartsWithInvariantCultureIgnoreCase(kind));
                    if (typeSig == null)
                    {
                        writer.WriteLine("Couldn't find kind '{0}'", kind);
                        ListKinds(writer);
                        return;
                    }
                }
                typeRes = typeof(object);
                writer.WriteLine("Available components for kind '{0}':", ComponentCatalog.SignatureToString(typeSig));
            }

            var infos = ComponentCatalog.GetAllDerivedClasses(typeRes, typeSig)
                        .Where(x => !x.IsHidden)
                        .OrderBy(x => x.LoadNames[0].ToLowerInvariant());

            using (writer.Nest())
            {
                var components = new List <Component>();
                foreach (var info in infos)
                {
                    _env.Assert(info.LoadNames.Count > 0);

                    writer.Write("{0}", info.LoadNames[0]);
                    if (!string.IsNullOrWhiteSpace(info.UserName))
                    {
                        writer.Write(": {0}", info.UserName);
                    }
                    writer.WriteLine();

                    using (writer.Nest())
                        ShowAliases(writer, info.LoadNames);
                    components.Add(new Component(kind, info, info.CreateArguments()));
                }

                if (components.Count > 0)
                {
                    Serialize(components);
                }
            }
        }