Thursday, December 16, 2010

Using an HTA to launch an .exe (be very afraid)


Turns out you can script a .HTA to launch just about anything. Which likely is why even the BPOS site for my RnD project blocks saving them by default.
The example below will launch an executable with a button click. One use I am considering using this for is to launch some of my legacy .exe code inside of a Share Point Web Part.
Of course if I allow access to HTA's on a production server I am just begging for the script-kiddies to turn my life into a living hell. But if I can get it into a Web Part that cannot be modified expect by me it might be worth trying.
Meanwhile here is the launcher bits for running remote desktop:
'<'INPUT style="background-color:transparent; width:160;height:25"
TYPE="button" VALUE="Terminal Svcs" ID="essctermsvcs">

essctermsvcs.onclick = function runtermsvcs()
{
var shell = new ActiveXObject("WScript.shell");
if (shell)
{
shell.run("mstsc.exe");
}
else
{
alert("Terminal Services Not available");
}
}

OLAP and SASS (get cubic)


After my first class was canceled, they gave me a 10% discount on the next, which is SASS, SQL Analytics and MDX to get into the cube.
At first glance OLAP is very similar to SQL, at which I am an old hand. But the OLAP concept is multi-dimensional cubes with a lot of spreadsheet type functionality.
Here is a code snippet:

SELECT
{ [Measures].[Store Sales] } ON COLUMNS,
{
[Date].[2002],
[Date].[2003] } ON ROWS
FROM Sales
WHERE (
[Store].[USA].[CA] )

That translates into the cube above, with a measurement dimension of sales, two date dimensions for 2002 and 2003, all sliced by the state of California.

This could be an interesting and useful class

Thursday, December 9, 2010

Adventures with IPSec


Looking at how to control access on what MS calls an External Secure Communication Mode for SharePoint and Project Sophia I ran across the improvements made by MS in Windows 7 to IPSec configuration.
First question out of the box is, can I dump the gunky Sonicwall Software VPN that is such a pain?
Second question is what is up with the "Join to your companies Domain" stuff?
When I have the answers, I'll update this post...

Wednesday, December 8, 2010

@Home php equal to an RSS Feed

Is something that I can never remember...

So here: http://essc-home.org/feed.php

Friday, November 19, 2010

Bypassing Validation

To test my IIR Form, I needed to bypass all the Infopath required fields. My method was simple enough, I saved a copy of the form to a local drive as testbeta.xml, and then replaced the input for the webservice with an xmldocument type taht loaded the test form...

xmlDoc := XmlDocument.Create;
xmlDoc.Load('C:\testbeta.xml');
Root := TParticipantRecord.Create;
// Root.LoadFromXML(Root,IIRForm);
Root.LoadFromXML(Root,xmlDoc);

Friday, November 12, 2010

The Roadmap

Big...Huge...Gigantic...

I’ve been asked for an expanded vision for ESSC I.T.

I get the understanding that the gloves are off and we need to push forward under the assumption that the resources can be found, likely using grants and such. Considering the mess that C.A.D.D.I.S and the boys from Oracle left behind it is both exciting and a bit frightening to consider that little old me might be allowed to take a shot where all the old gods failed…

The key, in my own mind, is to decouple the different parts into something far more flexible than tradition allows, balancing the rigor of the ‘reported’ data entry with the ad-hoc nature of InfoPath forms services.

Thursday, November 4, 2010

Drop Dead Drop Downs



When consuming a dataset created from a table with a key and description, by selecting at the top element and splitting the value and display, we can get a return value in the xmlDocument to post the foreign key and bind the joins together.

In this case the segment of xml is like:




->editregion
id->1
Desc->North Los Angeles
vpid->1227
vpname->Kolenda, Kathleen
vpstring->Kolenda, Kathleen
->/editregion


Then if the default value is -1, the value returned can be handled by determining if the result sent is a -1, in which case the source for VPName is the value (or in this case the VP’s Employee ID Number). What is funky is that the VPName will be the Display Name rather than the value if it’s an edit but if left untouched the VPName will be the Display Value. My solution is to load the table with a VPString field that doesn’t show and has the original name so that if they don’t match I know to use the VPName field but if they do I can use the VPID field.

With this code segment to load the repeating group in the main data section, I can get around the funkyness…


function LoadESSCRegions()
{ // Get the list of Services. var
regions = Document.GetDOM("AsRegionsList").selectNodes("//REGIONS");

// If nothing was found, then return; there will be no items to
insert.
if(regions == null)
{

XDocument.UI.Alert("Error-> Unable to load Regions List");
return;
}

var reg;

while
(reg = regions.nextNode())
{
var row =
XDocument.DOM.selectSingleNode("//my:myFields/my:RegionsTable/my:EditRegions");
row = row.cloneNode(true);
row.selectSingleNode("my:ESSCRegion_ID").text
= reg.selectSingleNode("ESSCRegion_ID").text;
row.selectSingleNode("my:RegionDescription").text =
reg.selectSingleNode("Description").text;
row.selectSingleNode("my:RegionIsActive").text =
reg.selectSingleNode("IsActive").text;
if (reg.selectSingleNode("RVP") ==
null)
row.selectSingleNode("my:RVPID").text = "-1"
else
row.selectSingleNode("my:RVPID").text = reg.selectSingleNode("RVP").text;

if (reg.selectSingleNode("NAME") == null)
row.selectSingleNode("my:RVPString").text = ""
else
row.selectSingleNode("my:RVPString").text =
reg.selectSingleNode("NAME").text;

var parent =
XDocument.DOM.selectSingleNode("//my:myFields/my:RegionsTable");
parent.appendChild(row);
}

}

Friday, October 29, 2010

Recursion of the mummy


Recursion of the mummy

It’s Halloween, and its recursion which often makes me curse but it is the only realistic way to parse an xmldocument. It is critical for us, using Infopath, to get the functionality of the form libraries along with the aggregation type of goodies I can grab out of a traditional DBMS. So our submit logic often starts with a submit to DBMS and then save the form to the library, while the associated onopen event for the form updates the fields from a secondary datasource grabbed from the DBMS by a webservice.

So, to parse a whole InfoPath form I first create an object for each repeating group in the form like so…
TLocationRecord = class(System.Object)
private
function isNewRecord(thisNode : xmlNode) : Boolean;
function isComplete : Boolean;
procedure ParseNode(thisNode : xmlNode;
thisRecord : TLocationRecord);
procedure RecurseChildNodes(ThisNode : xmlNode;
thisRecord : TLocationRecord);
public
Location_ID : Integer;
Name : String;
Address : String;
City : String;
Zip : String;
Phone : String;
Fax : String;
isActive : String;

Next_Location : TLocationRecord;

procedure LoadFromXML(RootNode : TLocationRecord;
xml : xmlDocument);
end;

The only tricky part is the recursion of course, so in this case after tossing the whole document to the LoadFromXML procedure I grab the first element of the form in a xmlNode object and feed into the recursion.

The recursion looks for the specific part of the form I want to parse, in this case the locations repeating table named my:EditLocations, which will return true on the NewRecord function, at which point I add another node to then end of my own object and recurse. Otherwise I just toss it to the parser until I run out of document.

procedure TLocationRecord.RecurseChildNodes(ThisNode : xmlNode;
thisRecord : TLocationRecord);
var
wrkNode : xmlNode;
NextRecord : TLocationRecord;
wrkRecord : TLocationRecord;
begin
while ThisNode <> nil do
begin
if isNewRecord(thisNode) then
begin
NextRecord := TLocationRecord.Create;
NextRecord.Next_Location := nil;

wrkRecord := thisRecord;
wrkRecord.IsWellFormed := self.isComplete;

while wrkrecord.Next_Location <> nil do
wrkRecord := wrkRecord.Next_Location;

wrkRecord.Next_Location := NextRecord;
RecurseChildNodes(ThisNode.FirstChild,NextRecord);
end
else
if ThisNode.HasChildNodes then
begin
wrkNode := thisNode.FirstChild;
ParseNode(thisNode,thisRecord);
RecurseChildNodes(wrkNode,thisRecord);
end;
thisNode := thisNode.NextSibling;
end;
end;

procedure TLocationRecord.ParseNode(thisNode : xmlNode;
thisRecord : TLocationRecord);
var
wrkNode : xmlNode;
begin
If ThisNode.Name = 'my:Name' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.Name := wrkNode.Value;
end
else
If ThisNode.Name = 'my:Address' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.Address := wrkNode.Value;
end
else
If ThisNode.Name = 'my:City' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.City := wrkNode.Value;
end
else
If ThisNode.Name = 'my:Zip' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.Zip := wrkNode.Value;
end
else
If ThisNode.Name = 'my:Phone' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.Phone := wrkNode.Value;
end
else
If ThisNode.Name = 'my:Fax' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.Fax := wrkNode.Value;
end
else
If ThisNode.Name = 'my:isActive' then
begin
wrkNode := ThisNode.FirstChild;
if wrkNode.NodeType = xmlNodeType.Text then
thisRecord.isActive := wrkNode.Value;
end;
end;

function TWebService1.maintUpdateLocations(IIRForm : xmlDocument) : integer;
var
insstr : String;
editStr : String;
inscmd : sqlCommand;
editcmd : sqlcommand;
Root : TLocationRecord;
wrkRecord : TLocationRecord;
RVal : Integer;
begin
Root := TLocationRecord.Create;
Root.Next_Location := nil;

Root.LoadFromXML(Root,IIRForm);

IIR_SQL_CONNECTION.Open;

insstr := 'INSERT INTO LOCATIONS(NAME,ADDRESS,CITY,ZIP,PHONE,FAX) '+
'VALUES (@NAMEPARAM,@ADDRPARAM,@CITYPARAM,@ZIPPARAM,@PHONEPARAM,@FAXPARAM)';

inscmd := sqlCommand.Create;
inscmd.Connection := IIR_SQL_CONNECTION;
inscmd.CommandText := insstr;

editStr := 'UPDATE LOCATIONS SET(NAME,ADDRESS,CITY,ZIP,PHONE,FAX) '+
'VALUES (@NAMEPARAM,@ADDRPARAM,@CITYPARAM,@ZIPPARAM,@PHONEPARAM,@FAXPARAM) '+
'WHERE LOCATION_ID = @LOCPARAM';

editcmd := sqlCommand.Create;
editcmd.Connection := IIR_SQL_CONNECTION;
editcmd.CommandText := editstr;

inscmd.Parameters.Add('@NAMEPARAM',sqldbType.NVarChar,50);
inscmd.Parameters.Add('@ADDRPARAM',sqldbType.NVarChar,75);
inscmd.Parameters.Add('@CITYPARAM',sqldbType.NVarChar,50);
inscmd.Parameters.Add('@ZIPPARAM',sqldbType.NVarChar,10);
inscmd.Parameters.Add('@PHONEPARAM',sqldbType.NVarChar,14);
inscmd.Parameters.Add('@FAXPARAM',sqldbType.NVarChar,14);


// Walk the list and either update or insert.....
wrkRecord := Root.Next_Location;

while wrkRecord <> nil do
begin
if (wrkRecord.Location_ID > 0) then
begin
// edit existing record
if wrkRecord.isComplete then
begin
editcmd.Parameters.Item['@NAMEPARAM'].Value := wrkRecord.Name;
editcmd.Parameters.Item['@ADDRPARAM'].Value := (wrkRecord.Address as TObject);
editcmd.Parameters.Item['@CITYPARAM'].Value := (wrkRecord.City as TObject);
editcmd.Parameters.Item['@ZIPPARAM'].Value := (wrkRecord.Zip as TObject);
editcmd.Parameters.Item['@PHONEPARAM'].Value := (wrkRecord.Phone as TObject);
editcmd.Parameters.Item['@FAXPARAM'].Value := (wrkRecord.Fax as TObject);
editcmd.Parameters.Item['@ISACTIVE'].Value := (wrkRecord.IsActive as TObject);
editcmd.Parameters.Item['@LOCPARAM'].Value := (wrkRecord.Location_ID as TObject);

RVal := RVal + inscmd.ExecuteNonQuery;
end;
end
else
begin
// Insert new record
// Validate Record for completeness...
If wrkRecord.isComplete then
begin
inscmd.Parameters.Item['@NAMEPARAM'].Value := wrkRecord.Name;
inscmd.Parameters.Item['@ADDRPARAM'].Value := (wrkRecord.Address as TObject);
inscmd.Parameters.Item['@CITYPARAM'].Value := (wrkRecord.City as TObject);
inscmd.Parameters.Item['@ZIPPARAM'].Value := (wrkRecord.Zip as TObject);
inscmd.Parameters.Item['@PHONEPARAM'].Value := (wrkRecord.Phone as TObject);
inscmd.Parameters.Item['@FAXPARAM'].Value := (wrkRecord.Fax as TObject);

RVal := RVal + inscmd.ExecuteNonQuery;
end;
end;
wrkRecord := wrkRecord.Next_Location;
end;
Result := RVal;
end;

Then it is just a matter of walking the TLocation Object and editing or inserting the rows.