Beispiel #1
0
        private async Task SynEnrollmentData()
        {
            var progressHandler = new Progress <int>(value =>
            {
                labelTotalSuccess.Text = value.ToString();
            });
            var progress = (IProgress <int>)progressHandler;

            //Download User Profiles
            toolStripStatusLabel.Text = @"Searching and Downloading New User Profiles, Please Wait... ";
            await Task.Run(() => DatabaseOpperations.DownloadNewUserProfiles());

            toolStripStatusLabel.Text = @"User Profiles Update Completed ";

            if (_UserProfile == null)
            {
                toolStripStatusLabel.Text = @"Sync Job Terminated, User Must Login";
                return;
            }

            //Scroll through records in result
            if (_BaseDatas.Any())
            {
                toolStripStatusLabel.Text = @"Sync Job Processing, Please Wait...";
                var startDate = DateTime.Now;
                labelSyncStartTime.Text = startDate.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(false);

                //0. Create Entry into the SyncJobLog
                var syncJobId = DatabaseOpperations.CreateSyncJobSession(_UserProfile, startDate);

                //1. Find User Custom Datas
                var i = 0;//This is the counter to Updating UI on total Completed So For
                _BaseDatas.ForEach(async res =>
                {
                    var enrollmentRecordInfo = await Task.Run(() =>
                    {
                        try
                        {
                            var enrollmentRecordDetails = new EnrollmentRecord
                            {
                                CustomDatas         = DatabaseOpperations.GetEnrolleeCustomData(res.EnrollmentId),
                                Photograph          = DatabaseOpperations.GetEnrolleePhotoGraph(res.EnrollmentId),
                                FingerprintTemplate = DatabaseOpperations.GetEnrolleeFingerprintTemplate(res.EnrollmentId),
                                FingerprintImages   = DatabaseOpperations.GetEnrolleeFingerprintImages(res.EnrollmentId),
                                Signature           = DatabaseOpperations.GetEnrolleeSignature(res.EnrollmentId)
                            };
                            return(enrollmentRecordDetails);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return(new EnrollmentRecord());
                        }
                    });

                    if (enrollmentRecordInfo == null || !enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"An error was encountered. Data to be synchronised could not be retrieved");
                        return;
                    }

                    enrollmentRecordInfo.BaseData = res;

                    if (!enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised with empty Custom data!");
                        return;
                    }

                    if (!enrollmentRecordInfo.FingerprintImages.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    if (string.IsNullOrEmpty(enrollmentRecordInfo.Photograph?.EnrollmentId))
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    await Task.Run(() => DatabaseOpperations.SynchroniseDataToServer(enrollmentRecordInfo));

                    //5. Update Local Database SyncJobHistoy for specific Record
                    DatabaseOpperations.UpdateDbSyncHistory(syncJobId, res.EnrollmentId);

                    i++; // IncreamentItems Completed Counter
                    if (progress != null)
                    {
                        progress.Report(i);
                    }
                });

                //6. Log Sync End Time for Sync Job
                DatabaseOpperations.CloseSyncJobSession(syncJobId);
                toolStripStatusLabel.Text = @"Sync Job Completed Succesfully";
                labelSyncEndTime.Text     = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(true);
            }
            else
            {
                toolStripStatusLabel.Text = @"No Records to Synchronize. Try Applying a Filter.";
            }
        }