Skip to content

Commit

Permalink
Adding the frame for #7
Browse files Browse the repository at this point in the history
Settings creation and first calls are already working. This uses the most current code of channel implementation.
  • Loading branch information
gitfvb committed Jul 6, 2022
1 parent 3a67bac commit d4207cf
Show file tree
Hide file tree
Showing 28 changed files with 2,448 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ EpiServerCampaign/MarketingAutomation/recipientlists.json
*.xml
*.sqlite
*.zip
*.json.*
10 changes: 10 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/general_settings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

$functionsSubfolder = "functions"
$libSubfolder = "lib"
$settingsFilename = "settings.json"
if ( $params.ProcessId ) {
$processId = $params.ProcessId
} else {
$processId = [guid]::NewGuid()
}
$timestamp = [datetime]::Now
36 changes: 36 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/load_functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Load all PowerShell Code
"Loading..."
Get-ChildItem -Path ".\$( $functionsSubfolder )" -Recurse -Include @("*.ps1") | ForEach {
. $_.FullName
"... $( $_.FullName )"
}

If ( $configMode -and -not $settings) {

# Don't load yet, when in config mode and settings object not yet available

} else {

If ( Test-Path -Path $libSubfolder ) {

# Load all exe files in subfolder
$libExecutables = Get-ChildItem -Path ".\$( $libSubfolder )" -Recurse -Include @("*.exe")
$libExecutables | ForEach {
"... $( $_.FullName )"

}

# Load dll files in subfolder
$libDlls = Get-ChildItem -Path ".\$( $libSubfolder )" -Recurse -Include @("*.dll")
$libDlls | ForEach {
"Loading $( $_.FullName )"
[Reflection.Assembly]::LoadFile($_.FullName)
}

}

}


#Add-Type -AssemblyName System.Security
95 changes: 95 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/load_networksettings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Allow only newer security protocols
# hints: https://www.frankysweb.de/powershell-es-konnte-kein-geschuetzter-ssltls-kanal-erstellt-werden/
if ( $settings.changeTLS ) {
$AllProtocols = @(
[System.Net.SecurityProtocolType]::Tls12
)
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
}

# Setup default credentials for proxy communication per default
$proxyUrl = $null
if ( $settings.proxy.proxyUrl ) {
$proxyUrl = $settings.proxy.proxyUrl
$useDefaultCredentials = $true

if ( $settings.proxy.proxyUseDefaultCredentials ) {
$proxyUseDefaultCredentials = $true
[System.Net.WebRequest]::DefaultWebProxy.Credentials=[System.Net.CredentialCache]::DefaultCredentials
} else {
$proxyUseDefaultCredentials = $false
$proxyCredentials = New-Object PSCredential $settings.proxy.credentials.username,( Get-SecureToPlaintext -String $settings.proxy.credentials.password )
}

}

function Check-Proxy {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][Hashtable]$invokeParams
)

begin {

}

process {
if ( $script:proxyUrl ) {
$invokeParams.Add("Proxy", $script:proxyUrl)
$invokeParams.Add("UseDefaultCredentials", $script:useDefaultCredentials)
if ( $script:proxyUseDefaultCredentials ) {
$invokeParams.Add("ProxyUseDefaultCredentials", $true)
} else {
$invokeParams.Add("ProxyCredential", $script:proxyCredentials)
}
}
}

end {

}
}

<#
# Add proxy settings
if ( $proxyUrl ) {
$paramsPost.Add("Proxy", $proxyUrl)
$paramsPost.Add("UseDefaultCredentials", $useDefaultCredentials)
if ( $proxyUseDefaultCredentials ) {
$paramsPost.Add("ProxyUseDefaultCredentials", $true)
} else {
$paramsPost.Add("ProxyCredential", $proxyCredentials)
}
}
#>











<#
# The following can be added to api calls
if ( $proxyUrl ) {
$paramsPost.Add("UseDefaultCredentials", $useDefaultCredentials)
$paramsPost.Add("Proxy", $proxyUrl)
}
#if ( $settings.useDefaultCredentials ) {
# $paramsPost.Add("UseDefaultCredentials", $true)
#}
$paramsPost.Add("ProxyCredential", pscredential)
if ( $settings.ProxyUseDefaultCredentials ) {
$paramsPost.Add("ProxyUseDefaultCredentials", $true)
}
#>
3 changes: 3 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/load_settings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Load settings
$settings = Get-Content -Path $settingsFilename -Encoding UTF8 -Raw | ConvertFrom-Json #"$( $scriptPath )\$( $settingsFilename )"

6 changes: 6 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/preparation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#-----------------------------------------------
# OPTI SESSIONS
#-----------------------------------------------

Get-EpiSession
34 changes: 34 additions & 0 deletions OptimizelyCampaign/Unsubscribes/bin/startup_logging.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Log
$logfile = $settings.logfile

# append a suffix, if in debug mode
if ( $debug -and -not $configMode) {
$logfile = "$( $logfile ).debug"
}

# Start the log
Write-Log -message "----------------------------------------------------"
Write-Log -message "$( $modulename )"
Write-Log -message "Got a file with these arguments: $( [Environment]::GetCommandLineArgs() )" -writeToHostToo $false

# Check if params object exists
if (Get-Variable "params" -Scope Global -ErrorAction SilentlyContinue) {
$paramsExisting = $true
} else {
$paramsExisting = $false
}

# Log the params, if existing
if ( $paramsExisting ) {
$params.Keys | ForEach-Object {
$param = $_
Write-Log -message " $( $param ) = '$( $params[$param] )'" -writeToHostToo $false
}
}

# Add note in log file, that the file is a converted file
# TODO [ ] Add these notes to other scripts, too
if ( $params.path -match "\.converted$") {
Write-Log -message "Be aware, that the exports are generated in Codepage 1252 and not UTF8. Please change this in the Channel Editor." -severity ( [LogSeverity]::WARNING )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Function Count-Dimensions {

param(
[Parameter(Mandatory=$true)]$var
)

$return = 0
if ( $var -is [array] ) {
$add = Count-Dimensions -var $var[0]
$return = $add + 1
}

return $return

}
10 changes: 10 additions & 0 deletions OptimizelyCampaign/Unsubscribes/functions/DataTypes/Is-Numeric.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


Function Is-Numeric {

param(
[Parameter(Mandatory=$true)]$Value
)

return $Value -match "^[\d\.]+$"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

<#
Is-Numeric 10 # True
Is-Numeric "10" # True
Is-Numeric "10f" # False
Is-Numeric "+10" # True
Is-Numeric "-10" # True
Is-Numeric "-10.5" # False
#>
function Is-Int ($value) {
return $value -match "^[+-]?[\d]+$"
}

<#
Is-Float 10 # False
Is-Float "10" # False
Is-Float "10." # False
Is-Float "10.5" # True
Is-Float "10.545" # True
Is-Float "+10.5" # True
Is-Float "-10.5" # True
#>
function Is-Float () {
return $value -match "^[+-]?[\d]+[\.]+[\d]+$"
}

<#
# This should be True
Is-Link "https://www.apteco.com/blog?customerId=123"
# This should be False
Is-Link "ftp://www.google.com"
#>
function Is-Link ($value) {
$regexForLinks = "(http[s]?)(:\/\/)({{(.*?)}}|[^\s,])+"
$containedLinks = [Regex]::Matches($value, $regexForLinks) | Select -ExpandProperty Value
return $containedLinks.count -eq 1
}
64 changes: 64 additions & 0 deletions OptimizelyCampaign/Unsubscribes/functions/Files/Check-Path.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Function Check-Path {

param(
[Parameter(Mandatory=$false)][string]$Path
)

$b = $false

try {
$b = Test-Path -Path $Path
} catch [System.Exception] {
#$errText = $_.Exception
#$errText | Write-Output
#"$( [datetime]::UtcNow.ToString("yyyyMMddHHmmss") )`tError: $( $errText )" >> $logfile
#$b = $false
}

return $b

}

<#
Checks if an path is free
Can be used like to wait for a path to be free
$outArgs = @{
Path = "C:\temp\test.lock"
fireExceptionIfUsed = $true
}
Retry-Command -Command 'Is-PathFree' -Args $outArgs -retries 10 -MillisecondsDelay 1000
#>
function Is-PathFree {

[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$Path
,[Parameter(Mandatory=$false)][switch]$fireExceptionIfUsed = $false
)

# Check validity
if ( ( Test-Path -Path $Path -IsValid ) -eq $false ) {
throw [System.Management.Automation.ItemNotFoundException]
}

# Check if path is free
$pathAlreadyUsed = Test-Path -Path $Path

# Fire exception if not free
if ( $fireExceptionIfUsed -and $pathAlreadyUsed) {
throw [System.IO.InvalidDataException]
}

# Return the inverted value
-not $pathAlreadyUsed
}

#Is-PathFree -Path "C:\temp\test.lock" -fireExceptionIfUsed

#exit 0

Loading

0 comments on commit d4207cf

Please sign in to comment.