【问题标题】:Reading the content of a PDA directory while sync with ActiveSync在与 ActiveSync 同步时读取 PDA 目录的内容
【发布时间】:2011-01-20 15:09:17
【问题描述】:

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

有没有办法在 PDA 内部进行一些 IO,同时它是对接的并与 ActiveSync 同步。

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

谢谢

【问题讨论】:

    标签: .net io rapi handhelddevice


    【解决方案1】:

    使用RAPI。这是一个为 Rapi.dll 和 ActiveSync 提供托管包装类的 codeplex 项目。它允许桌面 .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;
    
    }
    

    【讨论】:

    • 听起来正是我需要的!但是,我还不能测试它。由于我只需要从 PDA 获取文件,这些文件位于特定的常量目录中,因此这似乎可行。
    • 我无法完成这项工作。你在用什么样的项目?我应该知道的代码中没有的任何内容...?我尤其无法制作 DCCMan 或 AdviceCode 类型的任何东西。谢谢。
    • 什么意思? “制作任何类型的东西......”。您将需要 codeplex.com 上的 RAPI 项目中的代码。你有那个,对吧?该代码中定义了 DccManSink 和 RAPI 等类。 AdviceCode 只是一个整数。 (是的,我在从工作项目中摘录这段代码时错误地将其遗漏了)
    猜你喜欢
    • 2011-10-24
    • 2015-04-30
    • 1970-01-01
    • 2018-03-07
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 2010-09-06
    相关资源
    最近更新 更多