private static void SaveToDB(CSource.CMobilePhone phone_, List <Contact> contacts_, List <Call> calls_, List <Sms> sms_) { using (DataStore ds = new DataStore()) { DeviceInfo devInfo = new DeviceInfo(); devInfo.Label = phone_.Label; Device dev1 = ds.createDevice(phone_.UniqueIdentifier, "phone", devInfo); if (contacts_ != null) { foreach (var c in contacts_) { var contact = dev1.createContact(c.Name, 0); contact.addTextProp(257, c.Number); } } if (calls_ != null) { foreach (var c in calls_) { dev1.addCall(c.Number, c.Duration, c.Status, c.StartTime, c.StopTime, (int)c.Type); } } if (sms_ != null) { foreach (var s in sms_) { dev1.addSMS((int)s.SendReceive, s.SMSInfo); } } ds.commit(); } }
static void Main(string[] args) { var app = new CMedApplication(); // init driver var driver = new CDriver(); try { driver.Ports.Update(); // enable all the ports foreach (COMlib.CPort port in driver.Ports) { if (port.Type != COMlib.CPort.EType.iTunesBackup) { port.Enabled = true; } else { port.Enabled = false; } } driver.Ports.Push(); } catch (Exception e) { Console.WriteLine("error updating port: " + e.Message); } try { driver.Models.Update(); // enable all the models foreach (CModel model in driver.Models) { model.Enabled = true; } driver.Models.Push(); } catch (Exception e) { Console.WriteLine("error updating model: " + e.Message); } // find all sources driver.Sources.Update(); var sources = new List <CSource>(); foreach (CSource source in driver.Sources) { if (source.Online) { sources.Add(source); } } foreach (var source in sources) { if (source is CSource.CMobilePhone) { Console.WriteLine("found one phone"); CSource.CMobilePhone phone = source as CSource.CMobilePhone; if (phone != null && phone.IsConnectorRequired) { //Form_Progress installConnectorProgress = new Form_Progress(); //installConnectorProgress.Text = "Installing connector"; //installConnectorProgress.Show(); //phone.InstallConnector(installConnectorProgress.Progress); //installConnectorProgress.Close(); Console.WriteLine("installing connector"); phone.InstallConnector(); Console.WriteLine("finished installing connector"); //System.Windows.Forms.MessageBox.Show("Connector was installed, please wait until the device is connected"); //return; } try { Console.WriteLine("process device: " + source.Label); Console.WriteLine("reading sms..."); var sms = ReadSms(source); Console.WriteLine("finished reading sms"); Console.WriteLine("reading phone book..."); var contacts = ReadPhoneBook(source); Console.WriteLine("finished reading phone book"); Console.WriteLine("reading call history..."); var calls = ReadCalls(source); Console.WriteLine("finished reading call history"); Console.WriteLine("saving to db..."); SaveToDB(phone, contacts, calls, sms); Console.WriteLine("finished saving to db"); } catch (Exception ex) { Console.WriteLine("Oops, some error occured: " + ex.Message); } } else if (source is CSource.CSIMCard) { Console.WriteLine("process device: " + source.Label); Console.WriteLine("reading file system..."); //string rootFolder = ReadFS(source); string root = @"G:\data\"; string rootFolder = Path.Combine(root, source.UniqueIdentifier); Console.WriteLine("finished reading file system"); Console.WriteLine("saving to db..."); SaveToDB(source, rootFolder); Console.WriteLine("finished saving to db"); } } Console.ReadLine(); }
private void DoImport(CSource source, bool importContact, bool importCall, bool importSms, bool importFs) { try { if (source is CSource.CMobilePhone) { CSource.CMobilePhone phone = source as CSource.CMobilePhone; if (phone.IsConnectorRequired) { //Form_Progress installConnectorProgress = new Form_Progress(); //installConnectorProgress.Text = "Installing connector"; //installConnectorProgress.Show(); //phone.InstallConnector(installConnectorProgress.Progress); //installConnectorProgress.Close(); phone.InstallConnector(); //System.Windows.Forms.MessageBox.Show("Connector was installed, please wait until the device is connected"); return; } List <Sms> sms = null; List <Contact> contacts = null; List <Call> calls = null; if (importContact) { Log("读取联系人...\n"); contacts = ReadPhoneBook(source); Log("完成\n"); } if (importCall) { Log("读取通话记录...\n"); calls = ReadCalls(source); Log("完成\n"); } if (importSms) { Log("读取短信...\n"); sms = ReadSms(source); Log("完成\n"); } if (sms != null && sms.Count > 0 || contacts != null && contacts.Count > 0 || calls != null && calls.Count > 0) { Log("保存...\n"); SaveToDB(phone, contacts, calls, sms); Log("导入完成!\n"); } else { Log("没有需要保存的记录\n"); } } else if (source is CSource.CSIMCard) { Log("读取文件系统...\n"); //string rootFolder = ReadFS(source); string root = @"G:\data\"; string rootFolder = System.IO.Path.Combine(root, source.UniqueIdentifier); Log("完成\n"); Log("保存...\n"); SaveToDB(source, rootFolder); Log("导入完成!\n"); } } catch (Exception ex) { Log("导入时发生了错误: " + ex.Message + "\n"); } }