Domanda

Ho un progetto in cui avrei avuto bisogno di copiare i file trovati all'interno di un PDA (nel mio caso, si tratta di un MC3000 se questo fa alcuna differenza). Ho installato ActiveSync e creare la cartella syncronisation per me più che bene. Tuttavia, vorrei essere in grado di leggere il contenuto del PDA non solo nella sua cartella myDocument quindi non posso usare questa (più è lavorare con 20+ possibile PDA dello stesso modello, rendendo così 20+ directory)

C'è un modo per fare un po 'IO all'interno del PDA, mentre è ancorata e la sincronizzazione con ActiveSync che è.

Posso vedere il 'Mobile Device' in Explorer.

Grazie

È stato utile?

Soluzione

RAPARE . E 'un progetto CodePlex, che fornisce le classi wrapper gestito per rapi.dll ActiveSync. Esso consente applicazioni del desktop NET comunicare con i dispositivi mobili legato. L'involucro ha avuto origine all'interno della OpenNETCF progetto , ma è ora gestito separatamente.

È possibile utilizzare l'intero progetto di DLL RAPARE come le navi da quel progetto, o semplicemente usare il sottoinsieme di codice che avete bisogno. Avevo bisogno di creare file sul dispositivo quando connesso, quindi non ho bisogno di quella roba statistiche sulle prestazioni, o la roba del Registro di dispositivo che è incluso in Rapi. Così ho appena preso i 3 file di origine di cui avevo bisogno ...

Il modo in cui funziona per me, è questo:

  • Usa ActiveSync (DccManSink) per rilevare il collegamento dispositivo mobile / stato di sconnessione
  • Utilizzare l'involucro RAPARE per copiare i file sul dispositivo, creare i file sul dispositivo, copiare i file dal dispositivo, e così via.

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;

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top