Frage

Ich habe ein Projekt, in dem ich brauchen würde, um Dateien zu kopieren innerhalb eines PDA gefunden (in meinem Fall, es ist ein MC3000, wenn das einen Unterschied macht). Ich habe ActiveSync installiert und erstellen Sie den syncronisation Ordner nur für mich in Ordnung. Ich möchte jedoch den Inhalt des PDA nicht nur in seinen MyDocument Ordnern in die Lage sein zu lesen, damit ich das nicht verwenden kann (plus sie müssen die Arbeit mit 20+ möglich PDA des gleichen Modells, wodurch 20+ Verzeichnis)

Gibt es eine Möglichkeit, etwas IO innerhalb des PDA zu tun, während es angedockt ist und synchron mit ActiveSync das ist.

Ich kann das 'Mobile Device' im Explorer sehen.

Danke

War es hilfreich?

Lösung

Verwenden Sie RAPI . Es ist ein Codeplex-Projekt, das für rapi.dll Wrapper-Klassen verwaltet bietet und ActiveSync. Es ermöglicht Desktop-NET-Anwendungen mit angebundenen mobilen Geräten kommunizieren. Der Wrapper entstand innerhalb des OpenNetCF Projekt , wird aber nun separat verwaltet.

Sie können das ganze RAPI Projekt DLL, da es Schiffe aus diesem Projekt verwenden, oder einfach nur die Teilmenge von Code verwenden, die Sie benötigen. Ich brauchte Dateien auf dem Gerät zu erstellen, wenn sie verbunden sind, so dass ich nicht die Performance-Statistiken Sachen haben müssen, oder das Gerät Registry Sachen, die in Rapi enthalten ist. Also packte ich nur die drei Quelldateien Ich brauchte ...

So wie es für mich funktioniert, ist dies:

  • Verwenden ActiveSync (DccManSink) zu erfassen Mobilgeräteanschluss / disconnect Status
  • Verwenden Sie die RAPI-Wrapper-Dateien auf das Gerät zu kopieren, erstellen Sie Dateien auf dem Gerät, das Kopieren von Dateien aus dem Gerät, und so weiter.

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;

}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top