Dispose() публичный Метод

See IDisposable.Dispose for more information.
public Dispose ( ) : void
Результат void
Пример #1
0
        private void btnLoadFrom_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            DialogResult   res = dlg.ShowDialog(this);

            if (res == DialogResult.Cancel)
            {
                return;
            }
            string fpath = dlg.FileName;

            FileInfo fi = new FileInfo(fpath);

            if (fi.Length > MAX_BLOB_FILESIZE_MB * 1000 * 1024)
            {
                res = MessageBox.Show(this,
                                      "SQLite does not handle BLOBs larger than " + MAX_BLOB_FILESIZE_MB + "MB very well.\r\n" +
                                      "It is highly recommended that you don't add such large BLOB\r\n" +
                                      "fields into the database due to performance reasons.\r\n" +
                                      "Do you want to abort the operation?",
                                      "Warning",
                                      MessageBoxButtons.YesNo,
                                      MessageBoxIcon.Warning);
                if (res == DialogResult.Yes)
                {
                    return;
                }
            }

            if (_blobProvider != null)
            {
                Be.Windows.Forms.DynamicFileByteProvider dp = _blobProvider as Be.Windows.Forms.DynamicFileByteProvider;
                if (dp != null)
                {
                    dp.Dispose();
                }
            }

            try
            {
                // Copy the file to the temporary BLOB file
                if (File.Exists(Configuration.TempBlobFilePath))
                {
                    File.Delete(Configuration.TempBlobFilePath);
                }
                File.Copy(fpath, Configuration.TempBlobFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Internal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            } // catch

            _blobProvider            = new DynamicFileByteProvider(Configuration.TempBlobFilePath);
            ucHexEditor.ByteProvider = _blobProvider;
            lblBlobSize.Text         = "Blob contains " + Utils.FormatMemSize(fi.Length, MemFormat.KB);
        }
Пример #2
0
 private void CellValueEditorDialog_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.UserClosing)
     {
         Be.Windows.Forms.DynamicFileByteProvider dp = _blobProvider as Be.Windows.Forms.DynamicFileByteProvider;
         if (dp != null)
         {
             dp.Dispose();
         }
     }
 }
Пример #3
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (_blobProvider != null)
            {
                Be.Windows.Forms.DynamicFileByteProvider dp = _blobProvider as Be.Windows.Forms.DynamicFileByteProvider;
                if (dp != null)
                {
                    dp.Dispose();
                }
            }

            this.DialogResult = DialogResult.Cancel;
        }
Пример #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cbxSetAsNull.Checked)
            {
                // In case the user chose to Nullify a BLOB field - dispose of the dynamic file byte provider.
                // Otherwise - we'll have a resource leakage.
                if (_blobProvider != null && _blobProvider is Be.Windows.Forms.DynamicFileByteProvider)
                {
                    Be.Windows.Forms.DynamicFileByteProvider dp = _blobProvider as Be.Windows.Forms.DynamicFileByteProvider;
                    dp.Dispose();
                }

                _value = DBNull.Value;
            }
            else if (tbcTypes.SelectedTab == tbpEditBlob)
            {
                if (_column.ColumnType.TypeName == null ||
                    _column.ColumnType.TypeName == string.Empty ||
                    _column.ColumnType.TypeName.ToLower() == "blob")
                {
                    _value = _blobProvider;
                }
                else
                {
                    // Non BLOB column cannot be written as BLOB so I convert
                    // its value to string.
                    byte[] arr = new byte[_blobProvider.Length];
                    for (int i = 0; i < _blobProvider.Length; i++)
                    {
                        arr[i] = _blobProvider.ReadByte(i);
                    }
                    _value = Encoding.ASCII.GetString(arr);
                }
            }
            else if (tbcTypes.SelectedTab == tbpEditBoolean)
            {
                _value = rbtnTrue.Checked;
            }
            else if (tbcTypes.SelectedTab == tbpEditGuid)
            {
                _value = new Guid(txtGuid.Text);
            }
            else if (tbcTypes.SelectedTab == tbpEditFloatingPoint)
            {
                if (Utils.GetDbType(_column.ColumnType) == DbType.Single)
                {
                    _value = float.Parse(txtFloatingPoint.Text);
                }
                else
                {
                    _value = double.Parse(txtFloatingPoint.Text);
                }
            }
            else if (tbcTypes.SelectedTab == tbpEditInteger)
            {
                _value = (long)numInteger.Value;
            }
            else if (tbcTypes.SelectedTab == tbpEditText)
            {
                _value = txtValue.Text;
            }
            else if (tbcTypes.SelectedTab == tbpEditDateTime)
            {
                _value = new DateTime(dtpDate.Value.Year, dtpDate.Value.Month, dtpDate.Value.Day, dtpTime.Value.Hour,
                                      dtpTime.Value.Minute, dtpTime.Value.Second, dtpTime.Value.Millisecond);
            }
            else
            {
                throw new ArgumentException($"Illegal tab page (name={tbcTypes.SelectedTab.Name})");
            }

            this.DialogResult = DialogResult.OK;
        }