Ejemplo n.º 1
0
        /// <summary>
        /// Handles the ProgressChanged event of the BackgroundWorker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ProgressChangedEventArgs"/> instance containing the event data.</param>
        private void _importer_OnProgress(object sender, object e)
        {
            Rock.Slingshot.SlingshotImporter _importer = sender as Rock.Slingshot.SlingshotImporter;

            string          progressMessage = string.Empty;
            DescriptionList progressResults = new DescriptionList();

            if (e is string)
            {
                progressMessage = e.ToString();
            }

            var exceptionsCopy = _importer.Exceptions.ToArray();

            if (exceptionsCopy.Any())
            {
                if (exceptionsCopy.Count() > 50)
                {
                    var exceptionsSummary = exceptionsCopy.GroupBy(a => a.GetBaseException().Message).Select(a => a.Key + "(" + a.Count().ToString() + ")");
                    progressResults.Add("Exceptions", string.Join(Environment.NewLine, exceptionsSummary));
                }
                else
                {
                    progressResults.Add("Exception", string.Join(Environment.NewLine, exceptionsCopy.Select(a => a.Message).ToArray()));
                }
            }

            var resultsCopy = _importer.Results.ToArray();

            foreach (var result in resultsCopy)
            {
                progressResults.Add(result.Key, result.Value);
            }

            WriteProgressMessage(progressMessage, progressResults.Html);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the import.
        /// </summary>
        /// <param name="importType">Type of the import.</param>
        private void StartImport(ImportType importType)
        {
            var  physicalSlingshotFile = this.Request.MapPath(hfMainSlingshotFileName.Value);
            long totalMilliseconds     = 0;

            Rock.Slingshot.SlingshotImporter _importer = null;

            var importTask = new Task(() =>
            {
                // wait a little so the browser can render and start listening to events
                System.Threading.Thread.Sleep(1000);
                _hubContext.Clients.All.showButtons(this.SignalRNotificationKey, false);

                Stopwatch stopwatch = Stopwatch.StartNew();

                BulkImporter.ImportUpdateType importUpdateType;

                if (rbOnlyAddNewRecords.Checked)
                {
                    importUpdateType = BulkImporter.ImportUpdateType.AddOnly;
                }
                else if (rbMostRecentWins.Checked)
                {
                    importUpdateType = BulkImporter.ImportUpdateType.MostRecentWins;
                }
                else
                {
                    importUpdateType = BulkImporter.ImportUpdateType.AlwaysUpdate;
                }

                _importer = new Rock.Slingshot.SlingshotImporter(physicalSlingshotFile, tbForeignSystemKey.Text, importUpdateType, _importer_OnProgress);
                _importer.FinancialTransactionChunkSize = 100000;

                if (importType == ImportType.Import || importType == ImportType.All)
                {
                    _importer.DoImport();
                }

                if (importType == ImportType.Photos || importType == ImportType.All)
                {
                    _importer.TEST_UseSampleLocalPhotos = false;
                    _importer.DoImportPhotos();
                }

                stopwatch.Stop();

                if (_importer.Exceptions.Any())
                {
                    _importer.Results.Add("ERRORS", string.Join(Environment.NewLine, _importer.Exceptions.Select(a => a.Message).ToArray()));
                }

                totalMilliseconds = stopwatch.ElapsedMilliseconds;

                _hubContext.Clients.All.showButtons(this.SignalRNotificationKey, true);
            });

            importTask.ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    foreach (var exception in t.Exception.InnerExceptions)
                    {
                        LogException(exception);
                        if (_importer.Exceptions != null)
                        {
                            _importer.Exceptions.Add(exception.GetBaseException());
                        }
                    }

                    _importer_OnProgress(_importer, "ERROR: " + t.Exception.Message);
                }
                else
                {
                    _importer_OnProgress(_importer, string.Format("{0} Complete: [{1}ms]", importType.ConvertToString(), totalMilliseconds));
                }
            });

            importTask.Start();
        }