public CodeCampService(string baseUrl, string campKey) { // ideally each app would just send in its folder path or helper instead of doing it this way // including this as a example of how to use compiler directives in shared layers #if WINDOWS_PHONE _fileHelper = new IsolatedStorageFileSystemHelper(); #elif __ANDROID__ string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "../cache"); _fileHelper = new StandardFileSystemHelper(folderPath); #else string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "../Library/Caches"); _fileHelper = new StandardFileSystemHelper(folderPath); #endif _fileName = campKey + ".xml"; Repository = new CodeCampRepository(null); _client = new CodeCampDataClient(baseUrl, campKey); if (!_fileHelper.FileExists(_fileName)) { downloadNewXmlFile(); } else { Repository = new CodeCampRepository(_fileHelper.ReadFile(_fileName)); } }
internal override void InternalExecute() { using (var zipInputStream = new ZipInputStream(_fileSystemHelper.ReadFile(_pathToArchive))) { zipInputStream.Password = _password; ZipEntry entry; while ((entry = zipInputStream.GetNextEntry()) != null) { Stream streamWriter = _fileSystemHelper.CreateFile(System.IO.Path.Combine(_outputPath + "\\", entry.Name)); long size = entry.Size; var data = new byte[size]; while (true) { size = zipInputStream.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, (int)size); } else { break; } } streamWriter.Close(); } } }
internal override void InternalExecute() { using (var zipOut = new ZipOutputStream(_fileSystemHelper.CreateFile(_outputPath))) { zipOut.SetLevel(CompressionLevel); zipOut.Password = _password; foreach (string fileName in GetFiles()) { //strip of the base folder //this will keep folders preserved string path; if (_path == null) //we are only compressing a single file { path = fileName; } else { path = fileName.Replace(_path, ""); } if (path.StartsWith("\\")) { path = path.Substring(1); //removes the leading \ } var entry = new ZipEntry(path); Stream sReader = _fileSystemHelper.ReadFile(fileName); var buff = new byte[Convert.ToInt32(sReader.Length)]; sReader.Read(buff, 0, (int)sReader.Length); var fileInfo = new FileInfo(fileName); entry.DateTime = fileInfo.LastWriteTime; entry.Size = sReader.Length; sReader.Close(); zipOut.PutNextEntry(entry); zipOut.Write(buff, 0, buff.Length); } zipOut.Finish(); zipOut.Close(); } }