.net - 在与 ActiveSync 同步的同时读取 PDA 目录的内容

标签 .net io rapi handhelddevice

我有一个项目,需要复制 PDA 中找到的文件(就我而言,如果这有什么区别的话,它是 MC3000)。我安装了 ActiveSync,它为我创建了同步文件夹,效果很好。但是,我希望不仅能够在其 MyDocument 文件夹中读取 PDA 的内容,所以我不能使用它(另外它必须与 20 多个可能的同一型号的 PDA 一起使用,从而形成 20 多个目录)

有没有办法在 PDA 与 ActiveSync 对接并同步时在 PDA 内部执行一些 IO。

我可以在资源管理器中看到“移动设备”。

谢谢

最佳答案

使用RAPI 。这是一个 Codeplex 项目,为 Rapi.dll 提供托管包装类。和 ActiveSync。它允许桌面 .NET 应用程序与系留移动设备进行通信。包装器起源于 OpenNetCF project ,但现在是单独管理的。

您可以使用从该项目附带的整个 RAPI 项目 DLL,或者仅使用您需要的代码子集。我需要在设备连接时在设备上创建文件,因此我不需要性能统计信息或 Rapi 中包含的设备注册表信息。所以我只获取了我需要的 3 个源文件...

它对我来说是这样的:

  • 使用 ActiveSync (DccManSink) 检测移动设备连接/断开状态
  • 使用 RAPI 包装器将文件复制到设备、在设备上创建文件、从设备复制文件等。

private DccMan DeviceConnectionMgr;
private int AdviceCode;
private int ConnectionStatus = 1;
private System.Threading.AutoResetEvent DeviceConnectionNotification = new System.Threading.AutoResetEvent(false);


public void OnConnectionError()
{
    ConnectionStatus = -1;
    DeviceConnectionNotification.Set();
}

public void OnIpAssigned(int address)
{
    ConnectionStatus = 0;
    DeviceConnectionNotification.Set();
}


private void btnCopyToDevice_Click(object sender, EventArgs e)
{
    // copy the database (in the form of an XML file) to the connected device
    Cursor.Current = Cursors.WaitCursor;

    // register for events and wait.
    this.DeviceConnectionMgr = new DccMan();

    DccManSink deviceEvents = new DccManSink();
    deviceEvents.IPChange += new IPAddrHandler(this.OnIpAssigned);
    deviceEvents.Error += new ErrorHandler(this.OnConnectionError);
    ((IDccMan)DeviceConnectionMgr).Advise(deviceEvents, out this.AdviceCode);

    // should do this asynchronously, with a timeout; too lazy.
    this.statusLabel.Text = "Waiting for a Windows Mobile device to connect....";

    this.Update();
    Application.DoEvents();  // allow the form to update

    bool exitSynchContextBeforeWait = false;
    DeviceConnectionNotification.WaitOne(SECONDS_TO_WAIT_FOR_DEVICE * 1000, exitSynchContextBeforeWait);

    if (ConnectionStatus == 0)
    {
        this.statusLabel.Text = "The Device is now connected.";
        this.Update();
        Application.DoEvents();  // allow the form to update

        RAPI deviceConnection = new RAPI();
        deviceConnection.Connect(true, 120);  // wait up to 2 minutes until connected
        if (deviceConnection.Connected)
        {
            this.statusLabel.Text = "Copying the database file to the connected Windows Mobile device.";
            this.Update();
            Application.DoEvents();  // allow the form to update
            string destPath = "\\Storage Card\\Application Data\\MyApp\\db.xml";
            deviceConnection.CopyFileToDevice(sourceFile,
                                              destPath,
                                              true);

            this.statusLabel.Text = "Successfully copied the file to the Windows Mobile device....";
        }
        else
        {
            this.statusLabel.Text = "Oh, wait, it seems the Windows Mobile device isn't really connected? Sorry.";
        }

    }
    else
    {
        this.statusLabel.Text = "Could not copy the file because the Device does not seem to be connected.";
    }

    Cursor.Current = Cursors.Default;

}

关于.net - 在与 ActiveSync 同步的同时读取 PDA 目录的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2327794/

相关文章:

windows-ce - 从桌面应用程序终止 WinCE 设备进程

java 将 InputStream 呈现为 ByteBuffer 而无需将整个内容加载到数组中

c - C 中使用动态字符串的文件 I/O

c# - 在 WinCE 上通过 RAPI 查找/复制目录中的所有文件

.net - 如何在没有管理员权限的情况下初始化Windows套接字库

java - Apache 公共(public) I/O。如何通过通配符过滤文件?

.NET ServiceModel.Syndication - 更改 RSS 源的编码

.net - Right$(string, 3) 的含义

.net - 当数据库中数据不可用时测试 SQL Server 存储过程的任何工具。