private static void SaveToDB(CSource source_, string rootFolder_) { using (DataStore ds = new DataStore()) { DeviceInfo devInfo = new DeviceInfo(); devInfo.Label = source_.Label; Device dev1 = ds.createDevice(source_.UniqueIdentifier, "simcard", devInfo); if (rootFolder_ != null) { dDevFileSystem devFS = dev1.createDevFileSystem(rootFolder_); ds.commit(); } } }
private static void copyDir(DirectoryInfo dir, String rootPath, dDevFileSystem devFS) { DirectoryInfo[] subDirs = dir.GetDirectories(); foreach (DirectoryInfo subDir in subDirs) { copyDir(subDir, rootPath, devFS); } FileInfo[] files = dir.GetFiles(); byte[] buffer = new byte[1 << 12]; foreach (FileInfo file in files) { using (dDevFile devFile = devFS.createFile(file.FullName.Substring(rootPath.Length))) { FileStream fs = file.OpenRead(); int readByte = 0; while ((readByte = fs.Read(buffer, 0, buffer.Length)) > 0) { devFile.write(buffer, 0, readByte); } } } }
private static void loadData() { using (DataStore ds = new DataStore()) { String guid1 = "01123304408844223"; dDeviceInfo devInfo = new dDeviceInfo(); devInfo.Label = "IPHONE 5"; devInfo.OwnerName = "Steven"; devInfo.OwnerID = "310112345677890x"; dDevice dev1 = ds.createDevice(guid1, "phone", devInfo); dDevice dev2 = ds.createDevice(guid1, "phone"); devInfo.Label = "GSM"; dDevice dev3 = ds.createDevice("394485837722722055055", "SIMCard", devInfo, dev1); for (int i = 0; i < 100; ++i) { dev1.addCall("123456789", 30, 0, DateTime.Parse("2013/4/3 12:41:22"), DateTime.Parse("2013/4/3 12:41:52"), 0); dContact helen = dev1.createContact("Helen " + i, i); helen.addTextProp((int)datasource.dContact.PropertyType.HOME_NUM, "abc"); helen.addDateTimeProp((int)datasource.dContact.PropertyType.DATE, DateTime.Now); byte[] data = System.Text.Encoding.Unicode.GetBytes("data" + i); helen.addBinaryProp((int)datasource.dContact.PropertyType.ITEMPICTURE, data, 0, data.Length); SMSInfo smsInfo = new SMSInfo(); smsInfo.FromNumber = "938740182" + i; smsInfo.Text = "hello" + i; dev3.addSMS(0x02008000, smsInfo); } dDevFileSystem devFS = dev1.createDevFileSystem("D:\\Steven\\temp"); DirectoryInfo dir = new DirectoryInfo("D:\\HEROSOFT"); copyDir(dir, dir.FullName, devFS); ds.commit(); // rollback dDevice dev = ds.createDevice("never be added", "PHONE"); } }