|
|
|
|
|
 |
|
|
| View previous topic :: View next topic |
AlanF Forum Member

Joined: 04 Dec 2008 Posts: 7 Location: Texas
|
Posted: Mon Apr 12, 2010 4:11 pm Post subject: Using UMRA COM...
|
|
|
|
I noticed several online examples for leveraging the UMRA COM object (UMRACOM.DLL) using classic ASP and VBScript; however, I couldn’t find anything when it came to ASP.NET and managed code. After playing around with the Umra interface, I thought I would post a few quick samples in case anyone else might want to leverage the DLL via Interop. I prefer C# in my code behind page, but it shouldn’t be too difficult to convert to VB.
First off is to add a reference to the UmraCom type library to your VS project. You will need to install the Forms client locally unless you are developing on the same server that is running the Umra instance. I tried to simply register the DLL without the install, but regsvr32 wasn’t too happy with that method. Next, be sure to add a using statement to the UMRAcomLib namespace.
using UMRAcomLib;
Now we need to create a new object for the UMRAcomLib namespace; Umra class. The constructor won’t need any parameters when initialized so we can simply use something like this:
Umra umraobj = new Umra();
This is the equivalent to the VBScript CreateObject function used to instantiate an object reference.
Moving right along we now need to create a connection to the UMRA server which is done using the Connect method:
| Code: | int retval = umraobj.Connect("UMRASERVER", 56814);
if (retval != 0)
{
Response.Write("Error connecting to UMRASERVER");
return;
} |
To pass variables back to the UMRA server from the web page, use the SetVariableText method as demonstrated:
| Code: | umraobj.SetVariableText("%FirstName%", TextBox1.Text);
umraobj.SetVariableText("%MiddleName%", TextBox2.Text);
umraobj.SetVariableText("%LastName%", TextBox3.Text); |
Now that we’ve added some variables, let’s kick off our project on the UMRA server. Since we are using managed code we will need to declare our variables ahead of time as the ExecuteProjectScript method requires two arguments. If we were using VBScript this would not be necessary as the object type VARIANT is returned. For this method, the first overload is a type integer and the second is a VARIANT for which we will use type object. We will also need to use the out modifier for the variables in the method.
| Code: | int errcount;
object scriptmessage;
int retval = umraobj.ExecuteProjectScript("CreateUser");
if (retval != 0)
{
retval = umraobj.GetScriptExecutionInfo(out errcount, out scriptmessage);
Response.Write("Error executing CreateUser.<BR>" +
scriptmessage.ToString();
return;
} |
What about getting data stored in a variable from the project? No sweat, just declare variables as type object to hold the data and use the GetVariableText method.
| Code: | object fullname, username;
int retval;
retval = umraobj.GetVariableText("%UserName%",out username);
retval = umraobj.GetVariableText("%FullName%", out fullname);
Response.Write("Username is: " + username + "<BR>" +
"Full name is: " + fullname); |
What if that variable happens to store table data? No sweat, we just need to create a new object using the UmraDataTable class first.
UmraDataTable searchresults = new UmraDataTable();
Let’s present that information in a GridView object on the page shall we? First, let’s create a DataTable to store the data from the UmraDataTable and use as a data source for the GridView object. The DataTable is a member of the System.Data namespace.
| Code: | DataTable dt = new DataTable("UserList");
DataColumn dc;
DataRow dr;
dc = new DataColumn();
dc.ColumnName = "UserName";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "DisplayName";
dc.ReadOnly = true;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "Description";
dc.ReadOnly = true;
dt.Columns.Add(dc); |
Next we need to get the data from the Umra variable table into the searchresults UmraDataTable object we created earlier. The %SearchResults% variable is the name of the variable on the UMRA server that is storing the variable table data.
int retval = umraobj.GetVariableDataTable("%SearchResults%", searchresults);
Finally, let’s loop through the UmraDataTable object and store the data into our DataTable object which will be used as the data source for the GridView object.
| Code: | int rowindex = 0;
object user_username, user_displayname, user_description;
while (retval == 0)
{
retval = searchresults.GetCellText(rowindex, 0, out user_username);
retval = searchresults.GetCellText(rowindex, 1, out user_displayname);
retval = searchresults.GetCellText(rowindex, 2, out user_description);
if (retval == 0)
{
dr = dt.NewRow();
dr["UserName"] = user_username;
dr["DisplayName"] = user_displayname;
dr["Description"] = user_description;
dt.Rows.Add(dr);
rowindex++;
}
}
if (dt.Rows.Count == 0)
{
Response.Write("No information found in table”);
}
GridView1.DataSource = dt;
GridView1.DataBind(); |
Nothing too detailed, but thought it might give a little insight as to leveraging the UMRA COM object in the ASP.NET environment. Hope it helps. |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group |
|
|
|
|
|