Skip to content

Commit

Permalink
Last changes commited. Project was suspended.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcota committed Sep 24, 2021
1 parent 857b9aa commit 8a355bb
Show file tree
Hide file tree
Showing 10 changed files with 896 additions and 37 deletions.
221 changes: 221 additions & 0 deletions Land.Core/Media/Domain/ImageProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/* Empiria Land **********************************************************************************************
* *
* Solution : Empiria Land System : Land Registration System *
* Namespace : Empiria.Land.Documentation Assembly : Empiria.Land.Documentation *
* Type : ImageProcessor Pattern : Domain Service *
* Version : 3.0 License : Please read license.txt file *
* *
* Summary : It is the responsible of the image processing service. *
* *
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/
using System;
using System.Collections.Generic;
using System.IO;

using Empiria.Documents.IO;

namespace Empiria.Land.Media {

/// <summary>It is the responsible of the image processing service.</summary>
static public class ImageProcessor {

#region Fields

static readonly int maxFilesToProcess = ConfigurationData.GetInteger("ImageProcessor.MaxFilesToProcess");

#endregion Fields

#region Public properties

static private string _errorsFolderPath = null;
static public string ErrorsFolderPath {
get {
if (_errorsFolderPath == null) {
_errorsFolderPath = GetImagingFolder("ImageProcessor.ErrorsFolderPath");
}
return _errorsFolderPath;
}
}

static private string _mainFolderPath = null;
static public string MainFolderPath {
get {
if (_mainFolderPath == null) {
_mainFolderPath = GetImagingFolder("ImageProcessor.MainFolderPath");
}
return _mainFolderPath;
}
}

static private string _substitutionsFolderPath = null;
static public string SubstitutionsFolderPath {
get {
if (_substitutionsFolderPath == null) {
_substitutionsFolderPath = GetImagingFolder("ImageProcessor.SubstitutionsFolderPath");
}
return _substitutionsFolderPath;
}
}

#endregion Public properties

#region Public methods

//static internal CandidateImage[] GetImagesToProcess() {
// CandidateImage[] files = ImageProcessor.GetImagesToProcess(ImageProcessor.SubstitutionsFolderPath, true);
// if (files.Length != 0) {
// return files;
// }

// return ImageProcessor.GetImagesToProcess(ImageProcessor.MainFolderPath, false);
//}

private static void CleanFolders(string rootPath) {
FileServices.DeleteEmptyDirectories(rootPath);
}

#endregion Public methods

#region Private methods

static private void AssertFileExists(string sourceFileName) {
if (!File.Exists(sourceFileName)) {
Assertion.AssertFail(new LandMediaException(LandMediaException.Msg.FileNotExists,
sourceFileName));
}
}


static void DeleteSourceFolderIfEmpty(string sourceFolderToDelete) {
if (sourceFolderToDelete != MainFolderPath) {
FileServices.DeleteWhenIsEmpty(sourceFolderToDelete);
}
}

internal static FileInfo[] GetImagesToProcess() {
throw new NotImplementedException();
}

internal static void ProcessMediaFile(FileInfo image) {
throw new NotImplementedException();
}


//static private CandidateImage[] GetImagesToProcess(string rootFolderPath, bool replaceDuplicated) {
// FileInfo[] filesInDirectory = FileServices.GetFiles(rootFolderPath);

// MediaFilesProcessorAuditTrail.LogText("Se leyeron " + filesInDirectory.Length +
// " archivos del directorio " + rootFolderPath);
// MediaFilesProcessorAuditTrail.LogText("Revisando y descartando archivos previo al procesamiento ...\n");
// var candidateImages =
// new List<CandidateImage>(Math.Min(filesInDirectory.Length, maxFilesToProcess));
// foreach (FileInfo file in filesInDirectory) {
// var candidate = CandidateImage.Parse(file);
// try {
// candidate.AssertCanBeProcessed(replaceDuplicated);

// candidateImages.Add(candidate);
// if (candidateImages.Count > maxFilesToProcess) {
// break;
// }
// } catch (Exception exception) {
// SendCandidateImageToErrorsBin(candidate, exception);
// }
// } // foreach
// return candidateImages.ToArray();
//}


static private string GetImagingFolder(string folderName) {
string path = ConfigurationData.GetString(folderName);

path = path.TrimEnd('\\');

if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
MediaFilesProcessorAuditTrail.LogText("MSG: Se creó el directorio '" + path + "'");
}
return path;
}


static private string ReplaceImagingFolder(string folderPath, string replacedPath) {
if (folderPath.StartsWith(ImageProcessor.ErrorsFolderPath)) {
return folderPath.Replace(ImageProcessor.ErrorsFolderPath, replacedPath);
}

if (folderPath.StartsWith(ImageProcessor.MainFolderPath)) {
return folderPath.Replace(ImageProcessor.MainFolderPath, replacedPath);
}

if (folderPath.StartsWith(ImageProcessor.SubstitutionsFolderPath)) {
return folderPath.Replace(ImageProcessor.SubstitutionsFolderPath, replacedPath);
}

throw Assertion.AssertNoReachThisCode(folderPath + " doesn't start with a recognized path pattern.");
}


//static private void SendCandidateImageToErrorsBin(CandidateImage image, Exception exception) {
// string sourceFolderPath = image.SourceFile.DirectoryName;
// try {
// var destinationFolder = ReplaceImagingFolder(sourceFolderPath,
// ImageProcessor.ErrorsFolderPath + GetSpecialErrorFolder(exception));

// FileServices.MoveFileTo(image.SourceFile, destinationFolder);

// MediaFilesProcessorAuditTrail.LogException(image, exception, GetShortExceptionMessage(exception),
// "ERR: " + image.SourceFile.Name +
// " se envió a la bandeja de errores debido a:\n\t" + exception.Message + "\n\t" +
// "Origen: " + sourceFolderPath + "\n\t" +
// "Destino: " + destinationFolder);

// DeleteSourceFolderIfEmpty(sourceFolderPath);
// } catch (Exception e) {
// MediaFilesProcessorAuditTrail.LogException(image, exception, GetShortExceptionMessage(exception),
// "ERR: " + image.SourceFile.Name + " no se pudo procesar debido a:\n\t" +
// exception.Message + "\n\t" +
// "Tampoco se pudo enviar a la bandeja de errores por:\n\t" + e.Message + "\n\t" +
// "Origen: " + sourceFolderPath);
// }
//}

private static string GetShortExceptionMessage(Exception exception) {
if (!(exception is LandMediaException)) {
return exception.Message;
}
string exceptionTag = ((LandMediaException) exception).ExceptionTag;

if (exceptionTag == LandMediaException.Msg.FileNameBadFormed.ToString()) {
return "Archivo mal nombrado";
} else if (exceptionTag == LandMediaException.Msg.DocumentAlreadyDigitalized.ToString()) {
return "Ya fue digitalizado";
} else if (exceptionTag == LandMediaException.Msg.DocumentForFileNameNotFound.ToString()) {
return "El documento registral no existe";
} else {
return exception.Message;
}
}

private static string GetSpecialErrorFolder(Exception exception) {
if (!(exception is LandMediaException)) {
return @"\otros.errores";
}
string exceptionTag = ((LandMediaException) exception).ExceptionTag;

if (exceptionTag == LandMediaException.Msg.FileNameBadFormed.ToString()) {
return @"\mal.nombrados";
} else if (exceptionTag == LandMediaException.Msg.DocumentAlreadyDigitalized.ToString()) {
return @"\duplicados";
} else if (exceptionTag == LandMediaException.Msg.DocumentForFileNameNotFound.ToString()) {
return @"\sin.documento";
} else {
return @"\otros.errores";
}
}

#endregion Private methods

} // class ImageProcessor

} // namespace Empiria.Land.Documentation
70 changes: 70 additions & 0 deletions Land.Core/Media/Domain/LandMediaException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Empiria Land **********************************************************************************************
* *
* Solution : Empiria Land System : Land Registration System *
* Namespace : Empiria.Land.Documentation Assembly : Empiria.Land.Documentation *
* Type : LandMediaException Pattern : Exception Class *
* Version : 3.0 License : Please read license.txt file *
* *
* Summary : The exception that is thrown when a problem occurs in Empiria Land documentation services. *
* *
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/
using System;
using System.Reflection;

namespace Empiria.Land.Media {

/// <summary>The exception that is thrown when a problem occurs in Empiria Land
/// documentation services.</summary>
[Serializable]
public sealed class LandMediaException : EmpiriaException {

public enum Msg {
AttachmentFolderNotFound,
DocumentAlreadyDigitalized,
DocumentForFileNameNotFound,
FileNameBadFormed,
FileNotExists,
FolderNameBadFormed,
ImagingFolderNotExists,
InvalidImagePosition,
InvalidRecordingImageRange,
RecordingBookForFolderNameNotFound,
}

static private string resourceBaseName =
"Empiria.Land.Core.RootTypes.LandMediaException";

#region Constructors and parsers

/// <summary>Initializes a new instance of LandDocumentationException class with a specified error
/// message.</summary>
/// <param name="message">Used to indicate the description of the exception.</param>
/// <param name="args">An optional array of objects to format into the exception message.</param>
public LandMediaException(Msg message, params object[] args) :
base(message.ToString(), GetMessage(message, args)) {

}

/// <summary>Initializes a new instance of LandDocumentationException class with a specified error
/// message and a reference to the inner exception that is the cause of this exception.</summary>
/// <param name="message">Used to indicate the description of the exception.</param>
/// <param name="innerException">This is the inner exception.</param>
/// <param name="args">An optional array of objects to format into the exception message.</param>
public LandMediaException(Msg message, Exception innerException, params object[] args) :
base(message.ToString(), GetMessage(message, args), innerException) {

}

#endregion Constructors and parsers

#region Private methods

static private string GetMessage(Msg message, params object[] args) {
return GetResourceMessage(message.ToString(), resourceBaseName, Assembly.GetExecutingAssembly(), args);
}

#endregion Private methods

} // class LandMediaException

} // namespace Empiria.Land.Documentation
Loading

0 comments on commit 8a355bb

Please sign in to comment.