Permalink
Browse files

Added VM FileExistsInGuest, GetFileInfoInGuest, RunProgramInGuest MSB…

…uild tasks.

git-svn-id: https://vmwaretasks.svn.codeplex.com/svn/trunk@39424 9b283d60-5439-405e-af05-b73fd8c4d996
  • Loading branch information...
1 parent d7e9679 commit 7780edc510d7e70d9b8d398edfe9b56e1aaff6c7 @dblock committed Feb 2, 2010
@@ -29,8 +29,8 @@
<ul>
<li>Added support for VixCOM 1.8.1. VMWareTasks works against all 1.6.2, 1.7.0, 1.8.0
and 1.8.1 versions.</li>
- <li>Added Vestris.VMWareLib.MSBuildTasks.dll that adds support for MSBuild with a series
- of MSBuild tasks.</li>
+ <li>Added Vestris.VMWareLib.MSBuildTasks.dll that adds support for MSBuild with MSBuild
+ tasks that implement most common functions.</li>
<li>Added <code>Vestris.VMWareLib.VMWareRootSnapshotCollection.RemoveSnapshot</code>
that accepts a configurable timeout.</li>
</ul>
@@ -39,7 +39,7 @@
<ul>
<li><a href="http://vmwaretasks.codeplex.com/WorkItem/View.aspx?WorkItemId=5138">5138</a>:
Tools.Windows.Shell.GetEnvironmentVariables fails with a "File not found" error
- on some x64 systems where "tmp" resolves to a non-existent path.</li>
+ on some x64 systems where %tmp% resolves to a non-existent path.</li>
</ul>
</li>
</ul>
@@ -56,6 +56,8 @@
<Compile Include="VirtualMachineCreateTempFileInGuest.cs" />
<Compile Include="VirtualMachineDeleteDirectoryFromGuest.cs" />
<Compile Include="VirtualMachineDeleteFileFromGuest.cs" />
+ <Compile Include="VirtualMachineFileExistsInGuest.cs" />
+ <Compile Include="VirtualMachineGetFileInfoInGuest.cs" />
<Compile Include="VirtualMachineRemoveSnapshot.cs" />
<Compile Include="VirtualMachineLoginGuest.cs" />
<Compile Include="VirtualMachineOpen.cs" />
@@ -64,6 +66,7 @@
<Compile Include="VirtualMachinePowerOff.cs" />
<Compile Include="VirtualMachinePowerOn.cs" />
<Compile Include="VirtualMachineRevertToSnapshot.cs" />
+ <Compile Include="VirtualMachineRunProgramInGuest.cs" />
<Compile Include="VirtualMachineShutdownGuest.cs" />
</ItemGroup>
<ItemGroup>
@@ -16,6 +16,9 @@
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineDeleteDirectoryFromGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineDeleteFileFromGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineCreateTempFileInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineFileExistsInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRunProgramInGuest" />
+ <UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineGetFileInfoInGuest" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineCreateSnapshot" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRevertToSnapshot" />
<UsingTask AssemblyFile="$(VMWareLibMSBuildTasksLib)" TaskName="Vestris.VMWareLib.MSBuildTasks.VirtualMachineRemoveSnapshot" />
@@ -30,7 +30,7 @@ public int CreateTempFileTimeout
}
/// <summary>
- /// Source path on the guest operating system.
+ /// Temporary file path on the guest operating system.
/// </summary>
[Output]
public string GuestPathName
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Interop.VixCOM;
+
+namespace Vestris.VMWareLib.MSBuildTasks
+{
+ /// <summary>
+ /// Check whether a file exists in a guest operating system.
+ /// </summary>
+ public class VirtualMachineFileExistsInGuest : VirtualMachineLoginGuest
+ {
+ private int _fileExistsTimeout = VMWareInterop.Timeouts.FileExistsTimeout;
+ private string _guestPathName;
+ private bool _fileExists = false;
+
+ /// <summary>
+ /// Timeout in seconds.
+ /// </summary>
+ public int FileExistsTimeout
+ {
+ get
+ {
+ return _fileExistsTimeout;
+ }
+ set
+ {
+ _fileExistsTimeout = value;
+ }
+ }
+
+ /// <summary>
+ /// File path on the guest operating system.
+ /// </summary>
+ public string GuestPathName
+ {
+ get
+ {
+ return _guestPathName;
+ }
+ set
+ {
+ _guestPathName = value;
+ }
+ }
+
+ /// <summary>
+ /// True if file exists.
+ /// </summary>
+ [Output]
+ public bool FileExists
+ {
+ get
+ {
+ return _fileExists;
+ }
+ }
+
+ public override bool Execute()
+ {
+ using (VMWareVirtualHost host = GetConnectedHost())
+ {
+ using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
+ {
+ LoginGuest(virtualMachine);
+ Log.LogMessage(string.Format("Checking file '{0}' in guest os", _guestPathName));
+ _fileExists = virtualMachine.FileExistsInGuest(_guestPathName, _fileExistsTimeout);
+ }
+ }
+
+ return true;
+ }
+ }
+}
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Interop.VixCOM;
+
+namespace Vestris.VMWareLib.MSBuildTasks
+{
+ /// <summary>
+ /// Get file information from a guest operating system.
+ /// </summary>
+ public class VirtualMachineGetFileInfoInGuest : VirtualMachineLoginGuest
+ {
+ private int _getFileInfoTimeout = VMWareInterop.Timeouts.GetFileInfoTimeout;
+ private string _guestPathName;
+ private VMWareVirtualMachine.GuestFileInfo _fileInfo = null;
+
+ /// <summary>
+ /// Timeout in seconds.
+ /// </summary>
+ public int GetFileInfoTimeout
+ {
+ get
+ {
+ return _getFileInfoTimeout;
+ }
+ set
+ {
+ _getFileInfoTimeout = value;
+ }
+ }
+
+ /// <summary>
+ /// File path on the guest operating system.
+ /// </summary>
+ public string GuestPathName
+ {
+ get
+ {
+ return _guestPathName;
+ }
+ set
+ {
+ _guestPathName = value;
+ }
+ }
+
+ /// <summary>
+ /// File size.
+ /// </summary>
+ [Output]
+ public long FileSize
+ {
+ get
+ {
+ return _fileInfo.FileSize;
+ }
+ }
+
+ /// <summary>
+ /// True if the path belongs to a directory.
+ /// </summary>
+ [Output]
+ public bool IsDirectory
+ {
+ get
+ {
+ return _fileInfo.IsDirectory;
+ }
+ }
+
+ /// <summary>
+ /// True if the path belongs to a symbolic link.
+ /// </summary>
+ [Output]
+ public bool IsSymLink
+ {
+ get
+ {
+ return _fileInfo.IsSymLink;
+ }
+ }
+
+ /// <summary>
+ /// Date/time when the file was last modified.
+ /// </summary>
+ [Output]
+ public string LastModified
+ {
+ get
+ {
+ return _fileInfo.LastModified.HasValue
+ ? _fileInfo.LastModified.Value.ToString()
+ : string.Empty;
+ }
+ }
+
+ public override bool Execute()
+ {
+ using (VMWareVirtualHost host = GetConnectedHost())
+ {
+ using (VMWareVirtualMachine virtualMachine = OpenVirtualMachine(host))
+ {
+ LoginGuest(virtualMachine);
+ Log.LogMessage(string.Format("Retreiving file information for '{0}' from guest os", _guestPathName));
+ _fileInfo = virtualMachine.GetFileInfoInGuest(_guestPathName, _getFileInfoTimeout);
+ }
+ }
+
+ return true;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7780edc

Please sign in to comment.