예제 #1
0
        void UnzipBigFile(string fnZip, string fnOut)
        {
            ShowStatus("Unzipping...");

            var zip = new C1.C1Zip.C1ZipFile(fnZip);

            zip.Progress += (s, e) =>
            {
                double pct = e.FileLengthLong > 0 ? e.PositionLong / (double)e.FileLengthLong : 0;
                ShowStatus("Expanding... {0:p0}", pct);
            };
            zip.Entries[0].Extract(fnOut);
        }
예제 #2
0
 public static DataSet GetDataSet()
 {
     var ds = new DataSet();
     using (var s = GetStream("nwind.zip"))
     {
         var zip = new C1.C1Zip.C1ZipFile(s);
         using (var zr = zip.Entries[0].OpenReader())
         {
             ds.ReadXml(zr);
         }
     }
     return ds;
 }
예제 #3
0
        public static DataSet GetDataSet()
        {
            var ds = new DataSet();

            using (var s = GetStream("nwind.zip"))
            {
                var zip = new C1.C1Zip.C1ZipFile(s);
                using (var zr = zip.Entries[0].OpenReader())
                {
                    ds.ReadXml(zr);
                }
            }
            return(ds);
        }
예제 #4
0
        void ZipBigFile(string fnIn, string fnZip)
        {
            ShowStatus("Zipping big file");

            var zip = new C1.C1Zip.C1ZipFile(fnZip, true);

            //zip.CompressionLevel = C1.C1Zip.CompressionLevelEnum.BestCompression;
            zip.Progress += (s, e) =>
            {
                double pct = e.FileLengthLong > 0 ? e.PositionLong / (double)e.FileLengthLong : 0;
                ShowStatus("Zipping... {0:p0}", pct);
            };
            zip.Entries.Add(fnIn);
        }
예제 #5
0
        private static void UpdateFile()
        {
            try
            {
                string DownloadUri = ConfigurationManager.AppSettings["filepath"];
                string path        = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "UpdateFile.zip");
                var    c           = new WebClient();
                c.DownloadFile(DownloadUri, path);

                C1.C1Zip.C1ZipFile zipfile = new C1.C1Zip.C1ZipFile();
                zipfile.Open(path);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");
                zipfile.Entries.ExtractFolder(System.Windows.Forms.Application.StartupPath);
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
        }
예제 #6
0
 public static List<Song> Load()
 {
     var asm = Assembly.GetExecutingAssembly();
     foreach (var resName in asm.GetManifestResourceNames())
     {
         if (resName.EndsWith("data.zip"))
         {
             var zip = new C1.C1Zip.C1ZipFile(asm.GetManifestResourceStream(resName));
             using (var stream = zip.Entries["songs.xml"].OpenReader())
             {
                 var xmls = new XmlSerializer(typeof(List<Song>));
                 return (List<Song>)xmls.Deserialize(stream);
             }
         }
     }
     throw new Exception("Can't find 'data.zip' embedded resource.");
 }
예제 #7
0
        void _btnManyFiles_Click_Click(object sender, EventArgs e)
        {
            // prepare
            long fileSize   = 10 * 1024;
            int  entryCount = ushort.MaxValue + 10;
            var  fnIn       = Path.Combine(Application.StartupPath, "smallIn.txt");
            var  fnZip      = Path.Combine(Application.StartupPath, "manyFiles.zip");

            // crate a small file
            CreateTextFile(fnIn, fileSize, false);

            // add many copies to zip
            var zip = new C1.C1Zip.C1ZipFile(fnZip, true);

            for (int i = 0; i < entryCount; i++)
            {
                ShowStatus("Zipping entry {0:n0} of {1:n0}...", i + 1, entryCount);
                zip.Entries.Add(fnIn, string.Format("entry{0}", i + 1));
            }

            // check the copies
            var sr      = new StreamReader(fnIn);
            var content = sr.ReadToEnd();

            for (int i = 0; i < entryCount; i++)
            {
                var ze = zip.Entries[0];
                if (!ze.CheckCRC32())
                {
                    ShowStatus("Checking entry {0}...", i + 1);
                    throw new Exception("entry failed crc32, file is corrupted");
                }

                using (var srz = new StreamReader(ze.OpenReader()))
                {
                    var zcontent = srz.ReadToEnd();
                    if (!string.Equals(content, zcontent))
                    {
                        throw new Exception("entry contents are different!");
                    }
                }
            }

            // all done
            ShowStatus("All done, all good!");
        }
예제 #8
0
        public static List <Song> Load()
        {
            var asm = Assembly.GetExecutingAssembly();

            foreach (var resName in asm.GetManifestResourceNames())
            {
                if (resName.EndsWith("data.zip"))
                {
                    var zip = new C1.C1Zip.C1ZipFile(asm.GetManifestResourceStream(resName));
                    using (var stream = zip.Entries["songs.xml"].OpenReader())
                    {
                        var xmls = new XmlSerializer(typeof(List <Song>));
                        return((List <Song>)xmls.Deserialize(stream));
                    }
                }
            }
            throw new Exception("Can't find 'data.zip' embedded resource.");
        }
        // get a default list of financial items
        public static FinancialDataList GetFinancialData()
        {
            var list = new FinancialDataList();
            var rnd  = new Random(0);
            var asm  = Assembly.GetExecutingAssembly();

            foreach (string resName in asm.GetManifestResourceNames())
            {
                if (resName.EndsWith("data.zip"))
                {
                    var zip = new C1.C1Zip.C1ZipFile(asm.GetManifestResourceStream(resName));
                    using (var sr = new StreamReader(zip.Entries["StockSymbols.txt"].OpenReader()))
                    {
                        while (!sr.EndOfStream)
                        {
                            var sn = sr.ReadLine().Split('\t');
                            if (sn.Length > 1 && sn[0].Trim().Length > 0)
                            {
                                var data = new FinancialData();
                                data.SetProp("Symbol", sn[0]);
                                data.SetProp("Name", sn[1]);
                                data.SetProp("Bid", rnd.Next(1, 1000));
                                data.SetProp("Ask", (decimal)rnd.NextDouble());
                                data.SetProp("LastSale", (decimal)rnd.NextDouble());
                                data.SetProp("BidSize", rnd.Next(10, 500));
                                data.SetProp("AskSize", rnd.Next(10, 500));
                                data.SetProp("LastSize", rnd.Next(10, 500));
                                data.SetProp("Volume", rnd.Next(10000, 20000));
                                data.SetProp("QuoteTime", DateTime.Now);
                                data.SetProp("TradeTime", DateTime.Now);
                                list.Add(data);
                                FinancialData.BuildPropertyDescriptorCollection(data._propBag, false);
                            }
                        }
                    }
                    list.AutoUpdate = true;
                    return(list);
                }
            }
            throw new Exception("Can't find 'data.zip' embedded resource.");
        }
예제 #10
0
        // get a default list of financial items
        public static FinancialDataList GetFinancialData()
        {
            var list = new FinancialDataList();
            var rnd  = new Random(0);
            var asm  = Assembly.GetExecutingAssembly();

            foreach (string resName in asm.GetManifestResourceNames())
            {
                if (resName.EndsWith("data.zip"))
                {
                    var zip = new C1.C1Zip.C1ZipFile(asm.GetManifestResourceStream(resName));
                    using (var sr = new StreamReader(zip.Entries["StockSymbols.txt"].OpenReader()))
                    {
                        while (!sr.EndOfStream)
                        {
                            var sn = sr.ReadLine().Split('\t');
                            if (sn.Length > 1 && sn[0].Trim().Length > 0)
                            {
                                var data = new FinancialData();
                                data.Symbol    = sn[0];
                                data.Name      = sn[1];
                                data.Bid       = rnd.Next(1, 1000);
                                data.Ask       = data.Bid + (decimal)rnd.NextDouble();
                                data.LastSale  = data.Bid;
                                data.BidSize   = rnd.Next(10, 500);
                                data.AskSize   = rnd.Next(10, 500);
                                data.LastSize  = rnd.Next(10, 500);
                                data.Volume    = rnd.Next(10000, 20000);
                                data.QuoteTime = DateTime.Now;
                                data.TradeTime = DateTime.Now;
                                list.Add(data);
                            }
                        }
                    }
                    list.AutoUpdate = true;
                    return(list);
                }
            }
            throw new Exception("Can't find 'data.zip' embedded resource.");
        }
예제 #11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            C1.C1Zip.C1ZipFile czip = new C1.C1Zip.C1ZipFile();

            czip.Entries.Extract("aaa");
        }
        /// <summary>
        /// Saves the report as zip file.
        /// </summary>
        /// <param name="htmlReport"> The html report file path.</param>
        /// <param name="images"> The string array with images.</param>
        /// <param name="htmlFiles"> The string array with html file path.</param>
        /// <param name="fileName"> The zip file path.</param>
        private void SaveReportZip(string htmlReport,string[] images, string[] htmlFiles, string fileName)
        {
            // get file name
            string[] parts = fileName.Split('\\');
            string name = parts[parts.Length - 1];

            // check for . dots
            parts = name.Split('.');
            name = parts[0] + ".htm";

            try
            {
                C1.C1Zip.C1ZipFile zipFile = new C1.C1Zip.C1ZipFile();
                zipFile.Create(fileName);
                zipFile.Open(fileName);
                zipFile.Entries.Add(htmlReport, name);

                // resources
                foreach ( string s in images )
                {
                    if ( File.Exists(s) )
                        zipFile.Entries.Add(s);
                }

                // html files
                foreach ( string file in htmlFiles )
                {
                    if ( File.Exists(file) )
                        zipFile.Entries.Add(file,1);
                }

                zipFile.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,AppLocation.ApplicationName,MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Opens the report.
        /// </summary>
        /// <param name="filePath"> The file path.</param>
        private void OpenReportZip(string filePath)
        {
            C1.C1Zip.C1ZipFile zipFile = new C1.C1Zip.C1ZipFile();
            zipFile.Open(filePath);

            string htmlReportFile = string.Empty;
            ArrayList htmlResponseFiles = new ArrayList();

            // do not extract icons, extract only html data into temphtml
            for (int i=0;i<zipFile.Entries.Count;i++)
            {
                C1.C1Zip.C1ZipEntry entry = zipFile.Entries[i];

                if ( i == 0 )
                {
                    htmlReportFile = Application.UserAppDataPath + "\\temphtml\\" + entry.FileName;
                    zipFile.Entries.Extract(i, htmlReportFile);
                }
                else
                {
                    if ( entry.FileName.IndexOf("htm") > -1 )
                    {
                        string destinationFilePath = Application.UserAppDataPath + "\\temphtml\\" + entry.FileName.Replace("temphtml/","");
                        zipFile.Entries.Extract(i, destinationFilePath);
                        htmlResponseFiles.Add(destinationFilePath);
                    }
                }
            }

            zipFile.Close();

            // Open report preview viewer
            LoadHtmlReportFromFile(htmlReportFile, (string[])htmlResponseFiles.ToArray(typeof(string)));
        }
        /// <summary>
        /// Creates a new ScriptingApplicationPackage.
        /// </summary>
        /// <param name="application"> The scripting application.</param>
        /// <param name="arguments"> The application arguments.</param>
        /// <param name="filePath"> The output file path.</param>
        /// <param name="doEncrypt"> Sets the encrypttion setting for a scripting application.</param>
        public static void CreatePackage(ScriptingApplication application, ScriptingApplicationArgs arguments, string filePath, bool doEncrypt)
        {
            try
            {
                if ( application.Header.ApplicationID == null )
                {
                    application.Header.ApplicationID = System.Guid.NewGuid().ToString();
                }

                // Get all FileReference elements.
                FileReference[] fileReferences = application.GetFileReferences();
                string applicationPath = System.Windows.Forms.Application.UserAppDataPath;

                string temp = applicationPath + "/temp/";

                if ( !Directory.Exists(temp) )
                {
                    Directory.CreateDirectory(temp);
                }

                C1.C1Zip.C1ZipFile zipFile = new C1.C1Zip.C1ZipFile();
                zipFile.Create(filePath);
                zipFile.Open(filePath);

                string argumentsFileName = application.Header.ApplicationID + "-applicationArguments.xml";

                FileReference argumentsFileReference = new FileReference(argumentsFileName);
                application.Header.ScriptingApplicationArgumentsReference = argumentsFileReference;

                // Add Scripting Application
                string xml = string.Empty;
                if ( doEncrypt )
                {
                    xml = application.Encrypt();
                }
                else
                {
                    xml = application.ToXml();
                }

                MemoryStream mem = new MemoryStream(System.Text.Encoding.UTF8.GetByteCount(xml));
                StreamWriter writer =  new StreamWriter(mem, System.Text.Encoding.UTF8);
                writer.Write(xml);
                writer.Flush();
                mem.Position = 0;
                zipFile.Entries.Add(writer.BaseStream, application.Header.ApplicationID);
                writer.Close();

                string argsXml = "None";
                if ( arguments != null )
                {
                    // Add Scripting Application Arguments
                    argsXml = arguments.ToXml();
                }
                mem = new MemoryStream(System.Text.Encoding.UTF8.GetByteCount(argsXml));
                writer =  new StreamWriter(mem, System.Text.Encoding.UTF8);
                writer.Write(argsXml);
                writer.Flush();
                mem.Position = 0;
                zipFile.Entries.Add(writer.BaseStream, argumentsFileName);
                writer.Close();

                FileReference[] customTransforms = application.GetCustomTransforms();

                // add custom transforms
                foreach ( FileReference reference in customTransforms )
                {
                    if ( File.Exists(reference.FileName) )
                    {
                        FileInfo fileInfo = new FileInfo(reference.FileName);
                        zipFile.Entries.Add(reference.FileName, fileInfo.Name);
                    }
                }

                MemoryStream stream = new MemoryStream();
                stream.Write(new byte[] {0}, 0, 1);
                zipFile.Entries.Add(stream, "CustomTransformsSeparator");
                stream.Close();

                // add file references that are not custom transforms
                foreach ( FileReference reference in fileReferences )
                {
                    if ( File.Exists(reference.FileName) )
                    {
                        FileInfo fileInfo = new FileInfo(reference.FileName);
                        zipFile.Entries.Add(reference.FileName, fileInfo.Name);
                    }
                }

                zipFile.Close();
            }
            catch
            {
                throw;
            }
        }