Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-04
5
Medium Priority
?
236 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 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