예제 #1
0
        /// <summary>
        /// Handles the Click event of the btnLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            lblMessage.Text = string.Empty;

            if (txtHostname.Text != string.Empty && txtApiPassword.Text != string.Empty && txtApiUsername.Text != string.Empty &&
                txtApiConsumerKey.Text != string.Empty && txtApiConsumerSecret.Text != string.Empty)
            {
                F1Api.Connect(txtHostname.Text, txtApiConsumerKey.Text, txtApiConsumerSecret.Text, txtApiUsername.Text, txtApiPassword.Text);

                if (F1Api.IsConnected)
                {
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.exporter = new F1Api();
                    mainWindow.Show();
                    this.Close();
                }
                else
                {
                    lblMessage.Text = $"Could not login with the information provided. {F1Api.ErrorMessage}";
                }
            }
            else
            {
                lblMessage.Text = "Please provide the information needed to connect.";
            }
        }
        /// <summary>
        /// Handles the Loaded event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lblApiUsage.Text = $"API Usage: {F1Api.ApiCounter}";
            // add group types
            ExportGroupTypes = F1Api.GetGroupTypes();

            foreach (var groupType in ExportGroupTypes)
            {
                //cblGroupTypes.Items.Add( groupType );
                GroupTypesCheckboxItems.Add(new CheckListItem {
                    Id = groupType.Id, Text = groupType.Name, Checked = true
                });
            }

            cblGroupTypes.ItemsSource = GroupTypesCheckboxItems;

            txtImportCutOff.Text = DateTime.Now.ToShortDateString();
        }
        private void ExportWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            exportWorker.ReportProgress(0, "");
            _apiUpdateTimer.Start();

            var exportSettings = ( ExportSettings )e.Argument;

            // clear filesystem directories
            F1Api.InitializeExport();

            // export individuals
            if (exportSettings.ExportIndividuals)
            {
                exportWorker.ReportProgress(1, "Exporting Individuals...");
                F1Api.ExportIndividuals(exportSettings.ModifiedSince);

                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        exportWorker.ReportProgress(2, $"Error exporting individuals: {F1Api.ErrorMessage}");
                    });
                }
            }

            // export contributions
            if (exportSettings.ExportContributions)
            {
                exportWorker.ReportProgress(30, "Exporting Financial Accounts...");

                F1Api.ExportFinancialAccounts();
                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(31, $"Error exporting financial accounts: {F1Api.ErrorMessage}");
                }

                exportWorker.ReportProgress(32, "Exporting Financial Pledges...");

                F1Api.ExportFinancialPledges();
                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(33, $"Error exporting financial pledges: {F1Api.ErrorMessage}");
                }


                exportWorker.ReportProgress(34, "Exporting Financial Batches...");

                F1Api.ExportFinancialBatches(exportSettings.ModifiedSince);
                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(35, $"Error exporting financial batches: {F1Api.ErrorMessage}");
                }

                exportWorker.ReportProgress(36, "Exporting Contribution Information...");

                F1Api.ExportContributions(exportSettings.ModifiedSince, exportSettings.ExportContributionImages);
                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(37, $"Error exporting financial batches: {F1Api.ErrorMessage}");
                }
            }

            // export group types
            if (exportSettings.ExportGroupTypes.Count > 0)
            {
                exportWorker.ReportProgress(54, $"Exporting Groups...");

                F1Api.ExportGroups(ExportGroupTypes.Select(t => t.Id).ToList());

                if (F1Api.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(54, $"Error exporting groups: {F1Api.ErrorMessage}");
                }
            }

            // finalize the package
            ImportPackage.FinalizePackage("f1-export.slingshot");

            _apiUpdateTimer.Stop();
        }