Skip to content

Commit

Permalink
NetworkObject equality bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
adthom committed May 24, 2022
1 parent faa76c7 commit 6c7897f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 41 deletions.
10 changes: 5 additions & 5 deletions TeamsE911Automation/build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ foreach ( $p in $Parameters ) {

# Remove old release, copy all data from src to releasePath
if ( -not ( Test-Path -Path $releasePath -PathType Container) ) {
New-Item -Path $releasePath -ItemType Directory | Out-Null
$null = New-Item -Path $releasePath -ItemType Directory
}

Get-ChildItem "${releasePath}/" -Recurse | Remove-Item -Recurse | Out-Null
$null = Get-ChildItem "${releasePath}/" -Recurse | Remove-Item -Recurse

$srcPathPattern = [Regex]::Escape($srcPath)
foreach ($srcFile in @($Public + $Private)) {
Expand All @@ -176,7 +176,7 @@ foreach ($srcFile in @($Public + $Private)) {
$targetFile = $srcFile.FullName -Replace $srcPathPattern, $releasePath
$targetFolder = $srcFile.Directory.FullName -Replace $srcPathPattern, $releasePath
if (!(Test-Path -Path $targetFolder)) {
New-Item -Path $targetFolder -ItemType Directory | Out-Null
$null = New-Item -Path $targetFolder -ItemType Directory
}
if ((Test-Path -Path $targetFile)) {
Remove-Item -Path $targetFile -Force -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -227,12 +227,12 @@ foreach ($ClassFile in $ClassFiles) {
foreach ($line in $currClass) {
[void]$Classes.AppendLine($line)
}
[void]$Classes.AppendLine()
}
if ($Classes.Length -gt 0) {
Add-Content -Path $moduleFile -Value '# Loading Classes'
Add-Content -Path $moduleFile -Value ''
Add-Content -Path $moduleFile -Value $Classes.ToString()
Add-Content -Path $moduleFile -Value ''
}

#Get public and private function definition files.
Expand All @@ -249,7 +249,7 @@ foreach ($import in @($Private + $Public)) {
Add-Content -Path $moduleFile -Value "# $($import.BaseName)"
$Raw = Get-Content -Path $import.FullName -Raw
$Raw = ($Raw.Trim() -replace '(\r?\n){3,}',([Environment]::NewLine + [Environment]::NewLine)) + [Environment]::NewLine
$Raw | Add-Content -Path $moduleFile | Out-Null
$null = $Raw | Add-Content -Path $moduleFile
}
catch {
Write-Error -Message "Failed to import function $($import.FullName): $_"
Expand Down
4 changes: 2 additions & 2 deletions TeamsE911Automation/src/TeamsE911Automation.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#
# Generated by: Andy Thompson (andthom)
#
# Generated on: 5/22/2022
# Generated on: 5/24/2022
#

@{
# Script module or binary module file associated with this manifest.
RootModule = 'TeamsE911Automation.psm1'

# Version number of this module.
ModuleVersion = '0.2.22142.1'
ModuleVersion = '0.2.22144.1'

# Supported PSEditions
CompatiblePSEditions = 'Desktop', 'Core'
Expand Down
75 changes: 66 additions & 9 deletions TeamsE911Automation/src/TeamsE911Automation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ class E911ModuleState {
$dup = $false
if ([E911ModuleState]::NetworkObjects.ContainsKey($Hash)) {
$Test = [E911ModuleState]::NetworkObjects[$Hash]
if ([E911Location]::Equals($obj, $Test.Location)) {
if ([E911Location]::Equals($obj, $Test._location)) {
return $Test
}
$dup = $true
Expand Down Expand Up @@ -1785,7 +1785,7 @@ class E911NetworkObject {
else {
$LocationId = '"{0}"' -f $this._location.Id.ToString()
}
[void]$sb.AppendFormat('Set-CsOnlineLis{0} -LocationId {1}', $this.Type, $LocationId)
[void]$sb.AppendFormat('$null = Set-CsOnlineLis{0} -LocationId {1}', $this.Type, $LocationId)
if (![string]::IsNullOrEmpty($this.Description)) {
[void]$sb.AppendFormat(' -Description "{0}"', $this.Description)
}
Expand All @@ -1801,7 +1801,7 @@ class E911NetworkObject {
if ($this.Type -eq [NetworkObjectType]::WirelessAccessPoint) {
[void]$sb.AppendFormat(' -Bssid "{0}"', $this.Identifier.PhysicalAddress)
}
[void]$sb.Append(' -ErrorAction Stop | Out-Null')
[void]$sb.Append(' -ErrorAction Stop')
$this._command = $sb.ToString()
}
return $this._command
Expand Down Expand Up @@ -1881,8 +1881,59 @@ class E911NetworkObject {
$Desc2 = if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) { $Value2.NetworkDescription } else { $Value2.Description }
$D1 = if ([string]::IsNullOrEmpty($Desc1)) { '' } else { $Desc1 }
$D2 = if ([string]::IsNullOrEmpty($Desc2)) { '' } else { $Desc2 }
if ($D1 -ne $D2) {
return $false
}
# see if locations are the same
# if Value1 is row
$LocationsEqual = if ($null -eq $Value1.LocationId -and $Value1 -isnot [E911NetworkObject]) {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
[E911Location]::Equals($Value1, $Value2)
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
[E911Location]::Equals($Value1, $Value2._location)
}
# if Value2 is online
else {
# cannot compare online network object to row on anything other than hash... or should we see if the online location exists (that would be expensive)
throw "(Value2 is online) cannot compare online network object to row network object effectively"
}
}
# if Value1 is network object
elseif ($Value1 -is [E911NetworkObject]) {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
[E911Location]::Equals($Value1._location, $Value2)
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
$Value1._location.Equals($Value2._location)
}
# if Value2 is online
else {
$Value1.Id.ToString() -eq $Value2.LocationId
}
}
# if Value1 is online
else {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
# cannot compare online network object to row on anything other than hash... or should we see if the online location exists (that would be expensive)
throw "(Value2 is row) cannot compare online network object to row network object effectively"
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
$Value1.LocationId -eq $Value2.Id.ToString()
}
# if Value2 is online
else {
$Value1.LocationId -eq $Value2.LocationId
}
}

return $D1 -eq $D2
return $LocationsEqual
}

[bool] Equals($Value) {
Expand Down Expand Up @@ -2431,7 +2482,7 @@ function Get-CsE911OnlineConfiguration {

# (imported from .\public\Set-CsE911OnlineChange.ps1)
function Set-CsE911OnlineChange {
[CmdletBinding(DefaultParameterSetName = 'Execute')]
[CmdletBinding(DefaultParameterSetName = 'Execute', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param (
# Parameter help description
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Execute')]
Expand Down Expand Up @@ -2541,7 +2592,9 @@ function Set-CsE911OnlineChange {
try {
Write-Verbose "[$($vsw.Elapsed.TotalSeconds.ToString('F3'))] [$($MyInvocation.MyCommand.Name)] $($Change.ProcessInfo)"
if (!$ValidateOnly) {
Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop | Out-Null
if ($PSCmdlet.ShouldProcess()) {
$null = Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop
}
}
if (![string]::IsNullOrEmpty($ExecutionPlanPath)) {
$Change.ProcessInfo.ToString() | Add-Content -Path $ExecutionPlanPath
Expand Down Expand Up @@ -2621,7 +2674,9 @@ function Set-CsE911OnlineChange {
try {
Write-Verbose "[$($vsw.Elapsed.TotalSeconds.ToString('F3'))] [$($MyInvocation.MyCommand.Name)] $($Change.ProcessInfo)"
if (!$ValidateOnly) {
Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop | Out-Null
if ($PSCmdlet.ShouldProcess()) {
$null = Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop
}
}
if (![string]::IsNullOrEmpty($ExecutionPlanPath)) {
$Change.ProcessInfo.ToString() | Add-Content -Path $ExecutionPlanPath
Expand All @@ -2647,10 +2702,12 @@ function Set-CsE911OnlineChange {

# (imported from .\private\Reset-CsE911Cache.ps1)
function Reset-CsE911Cache {
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
param()
end {
[E911ModuleState]::FlushCaches($null)
if ($PSCmdlet.ShouldProcess()) {
[E911ModuleState]::FlushCaches($null)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion TeamsE911Automation/src/classes/E911ModuleState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class E911ModuleState {
$dup = $false
if ([E911ModuleState]::NetworkObjects.ContainsKey($Hash)) {
$Test = [E911ModuleState]::NetworkObjects[$Hash]
if ([E911Location]::Equals($obj, $Test.Location)) {
if ([E911Location]::Equals($obj, $Test._location)) {
return $Test
}
$dup = $true
Expand Down
57 changes: 54 additions & 3 deletions TeamsE911Automation/src/classes/E911NetworkObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class E911NetworkObject {
else {
$LocationId = '"{0}"' -f $this._location.Id.ToString()
}
[void]$sb.AppendFormat('Set-CsOnlineLis{0} -LocationId {1}', $this.Type, $LocationId)
[void]$sb.AppendFormat('$null = Set-CsOnlineLis{0} -LocationId {1}', $this.Type, $LocationId)
if (![string]::IsNullOrEmpty($this.Description)) {
[void]$sb.AppendFormat(' -Description "{0}"', $this.Description)
}
Expand All @@ -145,7 +145,7 @@ class E911NetworkObject {
if ($this.Type -eq [NetworkObjectType]::WirelessAccessPoint) {
[void]$sb.AppendFormat(' -Bssid "{0}"', $this.Identifier.PhysicalAddress)
}
[void]$sb.Append(' -ErrorAction Stop | Out-Null')
[void]$sb.Append(' -ErrorAction Stop')
$this._command = $sb.ToString()
}
return $this._command
Expand Down Expand Up @@ -225,8 +225,59 @@ class E911NetworkObject {
$Desc2 = if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) { $Value2.NetworkDescription } else { $Value2.Description }
$D1 = if ([string]::IsNullOrEmpty($Desc1)) { '' } else { $Desc1 }
$D2 = if ([string]::IsNullOrEmpty($Desc2)) { '' } else { $Desc2 }
if ($D1 -ne $D2) {
return $false
}
# see if locations are the same
# if Value1 is row
$LocationsEqual = if ($null -eq $Value1.LocationId -and $Value1 -isnot [E911NetworkObject]) {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
[E911Location]::Equals($Value1, $Value2)
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
[E911Location]::Equals($Value1, $Value2._location)
}
# if Value2 is online
else {
# cannot compare online network object to row on anything other than hash... or should we see if the online location exists (that would be expensive)
throw "(Value2 is online) cannot compare online network object to row network object effectively"
}
}
# if Value1 is network object
elseif ($Value1 -is [E911NetworkObject]) {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
[E911Location]::Equals($Value1._location, $Value2)
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
$Value1._location.Equals($Value2._location)
}
# if Value2 is online
else {
$Value1.Id.ToString() -eq $Value2.LocationId
}
}
# if Value1 is online
else {
# if Value2 is row
if ($null -eq $Value2.LocationId -and $Value2 -isnot [E911NetworkObject]) {
# cannot compare online network object to row on anything other than hash... or should we see if the online location exists (that would be expensive)
throw "(Value2 is row) cannot compare online network object to row network object effectively"
}
# if Value2 is network object
elseif ($Value2 -is [E911NetworkObject]) {
$Value1.LocationId -eq $Value2.Id.ToString()
}
# if Value2 is online
else {
$Value1.LocationId -eq $Value2.LocationId
}
}

return $D1 -eq $D2
return $LocationsEqual
}

[bool] Equals($Value) {
Expand Down
6 changes: 4 additions & 2 deletions TeamsE911Automation/src/private/Reset-CsE911Cache.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function Reset-CsE911Cache {
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
param()
end {
[E911ModuleState]::FlushCaches($null)
if ($PSCmdlet.ShouldProcess()) {
[E911ModuleState]::FlushCaches($null)
}
}
}
11 changes: 8 additions & 3 deletions TeamsE911Automation/src/public/Set-CsE911OnlineChange.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Set-CsE911OnlineChange {
[CmdletBinding(DefaultParameterSetName = 'Execute')]
[CmdletBinding(DefaultParameterSetName = 'Execute', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param (
# Parameter help description
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Execute')]
Expand Down Expand Up @@ -109,7 +109,9 @@ function Set-CsE911OnlineChange {
try {
Write-Verbose "[$($vsw.Elapsed.TotalSeconds.ToString('F3'))] [$($MyInvocation.MyCommand.Name)] $($Change.ProcessInfo)"
if (!$ValidateOnly) {
Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop | Out-Null
if ($PSCmdlet.ShouldProcess()) {
$null = Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop
}
}
if (![string]::IsNullOrEmpty($ExecutionPlanPath)) {
$Change.ProcessInfo.ToString() | Add-Content -Path $ExecutionPlanPath
Expand Down Expand Up @@ -189,7 +191,9 @@ function Set-CsE911OnlineChange {
try {
Write-Verbose "[$($vsw.Elapsed.TotalSeconds.ToString('F3'))] [$($MyInvocation.MyCommand.Name)] $($Change.ProcessInfo)"
if (!$ValidateOnly) {
Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop | Out-Null
if ($PSCmdlet.ShouldProcess()) {
$null = Invoke-Command -ScriptBlock $Change.ProcessInfo -NoNewScope -ErrorAction Stop
}
}
if (![string]::IsNullOrEmpty($ExecutionPlanPath)) {
$Change.ProcessInfo.ToString() | Add-Content -Path $ExecutionPlanPath
Expand All @@ -212,3 +216,4 @@ function Set-CsE911OnlineChange {
Write-Verbose "[$($vsw.Elapsed.TotalSeconds.ToString('F3'))] [$($MyInvocation.MyCommand.Name)] Finished"
}
}

8 changes: 4 additions & 4 deletions scripts/BulkUploadFunction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ try {{
}}
catch {{
$Connected = $false
Import-Module -Name MicrosoftTeams -ErrorAction Stop | Out-Null
$null = Import-Module -Name MicrosoftTeams -ErrorAction Stop
}}
if (!$Connected) {{
Connect-MicrosoftTeams -AccessTokens ($_sync.TokenCache.Values.AccessToken) -ErrorAction Stop | Out-Null
$null = Connect-MicrosoftTeams -AccessTokens ($_sync.TokenCache.Values.AccessToken) -ErrorAction Stop
[Microsoft.TeamsCmdlets.PowerShell.Connect.TokenProvider.AccessTokenCache]::AccessTokens = $_sync.TokenCache
[Microsoft.TeamsCmdlets.Powershell.Connect.TeamsPowerShellSession]::SessionProvider.PublicClientApplication = $_sync.Application
}}
Expand Down Expand Up @@ -217,9 +217,9 @@ finally {{
$Runspace = $Runspaces.Where({ $_.RunspaceAvailability -eq 'Available' }, 'First', 1)[0]
}
$newJob.PowerShell.Runspace = $Runspace
$newJob.PowerShell.AddScript(($BaseScript -f $Batches[$i].Script)) | Out-Null
$null = $newJob.PowerShell.AddScript(($BaseScript -f $Batches[$i].Script))
$newJob.Handle = $newJob.PowerShell.BeginInvoke()
$Jobs.Add($newJob) | Out-Null
$null = $Jobs.Add($newJob)
}
do {
if (([DateTime]::Now - $curr).TotalSeconds -ge $UpdateInterval) {
Expand Down
Loading

0 comments on commit 6c7897f

Please sign in to comment.