質問

PDA 内で見つかったファイルをコピーする必要があるプロジェクトがあります (私の場合、違いがあるとすれば、それは MC3000 です)。ActiveSync がインストールされており、同期フォルダーが問題なく作成されます。ただし、MyDocument フォルダーだけでなく PDA のコンテンツを読み取れるようにしたいので、これは使用できません(さらに、同じモデルの 20 台以上の可能な PDA で動作する必要があるため、20 個以上のディレクトリが作成されます)。

PDA がドッキングされている間に PDA 内で IO を実行し、ActiveSync と同期する方法はありますか。

エクスプローラーに「モバイルデバイス」が表示されます。

ありがとう

役に立ちましたか?

解決

使用 ラピ. 。これは、マネージド ラッパー クラスを提供する codeplex プロジェクトです。 ラピ.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;

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top