public static CuratedGallery BuildGalleryOutput(int id) { lock (GetGallerySyncRoot(id)) { CuratedGallery gallery = GetGallery(id); if (gallery == null) throw new Exception(string.Format("Gallery with id='{0}' was not found", id)); var outputDir = new DirectoryInfo(GalleryRuntime.GetGalleryOutputPath(id)); if (outputDir.Exists) { outputDir.Clear(); } else { outputDir.Create(); } BuildOutput(new DirectoryInfo(GalleryRuntime.GetTemplatePath(gallery.TemplateID)), outputDir, GetGallerySourcePath(id)); return gallery; } }
public void RenameFileWithoutExtension() { // Type var workingDirectory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System_IO_FileInfo_Rename")); workingDirectory.EnsureDirectoryExists(); workingDirectory.Clear(); var @this = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension.txt")); var @thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension2.txt")); bool result1 = @thisNewFile.Exists; // Intialization using (FileStream stream = @this.Create()) { } // Examples @this.RenameFileWithoutExtension("Examples_System_IO_FileInfo_RenameWithoutExtension2"); // Unit Test @thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension2.txt")); bool result2 = @thisNewFile.Exists; Assert.IsFalse(result1); Assert.IsTrue(result2); }
public void CreateZipFile() { var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile")); var dir2 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile_Zip")); if (dir.Exists) { dir.Clear(); } if (dir2.Exists) { dir2.Clear(); } // Type var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile", "Examples_System_IO_FileInfo_CreateZipFile.txt")); var zip = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile_Zip", "Examples_System_IO_FileInfo_CreateZipFile.zip")); Directory.CreateDirectory(@this.Directory.FullName); Directory.CreateDirectory(zip.Directory.FullName); // Intialization using (FileStream stream = @this.Create()) { } // Examples @this.Directory.CreateZipFile(zip); // Unit Test Assert.IsTrue(zip.Exists); }
public void Clear() { // Type var @this = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DirectoryInfo_Clear")); Directory.CreateDirectory(@this.FullName); @this.CreateSubdirectory("FizzBuzz"); int result1 = @this.GetDirectories().Length; // Exemples @this.Clear(); // Remove all file and directory in this directory // Unit Test int result2 = @this.GetDirectories().Length; Assert.AreEqual(1, result1); Assert.AreEqual(0, result2); }
public void Clear() { var dir = new DirectoryInfo("abc"); var subdir = dir.GetDirectory("test2"); subdir.Create(); using (var fs = new FileStream(subdir.GetFile("test3.txt").FullName, FileMode.Create)) { fs.WriteByte(1); } dir.Clear(); Assert.That(dir.Exists, Is.True); Assert.That(dir.SafeClear(), Is.True); Assert.That(dir.SafeDelete(), Is.True); dir.Refresh(); Assert.That(dir.Exists, Is.False); Assert.That(dir.SafeClear(), Is.False); }
public void CreateZipFile() { var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory")); var dir2 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Zip")); var dir3 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Output")); if (dir.Exists) { dir.Clear(); } if (dir2.Exists) { dir2.Clear(); } if (dir3.Exists) { dir3.Clear(); } // Type var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory", "Examples_System_IO_FileInfo_ExtractZipFileToDirectory.txt")); var zip = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Zip", "Examples_System_IO_FileInfo_ExtractZipFileToDirectory.zip")); var output = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Output")); Directory.CreateDirectory(@this.Directory.FullName); Directory.CreateDirectory(zip.Directory.FullName); Directory.CreateDirectory(output.FullName); // Intialization using (FileStream stream = @this.Create()) { } @this.Directory.CreateZipFile(zip); var file = output.GetFiles(); // Examples Assert.AreEqual(0, output.GetFiles().Length); zip.ExtractZipFileToDirectory(output); // Unit Test Assert.AreEqual(1, output.GetFiles().Length); }
public CachedFileGenerator(CachedFileGeneratorBase.Arguments Arguments, bool UnqualifiedEnvironment = false) : base(Arguments) { // http://stackoverflow.com/questions/867485/c-getting-the-path-of-appdata // http://support.microsoft.com/kb/2600217#UpdateReplacement var CommonApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var Version = Environment.Version.ToString(); if (UnqualifiedEnvironment) { Version = Version.TakeUntilLastIfAny("."); } var CacheFolder = new DirectoryInfo( Path.Combine( CommonApplicationData, "jsc/" + "cache/" + Version + "/" + this.ConstructorArguments.AssamblyFile.Name + "/" + this.ConstructorArguments.Language.ToString() ) ); // next new cache name var Cache = new FileInfo( Path.Combine( CacheFolder.FullName, this.ConstructorArguments.AssamblyFile.Name + ".zip" ) ); this.AtValidate += delegate { // time to extract the zip file if ready and emit the local token if (Cache.Exists) { // great. now compare the times if (this.ConstructorArguments.AssamblyFile.LastWriteTime > Cache.LastWriteTime) { // no dice. the target is newer than our cache. Cache.Delete(); Cache.Refresh(); } } if (Cache.Exists) { //Debugger.Launch(); var zip = Cache.ToZIPFile(); foreach (var item in zip.Entries) { var FilePath = Path.Combine( this.ConstructorArguments.TargetDirectory.FullName, item.FileName ); this.Add( FilePath, item.Text ); } this.WriteLocalTokens(); this.WriteLocalFiles(); } else { if (this.SourceVersion.Exists) this.SourceVersion.Delete(); CacheFolder.Create(); CacheFolder.Clear(); } }; this.AtWriteTokens += delegate { // if the cache still exists it's time to write the zip file //Console.WriteLine("CachedFileGenerator AtWriteTokens" + new { Cache.Exists }); if (Cache.Exists) return; CacheFolder.Create(); CacheFolder.Clear(); var zip = new ZIPFile(); foreach (var item in this.Files) { var RelativeFileName = item.FileName.Replace("\\", "/").SkipUntilIfAny(this.ConstructorArguments.TargetDirectory.FullName.Replace("\\", "/") + "/"); //Console.WriteLine("CachedFileGenerator AtWriteTokens" + new { RelativeFileName }); zip.Add(RelativeFileName, item.Content); } // should we mark NTFS it compressable? //Debugger.Launch(); zip.WriteToFile(Cache); #region SDK if (this.SDK != null) { var SDKCacheFolder = new DirectoryInfo( Path.Combine( SDK.FullName, "cache/" + Version + "/" + this.ConstructorArguments.AssamblyFile.Name + "/" + this.ConstructorArguments.Language.ToString() ) ); SDKCacheFolder.Create(); SDKCacheFolder.Clear(); var SDKCache = new FileInfo( Path.Combine( SDKCacheFolder.FullName, this.ConstructorArguments.AssamblyFile.Name + ".zip" ) ); zip.WriteToFile(SDKCache); } #endregion }; }
public static OperationResults UnPublishGallery(int id) { lock (GetGallerySyncRoot(id)) { OperationResult<OperationResults, object> ares = null; try { ares = GalleryRepository.UnPublish(id); } catch (Exception ex) { Logger.WriteError(ex); throw ex; } if (ares.Result != OperationResults.Success) return ares.Result; string livepath = GetGalleryLivePath(id); var dir = new DirectoryInfo(livepath); if (dir.Exists) { dir.Clear(); dir.Refresh(); try { dir.Delete(true); } catch (Exception) { } } return ares.Result; } }
public static OperationResults GoGalleryLive(int id) { lock (GetGallerySyncRoot(id)) { string livepath = GetGalleryLivePath(id); var dir = new DirectoryInfo(livepath); if (dir.Exists) { dir.Clear(); dir.Refresh(); } var gallery = BuildGalleryOutput(id); DirectoryInfo src = new DirectoryInfo(gallery.GetDevPath()); var content = gallery.LoadContent(false); ActionHandler<string, bool, bool> handler = content.SystemFilePathes == null || content.SystemFilePathes.Count == 0 ? (ActionHandler<string, bool, bool>)null : delegate(string path, bool isDir) { if (isDir) return true; return content.SystemFilePathes.FirstOrDefault(x => path.EndsWith(x)) == null; }; src.CopyTo(dir, handler); return OperationResults.Success; } }