Exemple #1
0
 public void ResetGame()
 {
     if (System.Windows.Forms.MessageBox.Show("OPGEPAST: U staat op het punt om een reset te doen, hierdoor kan de laatste wedstrijd niet meer hervat worden! Bent u zeker?", "Vraag", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.No))
     {
         return;
     }
     PhotomanagerFactory.CleanFolder(FolderFactory.ResponseFolder);
     System.Windows.Forms.MessageBox.Show("De wedstrijd werd succesvol gereset.", "Informatie", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
        public void Check()
        {
            ProgressValue = Error = Success = 0;
            IsBusy        = true;
            var bgWorker = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };

            bgWorker.DoWork += (sender, args) =>
            {
                try
                {
                    PhotomanagerFactory.CleanFolder(FolderFactory.ErrorFolder);
                    var mainFolder = new DirectoryInfo(FolderFactory.ErrorFolder);
                    foreach (var subFolder in mainFolder.GetDirectories())
                    {
                        PhotomanagerFactory.CleanFolder(subFolder.FullName);
                    }
                    var resolution = ApplicationSettings.ImageResolution.Split('x');
                    int maxWidth;
                    int maxHeight;
                    if (resolution[0].Equals("Andere"))
                    {
                        maxWidth  = ApplicationSettings.OwnResolutionWidth;
                        maxHeight = ApplicationSettings.OwnResolutionHeight;
                    }
                    else
                    {
                        maxWidth  = int.Parse(resolution[0]);
                        maxHeight = int.Parse(resolution[1]);
                    }
                    for (var indx = 0; indx < FileCounter; indx++)
                    {
                        var errMessage = "";
                        try
                        {
                            ProgressValue++;
                            var img = PhotomanagerFactory.ShowImage(ApplicationSettings.StartFolder, indx);
                            var fi  = new FileInfo(Uri.UnescapeDataString(img.UriSource.AbsolutePath));
                            errMessage = PhotomanagerFactory.IsImageCorrect(CheckFileResolution, CheckFileMembers, fi.Name, maxWidth, maxHeight, img.PixelWidth, img.PixelHeight, MemberSeparator, IsMemberIdNumeric);
                            if (!string.IsNullOrEmpty(errMessage))
                            {
                                throw new Exception("Wrong");
                            }
                            Success++;
                        } catch (Exception ex)
                        {
                            // move to error folder
                            var file       = Directory.GetFiles(ApplicationSettings.StartFolder)[indx];
                            var sourceFile = new FileInfo(file);

                            if (ex.Message.Equals("Wrong"))
                            {
                                if (errMessage != null && errMessage.Contains("WrongResolution"))
                                {
                                    var destinationResolutionFolder = Path.Combine(FolderFactory.ErrorFolder, "Resolution");
                                    if (!Directory.Exists(destinationResolutionFolder))
                                    {
                                        Directory.CreateDirectory(destinationResolutionFolder);
                                    }
                                    var destinationResolutionFile = Path.Combine(destinationResolutionFolder, sourceFile.Name);
                                    File.Copy(file, destinationResolutionFile, true);
                                }

                                if (errMessage != null && errMessage.Contains("WrongMemberFilename"))
                                {
                                    var destinationMemberFolder = Path.Combine(FolderFactory.ErrorFolder, "MemberFile");
                                    if (!Directory.Exists(destinationMemberFolder))
                                    {
                                        Directory.CreateDirectory(destinationMemberFolder);
                                    }
                                    var destinationMemberFile = Path.Combine(destinationMemberFolder, sourceFile.Name);
                                    File.Copy(file, destinationMemberFile, true);
                                }
                            }
                            else
                            {
                                var destinationFolder = Path.Combine(FolderFactory.ErrorFolder);
                                if (!Directory.Exists(destinationFolder))
                                {
                                    Directory.CreateDirectory(destinationFolder);
                                }
                                var destinationFile = Path.Combine(destinationFolder, sourceFile.Name);
                                File.Copy(file, destinationFile, true);
                            }

                            Error++;
                        }
                    }

                    LogFactory.WriteToLog(
                        $"Alle wedstrijdfoto's zijn gecontroleerd. Succes: {Success} - Error: {Error}", "ImageCheckerViewModel.Check",
                        ActivityLogTypes.Success, App.ActivityLogFileName);
                    IsBusy = false;
                    MessageBox.Show($"Alle wedstrijdfoto's zijn gecontroleerd. Succes: {Success} - Error: {Error}", "Informatie",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    LogFactory.WriteToLog(ex.Message, "ImageCheckerViewModel.Check", ActivityLogTypes.Error,
                                          App.ActivityLogFileName);
                    IsBusy = false;
                    MessageBox.Show("Er is een fout opgetreden tijdens het controleren van de fotos.", "Fout",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            };

            bgWorker.RunWorkerAsync();
        }