Example #1
0
        private void GetDirectory(string path)
        {
            try
            {
                SelectedPath = DialogService.OpenFolderDialog(path) ?? path;
            }
            catch (Exception ex)
            {
                var logMessage = $"[{GetType().Name}] Exception at {MethodBase.GetCurrentMethod()}: {ex}";
                Container.Resolve <ILoggerFacade>().Log(logMessage, Category.Exception, Priority.High);

                DialogService.Exception(ex, DialogService.ExceptionType.Universal);
            }
        }
Example #2
0
        [ExcludeFromCodeCoverage] // TODO: could maybe remove after creating a test of this
        private async void StartGeneration()
        {
            var metroDialog = new MetroMessageDisplayService(Container);
            var controller  =
                await metroDialog.ShowProgressAsync(infraProps.Resources.ProgressDialogTitle, infraProps.Resources.ProgressDialogPreviewContent);

            controller.SetIndeterminate();
            controller.SetCancelable(true);

            int sumFiles = SelectedFilesCollection.Count;
            int curFile  = 0;

            controller.Maximum = sumFiles;

            await Task.Delay(250);

            if (!Directory.Exists(PathNames.TempFolderPath))
            {
                Directory.CreateDirectory(PathNames.TempFolderPath);
            }

            foreach (var file in SelectedFilesCollection.Where(file => File.Exists(file.FullFilePath)))
            {
                try
                {
                    var tmpFile = PathNames.TempFolderPath + CharConverterService.ConvertCharsToAscii(file.FileName + EXTENSION);

                    File.Copy(file.FullFilePath, tmpFile, true);

                    await Task.Delay(50);

                    ExternalProgramService.OpenThirdParty("fix3ds.exe", " -m \"" + tmpFile + "\"", PathNames.ThirdPartyPath);

                    await Task.Delay(50);

                    File.Delete(file.FullFilePath);
                    File.Copy(tmpFile, SelectedPath + Path.GetFileName(tmpFile), true);
                    File.SetCreationTime(SelectedPath + Path.GetFileName(tmpFile), DateTime.Now);

                    await Task.Delay(50);

                    controller.SetProgress(++curFile);
                    controller.SetMessage(string.Format(infraProps.Resources.ProgressDialogRunningContent, curFile, sumFiles));

                    await Task.Delay(50);
                }
                catch (Exception ex)
                {
                    var logMessage = $"[{GetType().Name}] Exception at generation: {ex}";
                    Container.Resolve <ILoggerFacade>().Log(logMessage, Category.Exception, Priority.High);

                    DialogService.Exception(ex, DialogService.ExceptionType.Universal);
                }
            }

            await controller.CloseAsync();

            GetFiles();

            if (controller.IsCanceled)
            {
                await metroDialog.ShowMessageAsync(infraProps.Resources.MessageDialogCancelTitle, infraProps.Resources.MessageDialogCancelContent);

                return;
            }

            if (await
                metroDialog.ShowMessageAsync(infraProps.Resources.MessageDialogCompleteTitle,
                                             string.Format(infraProps.Resources.MessageDialogCompleteContent, "\n"),
                                             MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
            {
                ExternalProgramService.OpenExplorer(SelectedPath);
            }

            EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(string.Format(Resources.StatusBarFilesGenerated, sumFiles));
        }
Example #3
0
        /// <summary>Does the generation asynchronous.</summary>
        public async void DoGenerationAsync()
        {
            var metroDialog = new MetroMessageDisplayService(unityContainer);
            var controller  =
                await metroDialog.ShowProgressAsync(infraProps.Resources.ProgressDialogTitle, infraProps.Resources.ProgressDialogPreviewContent);

            controller.SetIndeterminate();
            controller.SetCancelable(true);

            int sumFiles = GenerationFiles.Count;
            int curFile  = 0;

            controller.Maximum = sumFiles;

            await Task.Delay(250);

            foreach (var file in GenerationFiles)
            {
                try
                {
                    var fileToGenerate = file.FullFilePath;
                    var filename       = CharConverterService.ConvertCharsToAscii(file.FileName) + Extension;

                    FileInfo fi = new FileInfo(fileToGenerate);

                    if (File.Exists(fileToGenerate))
                    {
                        var pathForOrig = fi.DirectoryName + suffixPathForOrig;

                        if (!Directory.Exists(pathForOrig))
                        {
                            Directory.CreateDirectory(pathForOrig);
                        }

                        var savedOriginalFile = pathForOrig + file.FileName + Extension;
                        if (!File.Exists(savedOriginalFile))
                        {
                            File.Copy(fileToGenerate, savedOriginalFile, false);
                        }

                        await Task.Delay(50);

                        var imageService = new ImageService();
                        var resizedImage = imageService.ResizeImage(savedOriginalFile, maxWidth, maxHeight, false);
                        resizedImage.Save(fileToGenerate, ImageFormat.Jpeg);
                        resizedImage.Dispose();

                        await Task.Delay(50);

                        fileToGenerate = $@"{fi.DirectoryName}\{filename}";

                        await Task.Delay(50);
                    }

                    if (!file.FullFilePath.Equals($@"{fi.DirectoryName}\{filename}"))
                    {
                        File.Move(file.FullFilePath, fileToGenerate);
                    }

                    await Task.Delay(50);

                    var rgb = File.Exists(fileToGenerate) ? ColorConverterService.GetRgbFromImage(fileToGenerate) : SolidRgb;

                    new GenerateThumbs().DoGeneration(fileToGenerate, rgb, IsFromJpg, ThumbnailService.ShowPreview.No);

                    await Task.Delay(50);

                    var generateFile = new GenerateMatFile(fileToGenerate, rgb, IsFromJpg);
                    generateFile.CreateMatFile();

                    await Task.Delay(50);

                    controller.SetProgress(++curFile);
                    controller.SetMessage(string.Format(infraProps.Resources.ProgressDialogRunningContent, curFile, sumFiles));

                    await Task.Delay(50);
                }
                catch (Exception ex)
                {
                    logMessage = $"[{GetType().Name}] Exception at {MethodBase.GetCurrentMethod()}: {ex}";
                    unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Exception, Priority.High);

                    DialogService.Exception(ex, DialogService.ExceptionType.Universal);
                }
            }

            await controller.CloseAsync();

            eventAggregator.GetEvent <FilesUpdateEvent>().Publish(FileCollection);

            if (controller.IsCanceled)
            {
                await metroDialog.ShowMessageAsync(infraProps.Resources.MessageDialogCancelTitle, infraProps.Resources.MessageDialogCancelContent);

                return;
            }

            if (await
                metroDialog.ShowMessageAsync(infraProps.Resources.MessageDialogCompleteTitle,
                                             string.Format(infraProps.Resources.MessageDialogCompleteContent, "\n"),
                                             MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
            {
                ExternalProgramService.OpenExplorer(SelectedPath);
            }

            eventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(string.Format(Resources.StatusBarFilesGenerated, sumFiles));

            logMessage = $"[{GetType().Name}] MatFileGeneration completed";
            unityContainer.Resolve <ILoggerFacade>().Log(logMessage, Category.Debug, Priority.None);
        }