<Activity mc:Ignorable="sads sap" x:Class="RDManagement.Publish_RemoteApplication" this:Publish_RemoteApplication.ShowInPortal="1" this:Publish_RemoteApplication.CommandLineSetting="0" this:Publish_RemoteApplication.IconContents="[{}]" this:Publish_RemoteApplication.Folder="[Nothing]" this:Publish_RemoteApplication.VirtualPath="[Nothing]" this:Publish_RemoteApplication.IconIndex="0"
 xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:mpa="clr-namespace:Microsoft.PowerShell.Activities;assembly=Microsoft.PowerShell.Activities"
 xmlns:mpma="clr-namespace:Microsoft.PowerShell.Management.Activities;assembly=Microsoft.PowerShell.Management.Activities"
 xmlns:mpua="clr-namespace:Microsoft.PowerShell.Utility.Activities;assembly=Microsoft.PowerShell.Utility.Activities"
 xmlns:mrc="clr-namespace:Microsoft.RemoteDesktopServices.Common;assembly=Microsoft.RemoteDesktopServices.Management.Activities"
 xmlns:mrma="clr-namespace:Microsoft.RemoteDesktopServices.Management.Activities;assembly=Microsoft.RemoteDesktopServices.Management.Activities"
 xmlns:mrmc="clr-namespace:Microsoft.RemoteDesktopServices.Management.Cmdlets;assembly=Microsoft.RemoteDesktopServices.Management.Activities"
 xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
 xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
 xmlns:s="clr-namespace:System;assembly=mscorlib"
 xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities"
 xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
 xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
 xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
 xmlns:sc="clr-namespace:System.Collections;assembly=mscorlib"
 xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
 xmlns:sm="clr-namespace:System.Management;assembly=System.Management"
 xmlns:sma="clr-namespace:System.Management.Automation;assembly=System.Management.Automation"
 xmlns:this="clr-namespace:RDManagement"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <x:Members>
    <x:Property Name="ShowInPortal" Type="InArgument(x:Int32)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="RequiredCommandLine" Type="InArgument(x:String)" />
    <x:Property Name="CommandLineSetting" Type="InArgument(x:Int32)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="SecurityDescriptor" Type="InArgument(x:String)" />
    <x:Property Name="IconContents" Type="InArgument(s:Byte[])">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="VirtualMachine" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="Folder" Type="InArgument(x:String)" />
    <x:Property Name="AppAlias" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="PoolName" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="DisplayName" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="AppPath" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="VirtualPath" Type="InArgument(x:String)" />
    <x:Property Name="IconPath" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
    <x:Property Name="IconIndex" Type="InArgument(x:Int32)" />
    <x:Property Name="RDMSServer" Type="InArgument(x:String)">
      <x:Property.Attributes>
        <RequiredArgumentAttribute />
      </x:Property.Attributes>
    </x:Property>
  </x:Members>
  <this:Publish_RemoteApplication.RequiredCommandLine>
    <InArgument x:TypeArguments="x:String">
      <Literal x:TypeArguments="x:String" Value="" />
    </InArgument>
  </this:Publish_RemoteApplication.RequiredCommandLine>
  <this:Publish_RemoteApplication.SecurityDescriptor>
    <InArgument x:TypeArguments="x:String">
      <Literal x:TypeArguments="x:String" Value="" />
    </InArgument>
  </this:Publish_RemoteApplication.SecurityDescriptor>
  <sap:VirtualizedContainerService.HintSize>725,8030</sap:VirtualizedContainerService.HintSize>
  <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
  <Sequence sap:VirtualizedContainerService.HintSize="685,7990">
    <Sequence.Variables>
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="VMFarmSetting" />
      <Variable x:TypeArguments="sc:Hashtable" Default="[New Hashtable()]" Name="farmSettingHTable" />
      <Variable x:TypeArguments="x:String" Name="VMXMLoutput" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="variable1" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="CPUBResult" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:ErrorRecord)" Default="[New PSDataCollection(Of ErrorRecord)()]" Name="PSError" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:ErrorRecord)" Default="[New PSDataCollection(Of ErrorRecord)()]" Name="UnpublishDesktopErrors" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:ErrorRecord)" Default="[New PSDataCollection(Of ErrorRecord)()]" Name="PSError2" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="RDMSDBUpdate" />
      <Variable x:TypeArguments="x:String" Name="variable2" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="FTAResult" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="RDMSJoinedNodes" />
      <Variable x:TypeArguments="x:String" Name="ConnectionBroker" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="FTAPathArgument" />
      <Variable x:TypeArguments="x:Boolean" Name="isSessionHostCollection" />
      <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="SessionHostCollections" />
    </Sequence.Variables>
    <sap:WorkflowViewStateService.ViewState>
      <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="ShouldExpandAll">False</x:Boolean>
        <x:Boolean x:Key="ShouldCollapseAll">True</x:Boolean>
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
      </scg:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <Assign sap:VirtualizedContainerService.HintSize="663,60">
      <Assign.To>
        <OutArgument x:TypeArguments="x:String">[ConnectionBroker]</OutArgument>
      </Assign.To>
      <Assign.Value>
        <InArgument x:TypeArguments="x:String">[RDMSServer]</InArgument>
      </Assign.Value>
    </Assign>
    <mpa:InlineScript DisplayName="Get RDSH Pool Object" Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Get-RDSHPool -Alias $using:PoolName -ManagementServer $using:ConnectionBroker" sap:VirtualizedContainerService.HintSize="663,139" PSError="[PSError]" Result="[SessionHostCollections]" />
    <If Condition="[Not PSError.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="663,208">
      <If.Then>
        <TerminateWorkflow Exception="[PSError.Item(0).Exception]" sap:VirtualizedContainerService.HintSize="200,22" Reason="[PSError.Item(0).Exception.Message]" />
      </If.Then>
    </If>
    <If Condition="[SessionHostCollections.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="663,208">
      <If.Then>
        <Assign sap:VirtualizedContainerService.HintSize="242,60">
          <Assign.To>
            <OutArgument x:TypeArguments="x:Boolean">[isSessionHostCollection]</OutArgument>
          </Assign.To>
          <Assign.Value>
            <InArgument x:TypeArguments="x:Boolean">False</InArgument>
          </Assign.Value>
        </Assign>
      </If.Then>
      <If.Else>
        <Assign sap:VirtualizedContainerService.HintSize="242,60">
          <Assign.To>
            <OutArgument x:TypeArguments="x:Boolean">[isSessionHostCollection]</OutArgument>
          </Assign.To>
          <Assign.Value>
            <InArgument x:TypeArguments="x:Boolean">True</InArgument>
          </Assign.Value>
        </Assign>
      </If.Else>
    </If>
    <If Condition="[isSessionHostCollection]" sap:VirtualizedContainerService.HintSize="663,2625">
      <If.Then>
        <Sequence sap:VirtualizedContainerService.HintSize="538,2517">
          <Sequence.Variables>
            <Variable x:TypeArguments="sma:PSDataCollection(sma:PSObject)" Name="PoolMachines" />
          </Sequence.Variables>
          <sap:WorkflowViewStateService.ViewState>
            <scg:Dictionary x:TypeArguments="x:String, x:Object">
              <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg:Dictionary>
          </sap:WorkflowViewStateService.ViewState>
          <mpa:InlineScript DisplayName="Get Pool Machines" Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Get-RDSHServer -Name &quot;*&quot; -CollectionAlias $using:PoolName -ManagementServer $using:ConnectionBroker" sap:VirtualizedContainerService.HintSize="516,139" PSError="[PSError]" Result="[PoolMachines]" />
          <If Condition="[Not PSError.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="516,208">
            <If.Then>
              <TerminateWorkflow Exception="[PSError.Item(0).Exception]" sap:VirtualizedContainerService.HintSize="200,22" Reason="[PSError.Item(0).Exception.Message]" />
            </If.Then>
          </If>


          <Sequence sap:VirtualizedContainerService.HintSize="536,510">
            <Sequence.Variables>
              <Variable x:TypeArguments="s:String[]" Default="[New String(PoolMachines.Count - 1) {}]" Name="ServerNames" />
              <Variable x:TypeArguments="x:Int32" Default="0" Name="i" />
              <Variable x:TypeArguments="x:String" Default="localhost" Name="LocalHost" />
            </Sequence.Variables>
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>

            <ForEach x:TypeArguments="sma:PSObject" DisplayName="Set server name array" sap:VirtualizedContainerService.HintSize="294,386" Values="[PoolMachines]">
              <ActivityAction x:TypeArguments="sma:PSObject">
                <ActivityAction.Argument>
                  <DelegateInArgument x:TypeArguments="sma:PSObject" Name="item" />
                </ActivityAction.Argument>
                <Sequence sap:VirtualizedContainerService.HintSize="264,280">
                  <sap:WorkflowViewStateService.ViewState>
                    <scg:Dictionary x:TypeArguments="x:String, x:Object">
                      <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                    </scg:Dictionary>
                  </sap:WorkflowViewStateService.ViewState>
                  <Assign sap:VirtualizedContainerService.HintSize="242,58">
                    <Assign.To>
                      <OutArgument x:TypeArguments="x:String">[ServerNames(i)]</OutArgument>
                    </Assign.To>
                    <Assign.Value>
                      <InArgument x:TypeArguments="x:String">[item.Properties("Name").Value.ToString()]</InArgument>
                    </Assign.Value>
                  </Assign>
                  <Assign sap:VirtualizedContainerService.HintSize="242,58">
                    <Assign.To>
                      <OutArgument x:TypeArguments="x:Int32">[i]</OutArgument>
                    </Assign.To>
                    <Assign.Value>
                      <InArgument x:TypeArguments="x:Int32">[i + 1]</InArgument>
                    </Assign.Value>
                  </Assign>
                </Sequence>
              </ActivityAction>
            </ForEach>

            <mpa:InlineScript DisplayName="Set Win32_TSPublishedApplication object on all servers" CommandName="{x:Null}" Parameters="{x:Null}" Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Add-TSPublishedApplication -ApplicationAlias $using:AppAlias -RequiredCommandLine $using:RequiredCommandLine -ApplicationPath $using:AppPath -Server $using:LocalHost -DisplayName $using:DisplayName -SecurityDescriptor $using:SecurityDescriptor -CommandLineSetting $using:CommandLineSetting" sap:VirtualizedContainerService.HintSize="508,139" PSComputerName="[ServerNames]" PSError="[PSError2]" />

            <If Condition="[PSError2.Count &gt; 0]" sap:VirtualizedContainerService.HintSize="464,354">
              <If.Then>
                <Sequence sap:VirtualizedContainerService.HintSize="536,330">
                  <sap:WorkflowViewStateService.ViewState>
                    <scg:Dictionary x:TypeArguments="x:String, x:Object">
                      <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                    </scg:Dictionary>
                  </sap:WorkflowViewStateService.ViewState>

                  <ForEach x:TypeArguments="sma:ErrorRecord" DisplayName="Consolidate errors from all the servers" sap:VirtualizedContainerService.HintSize="287,206" Values="[PSError2]">
                    <ActivityAction x:TypeArguments="sma:ErrorRecord">
                      <ActivityAction.Argument>
                        <DelegateInArgument x:TypeArguments="sma:ErrorRecord" Name="item" />
                      </ActivityAction.Argument>
                      <Sequence sap:VirtualizedContainerService.HintSize="264,246">
                        <Sequence.Variables>
                          <Variable x:TypeArguments="sma:ErrorRecord" Name="errorRecord" />
                        </Sequence.Variables>
                        <sap:WorkflowViewStateService.ViewState>
                          <scg:Dictionary x:TypeArguments="x:String, x:Object">
                            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                          </scg:Dictionary>
                        </sap:WorkflowViewStateService.ViewState>
                        <Assign sap:VirtualizedContainerService.HintSize="242,60">
                          <Assign.To>
                            <OutArgument x:TypeArguments="sma:ErrorRecord">[errorRecord]</OutArgument>
                          </Assign.To>
                          <Assign.Value>
                            <InArgument x:TypeArguments="sma:ErrorRecord">[ErrorUtility.GetErrorRecord(RDManagementResources.ResourceManager.GetString("FailedToSetSessionHostObjects"), string.Empty, ErrorId.ConfigureRDSessionHost, item.Exception)]</InArgument>
                          </Assign.Value>
                        </Assign>
                        <mpua:WriteError DisplayName="Write consolidated errors" ErrorRecord="[errorRecord]" sap:VirtualizedContainerService.HintSize="242,22" />
                      </Sequence>
                    </ActivityAction>
                  </ForEach>

                </Sequence>
              </If.Then>
            </If>

          </Sequence>


          <mpa:InlineScript Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Set-RDSHPoolGeneralSetting -Alias $using:PoolName -ManagementServer $using:ConnectionBroker -ShowInWebAccess 0" DisplayName="Unpublish remote desktop" sap:VirtualizedContainerService.HintSize="656,51" PSError="[UnpublishDesktopErrors]" />
          <If Condition="[UnpublishDesktopErrors.Count &lt;&gt; 0]" DisplayName="Quit If Error" sap:VirtualizedContainerService.HintSize="656,51">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">False</x:Boolean>
                <x:Boolean x:Key="IsPinned">False</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <If.Then>
              <Sequence sap:VirtualizedContainerService.HintSize="264,246">
                <Sequence.Variables>
                  <Variable x:TypeArguments="sma:ErrorRecord" Name="errorRecord" />
                </Sequence.Variables>
                <sap:WorkflowViewStateService.ViewState>
                  <scg:Dictionary x:TypeArguments="x:String, x:Object">
                    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                  </scg:Dictionary>
                </sap:WorkflowViewStateService.ViewState>
                <Assign sap:VirtualizedContainerService.HintSize="242,60">
                  <Assign.To>
                    <OutArgument x:TypeArguments="sma:ErrorRecord">[errorRecord]</OutArgument>
                  </Assign.To>
                  <Assign.Value>
                    <InArgument x:TypeArguments="sma:ErrorRecord">[ErrorUtility.GetErrorRecord(RDManagementResources.ResourceManager.GetString("RDMSRemovePublishRemoteDesktopError"), string.Empty, ErrorId.PublishRemoteApps, UnpublishDesktopErrors(0).Exception)]</InArgument>
                  </Assign.Value>
                </Assign>
                  <mpua:WriteError DisplayName="Write unpublishing errors" ErrorRecord="[errorRecord]" sap:VirtualizedContainerService.HintSize="242,22" />
              </Sequence>
            </If.Then>
          </If>
        </Sequence>
      </If.Then>
    </If>
    <If Condition="[Not isSessionHostCollection]" sap:VirtualizedContainerService.HintSize="663,776">
      <If.Then>
        <Sequence sap:VirtualizedContainerService.HintSize="486,668">
          <sap:WorkflowViewStateService.ViewState>
            <scg:Dictionary x:TypeArguments="x:String, x:Object">
              <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg:Dictionary>
          </sap:WorkflowViewStateService.ViewState>
          <Assign sap:VirtualizedContainerService.HintSize="464,60">
            <Assign.To>
              <OutArgument x:TypeArguments="sc:Hashtable">[farmSettingHTable]</OutArgument>
            </Assign.To>
            <Assign.Value>
              <InArgument x:TypeArguments="sc:Hashtable">[New Hashtable()]</InArgument>
            </Assign.Value>
          </Assign>
          <InvokeMethod sap:VirtualizedContainerService.HintSize="464,134" MethodName="Add">
            <InvokeMethod.TargetObject>
              <InArgument x:TypeArguments="sc:Hashtable">[farmSettingHTable]</InArgument>
            </InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="x:String">ShowInPortal</InArgument>
            <InArgument x:TypeArguments="x:Int32">0</InArgument>
          </InvokeMethod>
          <mpma:SetWmiInstance Arguments="[farmSettingHTable]" Authentication="[AuthenticationLevel.PacketPrivacy]" DisplayName="Unpublish-RemoteDesktop" sap:VirtualizedContainerService.HintSize="464,22" Impersonation="[ImpersonationLevel.Impersonate]" Namespace="root\cimv2\rdms" PSComputerName="[{RDMSServer}]" PSError="[PSError]" Path="[&quot;Win32_RDMSVirtualDesktopCollection.Alias=&quot;&quot;&quot; &amp; PoolName &amp; &quot;&quot;&quot;&quot;]" PutType="[PutType.UpdateOrCreate]" />
          <If Condition="[Not PSError.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="464,208">
            <If.Then>
              <TerminateWorkflow Exception="[New Exception(RDManagementResources.RDMSRemovePublishRemoteDesktopError, PSError.Item(0).Exception)]" sap:VirtualizedContainerService.HintSize="200,22" Reason="[RDManagementResources.RDMSRemovePublishRemoteDesktopError]" />
            </If.Then>
          </If>
        </Sequence>
      </If.Then>
    </If>
    <mpa:InlineScript DisplayName="Write published object to RDMS" CommandName="{x:Null}" Parameters="{x:Null}" Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Set-RDMSPublishedApplication -ApplicationAlias $using:AppAlias -PoolName $using:PoolName -ApplicationPath $using:AppPath -ManagementServer $using:ConnectionBroker -DisplayName $using:DisplayName -SecurityDescriptor $using:SecurityDescriptor -VirtualPath $using:VirtualPath -CommandLineSetting $using:CommandLineSetting -RequiredCommandLine $using:RequiredCommandLine -ShowInPortal $using:ShowInPortal -Folder $using:Folder -IconPath $using:IconPath -IconIndex $using:IconIndex -IconContents $using:IconContents" sap:VirtualizedContainerService.HintSize="707,139" PSError="[PSError]" />
    <If Condition="[Not PSError.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="611,208">
      <If.Then>
        <TerminateWorkflow Exception="[PSError.Item(0).Exception]" sap:VirtualizedContainerService.HintSize="269,100" Reason="[PSError.Item(0).Exception.Message]" />
      </If.Then>
    </If>
    <mpa:InlineScript DisplayName="Set FTA objects" CommandName="{x:Null}" Parameters="{x:Null}" Command="import-module $env:windir\System32\ServerManagerInternal\rdmanagement;&#xD;&#xA;Add-RDMSFileTypeAssociation -ApplicationAlias $using:AppAlias -PoolName $using:PoolName -ApplicationPath $using:AppPath -ManagementServer $using:ConnectionBroker -ServerToFetchRemoteApp $using:VirtualMachine" sap:VirtualizedContainerService.HintSize="707,139" PSError="[PSError]" />
    <If Condition="[Not PSError.Count.Equals(0)]" sap:VirtualizedContainerService.HintSize="611,208">
      <If.Then>
        <TerminateWorkflow Exception="[PSError.Item(0).Exception]" sap:VirtualizedContainerService.HintSize="269,100" Reason="[PSError.Item(0).Exception.Message]" />
      </If.Then>
    </If>
  </Sequence>
</Activity>
