From 6d9e32cc9f3d2de8fb062cf57ac156a71bb57477 Mon Sep 17 00:00:00 2001 From: Roland Bengtsson Date: Sat, 7 Dec 2024 20:39:50 +0200 Subject: [PATCH] Removed unit BoldOSSMessage #24 --- Source/BoldOSSMessage.pas | 237 ------------------ Source/BoldSnooper.pas | 10 +- .../BORepresentation/BoldOSSMessage.pas | 171 ------------- 3 files changed, 5 insertions(+), 413 deletions(-) delete mode 100644 Source/BoldOSSMessage.pas delete mode 100644 Source/ObjectSpace/BORepresentation/BoldOSSMessage.pas diff --git a/Source/BoldOSSMessage.pas b/Source/BoldOSSMessage.pas deleted file mode 100644 index e437cf2e..00000000 --- a/Source/BoldOSSMessage.pas +++ /dev/null @@ -1,237 +0,0 @@ - -{ Global compiler directives } -{$include bold.inc} -unit BoldOSSMessage; - -interface -{.$DEFINE CRCOSSMESSAGES} - -uses - Classes; // for TPersistent -// BoldDefs; // for TBoldTimeStampType - -const - cOSSMessageSync = 'SYNC'; - cOSSMessageFail = 'FAIL'; - -type - TSessionId = Int64; - TBoldTimeStampType = integer; // copy from BoldDefs - TBoldOSSMessageType = (mtSync, mtFail); - TDateTimeMS = TDateTime; - - TBoldOSSMessage = class(TInterfacedPersistent) - private - fMessageType: TBoldOSSMessageType; - fEvents: string; - fBoldTimeStamp: TBoldTimeStampType; - fTimeOfTimeStamp: TDateTimeMS; - fClientSendTime: TDateTimeMS; - fUser: string; - fApplication: string; - fComputer: string; - fModelCRC: string; - function GetAsString: string; - procedure SetAsString(const Value: string); -{$IFDEF CRCOSSMESSAGES} - function GetCrc: Cardinal; -{$ENDIF} - function GetDataLength: Integer; - protected - procedure AssignTo(Dest: TPersistent); override; - public - constructor Create; overload; - constructor Create( - AMessageType: TBoldOSSMessageType; - AEvents: string; - AModelCRC: string; - ABoldTimeStamp: TBoldTimeStampType; - ATimeOfTimeStamp: TDateTimeMS; - AClientSendTime: TDateTimeMS; - AUser: string = ''; - AComputer: string = ''; - AApplication: string = ''); overload; - constructor Create(AJSON: string); overload; - destructor Destroy; override; - function Clone: TBoldOSSMessage; - property AsString: string read GetAsString write SetAsString; - published - property MessageType: TBoldOSSMessageType read fMessageType; - property Events: string read fEvents; - property ModelCRC: string read fModelCRC; - property BoldTimeStamp: TBoldTimeStampType read fBoldTimeStamp; - property TimeOfTimeStamp: TDateTimeMS read fTimeOfTimeStamp; - property ClientSendTime: TDateTimeMS read fClientSendTime; - // writeable properties, can be sent blank and filled in by service - property Computer: string read fComputer write fComputer; - property Application: string read fApplication write fApplication; - property User: string read fUser write fUser; - property DataLength: Integer read GetDataLength; -{$IFDEF CRCOSSMESSAGES} - property Crc: Cardinal read GetCrc; -{$ENDIF} - end; - -implementation - -uses - System.SysUtils, - BoldIsoDateTime, - System.JSON, - System.JSON.Writers, - System.JSON.Readers, - TypInfo; - -{$IFDEF CRCOSSMESSAGES} -function CRCHash(const S: string): CARDINAL; -var - i: integer; -begin - Result := 0; - for i := 1 to Length(S) do - Result := ((Result shl 3) and 2147483647) or - (Result shr (32-3)) xor ord(S[i]); -end; - -function SumCRCs(CRC1, CRC2: Cardinal): Cardinal; -begin - result := ((CRC1 shl 3) and 2147483647) or - (CRC1 shr (32-3)) xor CRC2; -end; -{$ENDIF} - -{ TBoldOSSMessage } - -constructor TBoldOSSMessage.Create; -begin - inherited; -end; - -destructor TBoldOSSMessage.Destroy; -begin - inherited; -end; - -function TBoldOSSMessage.GetAsString: string; -var - JSONObject: TJSONObject; -begin - JSONObject := TJSONObject.Create; - try - JSONObject.AddPair('MessageType', String((GetEnumName(TypeInfo(TBoldOSSMessageType), Ord(MessageType))))); - JSONObject.AddPair('ModelCRC', ModelCRC); - JSONObject.AddPair('BoldTimeStamp', IntToStr(BoldTimeStamp)); - JSONObject.AddPair('BoldTimeOfTimeStamp', AsISODateTimeMS(TimeOfTimeStamp)); - JSONObject.AddPair('SendTime', AsISODateTimeMS(ClientSendTime)); - JSONObject.AddPair('User', User); - JSONObject.AddPair('Computer', Computer); - JSONObject.AddPair('Application', Application); - JSONObject.AddPair('Events', Events); - JSONObject.AddPair('DataLength', IntToStr(DataLength)); -{$IFDEF CRCOSSMESSAGES} - JSONObject.AddPair('Crc', UIntToStr(Crc)); -{$ENDIF} - result := JSONObject.ToString; - finally - JSONObject.free; - end; -end; - -{$IFDEF CRCOSSMESSAGES} -function TBoldOSSMessage.GetCrc: Cardinal; -begin - result := CRCHash(Events); -end; -{$ENDIF} - -function TBoldOSSMessage.GetDataLength: Integer; -begin - result := Length(Events); -end; - -procedure TBoldOSSMessage.SetAsString(const Value: string); -var - JSONObject: TJSONObject; - s: string; -begin - JSONObject:= TJSONObject.ParseJSONValue(Value) as TJSONObject; - try - s := JSONObject.GetValue('MessageType').Value; - if s = 'mtSync' then - fMessageType := mtSync - else - if s = 'mtFail' then - fMessageType := mtFail - else - raise Exception.Create('Unknown MessageType'); - fModelCRC := JSONObject.GetValue('ModelCRC').Value; - fBoldTimeStamp := StrToInt(JSONObject.GetValue('BoldTimeStamp').Value); - fTimeOfTimeStamp := ParseISODateTime(JSONObject.GetValue('BoldTimeOfTimeStamp').Value); - fClientSendTime := ParseISODateTime(JSONObject.GetValue('SendTime').Value); - fUser := JSONObject.GetValue('User').Value; - fComputer := JSONObject.GetValue('Computer').Value; - fApplication := JSONObject.GetValue('Application').Value; - fEvents := JSONObject.GetValue('Events').Value; - s := JSONObject.GetValue('DataLength').Value; - if s.ToInteger <> DataLength then - raise Exception.CreateFmt('Message length mismatch, expected %s received %d', [s, DataLength]); -{$IFDEF CRCOSSMESSAGES} - s := JSONObject.GetValue('Crc').Value; - if s.ToInteger <> Crc then - raise Exception.CreateFmt('Message CRC mismatch, expected %s received %d', [s, Crc]); -{$ENDIF} - finally - JSONObject.Free; - end; -end; - -constructor TBoldOSSMessage.Create(AMessageType: TBoldOSSMessageType; AEvents: string; - AModelCRC: string; - ABoldTimeStamp: TBoldTimeStampType; ATimeOfTimeStamp, - AClientSendTime: TDateTimeMS; - AUser: string; AComputer: string; AApplication: string); -begin - fMessageType := AMessageType; - fEvents := AEvents; - fModelCRC := AModelCRC; - fBoldTimeStamp := ABoldTimeStamp; - fTimeOfTimeStamp := ATimeOfTimeStamp; - fClientSendTime := AClientSendTime; - fUser := AUser; - fComputer := AComputer; - fApplication := AApplication; -end; - -procedure TBoldOSSMessage.AssignTo(Dest: TPersistent); -begin - if Dest is TBoldOSSMessage then - with Dest as TBoldOSSMessage do - begin - fMessageType := self.fMessageType; - fEvents := self.fEvents; - fModelCRC := self.fModelCRC; - fBoldTimeStamp := self.fBoldTimeStamp; - fTimeOfTimeStamp := self.fTimeOfTimeStamp; - fClientSendTime := self.fClientSendTime; - fApplication := self.fApplication; - fUser := self.fUser; - fComputer := self.fComputer; - end - else - inherited; -end; - -function TBoldOSSMessage.Clone: TBoldOSSMessage; -begin - result := TBoldOSSMessage.Create; - self.AssignTo(result); -end; - -constructor TBoldOSSMessage.Create(AJSON: string); -begin - inherited Create; - AsString := AJSon; -end; - -end. - diff --git a/Source/BoldSnooper.pas b/Source/BoldSnooper.pas index 3c26f79e..70e04a33 100644 --- a/Source/BoldSnooper.pas +++ b/Source/BoldSnooper.pas @@ -6,6 +6,7 @@ interface uses + Classes, BoldAbstractSnooper, BoldPropagatorInterfaces_TLB, BoldDefs, @@ -42,7 +43,6 @@ implementation uses Sysutils, Variants, - Classes, BoldPropagatorConstants, BoldLockingDefs, BoldUtils, @@ -82,10 +82,10 @@ procedure TBoldSnooper.TransmitEvents(const ClientID: TBoldClientID); try if (Events.Count <> 0) then CheckError(Propagator.SendEvents(ClientID, StringListToVarArray(Events)), 'SendEvents'); - if (Subscriptions.Count <> 0) then - CheckError(Propagator.AddSubscriptions(ClientID, StringListToVarArray(Subscriptions)), 'AddSubscriptions'); - if (CancelledSubscriptions.Count <> 0) then - CheckError(Propagator.CancelSubscriptions(ClientID, StringListToVarArray(CancelledSubscriptions)), 'CancelSubscriptions'); +// if (Subscriptions.Count <> 0) then +// CheckError(Propagator.AddSubscriptions(ClientID, StringListToVarArray(Subscriptions)), 'AddSubscriptions'); +// if (CancelledSubscriptions.Count <> 0) then +// CheckError(Propagator.CancelSubscriptions(ClientID, StringListToVarArray(CancelledSubscriptions)), 'CancelSubscriptions'); except on E: EOleSysError do DoPropagatorFailure(self, E.Message); end; diff --git a/Source/ObjectSpace/BORepresentation/BoldOSSMessage.pas b/Source/ObjectSpace/BORepresentation/BoldOSSMessage.pas deleted file mode 100644 index c61b044b..00000000 --- a/Source/ObjectSpace/BORepresentation/BoldOSSMessage.pas +++ /dev/null @@ -1,171 +0,0 @@ - -{ Global compiler directives } -{$include bold.inc} -unit BoldOSSMessage; - -interface - -uses - Classes; // for TPersistent -// BoldDefs; // for TBoldTimeStampType - -const - cOSSMessageSync = 'SYNC'; - cOSSMessageFail = 'FAIL'; - -type - TSessionId = Int64; - TBoldTimeStampType = integer; // copy from BoldDefs - TBoldOSSMessageType = (mtSync, mtFail); - TDateTimeMS = TDateTime; - - TBoldOSSMessage = class(TInterfacedPersistent) - private - fMessageType: TBoldOSSMessageType; - fEvents: string; - fBoldTimeStamp: TBoldTimeStampType; - fTimeOfTimeStamp: TDateTimeMS; - fClientSendTime: TDateTimeMS; - fUser: string; - fApplication: string; - fComputer: string; - function GetAsString: string; - procedure SetAsString(const Value: string); - protected - procedure AssignTo(Dest: TPersistent); override; - public - constructor Create; overload; - constructor Create( - AMessageType: TBoldOSSMessageType; - AEvents: string; - ABoldTimeStamp: TBoldTimeStampType; - ATimeOfTimeStamp: TDateTimeMS; - AClientSendTime: TDateTimeMS; - AUser: string = ''; - AComputer: string = ''; - AApplication: string = ''); overload; - destructor Destroy; override; - function Clone: TBoldOSSMessage; - property AsString: string read GetAsString write SetAsString; - published - property MessageType: TBoldOSSMessageType read fMessageType; - property Events: string read fEvents; - property BoldTimeStamp: TBoldTimeStampType read fBoldTimeStamp; - property TimeOfTimeStamp: TDateTimeMS read fTimeOfTimeStamp; - property ClientSendTime: TDateTimeMS read fClientSendTime; - // writeable properties, can be sent blank and filled in by service - property Computer: string read fComputer write fComputer; - property Application: string read fApplication write fApplication; - property User: string read fUser write fUser; - end; - -implementation - -uses - System.SysUtils, - BoldIsoDateTime, - System.JSON, - System.JSON.Writers, - System.JSON.Readers, - TypInfo; - -{ TBoldOSSMessage } - -constructor TBoldOSSMessage.Create; -begin - inherited; -end; - -destructor TBoldOSSMessage.Destroy; -begin - inherited; -end; - -function TBoldOSSMessage.GetAsString: string; -var - JSONObject,t1: TJSONObject; -begin - JSONObject := TJSONObject.Create; - try - JSONObject.AddPair('MessageType', String((GetEnumName(TypeInfo(TBoldOSSMessageType), Ord(MessageType))))); - JSONObject.AddPair('BoldTimeStamp', IntToStr(BoldTimeStamp)); - JSONObject.AddPair('BoldTimeOfTimeStamp', AsISODateTimeMS(TimeOfTimeStamp)); - JSONObject.AddPair('SendTime', AsISODateTimeMS(ClientSendTime)); - JSONObject.AddPair('User', User); - JSONObject.AddPair('Computer', Computer); - JSONObject.AddPair('Application', Application); - JSONObject.AddPair('Events', Events); - result := JSONObject.ToString; - finally - JSONObject.free; - end; -end; - -procedure TBoldOSSMessage.SetAsString(const Value: string); -var - JSONObject: TJSONObject; - s: string; -begin - JSONObject:= TJSONObject.ParseJSONValue(Value) as TJSONObject; - try - s := JSONObject.GetValue('MessageType').Value; - if s = 'mtSync' then - fMessageType := mtSync - else - if s = 'mtFail' then - fMessageType := mtFail - else - raise Exception.Create('Unknown MessageType'); - fBoldTimeStamp := StrToInt(JSONObject.GetValue('BoldTimeStamp').Value); - fTimeOfTimeStamp := ParseISODateTime(JSONObject.GetValue('BoldTimeOfTimeStamp').Value); - fClientSendTime := ParseISODateTime(JSONObject.GetValue('SendTime').Value); - fUser := JSONObject.GetValue('User').Value; - fComputer := JSONObject.GetValue('Computer').Value; - fApplication := JSONObject.GetValue('Application').Value; - fEvents := JSONObject.GetValue('Events').Value; - finally - JSONObject.Free; - end; -end; - -constructor TBoldOSSMessage.Create(AMessageType: TBoldOSSMessageType; AEvents: string; - ABoldTimeStamp: TBoldTimeStampType; ATimeOfTimeStamp, - AClientSendTime: TDateTimeMS; - AUser: string; AComputer: string; AApplication: string); -begin - fMessageType := AMessageType; - fEvents := AEvents; - fBoldTimeStamp := ABoldTimeStamp; - fTimeOfTimeStamp := ATimeOfTimeStamp; - fClientSendTime := AClientSendTime; - fUser := AUser; - fComputer := AComputer; - fApplication := AApplication; -end; - -procedure TBoldOSSMessage.AssignTo(Dest: TPersistent); -begin - if Dest is TBoldOSSMessage then - with Dest as TBoldOSSMessage do - begin - fMessageType := self.fMessageType; - fEvents := self.fEvents; - fBoldTimeStamp := self.fBoldTimeStamp; - fTimeOfTimeStamp := self.fTimeOfTimeStamp; - fClientSendTime := self.fClientSendTime; - fApplication := self.fApplication; - fUser := self.fUser; - fComputer := self.fComputer; - end - else - inherited; -end; - -function TBoldOSSMessage.Clone: TBoldOSSMessage; -begin - result := TBoldOSSMessage.Create; - self.AssignTo(result); -end; - -end. -