private string RetrieveNetworkInfoFile() { this.SendStatusUpdate("Waiting for network information file to be written to device."); RemoteIsolatedStorageFile storage = null; int retryCount = 0; string remoteFileName = string.Empty; while (string.IsNullOrEmpty(remoteFileName) && retryCount < 4) { // Need sleep here to allow application to launch. System.Threading.Thread.Sleep(1000); storage = this.browserApplication.GetIsolatedStore(null); List <RemoteFileInfo> files = storage.GetDirectoryListing(string.Empty); DateTime findTimeout = DateTime.Now.Add(TimeSpan.FromSeconds(15)); while (DateTime.Now < findTimeout) { foreach (RemoteFileInfo info in files) { if (info.Name.Contains("networkInfo.txt")) { remoteFileName = info.Name; break; } } if (!string.IsNullOrEmpty(remoteFileName)) { break; } System.Threading.Thread.Sleep(500); storage = this.browserApplication.GetIsolatedStore(null); files = storage.GetDirectoryListing(string.Empty); } retryCount++; } if (string.IsNullOrEmpty(remoteFileName)) { throw new WindowsPhoneDriverException("Application was installed and launched, but did not write network info file"); } this.SendStatusUpdate("Retrieving network information file from device."); string localFile = Path.Combine(Path.GetTempPath(), "networkInfo.txt"); storage.ReceiveFile("networkInfo.txt", localFile, true); storage.DeleteFile("networkInfo.txt"); return(localFile); }
private static void ReceiveDeviceDirectory(RemoteIsolatedStorageFile risf, string deviceRelativeDir, List <RemoteFileInfo> source, DirectoryInfo target, bool cleanDeviceDirectory) { if (cleanDeviceDirectory) { string fullName = target.FullName; try { if (Directory.Exists(fullName)) { target.Delete(true); target = Directory.CreateDirectory(fullName); } } catch (IOException ex) { Console.WriteLine("Error: Unable to create folder on desktop."); throw ex; } } foreach (RemoteFileInfo remoteFileInfo in source) { if (remoteFileInfo.IsDirectory()) { string fileName = Path.GetFileName(remoteFileInfo.Name); string str = deviceRelativeDir + (object)Path.DirectorySeparatorChar + fileName; DirectoryInfo subdirectory = target.CreateSubdirectory(fileName); try { List <RemoteFileInfo> directoryListing = risf.GetDirectoryListing(str); ReceiveDeviceDirectory(risf, str, directoryListing, subdirectory, false); } catch (FileNotFoundException ex) { } } else { string fileName = Path.GetFileName(remoteFileInfo.Name); string sourceDeviceFilePath = deviceRelativeDir + (object)Path.DirectorySeparatorChar + fileName; string targetDesktopFilePath = target.FullName + (object)Path.DirectorySeparatorChar + fileName; risf.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath, true); } } }
private static void ReceiveDirectory(RemoteIsolatedStorageFile risf, string desktopDirPath) { if (Path.DirectorySeparatorChar != desktopDirPath[desktopDirPath.Length - 1]) { desktopDirPath = desktopDirPath + (object)Path.DirectorySeparatorChar; } desktopDirPath = desktopDirPath + "IsolatedStore"; var target = new DirectoryInfo(desktopDirPath); try { List <RemoteFileInfo> directoryListing = risf.GetDirectoryListing(string.Empty); ReceiveDeviceDirectory(risf, string.Empty, directoryListing, target, true); } catch (FileNotFoundException ex) { Console.WriteLine("Info: IsolatedStore for this application is empty."); throw ex; } }
private static void ReceiveDeviceDirectory(RemoteIsolatedStorageFile risf, string deviceRelativeDir, List<RemoteFileInfo> source, DirectoryInfo target, bool cleanDeviceDirectory) { if (cleanDeviceDirectory) { string fullName = target.FullName; try { if (Directory.Exists(fullName)) { target.Delete(true); target = Directory.CreateDirectory(fullName); } } catch (IOException ex) { Console.WriteLine("Error: Unable to create folder on desktop."); throw ex; } } foreach (RemoteFileInfo remoteFileInfo in source) { if (remoteFileInfo.IsDirectory()) { string fileName = Path.GetFileName(remoteFileInfo.Name); string str = deviceRelativeDir + (object)Path.DirectorySeparatorChar + fileName; DirectoryInfo subdirectory = target.CreateSubdirectory(fileName); try { List<RemoteFileInfo> directoryListing = risf.GetDirectoryListing(str); ReceiveDeviceDirectory(risf, str, directoryListing, subdirectory, false); } catch (FileNotFoundException ex) { } } else { string fileName = Path.GetFileName(remoteFileInfo.Name); string sourceDeviceFilePath = deviceRelativeDir + (object)Path.DirectorySeparatorChar + fileName; string targetDesktopFilePath = target.FullName + (object)Path.DirectorySeparatorChar + fileName; risf.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath, true); } } }
private static void ReceiveDirectory(RemoteIsolatedStorageFile risf, string desktopDirPath) { if (Path.DirectorySeparatorChar != desktopDirPath[desktopDirPath.Length - 1]) { desktopDirPath = desktopDirPath + (object)Path.DirectorySeparatorChar; } desktopDirPath = desktopDirPath + "IsolatedStore"; var target = new DirectoryInfo(desktopDirPath); try { List<RemoteFileInfo> directoryListing = risf.GetDirectoryListing(string.Empty); ReceiveDeviceDirectory(risf, string.Empty, directoryListing, target, true); } catch (FileNotFoundException ex) { Console.WriteLine("Info: IsolatedStore for this application is empty."); throw ex; } }