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

发布于 2024-08-23 00:22:51 字数 275 浏览 12 评论 0原文

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

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

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

谢谢

I have a project in which I would need to copy files found within a PDA (in my case, it's a MC3000 if that makes any difference). I have ActiveSync installed and it create the syncronisation folder for me just fine. However, I would like to be able to read the content of the PDA not only in its MyDocument Folder so I can't use this (Plus it have to work with 20+ possible PDA of the same model, thus making 20+ directory)

Is there a way to do some IO inside the PDA, while it is docked and sync with ActiveSync that is.

I can see the 'Mobile Device' in Explorer.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红ご颜醉 2024-08-30 00:22:51

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

您可以使用从该项目附带的整个 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;

}

Use RAPI. It's a codeplex project that provides managed wrapper classes for Rapi.dll and ActiveSync. It lets desktop .NET apps communicate with tethered mobile devices. The wrapper originated within the OpenNetCF project, but is now managed separately.

You can use the whole RAPI project DLL as it ships from that project, or just use the subset of code that you need. I needed to create files on the device when it connected, so I didn't need the performance statistics stuff, or the device registry stuff that is included in Rapi. So I just grabbed the 3 source files I needed...

The way it works for me, is this:

  • Use ActiveSync (DccManSink) to detect mobile device connection/disconnect status
  • Use the RAPI wrapper to copy files to the device, create files on the device, copy files from the device, and so on.

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;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文