Solved

Newbie Question regarding this syntax --> public HttpRequestToken(string rsaKey) : base(rsaKey)

Posted on 2006-11-04
5
233 Views
Last Modified: 2011-09-20
I'm working through someones code and I'm not sure what is happening here.

Here's the method in question:

public HttpRequestToken(string rsaKey) : base(rsaKey)
{
}

This is called via this (the RSAKeyInXMLString is actually the RSA Signing Key as an XML string):

MyToken.HttpRequestToken oToken = new MyToken.HttpRequestToken (RSAKeyInXMLString);

Can anyone explain the syntax here? I'm confused over why this method is empty and what the ": base (rsaKey)" is all about?

Also after this, are these lines:

    oToken["UserID"] = idLoginName.Text;
    oToken["Password"] = idLoginPassword.Text;

Does this (oToken["SomeValue"]) represent some kind of Forms collection or something?

Cheers in advance.
0
Comment
Question by:w3digital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:w3digital
ID: 17874292
OK, I think I get it.

The ": base(rsaKey)" is refering back to the inherited class and passing it the key so in reality


public HttpRequestToken(string rsaKey) : base(rsaKey)
{
}

Is really calling this method in a different class:

public Token(string key)
            {
                  _des = new DESCryptoServiceProvider();
                  _des.GenerateIV();
                  _des.GenerateKey();

                  CspParameters cspParams = new CspParameters();
                  cspParams.Flags = CspProviderFlags.UseMachineKeyStore;

                  _rsa = new RSACryptoServiceProvider(cspParams);
                  
                  _rsa.FromXmlString(key);

                  EnsureDocument();
            }

Does that seem right?

Still no idea what the

oToken["UserID"] = idLoginName.Text;
oToken["Password"] = idLoginPassword.Text;

is all about though.

Ta.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17874483
Yes you are correct.

    base(rsaKey)

Means "pass the rsaKey value in my constructor to the contructor of the class I inherit from".

As for:

    oToken["UserID"] = idLoginName.Text;

Your HttpRequestToken class, or its base class, should have a method that looks something like:

     public string this[string key]
     {
     }

This is called an indexer and is usually used to expose some sort of collection object (ArrayList, HashTable, etc) stored inside the class and allows you to get/set values based on a name or index number. The specific signature may be a little different in your code, i'm just basing the sample above on what it probably looks like. The important part is "this[]" the return type and type within the square barackets may be different for you.
0
 

Author Comment

by:w3digital
ID: 17876139
Hey that's an awesome answer and perfect for what I need!!! I believe the code you are talking about is shown below?

So am I right in thinking that whatever I define as oToken["MyNewValue"] will become part of a dynamically created XML document (i.e. in the form of <MyNewValue>the value</MyNewValue>)? I suspected this but couldn't see where it was happening.

And I presume the code then checks if it already exists and if so it updates the value, otherwise it creates it as a new child node and appends it to the document?

Thanks so much that really helps me understand what's going on here.

public string this[string index]
            {
                  get
                  {
                        EnsureDocument(); // This ensures there is always an XML doc in place
                        XmlNode oNode = _document.SelectSingleNode("MyToken/Items/Item[@key='" + index + "']/@value");

                        if (oNode == null) return "";

                        return oNode.Value;
                  }
                  set
                  {
                        EnsureDocument();
                        XmlNode oNode = _document.SelectSingleNode("MyToken/Items/Item[@key='" + index + "']/@value");

                        if (oNode != null)
                              oNode.Value = value;
                        else
                        {
                              XmlElement oElement = _document.CreateElement("Item");
                              oElement.SetAttribute("key", index);
                              oElement.SetAttribute("value", value);

                              XmlElement oItems = (XmlElement)_document.SelectSingleNode("MyToken/Items");
                              oItems.AppendChild(oElement);
                        }
                  }
            }
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17876149
It appears to be looking for an "Item" node with an attribute called "key" whose value is whatever you pass in for "index", and then sets the "value" attribute of that node to the value you specify, otherwise it creates a new "Item" node.

So, if you call:

    oToken["UserID"] = "Bob";

And the node doesn't already exist, then it will create a node in the form:

    <Item key="UserID" value="Bob" />

Which it then appends to the "Items" node of the document.
0
 

Author Comment

by:w3digital
ID: 17876252
Great stuff. Thanks again!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question