public override void Run() { /// алгоритм /// Disconnect от КПК базы /// на основании ConnectionSettings скопировать /// базу с винчейстера на КПК /// event в самом конце (Max = 1 Pos = 1) /// Running не обрабатывается /// /// Дополнение: если ToPDA == true то копирование идет не на КПК а из КПК DataBasePDA.Disconnect(); RAPI rapi=new RAPI(); if(!ToPDA) try { if(rapi.DevicePresent) rapi.Connect(); rapi.CopyFileToDevice(ConnectionSettings.GetSettings().PDAConnectionString, ConnectionSettings.GetSettings().PDAConString, true); Loging.Loging.WriteLog("Coping to PDA complete", false, true); File.Delete(ConnectionSettings.GetSettings().PDAConnectionString); } catch (Exception e) { Loging.Loging.WriteLog("Coping to PDA failed: " + e.Message, false, true); } else try { if(rapi.DevicePresent) rapi.Connect(); rapi.CopyFileFromDevice(ConnectionSettings.GetSettings().PDAConnectionString, ConnectionSettings.GetSettings().PDAConString, true); Loging.Loging.WriteLog("Coping from PDA complete", false, true); } catch (Exception e) { if (e.Message == "Could not open remote file ") { if (ConnectionSettings.GetSettings().PDAConString == "\\Storage Card\\BelmostPDA.sdf") { ConnectionSettings.GetSettings().PDAConString = "\\Sd Card\\BelmostPDA.sdf"; } else ConnectionSettings.GetSettings().PDAConString = "\\Storage Card\\BelmostPDA.sdf"; try { rapi.CopyFileFromDevice(ConnectionSettings.GetSettings().PDAConnectionString, ConnectionSettings.GetSettings().PDAConString, true); Loging.Loging.WriteLog("Coping from PDA complete", false, true); } catch(Exception ex) { Loging.Loging.WriteLog("Coping from PDA failed: " + ex.Message, false, true); Coordinator.Canceled = true; } } else { Loging.Loging.WriteLog("Coping from PDA failed: " + e.Message, false, true); Coordinator.Canceled = true; } } Coordinator.ExecuteDelegateArgs args = new Coordinator.ExecuteDelegateArgs(); args.Maximum = 1; args.Pos = 1; args.runningAction = this; args.Name = Name(); OnExecute(this, args); }
private void button1_Click(object sender, EventArgs e) { try { DialogResult pesan; pesan = MessageBox.Show("Download data dari PDT?", "Konfirmasi", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (pesan == DialogResult.OK) { label1.Text = ""; using (RAPI MyRapi = new RAPI()) if (MyRapi.DevicePresent) { int x = 0; MyRapi.Connect(true); string pc = @"" + textBox2.Text; string pdt = @"\Application\Backup\Transfer\"; var fl = MyRapi.EnumFiles(pdt + @"\*"); if (fl == null) { MessageBox.Show("File Tidak Ditemukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } bool Hapus = false; if (checkBox1.Checked == true) { Hapus = true; } //DialogResult dr = MessageBox.Show("Delete Data di PDT ?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); //if (DialogResult.Yes == dr) //{ // Hapus = true; //} foreach (FileInformation file in fl) { if (File.Exists(pc + "\\" + file.FileName)) { File.Delete(pc + "\\" + file.FileName); } MyRapi.CopyFileFromDevice(pc + "\\" + file.FileName, pdt + "\\" + file.FileName); if (Hapus) { MyRapi.DeleteDeviceFile(pdt + "\\" + file.FileName); } x++; label1.Text = "Mohon Tunggu"; } MyRapi.Disconnect(); if (x != 0) { label1.Text = "Copy Berhasil"; MessageBox.Show("Copy file to "+textBox2.Text+" berhasil.", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } else { label1.Text = "Please Connect to the Mobile Device"; MessageBox.Show("Please Connect to the Mobile Device", "Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } } catch (Exception ex) { label1.Text = ""; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
//überarbeiten private void MobileToDesktop(Object o) { AutoResetEvent evnt = (AutoResetEvent)o; RAPI rap; //try //{ rap = new RAPI(); //} //catch (Exception e) //{ // MessageBox.Show("Unable to initialize Rapi! Please Connect manually."); // return; //} if (rap.DevicePresent == true) { try { rap.Connect(); rap.CopyFileFromDevice(progPath, mobileDBPath, true);//Datenbank in das ausführende Verzeichnis als ArbeitsDB kopieren activesync = true; } catch (Exception e) { MessageBox.Show("RapiError! Please copy Your Files manually"); activesync = false; } } else { activesync = false; } evnt.Set(); }