Example #1
0
        private async void btnExport_Click(object sender, EventArgs e)
        {
            BlackList.ListResult list = null;

            await Task.Run(() => { list = client.user.GetList(); });

            SaveFileDialog ExportJson = new SaveFileDialog();

            ExportJson.Filter           = "json files (*.json)|*.json|All files (*.*)|*.*";
            ExportJson.FilterIndex      = 1;
            ExportJson.RestoreDirectory = true;
            ExportJson.FileName         = "Database_Export";

            if (ExportJson.ShowDialog() == DialogResult.OK)
            {
                Debug.WriteLine($"File Path: {ExportJson.FileName}");
                string serialized = BlackList.ListResult.JsonSerialaized(list);
                bool   write      = BlackList.ListResult.WriteJson(ExportJson.FileName, serialized);

                if (write)
                {
                    MetroMessageBox.Show(this, "\nSaved!", "Database Exported", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                else
                {
                    MetroMessageBox.Show(this, $"\nUnable to write into the file {ExportJson.FileName}", "Database Exported Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        private async void btncheckall_Click(object sender, EventArgs e)
        {
            btncheckall.Text = "&Refresh";

            // Deserialize object, by using an async task
            //var list = client.user.GetList();
            BlackList.ListResult list = null;

            await Task.Run(() => { list = client.user.GetList(); });

            // Check API response
            if (list != null)
            {
                txtlist.Text = string.Empty;

                // printing all blacklist field in to the text_list
                foreach (var entry in list.blacklist)
                {
                    txtlist.Text += entry.email + Environment.NewLine;
                }
            }
            else
            {
                MetroMessageBox.Show(this, "\nConnection error, please restart the application!", "No Internet Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }