Author Topic: CommandLine Class (Tonys)  (Read 14793 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
CommandLine Class (Tonys)
« on: April 15, 2007, 10:37:55 AM »
I've been having a look at Tony's CommandLine class ;

Can someone who's familiar give me a hand please.
I've added using System.Collections; Namespace for the Hashtable class references .. I assume that's correct ?

The bit in the attached piccy has me stumped.
Part of the problem may be that I've never played with Hashtables, but the compiler errors have me scratching my head.

I'll just attach the relevant part .. Any Ideas ??

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: CommandLine Class (Tonys)
« Reply #1 on: April 15, 2007, 11:00:41 AM »
is this a constructor where the class name is Commands? I can't see the class name from your pic
ps where can I see the whole class?
« Last Edit: April 15, 2007, 11:03:54 AM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CommandLine Class (Tonys)
« Reply #2 on: April 15, 2007, 11:04:56 AM »
Hi Daniel,
The ClassName is CommandLine

I'm reticent about posting the class ..
You'll find it here. http://www.caddzone.com/CommandLine.cs

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: CommandLine Class (Tonys)
« Reply #3 on: April 15, 2007, 11:15:26 AM »
We’d probably better ask the boss but since there is no “return type”
I would say it’s a constructor and should be renamed CommandLine….
But But.. I really have no idea sorry for butting in..     ^-^

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CommandLine Class (Tonys)
« Reply #4 on: April 15, 2007, 11:19:43 AM »
don't be sorry, I'm glad to have someone sane to talk with at this hour of the night .. :D
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: CommandLine Class (Tonys)
« Reply #5 on: April 15, 2007, 01:17:05 PM »
To make it work do the following:

Quote
static Commands()

Change to:

Quote
static void Commands()

or you can make your Hashtable inside of TypedValueFromObject() like:

Quote
static TypedValue TypedValueFromObject(Object val)
{
    Hashtable ResTypes = new Hashtable();
    ResTypes.Clear();
// with the following too or as it is in the original below
    ////ResTypes.Add(typeof(string), RTSTR);
    ////ResTypes.Add(typeof(double), RTREAL);
    ////ResTypes.Add(typeof(Point3d), RT3DPOINT);
    ////ResTypes.Add(typeof(ObjectId), RTENAME);
    ////ResTypes.Add(typeof(Int32), RTLONG);
    ////ResTypes.Add(typeof(Int16), RTSHORT);
    ////ResTypes.Add(typeof(Point2d), RTPOINT);
    ResTypes[typeof(string)] = RTSTR;
    ResTypes[typeof(double)] = RTREAL;
    ResTypes[typeof(Point3d)] = RT3DPOINT;
    ResTypes[typeof(ObjectId)] = RTENAME;
    ResTypes[typeof(Int32)] = RTLONG;
    ResTypes[typeof(Int16)] = RTSHORT;
    ResTypes[typeof(Point2d)] = RTPOINT;

    object o = ResTypes[val.GetType()];

    if (o == null)
        throw new InvalidOperationException("Unsupported type in Command() method");
    return new TypedValue(o.GetHashCode(), val); //((int)o, val);
}

And as the code above use GetHashCode() instead of the (int) cast.
« Last Edit: April 15, 2007, 01:18:13 PM by LE »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CommandLine Class (Tonys)
« Reply #6 on: April 15, 2007, 05:00:23 PM »
Thanks for the comments Luis.

One issue with assuming it's a void method is that it never gets called from inside the class .. so the hashtable would never get filled, unless I misunderstand what's happening .. which IS likely.

How efficient would it be clearing and reloading the hashtable for each call to TypedValueFromObject ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: CommandLine Class (Tonys)
« Reply #7 on: April 15, 2007, 05:42:19 PM »
Thanks for the comments Luis.

One issue with assuming it's a void method is that it never gets called from inside the class .. so the hashtable would never get filled, unless I misunderstand what's happening .. which IS likely.

How efficient would it be clearing and reloading the hashtable for each call to TypedValueFromObject ?

I tried to use the code as-is and simple was adding a line in:

Quote
        public static int Command(params object[] args)           
        {
            Commands();
...

But, it gets filled every time is called, so that's why I used, what I have done in some of my functions, since the hashtable is being clear every time before is filled, and it is a very simple one, I don't think there is a overhead, but wait for the masters...
« Last Edit: April 15, 2007, 06:44:21 PM by LE »

LE

  • Guest
Re: CommandLine Class (Tonys)
« Reply #8 on: April 15, 2007, 07:00:11 PM »
I tested also by using the following to avoid the Clear() call

Code: [Select]
if (ResTypes.Count == 0)
{
    //ed.WriteMessage("\nEmpty ResTypes HatchTable!");
    ResTypes[typeof(string)]    = RTSTR;
    ResTypes[typeof(double)]    = RTREAL;
    ResTypes[typeof(Point3d)]   = RT3DPOINT;
    ResTypes[typeof(ObjectId)]  = RTENAME;
    ResTypes[typeof(Int32)]     = RTLONG;
    ResTypes[typeof(Int16)]     = RTSHORT;
    ResTypes[typeof(Point2d)]   = RTPOINT;
    //ed.WriteMessage("\nHatchTable count is {0}", ResTypes.Count);
}

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: CommandLine Class (Tonys)
« Reply #9 on: April 15, 2007, 08:30:24 PM »
How efficient would it be clearing and reloading the hashtable for each call to TypedValueFromObject ?

Correct, that’s why I still think it’s a static constructor.
The static constructor and the static hashtable would be initialized upon loading of the class. Correct?

LE

  • Guest
Re: CommandLine Class (Tonys)
« Reply #10 on: April 15, 2007, 08:58:11 PM »
Yes...

For doing that, change:

Quote
static void Commands()

To:
Quote
public CommandLine()

And test the class again... btw, the use of Clear() is not bad sample at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: CommandLine Class (Tonys)
« Reply #11 on: April 15, 2007, 09:15:53 PM »
I think that would be incorrect Luis, as only a static constructor initializes its object upon loading of the assembly

Change
 
Code: [Select]
static Commands() to
 
Code: [Select]
static CommandLine() ,
if you need to make another instance, you would need to add a public to the non static constructor the methods are static

Code: [Select]
public class myClass
{
  public myClass()
  {
    // Constructor.
  }
  static myClass()
  {
    // Initialization code goes here.
    // Can only access static members here.
  }
  //...
}
« Last Edit: April 15, 2007, 09:32:03 PM by Danielm103 »

LE

  • Guest
Re: CommandLine Class (Tonys)
« Reply #12 on: April 15, 2007, 09:24:59 PM »
I am using the arx wizard and was following the default constructors it creates, but I checked with the static and works too, here is the class modified.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: CommandLine Class (Tonys)
« Reply #13 on: April 15, 2007, 09:30:17 PM »
Great, you didn’t need to comment the first constructor.
It would not be the same as constructor overloading.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CommandLine Class (Tonys)
« Reply #14 on: April 15, 2007, 11:43:31 PM »
Thanks guys ..I made some time to test this.

I believe you were correct first time Daniel ..
I made it a static constructor ;
static CommandLine()
{
...
}

and

changed
return new TypedValue((int) o, val)
to
return new TypedValue(Convert.ToInt32(o), val);
because of a casting error ..

and got back to where I started .. loading a CUI menu ..
Code: [Select]
        //
        //
        [CommandMethod("Test_ZE")]
        public void test_ze()
        {
            CommandLine.ZoomExtents();
        }
        [CommandMethod("Test_LoadDbCUI")]
        public void test_Laconic()
        {
           string MenuQualifiedName = "K:\\DbCon.cui";
           string MenuGroupName = "DBCONNECT";
           CommandLine.Command(
                "FileDia", "0",
                "CuiUnLoad", MenuGroupName,
                "CuiLoad", MenuQualifiedName,
                "FileDia", "1"
                );
        }

.. and thanks to Tony for the original.


Quote
Command: Test_LoadDbCUI
Customization file unloaded successfully. Customization Group: DBCONNECT
Customization file loaded successfully. Customization Group: DBCONNECT
Command:

DUH: fat finger spelling !
« Last Edit: April 16, 2007, 12:59:59 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.