fredag den 9. september 2011

SuperOffice 7 – Connecting to the damn thing

updated 23-09-2011: Removed my remarks about superoffice. That was childish of me.
updated 23-09-2011: This config script wont work. The superoffice.config contain elements that will break when used from socrm.exe ( the client ) .. please look at my powershell snapin for the same thing

I really don’t like superoffice force me/us to use DNS instead of just giving the option to use connection strings. But that is just how it is for now.

Anyway, so in order to connect to SuperOffice you need to make a DSN link within ODCB administration in order for SuperOffice to be able to speak with its database. Once that is in place you need to create an app.config file defining how SuperOffice can connect to this database. They call this superoffice.config but it is just a plain app.config file. If using a client to connect you also need to put all this information in one more time, but in old school INI format .. ( how lame, talk about redundant redundancy )

I started with a PowerShell script to do all this but I ended up creating my own PowerShell PSCmdlet to handle all the SuperOffice stuff.

So first I need to create the DSN .. and of it needs to be the 32 bit version

function Create32bitDSNLink([string]$DSNName, [string]$DBServer, [string]$DBName, [string]$DriverName, [string]$Driverdll){
$HKLMPath1 = "HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" + $DSNName
$HKLMPath2 = "HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources"

md
$HKLMPath1 -ErrorAction silentlycontinue

set
-itemproperty -path $HKLMPath1 -name Driver -value $Driverdll
set
-itemproperty -path $HKLMPath1 -name Description -value $DSNName
set
-itemproperty -path $HKLMPath1 -name Server -value $DBServer
set
-itemproperty -path $HKLMPath1 -name LastUser -value ""
set
-itemproperty -path $HKLMPath1 -name Trusted_Connection -value "Yes"
set
-itemproperty -path $HKLMPath1 -name Database -value $DBName

## This is required to allow the ODBC connection to show up in the ODBC Administrator application.
md $HKLMPath2 -ErrorAction silentlycontinue
set
-itemproperty -path $HKLMPath2 -name "$DSNName" -value $DriverName
}


Next we need to create the ini file and superoffice.config


function CreateSuperOfficeconfig([string]$Path, [string]$dbserver, [string]$dbname, [string]$SOAdminUser, [string]$SOAdminPass){
$filename = ($Path + 'SuperOffice.config')
if ( (Test-Path $filename) -eq $true) { Clear-Content -path $filename }

add
-content -path $filename -value ('<?xml version="1.0" encoding="utf-8"?>')
add
-content -path $filename -value ('<configuration>')
add
-content -path $filename -value (' <configSections>')
add
-content -path $filename -value (' <sectionGroup name="SuperOffice">')
add
-content -path $filename -value (' <sectionGroup name="Security">')
add
-content -path $filename -value (' <section name="Cryptography" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' </sectionGroup>')
add
-content -path $filename -value (' <section name="ClientConfigurationProvider" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="Diagnostics" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <sectionGroup name="Data">')
add
-content -path $filename -value (' <section name="Session" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="Database" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="ImplicitAnonymous" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="Explicit" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' </sectionGroup>')
add
-content -path $filename -value (' <sectionGroup name="Factory">')
add
-content -path $filename -value (' <section name="CustomFactories" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="DynamicLoad" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' </sectionGroup>')
add
-content -path $filename -value (' <sectionGroup name="Mail">')
add
-content -path $filename -value (' <section name="Component" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>')
add
-content -path $filename -value (' </sectionGroup>')
add
-content -path $filename -value (' <section name="Documents" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="Globalization" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' <section name="Services" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />')
add
-content -path $filename -value (' </sectionGroup>')
add
-content -path $filename -value (' </configSections>')
add
-content -path $filename -value (' <Security>')
add
-content -path $filename -value (' <Cryptography>')
add
-content -path $filename -value (' <add key="SymmetricKey" value="mbiNaaa+3wWcbzGWCnvCvRBoLg8NADQiXaaChJ38W1w=" />')
add
-content -path $filename -value (' <add key="SymmetricIV" value="aBL3Kh0mXHzn+NvXkSS/Lg==" />')
add
-content -path $filename -value (' <add key="SymmetricSecret" value="SuperOffice NetServer 1.0 Alpha lab-testing" />')
add
-content -path $filename -value (' </Cryptography>')
add
-content -path $filename -value (' </Security>')
add
-content -path $filename -value (' <ClientConfigurationProvider>')
add
-content -path $filename -value (' <!-- FilePath should be the root directory of structure where GUI configuration XMLs are located. ')
add
-content -path $filename -value (' Application and instance names become subdirectories to this path. If empty, missing or invalid,')
add
-content -path $filename -value (' the path of the NetServer assemblies will be used as root. -->')
add
-content -path $filename -value (' <add key="FilePath" value="C:\RunningTests\TestConfiguration\" />')
add
-content -path $filename -value ('')
add
-content -path $filename -value (' <!-- If caching is true, the NetServer configuration services will cache configurations on a per-user or per-group basis in the')
add
-content -path $filename -value (' BinaryObject table, and the Six.Web client will cache them in session state. If false, no caching will be done and there will')
add
-content -path $filename -value (' be a significant amount of processing on each GUI refresh. However, you will see changes to the GUI immediately, useful for development. -->')
add
-content -path $filename -value (' <add key="CacheConfigurations" value="true" ></add>')
add
-content -path $filename -value (' </ClientConfigurationProvider>')
add
-content -path $filename -value ('')
add
-content -path $filename -value (' <Mail>')
add
-content -path $filename -value (' <Component>')
add
-content -path $filename -value (' </Component>')
add
-content -path $filename -value (' </Mail>')

add
-content -path $filename -value (' <SuperOffice>')
add
-content -path $filename -value (' <Factory>')
add
-content -path $filename -value (' <DynamicLoad>')
add
-content -path $filename -value (' </DynamicLoad>')
add
-content -path $filename -value (' </Factory>')
add
-content -path $filename -value (' <Diagnostics>')
add
-content -path $filename -value (' <!-- Log errors (default True). -->')
add
-content -path $filename -value (' <add key="LogError" value="True" />')
add
-content -path $filename -value (' <!-- Log warnings (default False) -->')
add
-content -path $filename -value (' <add key="LogWarning" value="False" />')
add
-content -path $filename -value (' <!-- Log general information. This includes successful SQLs passed to the database.')
add
-content -path $filename -value (' Only permit this option while debugging a bug. This will be a severe performance hit!')
add
-content -path $filename -value (' (default False) -->')
add
-content -path $filename -value (' <add key="LogInformation" value="False" />')
add
-content -path $filename -value (' <!-- Log failed authentications (default True) -->')
add
-content -path $filename -value (' <add key="LogFailureAudit" value="True" />')
add
-content -path $filename -value (' <!-- Log sucessfull authentications (default False) -->')
add
-content -path $filename -value (' <add key="LogSuccessAudit" value="False" />')
add
-content -path $filename -value (' <!-- Log to the OS event log (default True) -->')
add
-content -path $filename -value (' <add key="LogToEventLog" value="True" />')
add
-content -path $filename -value (' <!-- Log to SuperOffice Research and Product Development (Online through a WebService) (default False) -->')
add
-content -path $filename -value (' <add key="LogToSuperOffice" value="False" />')
add
-content -path $filename -value (' <!-- Log to a LogFile (default False) -->')
add
-content -path $filename -value (' <add key="LogToFile" value="True" />')
add
-content -path $filename -value (' <!-- Folder (e.g. UNC path) where the logfile is to recide. Note that the owner of the process needs to have access to manipulate files in this folder -->')
add
-content -path $filename -value (' <add key="LogFolder" value="P:\SO7\logs\" />')
add
-content -path $filename -value (' </Diagnostics>')
add
-content -path $filename -value (' <Data>')
add
-content -path $filename -value (' <Session>')
add
-content -path $filename -value (' <add key="Mode" value="Process" />')
add
-content -path $filename -value (' </Session>')
add
-content -path $filename -value (' <Database>')
add
-content -path $filename -value (' <add key="DatabaseMajor" value="MSSQL" />')
add
-content -path $filename -value (' <add key="DatabaseMinor" value="8" />')
add
-content -path $filename -value (' <add key="Server" value="' + $dbserver + '" />')
add
-content -path $filename -value (' <add key="Database" value="' + $dbname + '" />')
add
-content -path $filename -value (' <add key="CommandTimeOut" value="300" />')
add
-content -path $filename -value (' <add key="TablePrefix" value="dbo" />')
add
-content -path $filename -value (' <add key="ConnectionString" value="Server=[@Server];Database=[@Database];User ID=[@User];Password=[@Password]" />')
add
-content -path $filename -value (' </Database>')
add
-content -path $filename -value (' <ImplicitAnonymous>')
add
-content -path $filename -value (' <add key="Allowed" value="False" />')
add
-content -path $filename -value (' <add key="DBUser" value="" />')
add
-content -path $filename -value (' <add key="DBPassword" value="" />')
add
-content -path $filename -value (' <add key="CommonDBConnection" value="True" />')
add
-content -path $filename -value (' <add key="SoUser" value="" />')
add
-content -path $filename -value (' <add key="SoPassword" value="" />')
add
-content -path $filename -value (' </ImplicitAnonymous>')
add
-content -path $filename -value (' <Explicit>')
add
-content -path $filename -value (' <add key="ExternalPersonAllowed" value="False" />')
add
-content -path $filename -value (' <add key="EmployeeAllowed" value="True" />')
add
-content -path $filename -value (' <add key="SystemAllowed" value="True" />')
add
-content -path $filename -value (' <add key="DBUser" value="' + $SOAdminUser + '" />')
add
-content -path $filename -value (' <add key="DBPassword" value="' + $SOAdminPass + '" />')
add
-content -path $filename -value (' <add key="CommonDBConnection" value="True" />')
add
-content -path $filename -value (' </Explicit>')
add
-content -path $filename -value (' </Data>')
add
-content -path $filename -value (' <Documents>')
add
-content -path $filename -value (' <!-- Location of SO_ARC ; the Windows Client will override this with a real value at runtime (the value will not be visible in the file) -->')
add
-content -path $filename -value (' <add key="ArchivePath" value="c:\SO_ARC" />')
add
-content -path $filename -value (' <!-- Location of template folder. This folder only needs to be specifies when it is other than default. -->')
add
-content -path $filename -value (' <!-- Optional: add key="TemplatePath" value="" /-->')
add
-content -path $filename -value (' <!-- Location of temporary folder for streaming files. This path must resolve to the same location for farms/culsters. -->')
add
-content -path $filename -value (' <add key="TemporaryPath" value="" />')
add
-content -path $filename -value (' <!-- Impersonate user when accessing the document archive or the temporary folder -->')
add
-content -path $filename -value (' <add key="ImpersonateUser" value="false" />')
add
-content -path $filename -value (' <!-- Name of the user to impersonate with -->')
add
-content -path $filename -value (' <add key="ArchiveUser" value="" />')
add
-content -path $filename -value (' <!-- Password of the user to impersonate with -->')
add
-content -path $filename -value (' <add key="ArchivePassword" value="" />')
add
-content -path $filename -value (' <!-- Domain of the user to impersonate with -->')
add
-content -path $filename -value (' <add key="ArchiveDomain" value="" />')
add
-content -path $filename -value (' <!-- Size of internal buffer in KB -->')
add
-content -path $filename -value (' <add key="BufferSize" value="32" />')
add
-content -path $filename -value (' </Documents>')
add
-content -path $filename -value (' </SuperOffice>')
add
-content -path $filename -value ('</configuration>')
}


function CreateSuperOfficeini([string]$Path, [string]$dbserver, [string]$dbname, [string]$DriverName){
$filename = ($Path + 'SuperOffice.ini')
if ( (Test-Path $filename) -eq $true) { Clear-Content -path $filename }

add
-content -path $filename -value ('[Client]')
add
-content -path $filename -value ('PrefMailClient=Outlook2007')
add
-content -path $filename -value ('PrefWordProcessor=Word2007')
add
-content -path $filename -value ('PrefLang=US')
add
-content -path $filename -value ('[ODBC:' + $dbname + ']')
add
-content -path $filename -value ('Database=' + $dbname)
add
-content -path $filename -value ('Driver=' + $DriverName)
add
-content -path $filename -value ('Server=' + $dbserver)
add
-content -path $filename -value ('[SuperOffice]')
add
-content -path $filename -value ('Datapath=ODBC:' + $dbname)
add
-content -path $filename -value ('Archivepath=P:\SO7\SO_ARC')
add
-content -path $filename -value ('GlobalPrefix=dbo')
}


Well, not pretty but it works … I have pretty much the same code in VB.NET and together with this nifty little class it’s a piece of cake "”cheating” SuperOffice NetServer to connect to what ever database we want. ( Thanks too this link )


Imports System.Configuration
Imports System.Reflection

Public MustInherit Class AppConfig
Implements IDisposable
Public Shared Function Change(path As String) As AppConfig
Return New ChangeAppConfig(path)
End Function

Public MustOverride Sub Dispose() Implements IDisposable.Dispose

Private Class ChangeAppConfig
Inherits AppConfig
Private ReadOnly oldConfig As String = AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE").ToString()

Private disposedValue As Boolean

Public Sub New(path As String)
AppDomain.CurrentDomain.SetData(
"APP_CONFIG_FILE", path)
ResetConfigMechanism()
End Sub

Public Overrides Sub Dispose()
If Not disposedValue Then
AppDomain.CurrentDomain.SetData(
"APP_CONFIG_FILE", oldConfig)
ResetConfigMechanism()


disposedValue
= True
End If
GC.SuppressFinalize(
Me)
End Sub

Private Shared Sub ResetConfigMechanism()
GetType(ConfigurationManager).GetField("s_initState", BindingFlags.NonPublic Or BindingFlags.[Static]).SetValue(Nothing, 0)

GetType(ConfigurationManager).GetField("s_configSystem", BindingFlags.NonPublic Or BindingFlags.[Static]).SetValue(Nothing, Nothing)

GetType(ConfigurationManager).Assembly.GetTypes().Where(Function(x) x.FullName = "System.Configuration.ClientConfigPaths").First().GetField("s_current", BindingFlags.NonPublic Or BindingFlags.[Static]).SetValue(Nothing, Nothing)
End Sub
End Class
End Class

Ingen kommentarer:

Send en kommentar