PDA

View Full Version : Help !



madladuk
10-13-2003, 08:34 AM
Hi all.

New to DevStudio and need to create an installation package that basically prompts the user for information such as SQL Server, Name, Password etc, Web Site path details etc and then execute the following script which I guess I need to convert to install script as I want the user interface to show what stage the script is at, could someone point me in the right direction. Ive pasted the script below.

thanks

<code>

option explicit

Dim g_objSiteCfg, g_objGrpCfg, g_sMasterDSN

const sAppDefaultConfigName = "App Default Config"

Sub CreateSite(sSiteName, sSiteDescription, nAuthFlags)

Dim WshShell, wshSysEnv, wshNetwork
Dim wbSite,webfolder,webFile,strIIS
Dim strDWCWebSiteFlag
Dim strPredictorSiteFlag
strIIS = "IIS://localhost/w3svc/1/ROOT/"

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set WshNetwork = Wscript.CreateObject("Wscript.Network")

Dim BinPath, sComputerName
BinPath = WshSysEnv("COMMERCE_SERVER_ROOT")
sComputerName = WshNetwork.ComputerName

Rem Set up DSN's
Dim sTransactionsDSN, sTransactionConfigDSN
Dim sBizDataDSN

Dim sSQLComputerName
sSQLComputerName = sComputerName

g_sMasterDSN = "Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=master;Data Source=" + sSQLComputerName + ";"
sTransactionsDSN = "Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=" & sSiteName & "_commerce;Data Source=" + sSQLComputerName + ";"
sTransactionConfigDSN = "Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=" & sSiteName & "_commerce;Data Source=" + sSQLComputerName + ";"
sBizDataDSN = "Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=" & sSiteName & "_commerce;Data Source=" + sSQLComputerName + ";"


' These names won't change so you shouldn't change them
const L_sCatalogName_Text = "Product Catalog"
const L_sTransactionsName_Text = "Transactions"
const L_sTransactionConfigName_Text = "Transaction Config"
const L_sAuthManagerSiteName_Text = "Site CS Authentication"
const L_sBDSReferenceResourceName_Text = "Biz Data Service"
const sBizDataImportFile = ""

' Parse connection strings for data to execute scripts
Dim ParsedDSN
Dim sTransactionsDatabaseName, sTransactionsDatabaseUser, sTransactionsDatabasePwd, sTransactionsServer
ParsedDSN = Split(sTransactionsDSN, ";")
sTransactionsDatabaseName = FindItem("Initial Catalog", ParsedDSN)
sTransactionsDatabaseUser = FindItem("User ID", ParsedDSN)
sTransactionsDatabasePwd = FindItem("Password", ParsedDSN)
sTransactionsServer = FindItem("Data Source", ParsedDSN)

Dim sTransactionConfigDatabaseName, sTransactionConfigDatabaseUser, sTransactionConfigDatabasePwd, sTransactionConfigServer
ParsedDSN = Split(sTransactionConfigDSN, ";")
sTransactionConfigDatabaseName = FindItem("Initial Catalog", ParsedDSN)
sTransactionConfigDatabaseUser = FindItem("User ID", ParsedDSN)
sTransactionConfigDatabasePwd = FindItem("Password", ParsedDSN)
sTransactionConfigServer = FindItem("Data Source", ParsedDSN)

' Create the databases
Wscript.Echo "Creating Database"
Call CreateDatabases

' Create a group admin object
Wscript.Echo "Creating SiteConfig object"
Set g_objGrpCfg = CreateObject("Commerce.GlobalConfig")
g_objGrpCfg.Initialize

' Create a site in the group & add a service to it
call CreateSiteConfig

' Set up the Site description
g_objSiteCfg.Fields("s_Description").Value = sSiteDescription
g_objSiteCfg.SaveConfig

' Set up the App Default Config resource
Wscript.Echo "Creating AppDefaultConfig Resource"
call SetupAppDefaultConfigResource(g_objSiteCfg, sSiteName)


' Set up the transactions resource
Wscript.Echo "Creating transactions Resource"
g_objSiteCfg.CreateComponentConfig L_sTransactionsName_Text, "MSCS_Transactions"
'const L_sTransactionDescription_Text = "Transaction system"
'g_objSiteCfg.Fields(L_sTransactionsName_Text).Value.Fields("s_Description") = L_sTransactionDescription_Text
g_objSiteCfg.Fields(L_sTransactionsName_Text).Value.Fields("s_ProgidPUP") = "Commerce.GenericPup"
g_objSiteCfg.Fields(L_sTransactionsName_Text).Value.Fields("connstr_db_Transactions").Value = sTransactionsDSN
g_objSiteCfg.SaveConfig

' Set up the transaction config resource
Wscript.Echo "Creating transaction config Resource"
g_objSiteCfg.CreateComponentConfig L_sTransactionConfigName_Text, "MSCS_TransactionConfig"
'const L_sTransactionConfigDescription_Text = "Transaction Config system"
'g_objSiteCfg.Fields(L_sTransactionConfigName_Text).Value.Fields("s_Description") = L_sTransactionConfigDescription_Text
g_objSiteCfg.Fields(L_sTransactionConfigName_Text).Value.Fields("s_ProgidPUP") = "Commerce.GenericPup"
g_objSiteCfg.Fields(L_sTransactionConfigName_Text).Value.Fields("connstr_db_TransactionConfig").Value = sTransactionConfigDSN
g_objSiteCfg.SaveConfig


' Set up the Site Address resource
Wscript.Echo "Creating site address Resource "
Dim website, sResourceName
set webSite = GetObject("IIS://localhost/w3svc/1")
sResourceName = sSiteName
g_objSiteCfg.CreateComponentConfig sResourceName, "MSCS_Address"
'const L_sURLInformationDescription_Text = " URL information"
'g_objSiteCfg.Fields(sResourceName).Value.Fields("s_Description") = sSiteName & L_sURLInformationDescription_Text
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_VirtualRootName") = LCase(sSiteName)
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_ProgidPUP") = "Commerce.AddressPuP"
redim varWebServerMachine(0), varWebServerName(0), varWebServerInstance(0)
varWebServerMachine(0) = sComputerName
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_WebServerMachine").Value = g_objSiteCfg.MakeStringFromArray(varWebServerMachine)
varWebServerName(0) = webSite.ServerComment
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_WebServerName").Value = g_objSiteCfg.MakeStringFromArray(varWebServerName)
varWebServerInstance(0) = 1
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_WebServerInstance").Value = g_objSiteCfg.MakeStringFromArray(varWebServerInstance)

g_objSiteCfg.Fields(sResourceName).Value.Fields("s_NumberOfServers").Value = 1
g_objSiteCfg.Fields(sResourceName).Value.Fields("s_CurrentServer").Value = 0
g_objSiteCfg.SaveConfig


' ------------------------------------------
' Set up the biz data store resource
Wscript.Echo "Creating Profile Resource"
Dim objPuP, szPath
Dim sBDSGroupResourceName
set objPuP = CreateObject("Commerce.UPMPuP")
sBDSGroupResourceName = objPuP.CreateGroupResource(sSiteName, L_sBDSReferenceResourceName_Text, sBizDataDSN, szPath, True)
g_objSiteCfg.AddRefToGroupComponent L_sBDSReferenceResourceName_Text, sBDSGroupResourceName
g_objSiteCfg.SaveConfig
set g_objGrpCfg = Nothing
Set g_objGrpCfg = CreateObject("Commerce.GlobalConfig")
g_objGrpCfg.Initialize
g_objGrpCfg.Fields(sBDSGroupResourceName).Value.Fields("s_ProgidPUP").Value = "Commerce.UPMPuP"
g_objGrpCfg.SaveConfig
objPup.Import sSiteName, L_sBDSReferenceResourceName_Text, sBizDataImportFile, True
set objPuP = Nothing
set g_objGrpCfg = Nothing

call CreateProfile(sBizDataDSN)


' ------------------------------------------------
' Set up the Authentication Services resource

on error resume next

Dim sAuthGroupResourceName
Wscript.Echo "Creating Authentication Services Resource "
set objPuP = CreateObject("Commerce.AuthPuP")
sAuthGroupResourceName = objPuP.CreateGroupResource(sSiteName, L_sAuthManagerSiteName_Text, "", szPath,False)
Wscript.Echo "sAuthGroupResourceName: " + sAuthGroupResourceName
g_objSiteCfg.AddRefToGroupComponent L_sAuthManagerSiteName_Text, sAuthGroupResourceName
g_objSiteCfg.SaveConfig
set g_objGrpCfg = Nothing
Set g_objGrpCfg = CreateObject("Commerce.GlobalConfig")
g_objGrpCfg.Initialize
g_objGrpCfg.Fields(sAuthGroupResourceName).Value.Fields("s_ProgidPUP") = "Commerce.AuthPuP"
g_objGrpCfg.SaveConfig
objPup.Import sSiteName, L_sAuthManagerSiteName_Text, "", True
set objPuP = Nothing
set g_objGrpCfg = Nothing


Dim vRoot, sWWWRootPath
Dim fso, tf
Dim vDir
set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
sWWWRootPath = vRoot.Path + "\"

Wscript.Echo "Creating Metabase entries for Site"
On Error Resume Next ' Folder may already exist
' create dirs and default files for the site
' Create default.asp
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateFolder(sWWWRootPath + LCase(sSiteName))

Set tf = fso.CreateTextFile(sWWWRootPath + sSiteName + "\csapp.ini", True)
tf.WriteLine("SiteName=" + sSiteName)
tf.WriteLine("AddressKeyName=" + sSiteName)
tf.WriteLine("RelativeURL=" + sSiteName)
tf.WriteLine("CreatedBy=inSight")
tf.WriteLine("CreatedDate=")
tf.WriteLine("Version=1.0")
tf.Close

On Error Goto 0
' Add the Metabase entries
set vDir = vRoot.Create("IIsWebVirtualDir", LCase(sSiteName))

vDir.AccessRead = True
vDir.AccessExecute = True
vDir.AppFriendlyName = sSiteName & " application"
vDir.AppIsolated = 0
vDir.AuthFlags = nAuthFlags
vDir.AppCreate True
vDir.Path = sWWWRootPath + sSiteName
vDir.KeyType = "IIsWebVirtualDir"
vDir.SetInfo


On Error Resume Next ' Folder may already exist

' ------------------------------------------------
' Sync the Address resources for all the sites
set objPuP = CreateObject("Commerce.AddressPuP")
objPup.Import sSiteName, sSiteName, "", True
set objPuP = Nothing

Wscript.Echo "Finished Creating Site"

End Sub

Function FindItem(sParmTag, sParms)
Dim sParm
for each sParm in sParms
if LCase(sParmTag) = LCase(Left(sParm, len(sParmTag))) then
FindItem = Right(sParm, len(sParm) - len(sParmTag) - 1)
exit for
end if
next
end function

function CreateSiteConfig()
On Error Resume Next

CreateSiteConfig = true
Set g_objSiteCfg = g_objGrpCfg.CreateSiteConfig(sSiteName)
if Err.Number <> 0 then
Set g_objSiteCfg = CreateObject("Commerce.SiteConfig")
g_objSiteCfg.Initialize sSiteName
else
CreateSiteConfig = false
end if
Err.Clear
end Sub


Rem
Rem Loads a SQL script into the AdminDB pupdbscripts table using the SiteConfigAdmin object
Rem

Sub LoadResourceDBScript(oSiteCfgAdmin, sResource, sFilePath, sScriptName)
Dim oFS, oFile, sScriptContents

const ForReading = 1
const TristateUseDefault = -2

Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.OpenTextFile(sFilePath, ForReading, False, TristateUseDefault)
sScriptContents = oFile.ReadAll()
oFile.Close
set oFile = nothing

oSiteCfgAdmin.PutSQLScript sResource, sScriptName, sScriptContents

End Sub


sub CreateDatabases

Dim objADO

set objADO = CreateObject("ADODB.Connection")

objADO.Open g_sMasterDSN

On Error Resume Next
'objADO.Execute("Drop Database " & sSiteName & "_commerce")
'objADO.Execute("Create Database " & sSiteName & "_commerce")

end sub


Sub SetupAppDefaultConfigResource(g_objSiteCfg, sSiteName)
Dim rsAppDefaultConfig
Dim objDataFunctions

const L_sPageEncodingCharset_Text = "Windows-1252"
const L_AltCurrecncySymbol_Text = "€"
const L_BaseCurrenceSymbol_Text = "$"
const L_BaseCurrencyCode_Text = "USD"
const L_AltCurrencyCode_Text = "EUR"
const L_WeigtMeasure_Text = "lbs"


Set objDataFunctions = CreateObject("Commerce.DataFunctions")
g_objSiteCfg.CreateComponentConfig sAppDefaultConfigName, "MSCS_AppConfigDefault"
Set rsAppDefaultConfig = g_objSiteCfg.Fields(sAppDefaultConfigName).Value

' Set the AppConfig fields initialized the same on both B2B and B2C
rsAppDefaultConfig.Fields("s_SMTPServerName").Value = "TestSMTPServer"
rsAppDefaultConfig.Fields("i_AddItemRedirectOptions").Value = 1 'REDIRECT_TO_PRODUCT
rsAppDefaultConfig.Fields("s_AnonymousUserDefaultCatalogSet").Value = "{11111111-1111-1111-1111-111111111111}"
rsAppDefaultConfig.Fields("s_AuthenticatedUserDefaultCatalogSet").Value = "{22222222-2222-2222-2222-222222222222}"
rsAppDefaultConfig.Fields("i_AltCurrencyOptions").Value = 0 'ALTCURRENCY_DISPLAY_DISABLED
rsAppDefaultConfig.Fields("f_AltCurrencyConversionRate").Value = 2
rsAppDefaultConfig.Fields("i_AltCurrencyLocale").Value = objDataFunctions.Locale
rsAppDefaultConfig.Fields("s_AltCurrencySymbol").Value = L_AltCurrecncySymbol_Text
rsAppDefaultConfig.Fields("i_CurrencyDisplayOrderOptions").Value = 0 'EURO_DISPLAY_BASE_CURRENCY_FIRST
rsAppDefaultConfig.Fields("i_SiteDefaultLocale").Value = objDataFunctions.Locale
rsAppDefaultConfig.Fields("i_BaseCurrencyLocale").Value = objDataFunctions.Locale
rsAppDefaultConfig.Fields("s_BaseCurrencySymbol").Value = L_BaseCurrenceSymbol_Text
rsAppDefaultConfig.Fields("s_BaseCurrencyCode").Value = L_BaseCurrencyCode_Text
rsAppDefaultConfig.Fields("s_AltCurrencyCode").Value = L_AltCurrencyCode_Text
rsAppDefaultConfig.Fields("s_PageEncodingCharset").Value = L_sPageEncodingCharset_Text
rsAppDefaultConfig.Fields("i_SitePrivacyOptions").Value = 1 'PROFILE_ANONYMOUS_USER
rsAppDefaultConfig.Fields("i_SiteTicketOptions").Value = 2 'PUT_TICKET_IN_COOKIE
rsAppDefaultConfig.Fields("i_BizTalkOptions").Value = 0 'disabled
rsAppDefaultConfig.Fields("S_BizTalkSubmittypeQueue").Value = "1"
rsAppDefaultConfig.Fields("i_HostNameCorrectionOptions").Value = 1 'HOSTNAME_CORRECTION_ENABLED
rsAppDefaultConfig.Fields("i_CookiePathCorrectionOptions").Value = 1 'APP_BASED_CORRECTION
rsAppDefaultConfig.Fields("i_FormLoginTimeOut").Value = 60 'minutes
rsAppDefaultConfig.Fields("S_WeightMeasure").Value = L_WeigtMeasure_Text


'Properties currently not set
'S_BizTalkSourceQualifierID
'S_BizTalkSourceQualifierValue
'S_BizTalkOrderDocType
'S_BizTalkCatalogDocType
'S_BizTalkSubmittypeQueue
'S_BizTalkConnString
'i_ShipToLevelOptions '(not impl)
'i_ShoppingListOptions '(not impl)

' Initialize the AppConfig options differently based on type of site
' It is up to the caller to set the appcfg_i_* parameters
rsAppDefaultConfig.Fields("i_FormLoginOptions").Value = appcfg_i_FormLoginOptions
rsAppDefaultConfig.Fields("i_SiteRegistrationOptions").Value = appcfg_i_SiteRegistrationOptions

g_objSiteCfg.SaveConfig
Set objDataFunctions = Nothing

End Sub



'Create Default Catalog
Sub CreateProfile(sDSN)

Dim oBizDataAdmin

Set oBizDataAdmin = CreateObject("Commerce.BusinessDataAdmin2")

oBizDataAdmin.Connect sDSN

Dim xmlDoc
Set xmlDoc = CreateObject("MSXML2.DOMDocument.3.0")
xmlDoc.load "c:\test\Profile.xml"
oBizDataAdmin.ImportCatalogs xmlDoc.xml
Set oBizDataAdmin = nothing

End Sub
</code>:)

RichAquino
10-14-2003, 03:00 PM
Hi,

There are many dialogs that you can use to get information from a customer. The simplist for your case is the SdAskText dialog.

To display the progress to the user, I'd suggest a SdShowMsg call.

In InstallScript, you can use COM objects, so your CreateObject calls will work. You just have to declare the items as OBJECT.

i.e.
function foo()
OBJECT o;
begin
set o = CreateObject("Prog.ID");
end;

You can call methods on that object as you do in script:

i.e.

function foo()
OBJECT o;
begin
set o = CreateObject("Prog.ID");
o.prop1 = "test";
o.Run();
end;

Instead of using "On Error goto" statements, use a try...catch...endcatch block.

i.e.

function foo()
OBJECT o;
begin
try
set o = CreateObject("Prog.ID");
catch
MessageBox("error", SEVERE);
endcatch;
end;

This should get you started.

Rich