Пример #1
0
        private void btnBuild3GbJSON_Click(object sender, EventArgs e)
        {
            AbortRequested = false;
            ObjectEnabling(false);
            PhraseGenerator pg = new PhraseGenerator();

            MassiveXML.Clear();
            long TotalSize  = 0;
            int  OuterIndex = 0;

            while (!AbortRequested && TotalSize < 25000000L)
            {
                OuterIndex++;
                this.lblFileSizeJSON.Text = string.Format("{0} bytes and still working", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeJSON.Refresh();
                Application.DoEvents();
                System.Threading.Thread.Sleep(100);
                long ThisSize = 0;
                SerializableDictionary <int, string> Localized = new SerializableDictionary <int, string>();
                int InnerIndex = 0;
                while (!AbortRequested && ThisSize < 10000000L)
                {
                    foreach (string Phrase in pg.GetPhrase(1000))
                    {
                        InnerIndex++;
                        Localized.Add(InnerIndex, Phrase);
                        ThisSize += (long)Phrase.Length;
                    }
                    Application.DoEvents();
                }
                MassiveJSON.Add(OuterIndex, Localized);
                TotalSize += ThisSize;
            }
            if (!AbortRequested)
            {
                this.lblFileSizeJSON.Text = string.Format("{0} bytes..Saving JSON file", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeJSON.Refresh();
                ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveDocumentFormat(MassiveJSON, this.lblFileNameJSON.Text);

                this.lblFileSizeJSON.Text = string.Format("{0} bytes..Saving JSON GZ file", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeJSON.Refresh();
                ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveCompressedDocumentFormat(MassiveJSON, this.lblFileNameJSON.Text + ".gz");

                string rawSize = Formatting.KiloToYotta((double)new FileInfo(this.lblFileNameJSON.Text).Length);
                string gzSize  = Formatting.KiloToYotta((double)new FileInfo(this.lblFileNameJSON.Text + ".gz").Length);

                this.lblFileSizeJSON.Text = string.Format("Save Complete: Memory = {0}, JSON = {1}, JSON.GZ = {2}",
                                                          TotalSize, rawSize, gzSize);
                //new FileInfo(this.lblFileNameJSON.Text).Length,
                //new FileInfo(this.lblFileNameJSON.Text + ".gz").Length);
                this.lblFileSizeJSON.Refresh();
            }
            else
            {
                this.lblFileSizeJSON.Text = "Aborted by operator";
            }
            ObjectEnabling(true);
        }