Esempio n. 1
0
        static void Main(string[] args)
        {
            var crc = new Crc32Helper();

            crc.ComputeCrc32(new byte[] { 1, 2, 0xfe, 0xff });

            // Crc32Value = 0x3d414fa9

            var z = new ZIPFile
            {
                { "default.txt", "hello world" }
            };

            var m = z.ToBytes();

            var w = new StringBuilder();

            var xxi = 0;

            foreach (var xx in m)
            {
                xxi++;
                w.Append(" " + xx.ToString("x2"));
                if ((xxi % 16) == 0)
                {
                    w.AppendLine();
                }
            }

            Console.WriteLine(w.ToString());

            /*
             * flash
             * 50 4b 03 04 0a 00 00 00 00 00 80 5c fa 3a 16 ff
             * ff ff 0b 00 00 00 0b 00 00 00 0b 00 00 00 64 65
             * 66 61 75 6c 74 2e 74 78 74 50 4b 01 02 14 00 0a
             * 00 00 00 00 00 80 5c fa 3a 95 2e 51 ff 29 00 00
             * 00 29 00 00 00 0b 00 00 00 00 00 00 00 00 00 00
             * 00 00 00 00 00 00 00 64 65 66 61 75 6c 74 2e 74
             * 78 74 50 4b 05 06 00 00 00 00 01 00 01 00 39 00
             * 00 00 29 00 00 00 00 00
             *
             * .net
             * 50 4b 03 04 0a 00 00 00 00 00 fd 5c fa 3a 85 11
             * 4a 0d 0b 00 00 00 0b 00 00 00 0b 00 00 00 64 65
             * 66 61 75 6c 74 2e 74 78 74 68 65 6c 6c 6f 20 77
             * 6f 72 6c 64 50 4b 01 02 14 00 0a 00 00 00 00 00
             * fd 5c fa 3a 85 11 4a 0d 0b 00 00 00 0b 00 00 00
             * 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
             * 00 00 64 65 66 61 75 6c 74 2e 74 78 74 50 4b 05
             * 06 00 00 00 00 01 00 01 00 39 00 00 00 34 00 00
             * 00 00 00
             *
             *
             */

            File.WriteAllBytes("archive2.zip", m);
        }
        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 byte[] GetContent()
        {
            var z = new ZIPFile
            {
                { "default1.txt", "hello" },
                { "default2.txt", "world" },
                { "task1.zip",
                  new ZIPFile
                  {
                      { "default3.txt", "cool" },
                      { "ken/default4.txt", "huh" },
                  } }
            };


            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());
        }
        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();
        }
        public OrcasAvalonApplicationCanvas()
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;

            this.ClipToBounds = true;

            Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select(
                (c, i) =>
                new Rectangle
            {
                Fill   = new SolidColorBrush(c),
                Width  = DefaultWidth,
                Height = 4,
            }.MoveTo(0, i * 4).AttachTo(this)
                ).ToArray();


            var help_idle = new Image
            {
                Source = (KnownAssets.Path.Assets + "/help_idle.png").ToSource()
            }.AttachTo(this);

            var help = new Image
            {
                Source = (KnownAssets.Path.Assets + "/help.png").ToSource()
            }.AttachTo(this);

            help.Opacity = 0;

            var img = new Image
            {
                Source = (KnownAssets.Path.Assets + "/jsc.png").ToSource()
            }.MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this);

            (1000 / 30).AtIntervalWithCounter(
                c =>
            {
                img.MoveTo(DefaultWidth - 128, DefaultHeight - 128
                           + Math.Sin(c * 0.1) * 4
                           );
            }
                );

            var t = new TextBox
            {
                AcceptsReturn   = true,
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = Brushes.Blue,
                Background      = Brushes.White,
                IsReadOnly      = true,
                Width           = 400,
                Height          = 400
            }.MoveTo(32, 32).AttachTo(this);



            var cc = 0;

            this.MouseLeftButtonUp +=
                delegate
            {
                cc++;

                if (cc % 2 == 1)
                {
                    t.Text = "saving...";

                    var r = new FileDialog();

                    var z = new ZIPFile
                    {
                        { "default.txt", "hello world" },
                        { "readme.txt", "this was created in flash via c#" }
                    };

                    var m = z.ToBytes();

                    r.Save(new MemoryStream(m), "archive1.zip");

                    var w = new StringBuilder();


                    var xxi = 0;
                    foreach (var xx in m)
                    {
                        xxi++;
                        w.Append(" " + xx.ToString("x2"));
                        if ((xxi % 16) == 0)
                        {
                            w.AppendLine();
                        }
                    }

                    t.Text = w.ToString();
                }
                else
                {
                    t.Text = "loading...";

                    var r = new FileDialog();

                    r.Open(
                        m =>
                    {
                        m.Position = 0;

                        ZIPFile z = m;
                        var w     = new StringBuilder();

                        foreach (var zf in z.Entries)
                        {
                            w.AppendLine(zf.FileName);

                            var xxi = 0;
                            foreach (var xx in zf.Bytes)
                            {
                                xxi++;
                                w.Append(" " + xx.ToString("x2"));
                                if ((xxi % 16) == 0)
                                {
                                    w.AppendLine();
                                }
                            }
                            w.AppendLine();
                            w.AppendLine(zf.Text);
                        }

                        t.Text = w.ToString();
                    }
                        );
                }
            };
        }