Click here to Skip to main content
11,412,302 members (60,889 online)
Click here to Skip to main content
Add your own
alternative version

A JavaScript Shell

, 18 Nov 2010 CPOL
Bases to create your own JavaScript shell for your application
binaries.zip
binaries
Documentation.chm
Scaredfinger.JSShell.dll
samples.zip
samples
LocalShell
Properties
SampleShell
Properties
Scaredfinger.JSShell
Properties
ShellServer
Properties
source.zip
source
Scaredfinger.JSShell
Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Scaredfinger.JSShell;
using System.IO;
using System.ComponentModel;
using System.Reflection;

namespace SampleShell
{
  public class SampleShell : Shell
  {
    public TextWriter Output
    {
      get;
      set;
    }

    public SampleShell()
      : this(Console.Out)
    {
    }

    public SampleShell(TextWriter output)
    {
      Output = output;
    }

    [ShellOperation]
    [Description("Shows this help screen")]
    public void Help()
    {
      foreach (var method in GetType().GetMethods().Where(x => x.GetCustomAttributes(typeof(ShellOperationAttribute), false).Any()))
      {
        var attr = method.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute;
        
        var parameters = string.Join(",", 
          (
            from p in method.GetParameters()
            select string.Format("{0} {1}", p.ParameterType.Name, p.Name)
          ).ToArray()
        ) ;

        var text = string.Format("\t{0} {1}({2}):\t{3}", method.ReturnType.Name, method.Name, parameters,
          attr == null? "" : attr.Description);

        Print(text);
      }
    }

    [ShellOperation]
    [Description("Prints a text")]
    public void Print(string text)
    {
      Output.WriteLine(text);
    }

    [ShellOperation]
    [Description("Closes this shell")]
    public void Exit()
    {
      CloseShell();
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Erich Ledesma
Architect SunHotels
Spain Spain
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.

I mainly work in web applications using C# and some Javascript. Some very few times do some Java.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.5 | Last Updated 18 Nov 2010
Article Copyright 2010 by Erich Ledesma
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid