public async Task SaveTemplate(ScheduleTemplate template) { var templateList = await GetTemplatesList(); if (!templateList.Items.Any(templateInfo => templateInfo.Name.Equals(template.Name))) { templateList.Items.Add(template.GetTemplateInfo()); } var templateEncodedFile = Path.Combine(Path.GetTempPath(), String.Format("{0}.json", template.Name)); File.WriteAllText(templateEncodedFile, template.Serialize()); var templateArchiveFile = new StorageFile( AppProfileManager.Instance.SharedFolder.RelativePathParts.Merge( new[] { TemplatesFolderName, String.Format("{0}.zip", template.Name) })); ZipHelper.CompressFiles(new[] { templateEncodedFile }, templateArchiveFile.LocalPath); await templateArchiveFile.Upload(); await SaveTemplatesList(templateList); }
public void CompressDecompressFileTest() { string testPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\"); Assert.IsTrue(FileManager.DeleteAllFilesInFolder( Path.Combine(testPath, "CompressTestFolder"))); Assert.IsTrue(FileManager.DeleteAllFilesInFolder( Path.Combine(testPath, "CompressTestFolder"))); Assert.AreEqual( Directory.GetFiles( Path.Combine(testPath, "CompressTestFolder")).Length, 0); Assert.IsTrue(ZipHelper.DeCompressFiles( Path.Combine(testPath, "Test.zip"), Path.Combine(testPath, "CompressTestFolder"))); Assert.AreEqual(12, Directory.GetFiles( Path.Combine(testPath, "CompressTestFolder")).Length); Assert.IsTrue(ZipHelper.CompressFiles( Path.Combine(testPath, "CompressTestFolder"), Path.Combine(testPath, "TestNew.zip"), false)); Assert.AreEqual( Directory.GetFiles( testPath, "*.zip").Length, 2); Assert.IsTrue(FileManager.DeleteAllFilesInFolder( Path.Combine(testPath, "CompressTestFolder"))); Assert.AreEqual( Directory.GetFiles( Path.Combine(testPath, "CompressTestFolder")).Length, 0); Assert.IsTrue(ZipHelper.DeCompressFiles( Path.Combine(testPath, "TestNew.zip"), Path.Combine(testPath, "CompressTestFolder"))); Assert.AreEqual(12, Directory.GetFiles( Path.Combine(testPath, "CompressTestFolder")).Length); Assert.IsTrue(FileManager.DeleteAllFilesInFolder( testPath, "*New.zip")); Assert.AreEqual( Directory.GetFiles( testPath, "*.zip").Length, 1); Assert.IsTrue(FileManager.DeleteAllFilesInFolder( Path.Combine(testPath, "CompressTestFolder"))); Assert.AreEqual( Directory.GetFiles( Path.Combine(testPath, "CompressTestFolder")).Length, 0); }