The synchronization engine relies on a small set of utility classes that handle cross-cutting concerns: structured logging, INI-file configuration reading, OS-level memory management, file copying, console window visibility, and SAP DI-API connectivity. These classes are intentionally lightweight — none of them carry domain logic — and several of them use Windows P/Invoke (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/FCS-Consultores/hechizo-SAP-intercompany/llms.txt
Use this file to discover all available pages before exploring further.
kernel32, kernel32.dll, user32.dll) since the application targets .NET Framework 4.8 on a Windows Server host.
RegistroLog
Namespace:Inter_Hechiz.toolsFile:
Tools/RegistroLog.cs
RegistroLog is an instantiated (non-static) logging class. A single instance is created near the top of most Intercompany methods (static RegistroLog objRegistraLog = new RegistroLog()) and used throughout that method’s lifetime. All three write methods append text to files; they never truncate or overwrite.
Graba
strLog followed by a newline to a date-stamped text file in the Log/ subdirectory next to the executable. The file is named Log_YYYYMMDD.txt based on the current date, so a new file is started automatically at midnight without any scheduler intervention. The Log/ directory is created if it does not exist.
Log path pattern:
C:\Temp\log_fatal.txt.
GrabaJson
Graba in behavior but writes to a separate file named LogJson_YYYYMMDD.txt. This file is used to log raw JSON payloads for debugging Service Layer requests and responses, keeping them separate from the operational log.
Log path pattern:
GrabaProc
strLog to a non-rotating file LogProcesos/LogProc.txt, relative to the current working directory. Unlike Graba and GrabaJson, this file is not date-stamped and grows indefinitely. It is a legacy method retained for compatibility; active code primarily uses Graba. Always returns 0.
IniFile
Namespace:Inter_Hechiz.toolsFile:
Tools/IniFile.cs
IniFile wraps the Windows kernel32 GetPrivateProfileString and WritePrivateProfileString functions via P/Invoke to provide INI-file read/write operations. It is the sole mechanism by which the application reads its configuration — every class that needs a setting constructs an IniFile instance pointing to config.ini in the executable directory.
Constructor
INIPath as ficheroINI. No file I/O occurs at construction time; the path is simply held for use in subsequent read/write calls.
LeerINI
Clave within [Seccion] in the INI file. If the section or key does not exist, returns an empty string. Internally uses a 255-character StringBuilder buffer, so values longer than 254 characters will be silently truncated.
The INI section name, without brackets (e.g.
"ConexionHanaProd").The key name within the section (e.g.
"SERVERNODE").EscribirINI
Valor to [Seccion] > Clave in the INI file. Creates the key if it does not exist. This method is defined but is not called in any active code path — the application is read-only with respect to config.ini at runtime.
Target section name.
Target key name.
Value to write.
LiberaMemoria
Namespace:Inter_HechizFile:
Tools/LiberaMemoria.cs
LiberaMemoria is a utility class that releases .NET managed memory and trims the process working set after large synchronization operations. It is called at the end of the legacy SINCROERROR method and can be invoked anywhere a significant memory release is desired.
FlushMemory
- Calls
GC.Collect()andGC.WaitForPendingFinalizers()to trigger an immediate garbage collection and wait for all finalizers to complete. - On Windows (
PlatformID.Win32NT), callsSetProcessWorkingSetSize(handle, -1, -1)viakernel32.dllP/Invoke to instruct the OS to trim the process working set, returning physical RAM pages to the OS pool.
Passing
-1 for both the minimum and maximum working set size is the documented Windows technique for emptying the working set. The process will re-acquire physical pages as it continues executing; this is a soft release, not a termination.gestorarchivos
Namespace:Inter_Hechiz.ToolsFile:
Tools/gestorarchivos.cs
gestorarchivos is a static file-management helper that copies a named file from a source directory to a destination directory, creating the destination if it does not exist. It exposes a paso status flag that callers can inspect to determine whether the copy succeeded.
MoverArchivo
<rutaOrigen>/<nombreArchivo>.<ext> to <rutaDestino>/<nombreArchivo>.<ext>. The destination directory is created if it does not exist. If the destination file already exists it is overwritten. Sets paso = 1 on success; paso remains 0 if the source directory or file does not exist, or if an exception occurs.
File name without extension (e.g.
"attachment_123").Full path to the source directory (e.g.
@"C:\Attachments\Pending").Full path to the destination directory. Created automatically if it does not exist.
File extension without a leading dot (e.g.
"pdf", "xml").OcultarConsola
Namespace:Inter_Hechiz.toolsFile:
Tools/OcultarConsola.cs
OcultarConsola is a package-private class that hides the console window at application startup. Because the application runs as a scheduled task, leaving the console window visible would create a distracting UI flash each time the task fires. Hiding the window keeps execution invisible to interactive desktop sessions.
DisappearConsole
GetConsoleWindow() (kernel32.dll) and then calls ShowWindow(handle, 0) (user32.dll SW_HIDE) to hide it. The window handle is obtained at call time; the call is a no-op if there is no associated console window.
DisappearConsole hides the window but does not detach the process from its console session. Standard output and error streams remain open. Log output goes to files via RegistroLog, not to the console.ConexionDiapi
Namespace:MCH_IC.ToolsFile:
Tools/ConexionDiapi.cs
ConexionDiapi establishes a direct SAP Business One DI-API (COM SDK) connection for operations that are not available through the REST Service Layer — specifically, attachment creation. An instance is created, Open() is called, and the resulting myCompany object is used for DI-API calls.
Open
[ConexionSap] credentials from config.ini (Server, UserName, Password, DbUserName, DbPassword), configures a SAPbobsCOM.Company object for HANA (dst_HANADB), and calls myCompany.Connect(). The target company database is read from the static field Diapiattachment.bdpublica (set externally before calling Open).
Returns true if Connect() returns error code 0; returns false and logs the SAP error description otherwise. On exception, logs the exception message and returns false.
config.ini keys read by ConexionDiapi.Open
config.ini keys read by ConexionDiapi.Open
| Key | Section | Description |
|---|---|---|
Server | ConexionSap | SAP HANA server address and port |
UserName | ConexionSap | SAP Business One username |
Password | ConexionSap | SAP Business One password |
DbUserName | ConexionSap | HANA database user (currently commented out) |
DbPassword | ConexionSap | HANA database password (currently commented out) |