コード例 #1
0
        private void btnBuild3GbXML_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.lblFileSizeXML.Text = string.Format("{0} bytes and still working", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeXML.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();
                }
                MassiveXML.Add(OuterIndex, Localized);
                TotalSize += ThisSize;
            }
            if (!AbortRequested)
            {
                this.lblFileSizeXML.Text = string.Format("{0} bytes..Saving XML file", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeXML.Refresh();
                ObjectXMLSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveDocumentFormat(MassiveXML, this.lblFileNameXML.Text);

                this.lblFileSizeXML.Text = string.Format("{0} bytes..Saving XML GZ file", Formatting.KiloToYotta(TotalSize));
                this.lblFileSizeXML.Refresh();
                ObjectXMLSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveCompressedDocumentFormat(MassiveXML, this.lblFileNameXML.Text + ".gz");

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

                this.lblFileSizeXML.Text = string.Format("Save Complete: Memory = {0}, XML = {1}, XML/GZ = {2}",
                                                         TotalSize, rawSize, gzSize);
                //new FileInfo(this.lblFileNameXML.Text).Length,
                //new FileInfo(this.lblFileNameXML.Text + ".gz").Length);
            }
            else
            {
                this.lblFileSizeXML.Text = "Aborted by operator";
            }
            ObjectEnabling(true);
        }
コード例 #2
0
ファイル: SetEditor.cs プロジェクト: rambotech/BOG.Weedkiller
        public bool SaveToFile(string TargetFile, bool PublishingMode)
        {
            string SaveTargetFile = TargetFile;

            if (!_Saved && PublishingMode && _ConfigurationFilePath != string.Empty)
            {
                _Saved = SaveToFile(_ConfigurationFilePath, false);
            }
            if (!_Saved && PublishingMode)
            {
                MessageBox.Show("You are attempting to publish a file you have not yet saved.  You must first save the file, before publishing it.", "Configuration not saved", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(_Saved);
            }

            if (SaveTargetFile == string.Empty)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.InitialDirectory = _StorageFolder;
                saveFileDialog.Title            = PublishingMode ? "Location to publish the configuration file (i.e. visible to worker)" : "Location to save configuration file";
                saveFileDialog.Filter           = "Weed Killer Config Files (*.wkconf)|*.wkconf";
                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    SaveTargetFile = saveFileDialog.FileName;
                    _Saved         = true;
                }
            }

            if (SaveTargetFile != string.Empty)
            {
                try
                {
                    cs.ConfigSet.Clear();
                    cs.Updated = DateTime.Now;
                    foreach (ListViewItem i in this.lvwConfigSet.Items)
                    {
                        cs.ConfigSet.Add((WeedKillerConfig)i.Tag);
                    }
                    ObjectXMLSerializer <WeedKillerConfigSet> .SaveDocumentFormat(cs, SaveTargetFile);

                    if (!PublishingMode)
                    {
                        _Saved = true;
                        _ConfigurationFilePath = SaveTargetFile;
                        this.Text = Path.GetFileNameWithoutExtension(_ConfigurationFilePath);

                        Form z = Application.OpenForms["ManagerMDI"];
                        ((ManagerMDI)z).AddMRU(SaveTargetFile);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error saving configuration to file", string.Format("Can't save file: {0}", e.Message), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(_Saved);
        }