GithubHelp home page GithubHelp logo

Comments (12)

ykuijs avatar ykuijs commented on June 12, 2024

I am on it.

Will extend this resource with the configuration of the Service App. See https://technet.microsoft.com/EN-US/library/ff608107.aspx for more info. Will post a proposal for the extended structure later.

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

hello. I had just started this one too, will check it in anyway as I am almost done with it

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

hey @ykuijs I take you are talking about the Set-WordConversionServiceApp parameters, so I will leave this with you :)

from sharepointdsc.

ykuijs avatar ykuijs commented on June 12, 2024

@camiloborges Correct, I was talking about that cmdlet. Since you are already done with the initial resource, go ahead and check it in. Then I can use that as a starting point :-)

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

cool, give me 10 minutes to finish unit tests

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

https://github.com/camiloborges/xSharePoint/tree/xSPWordAutomationServiceApp

from sharepointdsc.

ykuijs avatar ykuijs commented on June 12, 2024

Did you sync your local copy?? I do not see any resource there?

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

hmmm, I had, but I screwed up my brnches

[CmdletBinding()]
param(
[string] $SharePointCmdletModule = (Join-Path $PSScriptRoot "..\Stubs\SharePoint\15.0.4693.1000\Microsoft.SharePoint.PowerShell.psm1" -Resolve)
)

$ErrorActionPreference = 'stop'
Set-StrictMode -Version latest

$RepoRoot = (Resolve-Path $PSScriptRoot....).Path
$Global:CurrentSharePointStubModule = $SharePointCmdletModule

$ModuleName = "MSFT_xSPWordAutomationServiceApp"
Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources$ModuleName$ModuleName.psm1")

Describe "xSPWordAutomationServiceApp" {
InModuleScope $ModuleName {
$testParams = @{
Name = "Test Word App"
ApplicationPool = "Test App Pool"
DatabaseName = "WordAutomationn"
}
Import-Module (Join-Path ((Resolve-Path $PSScriptRoot....).Path) "Modules\xSharePoint")

    Mock Invoke-xSharePointCommand { 
        return Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments -NoNewScope
    }

    Import-Module $Global:CurrentSharePointStubModule -WarningAction SilentlyContinue

    Context "When no service applications exist in the current farm" {

        Mock Get-SPServiceApplication { return $null }
        Mock New-SPWordConversionServiceApplication { }

        It "returns null from the Get method" {
            Get-TargetResource @testParams | Should BeNullOrEmpty
            Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.Name } 
        }

        It "returns false when the Test method is called" {
            Test-TargetResource @testParams | Should Be $false
        }

        It "creates a new service application in the set method" {
            Set-TargetResource @testParams
            Assert-MockCalled New-SPWordConversionServiceApplication 
        }
    }

    Context "When service applications exist in the current farm but the specific word automation app does not" {

        Mock Get-SPServiceApplication { return @(@{
            TypeName = "Some other service app type"
        }) }

        It "returns null from the Get method" {
            Get-TargetResource @testParams | Should BeNullOrEmpty
            Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.Name } 
        }

    }

    Context "When a service application exists and is configured correctly" {
        Mock Get-SPServiceApplication { 
            return @(@{
                TypeName = "Word Automation Services"
                DisplayName = $testParams.Name
                ApplicationPool = @{ Name = $testParams.ApplicationPool }
            })
        }

        It "returns values from the get method" {
            Get-TargetResource @testParams | Should Not BeNullOrEmpty
            Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.Name } 
        }

        It "returns true when the Test method is called" {
            Test-TargetResource @testParams | Should Be $true
        }
    }

    Context "When a service application exists and is not configured correctly" {
        Mock Get-SPServiceApplication { 
            return @(@{
                TypeName = "Word Automation Services"
                DisplayName = $testParams.Name
                ApplicationPool = @{ Name = "Wrong App Pool Name" }
            })
        }
        Mock Get-SPServiceApplicationPool { return @{ Name = $testParams.ApplicationPool } }
        Mock Set-SPWordConversionServiceApplication {}
        It "returns false when the Test method is called" {
            Test-TargetResource @testParams | Should Be $false
        }

        It "calls the update service app cmdlet from the set method" {
            Set-TargetResource @testParams

            Assert-MockCalled Get-SPServiceApplicationPool
            Assert-MockCalled Set-SPWordConversionServiceApplication
        }
    }
}

}

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DatabaseCredentials,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

    Write-Verbose -Message "Getting Word Automation service app '$Name'"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
    $params = $args[0]

    $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue 
    if ($null -eq $serviceApps) { 
        return $null 
    }
    $serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Word Automation Services" }

    If ($null -eq $serviceApp) { 
        return $null 
    } else {
        $returnVal =  @{
            Name = $serviceApp.DisplayName
            ApplicationPool = $serviceApp.ApplicationPool.Name
            DatabaseName = $serviceApp.Databases.Name
            DatabaseServer = $serviceApp.Databases.Server.Name

        }
        return $returnVal
    }
}
return $result

}

function Set-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DatabaseCredentials,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

$result = Get-TargetResource @PSBoundParameters

if ($result -eq $null) { 
    Write-Verbose -Message "Creating Word Automation Service Application $Name"
    Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        if($params.ContainsKey("InstallAccount")){ $params.Remove("InstallAccount")}

        New-SPWordConversionServiceApplication @params 
    }
}
else {
    if ($ApplicationPool -ne $result.ApplicationPool) {
        Write-Verbose -Message "Updating Word Automation Service Application $Name"
        Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
            $params = $args[0]               

            $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool

            Get-SPServiceApplication -Name $params.Name `
                | Where-Object { $_.TypeName -eq "Word Automation Services" } `
                | Set-SPWordConversionServiceApplication -ApplicationPool $appPool
        }
    }
}

}

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DatabaseCredentials,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Testing for Word Automation Service Application '$Name'"
$CurrentValues = Get-TargetResource @PSBoundParameters

if ($null -eq $CurrentValues) { return $false }
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("ApplicationPool")

}

Export-ModuleMember -Function *-TargetResource

from sharepointdsc.

ykuijs avatar ykuijs commented on June 12, 2024

Been there, done that :-)

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

here we go again, https://github.com/camiloborges/xSharePoint/tree/xSPWordAutomationApp

from sharepointdsc.

camiloborges avatar camiloborges commented on June 12, 2024

note to myself.
will separate 'new' and 'set' parameters with a query
$newPArams = $params.GetEnumerator() | ?{ @("DatabaseName","DatabaseServer","Name", "ApplicationPool" ).Contains($_.Key)}

$setPArams = $params.GetEnumerator() | ?{ @("DatabaseName","DatabaseServer").Contains($_.Key)-eq $false}

from sharepointdsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.