public static ZIPFile WriteToArchive(this SolutionBuilder that) { var zip = new ZIPFile(); that.WriteTo( f => zip.Add(f.Name, f.Content) ); return(zip); }
private static byte[] GetContent() { var z = new ZIPFile(); var c = 0; foreach (Tag k in new MemcacheCollection { ElementType = typeof(Tag) }) { c++; z.Add("file-" + c + ".txt", k.PathAndQuery); } return(z.ToBytes()); }
private static void DownloadJavaZip(WebServiceHandler h, string TypesList) { var Types = TypesList.Split(','); var zip = new ZIPFile(); foreach (var item in Types) { var w = new StringBuilder(); var p = new global::Bulldog.Server.CodeGenerators.Java.DefinitionProvider( item, new WebClient().DownloadString ) { Server = "www.jsc-solutions.net" }; zip.Add( item.Replace(".", "/") + ".cs", p.GetString() ); } // http://www.ietf.org/rfc/rfc2183.txt h.Context.Response.ContentType = ZIPFile.ContentType; h.Context.Response.AddHeader( "Content-Disposition", "attachment; filename=" + TypesList + ".zip" ); var bytes = zip.ToBytes(); h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); }
// to be used only on .net public static void WriteToConsole(this SolutionBuilder that) { var Lookup = new Dictionary <SolutionFileTextFragment, ConsoleColor> { { SolutionFileTextFragment.Comment, ConsoleColor.Green }, { SolutionFileTextFragment.Keyword, ConsoleColor.Cyan }, { SolutionFileTextFragment.None, ConsoleColor.Gray }, { SolutionFileTextFragment.String, ConsoleColor.Red }, { SolutionFileTextFragment.XMLAttributeName, ConsoleColor.Red }, { SolutionFileTextFragment.XMLAttributeValue, ConsoleColor.Blue }, { SolutionFileTextFragment.XMLComment, ConsoleColor.Green }, { SolutionFileTextFragment.XMLKeyword, ConsoleColor.Blue }, { SolutionFileTextFragment.Type, ConsoleColor.Yellow }, }; var zip = new ZIPFile(); that.WriteTo( SolutionFile => { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" " + SolutionFile.Name + " "); //if (SolutionFile.WriteHistory.Count > 1) foreach (var item in SolutionFile.WriteHistory) { if (item.Fragment == SolutionFileTextFragment.Indent) { Console.BackgroundColor = ConsoleColor.DarkGray; } else if (item.Fragment == SolutionFileTextFragment.XMLText) { Console.BackgroundColor = ConsoleColor.DarkCyan; } else { Console.BackgroundColor = ConsoleColor.Black; } if (Lookup.ContainsKey(item.Fragment)) { Console.ForegroundColor = Lookup[item.Fragment]; } else { Console.ForegroundColor = ConsoleColor.Gray; } Console.Write(item.Text); } Console.WriteLine(); zip.Add(SolutionFile.Name, SolutionFile.Content); } ); var Output = new FileInfo(that.Name).FullName + ".zip"; Console.WriteLine(Output); File.WriteAllBytes(Output, zip.ToBytes()); }
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 void Add(string name, XElement data) { zip.Add(name, data.ToString()); }
public static void TransformRobocode() { var w = new Uri("http://robocode.sourceforge.net/docs/robocode/allclasses-noframe.html").ToWebString(); var zip = new ZIPFile(); var o = 0; while (o >= 0) { const string pregfix = "<A HREF=\""; var i = w.IndexOf(pregfix, o); if (i >= 0) { var j = w.IndexOf("\"", i + pregfix.Length); if (j >= 0) { var type = w.Substring(i + pregfix.Length, j - (i + pregfix.Length)); const string suffix = ".html"; if (type.EndsWith(suffix)) { o = j + 1; type = type.Substring(0, type.Length - suffix.Length).Replace("/", "."); Console.WriteLine(type); zip.Add(type.Replace(".", "/") + ".cs", new DefinitionProvider( type // "robocode.BattleRules" // //"java.net.InetSocketAddress" // //"java.net.ServerSocket" // //"java.nio.channels.ServerSocketChannel" , k => k.ToWebString()).GetString() ); } else { o = -1; } } else { o = -1; } } else { o = -1; } } using (var ww = new BinaryWriter(File.OpenWrite("Robocode.zip"))) { zip.WriteTo(ww); } }