FileDeployer 类

更新:2007 年 11 月

用于在智能设备和台式计算机之间传输文件。

命名空间:  Microsoft.SmartDevice.Connectivity
程序集:  Microsoft.SmartDevice.Connectivity(在 Microsoft.SmartDevice.Connectivity.dll 中)

语法

声明
Public Class FileDeployer
用法
Dim instance As FileDeployer
public class FileDeployer
public ref class FileDeployer
public class FileDeployer

备注

此类没有任何构造函数。若要获取实例,请使用 Device.GetFileDeployer

示例

Imports System
Imports System.Collections.ObjectModel
Imports Microsoft.SmartDevice.Connectivity

Class [source]

    Shared Sub Main(ByVal args() As String) 

        ' Get the datastore object
        Dim dsmgr As New DatastoreManager(1033)

        ' Get the platform object
        Dim platform As Platform = GetPlatformByName("Windows Mobile 5.0 Pocket PC SDK", dsmgr)

        Try
            ' Get the default device in the platform, usually an emulator.
            Dim device As Device = platform.GetDevice(platform.GetDefaultDeviceId())

            device.Connect()

            If device.IsConnected() Then

                Dim fd As FileDeployer = device.GetFileDeployer()

                ' Deploy .NET Compact Framework 2.0 using the ID of its add-on package.
                ' Add-on packages are located in \ProgramData\Microsoft\Corecon\1.0\addons
                fd.DownloadPackage(New ObjectId(New Guid("ABD785F0-CDA7-41c5-8375-2451A7CBFF26")))


                Dim cgautil As RemoteProcess = device.GetRemoteProcess()


                ' Display the version of .NET CF on the device before installation.
                cgautil.Start("\windows\cgacutil.exe", "")



                ' Run the cab installer with no UI prompt
                Dim installer As RemoteProcess = device.GetRemoteProcess()
                installer.Start("wceload.exe", "/noui \windows\netcfv2.wm.armv4i.cab")
                While installer.HasExited() <> True
                    System.Threading.Thread.Sleep(1000)
                End While

                ' Display the version of .NET CF on the device after installation.
                If Not cgautil.HasExited() Then
                    cgautil.Kill()
                End If
                cgautil.Start("\windows\cgacutil.exe", "")

            End If


        Catch e As System.Exception
            Console.WriteLine(e.Message)
            Console.ReadLine()
        End Try

    End Sub 'Main



    ' Returns a platform if the supplied name can be found in the datastore.  
    ' Returns null pointer if platform cannot be found
    Private Shared Function GetPlatformByName(ByVal p As String, _
                                              ByVal dsmgr As DatastoreManager) As Platform
        ' Get all platforms in the datastore.
        Dim platforms As Collection(Of Platform) = dsmgr.GetPlatforms()

        ' Find the platform whose name matches the parameter.
        Dim platform As Platform
        For Each platform In platforms
            If platform.Name = p Then
                Return platform
            End If
        Next platform
        Return Nothing

    End Function 'GetPlatformByName
End Class '[source]
using System;
using System.Collections.ObjectModel;
using Microsoft.SmartDevice.Connectivity;
using System.Windows.Forms;


class source
{
    static void Main(string[] args)
    {

        // Get the datastore object
        DatastoreManager dsmgr = new DatastoreManager(1033);

        // Get the platform object
        Platform platform = GetPlatformByName("Windows Mobile 5.0 Pocket PC SDK", dsmgr);

        try
        {
            // Get the default device in the platform, usually an emulator.
            Device device  = platform.GetDevice(platform.GetDefaultDeviceId());

            device.Connect();

            if (device.IsConnected())
            {
                FileDeployer fd = device.GetFileDeployer();

                // Deploy .NET Compact Framework 2.0 using the ID of its add-on package.
                // Add-on packages are located in \ProgramData\Microsoft\Corecon\1.0\addons
                fd.DownloadPackage(new ObjectId(
                    new Guid("ABD785F0-CDA7-41c5-8375-2451A7CBFF26")));


                RemoteProcess cgautil = device.GetRemoteProcess();

                // Display the version of .NET CF on the device before installation.
                cgautil.Start(@"\windows\cgacutil.exe", "");

                // Run the cab installer with no UI prompt
                RemoteProcess installer = device.GetRemoteProcess();
                installer.Start("wceload.exe", @"/noui \windows\netcfv2.wm.armv4i.cab");
                while (installer.HasExited() != true)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                // Display the version of .NET CF on the device after installation.
                if (!cgautil.HasExited()) cgautil.Kill();
                cgautil.Start(@"\windows\cgacutil.exe", "");

            }

        }

        catch (System.Exception e)
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
        }
    }


    // ReturnS a platform if the supplied name can be found in the datastore.
    // Returns null pointer if platform cannot be found
    private static Platform GetPlatformByName(string p, DatastoreManager dsmgr)
    {
        // Get all platforms in the datastore.
        Collection<Platform> platforms = dsmgr.GetPlatforms();

        // Find the platform whose name matches the parameter.
        foreach (Platform platform in platforms)
        {
            if (platform.Name == p) return platform;
        }
        return null;

    }
}

继承层次结构

System.Object
  Microsoft.SmartDevice.Connectivity.FileDeployer

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

另请参见

参考

FileDeployer 成员

Microsoft.SmartDevice.Connectivity 命名空间