قراءة محتوى دليل PDA أثناء المزامنة مع ActiveSync
-
22-09-2019 - |
سؤال
لديّ مشروع أحتاج فيه إلى نسخ الملفات الموجودة داخل PDA (في حالتي ، إنه MC3000 إذا كان ذلك يحدث أي فرق). لقد قمت بتثبيت ActiveSync وإنشاء مجلد Syncronisation بالنسبة لي على ما يرام. ومع ذلك ، أود أن أكون قادرًا على قراءة محتوى PDA ليس فقط في مجلد MyDocument الخاص به ، لذا لا يمكنني استخدام هذا (بالإضافة إلى أنه يجب أن يعمل مع 20+ PDA ممكن من نفس النموذج ، وبالتالي صنع دليل أكثر من 20 عامًا)
هل هناك طريقة للقيام ببعض IO داخل PDA ، في حين يتم رستها ومزامنة مع ActiveSync.
أستطيع أن أرى "الجهاز المحمول" في Explorer.
شكرًا
المحلول
يستخدم رابي. إنه مشروع codeplex يوفر فئات التفاف المدارة لـ Rapi.dll و ActiveSync. يتيح لتطبيقات سطح المكتب .NET التواصل مع الأجهزة المحمولة المربوطة. نشأ الغلاف داخل مشروع OpenNetCF, ، ولكن الآن تدار بشكل منفصل.
يمكنك استخدام DLL Project Project بالكامل أثناء شحنه من هذا المشروع ، أو مجرد استخدام المجموعة الفرعية من التعليمات البرمجية التي تحتاجها. كنت بحاجة إلى إنشاء ملفات على الجهاز عند توصيلها ، لذلك لم أكن بحاجة إلى أشياء إحصائيات الأداء ، أو أشياء تسجيل الجهاز المضمنة في Rapi. لذلك أمسكت للتو ملفات المصدر الثلاثة التي احتاجها ...
الطريقة التي تعمل بها بالنسبة لي ، هي:
- استخدم ActiveSync (DCCMansink) للكشف عن حالة/فصل الجهاز المحمول
- استخدم Rapi Wrapper لنسخ الملفات إلى الجهاز ، وإنشاء ملفات على الجهاز ، ونسخ الملفات من الجهاز ، وما إلى ذلك.
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;
}