2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
using System.Configuration ;
using System.Linq ;
using System.ServiceModel ;
2016-11-08 13:50:58 +01:00
using System.Text ;
2016-06-27 01:45:38 +02:00
using BeWo.Data.Access ;
using BeWo.Data.Entities ;
using BeWo.Service.Core ;
using BeWo.Service.DCEntityMapper ;
2024-06-19 16:13:56 +02:00
using BeWo.Service.Import.Perseh ;
2016-06-27 01:45:38 +02:00
using BeWo.Service.MessageContracts ;
2017-03-24 10:30:18 +01:00
using BeWo.Service.Plugins ;
2016-06-27 01:45:38 +02:00
using BeWo.Service.ServiceContracts ;
using BS.Shared ;
2025-06-02 12:33:14 +02:00
using BS.Shared.Core ;
2016-06-27 01:45:38 +02:00
using BS.Shared.DataContracts ;
2016-11-08 13:50:58 +01:00
using Utils = BeWo . Service . Core . Utils ;
2016-06-27 01:45:38 +02:00
namespace BeWo.Service.ServiceImplementations
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class StreamingServiceImp : IStreamingService
{
public void DeactivateBeWoFolders ( List < BeWoFolderDC > dcs )
{
try
{
ServiceLogic . SetActivationType < BeWoFolder > ( dcs . ToDictionary ( i = > i . BeWoFolderOid . Value , i = > i . BeWoFolderVersion . Value ) , ActivationTypeId . Deleted ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public List < BeWoFolderDC > GetAllBeWoFolders ( )
{
try
{
return MapperFactory . BeWoFolderDC_BeWoFolder . MapToNewDCs ( DAOFactory . GenericDAO . GetAllActive < BeWoFolder > ( ) ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public List < long > InsertNewBeWoFolders ( List < BeWoFolderDC > dcs )
{
try
{
var newBeWoFolders = MapperFactory . BeWoFolderDC_BeWoFolder . MapToNewEntities ( dcs ) ;
DAOFactory . GenericDAO . Insert ( newBeWoFolders ) ;
return newBeWoFolders . Select ( i = > i . Oid . Value ) . ToList ( ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public void UpdateBeWoFolders ( List < BeWoFolderDC > dcs )
{
try
{
var originals = DAOFactory . GenericDAO . LoadByIDs < BeWoFolder > ( dcs . Select ( i = > i . BeWoFolderOid . Value ) ) ;
MapperFactory . BeWoFolderDC_BeWoFolder . MergeWithEntitys ( dcs , originals ) ;
DAOFactory . GenericDAO . Update ( originals ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public UploadResult UploadDocument ( UploadPackage pUpload )
{
2017-04-25 18:07:24 +02:00
PluginLoader . FindClass < IpAddressChecker > ( ) . CheckIpAddress ( ) ;
2021-03-30 16:35:45 +02:00
var entityData = BS . Shared . Core . Utils . ReadFully ( pUpload . Stream ) ;
2016-06-27 01:45:38 +02:00
var lEntity = new FileAttachment
{
2021-03-30 16:35:45 +02:00
IsLocked = false ,
Path = pUpload . FileName ,
Notice = pUpload . Notice ,
ObjectTid = ( TableID ) pUpload . TableID ,
ObjectOid = pUpload . ObjectOid ,
2016-06-27 01:45:38 +02:00
BeWoFolderOid = pUpload . BeWoFolderOid ,
2021-03-30 16:35:45 +02:00
Type = ( FileAttachmentType ) pUpload . FileAttachmentTypeId
2016-06-27 01:45:38 +02:00
} ;
pUpload . Stream . Close ( ) ;
pUpload . Stream . Dispose ( ) ;
long maxSize = 20 * 1024 * 1024 ;
2021-03-30 16:35:45 +02:00
2016-06-27 01:45:38 +02:00
var maxSizeConfig = ConfigurationManager . AppSettings . Get ( "MaxDocumentSize" ) ;
2021-03-30 16:35:45 +02:00
if ( ! string . IsNullOrEmpty ( maxSizeConfig ) )
2016-06-27 01:45:38 +02:00
{
2021-03-30 16:35:45 +02:00
var s = 0L ;
if ( long . TryParse ( maxSizeConfig , out s ) )
2016-06-27 01:45:38 +02:00
{
maxSize = s ;
}
}
2021-03-30 16:35:45 +02:00
if ( entityData ! = null & & entityData . Length > 0 )
2016-06-27 01:45:38 +02:00
{
2021-03-30 16:35:45 +02:00
if ( entityData . Length > maxSize )
2016-06-27 01:45:38 +02:00
{
throw new FaultException < BeWoFault > ( new BeWoFault (
2021-03-30 16:35:45 +02:00
$"Fehler beim Speichern des Dokuments. Das Dokument überschreitet die maximale erlaubte Größe.\nDie maximale Größe liegt bei {maxSize / (1024 * 1024):0.##} MB" , BeWoFaultType . Unknown ) ) ;
2016-06-27 01:45:38 +02:00
}
2021-03-30 16:35:45 +02:00
2016-06-27 01:45:38 +02:00
DAOFactory . GenericDAO . Insert ( lEntity ) ;
2021-03-30 16:35:45 +02:00
FileAttachmentUtils . SaveFileToFileDirectory ( lEntity , entityData ) ;
2016-06-27 01:45:38 +02:00
}
else
{
throw new FaultException < BeWoFault > ( new BeWoFault ( "Fehler beim Speichern des Dokuments. Das Dokument enthält keine Daten." , BeWoFaultType . Unknown ) ) ;
}
try
{
var a = MapperFactory . FileAttachmentDC_FileAttachmentInfo . MapToNewDC ( DAOFactory . GenericDAO . LoadByID < FileAttachmentInfo > ( lEntity . Oid . Value ) ) ;
return new UploadResult { Attachment = a } ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public UploadResult UpdateDocument ( UpdatePackage pUpload )
{
try
{
2017-04-25 18:07:24 +02:00
PluginLoader . FindClass < IpAddressChecker > ( ) . CheckIpAddress ( ) ;
2016-06-27 01:45:38 +02:00
var pFileId = pUpload . FileOid ;
var original = DAOFactory . GenericDAO . GetByID < FileAttachment > ( pFileId ) ;
original . IsLocked = false ;
original . Path = pUpload . FileName ;
original . Notice = pUpload . Notice ;
original . ObjectTid = ( TableID ) pUpload . TableID ;
original . ObjectOid = pUpload . ObjectOid ;
original . BeWoFolderOid = pUpload . BeWoFolderOid ;
original . Data = BS . Shared . Core . Utils . ReadFully ( pUpload . Stream ) ;
original . Type = ( FileAttachmentType ) pUpload . FileAttachmentTypeId ;
pUpload . Stream . Close ( ) ;
pUpload . Stream . Dispose ( ) ;
if ( original . Data ! = null & & original . Data . Length > 0 )
{
2021-03-30 16:35:45 +02:00
FileAttachmentUtils . SaveFileToFileDirectory ( original ) ;
2016-06-27 01:45:38 +02:00
}
else
{
throw new FaultException < BeWoFault > ( new BeWoFault ( "Fehler beim Speichern des Dokuments. Das Dokument enthält keine Daten." , BeWoFaultType . Unknown ) ) ;
}
return new UploadResult { Attachment = MapperFactory . FileAttachmentDC_FileAttachment . MapToNewDC ( original ) } ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
2016-11-08 13:50:58 +01:00
2017-03-24 10:30:18 +01:00
public UploadImportFileResult UploadImportFile ( UploadPackage upload )
{
try
{
2021-03-30 16:35:45 +02:00
var filename = upload . FileName ;
2017-03-24 10:30:18 +01:00
var daten = BS . Shared . Core . Utils . ReadFully ( upload . Stream ) ;
upload . Stream . Close ( ) ;
upload . Stream . Dispose ( ) ;
var importer = PluginLoader . FindClass < DataImporter > ( ) ;
2021-03-30 16:35:45 +02:00
var result = new UploadImportFileResult
{
ResultMessage = "Die Datei konnte nicht importiert werden."
} ;
2017-03-24 10:30:18 +01:00
if ( importer ! = null )
{
2017-04-03 13:07:06 +02:00
result = importer . ImportData ( filename , daten ) ;
2017-03-24 10:30:18 +01:00
}
2017-04-03 13:07:06 +02:00
return result ;
2017-03-24 10:30:18 +01:00
}
catch ( Exception e )
{
2024-03-03 19:07:45 +01:00
throw Utils . CreateBeWoFaultException ( e ) ;
2025-12-18 23:47:02 +01:00
}
}
public UploadImportFileResult UploadAviseFile ( UploadPackage upload )
{
try
{
var filename = upload . FileName ;
var daten = BS . Shared . Core . Utils . ReadFully ( upload . Stream ) ;
upload . Stream . Close ( ) ;
upload . Stream . Dispose ( ) ;
var importer = PluginLoader . FindClass < DataImporter > ( ) ;
var result = new UploadImportFileResult
{
ResultMessage = "Die Datei konnte nicht importiert werden."
} ;
if ( importer ! = null )
{
DateTime buchungsdatum = DateTime . Now . Date ;
2026-01-09 01:06:18 +01:00
if ( ! String . IsNullOrEmpty ( upload . Notice ) & & DateTime . TryParse ( upload . Notice , out var dt ) )
{
buchungsdatum = dt ;
}
2025-12-18 23:47:02 +01:00
result = importer . ImportAvise ( filename , buchungsdatum , daten ) ;
}
return result ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
2024-03-03 19:07:45 +01:00
2017-03-24 10:30:18 +01:00
}
}
2016-11-08 13:50:58 +01:00
2024-06-19 16:13:56 +02:00
public UploadPersehDocumentResult UploadPersehFile ( UploadPackage upload )
{
try
{
var filename = upload . FileName ;
var daten = BS . Shared . Core . Utils . ReadFully ( upload . Stream ) ;
upload . Stream . Close ( ) ;
upload . Stream . Dispose ( ) ;
var pr = PluginLoader . FindClass < PersehReader > ( ) ;
var result = new UploadPersehDocumentResult ( ) ;
result . HilfeplanImportData = pr . ReadPdfDocument ( daten ) ;
return result ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
2016-11-08 13:50:58 +01:00
public UploadChatResult CreateNewSpeziallStreamChatMessagesDC ( UploadChatPackage istream )
{
try
{
var chatMessage = new ChatMessage
{
EmpfaengerPersonOid = istream . empfängerOid ,
SenderPersonOid = istream . senderOid ,
Uhrzeit = DateTime . Now ,
IsDelivered = istream . isDeliverd ,
2016-11-16 15:46:13 +01:00
ChatText = Encoding . UTF8 . GetBytes ( istream . message ) ,
2016-11-08 13:50:58 +01:00
MediaTyp = istream . mediatype ,
IstGelesen = 0 ,
MessageId = istream . messageid
} ;
2021-03-30 16:35:45 +02:00
2016-11-08 13:50:58 +01:00
if ( istream . teamid ! = 0 )
{
chatMessage . TeamOid = istream . teamid ;
}
else
{
chatMessage . TeamOid = null ;
}
DAOFactory . GenericDAO . Insert ( chatMessage ) ;
2021-03-30 16:35:45 +02:00
var media = BS . Shared . Core . Utils . ReadFully ( istream . Stream ) ;
2016-11-16 15:46:13 +01:00
byte [ ] ThImage = null ;
2016-11-17 14:46:54 +01:00
2016-11-16 15:46:13 +01:00
if ( istream . mediatype = = 1 )
{
2016-11-17 14:46:54 +01:00
ThImage = media ;
2016-11-16 15:46:13 +01:00
}
var chatMediaMessage = new ChatMediaMessage
{
2016-11-17 14:46:54 +01:00
Media = media ,
ImageThumpNail = BS . Shared . Core . Utils . ErstelleThumbnail ( ThImage , 150 , 150 ) ,
2016-11-16 15:46:13 +01:00
ChatMessageOid = chatMessage . Oid
} ;
DAOFactory . GenericDAO . Insert ( chatMediaMessage ) ;
istream . Stream . Close ( ) ;
istream . Stream . Dispose ( ) ;
2016-11-08 13:50:58 +01:00
var result = MapperFactory . ChatMessagesDC_ChatMessages . MapToNewDC ( chatMessage ) ;
2016-11-17 14:46:54 +01:00
result . ImageThumpNail = null ;
2016-11-08 13:50:58 +01:00
//return new UploadChatResult { ChatMessage = MapperFactory.ChatMessagesDC_ChatMessages.MapToNewDC(chatMessage)};
return new UploadChatResult { ChatMessage = result } ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
2016-06-27 01:45:38 +02:00
}
}