221 lines
8.0 KiB
C#
221 lines
8.0 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Core.Procs.Interfaces;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Interfaces;
|
|
using Sarand.Net.Standard.Base.ItemOptions;
|
|
using Sarand.Net.Standard.Base.Procs;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Consoles
|
|
{
|
|
//=======================================================================
|
|
public class SbmProcessConsole
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// I n t e r f a c e O p t i o n D e f i n i t i o n s
|
|
//-------------------------------------------------------------------
|
|
public static List<SaItemOptionDfn> GetInterfaceItemOptionDfns(ISbmUserOrganisationContext userContext, SaInterfaceCategory interfaceCategory, short interfaceType)
|
|
{
|
|
switch (interfaceCategory)
|
|
{
|
|
case SaInterfaceCategory.Website:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Accounts:
|
|
{
|
|
return new SbmAccountsDfn(userContext).GetInterfaceItemOptionDfns((Sbm.InterfaceType_Accounts)interfaceType);
|
|
}
|
|
case SaInterfaceCategory.System:
|
|
{
|
|
//if (interfaceType == (int)Sbm.InterfaceType_System.MSOutlook)
|
|
//return SbmInterface_System_MSOutlook.GetInterfaceItemOptionDfns();
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.File:
|
|
{
|
|
if (interfaceType == (short)Sbm.InterfaceType_File.CommodityExport)
|
|
{
|
|
SbmInterfaceProcess_Commodity_Export.Config processConfig = new SbmInterfaceProcess_Commodity_Export.Config(userContext);
|
|
SbmInterfaceProcess_Commodity_Export process = new SbmInterfaceProcess_Commodity_Export(processConfig);
|
|
return process.GetInterfaceItemOptionDfns();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return new List<SaItemOptionDfn>();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P r o c e s s i n g O p t i o n s
|
|
//-------------------------------------------------------------------
|
|
public static List<SaProcess_Base.GroupData> GetProcessingOptions(ISbmUserOrganisationContext userContext, SaInterface interfaceObj)
|
|
{
|
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return new List<SaProcess_Base.GroupData>();
|
|
List<SaProcess_Base.GroupData> optionGroups = null;
|
|
switch (interfaceObj.Category)
|
|
{
|
|
case SaInterfaceCategory.System:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Website:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Accounts:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.File:
|
|
{
|
|
if (interfaceObj.Type == (short)Sbm.InterfaceType_File.CommodityExport)
|
|
optionGroups = SbmInterfaceProcess_Commodity_Export.GetProcessingOptions(userContext, interfaceObj);
|
|
break;
|
|
}
|
|
}
|
|
return optionGroups ?? new List<SaProcess_Base.GroupData>();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n f i g u r e P r o c e s s
|
|
//-------------------------------------------------------------------
|
|
public static SbmInterfaceProcess ConfigureProcess(ISbmUserOrganisationContext userContext, SaInterface interfaceObj, SaProcess_Base.GroupData processGroup)
|
|
{
|
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return null;
|
|
switch (interfaceObj.Category)
|
|
{
|
|
case SaInterfaceCategory.System:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Website:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Accounts:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.File:
|
|
{
|
|
if (interfaceObj.Type == (short)Sbm.InterfaceType_File.CommodityExport)
|
|
return SbmInterfaceProcess_Commodity_Export.ConfigureProcess(userContext, interfaceObj, processGroup);
|
|
break;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P r o c e s s I n t e r f a c e
|
|
//-------------------------------------------------------------------
|
|
public static bool ProcessInterface(ISbmUserOrganisationContext userContext, SaInterface interfaceObj)
|
|
{
|
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return false;
|
|
switch (interfaceObj.Category)
|
|
{
|
|
case SaInterfaceCategory.System:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Website:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.Accounts:
|
|
{
|
|
break;
|
|
}
|
|
case SaInterfaceCategory.File:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n v o k e P r o c e s s D e f i n i t i o n
|
|
//-------------------------------------------------------------------
|
|
// Invoke process based on definition from command line argument.
|
|
public static bool InvokeProcessDefinition(ISbmUserOrganisationContext userContext, SacsProcessDefinition processDfn)
|
|
{
|
|
//----------------------------------------------------------------
|
|
// Log process definition.
|
|
SaLogger.Info("Running process: " + processDfn.ProcessName + "." + (processDfn.Params.Count > 0 ? " Params: " + processDfn.Params.Concat() : ""), true);
|
|
|
|
//----------------------------------------------------------------
|
|
// Hapag-Lloyd EDI.
|
|
if (processDfn.ProcessName.EqualsCI("ApplicationParameterName..."))
|
|
{
|
|
String caption = "System Interface ...";
|
|
SaInterface saInterface = GetSystemInterfaceByType(userContext, (short)Sbm.InterfaceType_System.MSOutlook, caption);
|
|
if (saInterface != null)
|
|
{
|
|
/*
|
|
SbmInterface_System_HapagLloyd_Import.Config configInterface = new SbmInterface_System_HapagLloyd_Import.Config(dbUpdateInfo);
|
|
configInterface.InterfaceId = saInterface.Id;
|
|
configInterface.ImportNotifications = true;
|
|
configInterface.Automated = true;
|
|
SbmInterface_System_HapagLloyd_Import process = new SbmInterface_System_HapagLloyd_Import(configInterface);
|
|
process.RunProcess();
|
|
if (process.HasProcessError())
|
|
SaLogger.Warn(caption + " reported: " + process.GetProcessError(), true);
|
|
else if (process.IsInterrupted)
|
|
SaLogger.Warn(caption + " interrupted - processing may be incomplete.", true);
|
|
else
|
|
SaLogger.Info(caption + " run successfully", true);
|
|
*/
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve interface.
|
|
private static SaInterface GetSystemInterfaceByType(ISbmUserOrganisationContext userContext, short interfaceType, String caption)
|
|
{
|
|
return GetInterfaceByCategoryType(userContext, SaInterfaceCategory.System, interfaceType, caption);
|
|
}
|
|
private static SaInterface GetInterfaceByCategoryType(ISbmUserOrganisationContext userContext, SaInterfaceCategory interfaceCategory, short interfaceType, String caption)
|
|
{
|
|
SaInterface saInterface = null;
|
|
SaInterface.Params prmInterface = new SaInterface.Params();
|
|
prmInterface.InterfaceCategory = interfaceCategory;
|
|
prmInterface.IncludedInterfaceTypes.Add(interfaceType);
|
|
prmInterface.StatusCat = SaInterface.StatusCat.Any;
|
|
using (SaInterfaceConsole interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(userContext))
|
|
{
|
|
saInterface = interfaceConsole.GetInterface(prmInterface);
|
|
if (saInterface == null)
|
|
{
|
|
SaLogger.Warn("Unable to run " + caption + " - Interface not found", true);
|
|
return null;
|
|
}
|
|
if (!saInterface.Active)
|
|
{
|
|
SaLogger.Warn("Unable to run " + caption + " - Interface is not active", true);
|
|
return null;
|
|
}
|
|
}
|
|
return saInterface;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|