📄 jvqschedevtstore.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
Project JEDI Visible Component Library (J-VCL)
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Marcel Bestebroer
<marcelb@zeelandnet.nl>.
Portions created by Marcel Bestebroer are Copyright (C) 2000 - 2002 mbeSoft.
All Rights Reserved.
******************************************************************************
Persistency layer for JvScheduledEvents
You may retrieve the latest version of this file at the Project JEDI home
page, located at http://www.delphi-jedi.org
-----------------------------------------------------------------------------}
// $Id: JvQSchedEvtStore.pas,v 1.5 2004/05/26 15:19:27 asnepvangers Exp $
{$I jvcl.inc}
unit JvQSchedEvtStore;
interface
uses
Classes,
JvQScheduledEvents;
type
TSchedEvtStoreAttribute = (sesaStructured, sesaIdentifiers);
TSchedEvtStoreAttributes = set of TSchedEvtStoreAttribute;
TSchedEvtStructKind =
(seskState, seskEvent, seskSchedule, seskScheduleRecurInfo,
seskScheduleEndInfo, seskScheduleDayFreq, seskScheduleDaily,
seskScheduleWeekly, seskScheduleMonthly, seskScheduleMonthlyIndex,
seskScheduleYearly, seskScheduleYearlyIndex);
TSchedEvtItemKind =
(seikUnknown, seikScheduleStart, seikScheduleRecurType,
seikScheduleEndType, seikScheduleEndCount, seikScheduleEndDate,
seikFreqStart, seikFreqEnd, seikFreqInterval, seikScheduleDailyWeekdays,
seikScheduleDailyInterval, seikScheduleWeeklyDays,
seikScheduleWeeklyInterval, seikScheduleMonthlyDay,
seikScheduleMonthlyIndexType, seikScheduleMonthlyIndex,
seikScheduleMonthlyInterval, seikScheduleYearlyDay,
seikScheduleYearlyMonth, seikScheduleYearlyIndexType,
seikScheduleYearlyIndex, seikScheduleYearlyInterval);
IJvScheduledEventsStore = interface
['{FD6437D8-B951-4C72-AA5F-B96911D51B65}']
procedure LoadState(const Event: TJvEventCollectionItem);
procedure SaveState(const Event: TJvEventCollectionItem);
procedure LoadSchedule(const Event: TJvEventCollectionItem);
procedure SaveSchedule(const Event: TJvEventCollectionItem);
procedure LoadEventSettings(const Event: TJvEventCollectionItem);
procedure SaveEventSettings(const Event: TJvEventCollectionItem);
end;
TJvSchedEvtStore = class(TInterfacedObject, IJvScheduledEventsStore)
private
FEvent: TJvEventCollectionItem;
FStructStack: array of TSchedEvtStructKind;
protected
// Structure stack managment: low level
procedure PushStruct(const StructType: TSchedEvtStructKind);
function PeekStruct: TSchedEvtStructKind;
function PopStruct: TSchedEvtStructKind;
// property access methods
function GetEvent: TJvEventCollectionItem;
// Retrieving items: Schedule
procedure CheckSignature; virtual; abstract;
procedure CheckVersion; virtual; abstract;
function NextItemKind: TSchedEvtItemKind; virtual;
procedure RestoreScheduleStart; virtual; abstract;
procedure RestoreScheduleRecurType; virtual; abstract;
procedure RestoreScheduleEndType; virtual; abstract;
procedure RestoreScheduleEndCount; virtual; abstract;
procedure RestoreScheduleEndDate; virtual; abstract;
procedure RestoreFreqStart; virtual; abstract;
procedure RestoreFreqEnd; virtual; abstract;
procedure RestoreFreqInterval; virtual; abstract;
procedure RestoreScheduleDailyWeekdays; virtual; abstract;
procedure RestoreScheduleDailyInterval; virtual; abstract;
procedure RestoreScheduleWeeklyDays; virtual; abstract;
procedure RestoreScheduleWeeklyInterval; virtual; abstract;
procedure RestoreScheduleMonthlyDay; virtual; abstract;
procedure RestoreScheduleMonthlyIndexType; virtual; abstract;
procedure RestoreScheduleMonthlyIndex; virtual; abstract;
procedure RestoreScheduleMonthlyInterval; virtual; abstract;
procedure RestoreScheduleYearlyDay; virtual; abstract;
procedure RestoreScheduleYearlyMonth; virtual; abstract;
procedure RestoreScheduleYearlyIndexType; virtual; abstract;
procedure RestoreScheduleYearlyIndex; virtual; abstract;
procedure RestoreScheduleYearlyInterval; virtual; abstract;
// Storing items: signature (only for unstructured storages) and versioning
procedure StoreSignature; virtual;
procedure StoreVersion; virtual; abstract;
// Storing items: Schedule
procedure StoreScheduleStart; virtual; abstract;
procedure StoreScheduleRecurType; virtual; abstract;
procedure StoreScheduleEndType; virtual; abstract;
procedure StoreScheduleEndCount; virtual; abstract;
procedure StoreScheduleEndDate; virtual; abstract;
procedure StoreFreqStart; virtual; abstract;
procedure StoreFreqEnd; virtual; abstract;
procedure StoreFreqInterval; virtual; abstract;
procedure StoreScheduleDailyWeekdays; virtual; abstract;
procedure StoreScheduleDailyInterval; virtual; abstract;
procedure StoreScheduleWeeklyDays; virtual; abstract;
procedure StoreScheduleWeeklyInterval; virtual; abstract;
procedure StoreScheduleMonthlyDay; virtual; abstract;
procedure StoreScheduleMonthlyIndexType; virtual; abstract;
procedure StoreScheduleMonthlyIndex; virtual; abstract;
procedure StoreScheduleMonthlyInterval; virtual; abstract;
procedure StoreScheduleYearlyDay; virtual; abstract;
procedure StoreScheduleYearlyMonth; virtual; abstract;
procedure StoreScheduleYearlyIndexType; virtual; abstract;
procedure StoreScheduleYearlyIndex; virtual; abstract;
procedure StoreScheduleYearlyInterval; virtual; abstract;
// Structure stack managment: high level
procedure BeginStruct(const StructType: TSchedEvtStructKind); virtual;
procedure EndStruct; virtual;
procedure CheckBeginStruct(const StructType: TSchedEvtStructKind); virtual;
procedure CheckEndStruct; virtual;
property Event: TJvEventCollectionItem read GetEvent;
public
function IsStructured: Boolean;
function UsesIdentifiers: Boolean;
function GetAttributes: TSchedEvtStoreAttributes; virtual;
procedure LoadState(const Event: TJvEventCollectionItem);
procedure SaveState(const Event: TJvEventCollectionItem);
procedure LoadSchedule(const Event: TJvEventCollectionItem);
procedure SaveSchedule(const Event: TJvEventCollectionItem);
procedure LoadEventSettings(const Event: TJvEventCollectionItem);
procedure SaveEventSettings(const Event: TJvEventCollectionItem);
end;
function ScheduledEventStore_Stream(const Stream: TStream; const Binary: Boolean = False;
const OwnsStream: Boolean = True): IJvScheduledEventsStore;
implementation
uses
SysUtils, TypInfo,
JclRTTI, JclSchedule,
JvQConsts, JvQTypes, JvQResources;
//=== TJvSchedEvtStore =======================================================
procedure TJvSchedEvtStore.PushStruct(const StructType: TSchedEvtStructKind);
begin
SetLength(FStructStack, Length(FStructStack) + 1);
FStructStack[High(FStructStack)] := StructType;
end;
function TJvSchedEvtStore.PeekStruct: TSchedEvtStructKind;
begin
if Length(FStructStack) = 0 then
raise EJVCLException.CreateRes(@RsEStructureStackIsEmpty);
Result := FStructStack[High(FStructStack)];
end;
function TJvSchedEvtStore.PopStruct: TSchedEvtStructKind;
begin
Result := PeekStruct;
SetLength(FStructStack, High(FStructStack));
end;
function TJvSchedEvtStore.GetEvent: TJvEventCollectionItem;
begin
Result := FEvent;
end;
function TJvSchedEvtStore.NextItemKind: TSchedEvtItemKind;
begin
Result := seikUnknown;
end;
procedure TJvSchedEvtStore.StoreSignature;
begin
// override for non-structured storages to store an identification of the stream if needed.
TProcedure(AbstractErrorProc);
end;
procedure TJvSchedEvtStore.BeginStruct(const StructType: TSchedEvtStructKind);
begin
{ override to take additional steps when a new structure is to be written. Either call inherited
or use PushStruct to store the current structure information on the stack. }
PushStruct(StructType);
end;
procedure TJvSchedEvtStore.EndStruct;
begin
{ override to take additional steps when a structure is to be terminated. Either call inherited
or use PopStruct to retrieve the structure information from the stack. }
PopStruct;
end;
procedure TJvSchedEvtStore.CheckBeginStruct(const StructType: TSchedEvtStructKind);
begin
{ override to check if the next structure is the one specified and raise an exception if it isn't.
Either call inherited or use PushStruct to store the current structure information on the
stack. }
PushStruct(StructType);
end;
procedure TJvSchedEvtStore.CheckEndStruct;
begin
{ override to check if the next item marks the end of the structure as specified on the current
stack (use PopStruct to retrieve the structure information from the stack). Raise an exception
if the next item does not mark the end of the currently active structure. }
PopStruct;
end;
function TJvSchedEvtStore.IsStructured: Boolean;
begin
Result := sesaStructured in GetAttributes;
end;
function TJvSchedEvtStore.UsesIdentifiers: Boolean;
begin
Result := sesaIdentifiers in GetAttributes;
end;
function TJvSchedEvtStore.GetAttributes: TSchedEvtStoreAttributes;
begin
Result := [];
end;
procedure TJvSchedEvtStore.LoadState(const Event: TJvEventCollectionItem);
begin
raise EJVCLException.CreateRes(@RsENotImplemented);
end;
procedure TJvSchedEvtStore.SaveState(const Event: TJvEventCollectionItem);
begin
raise EJVCLException.CreateRes(@RsENotImplemented);
end;
procedure TJvSchedEvtStore.LoadSchedule(const Event: TJvEventCollectionItem);
var
OrgSchedule: IJclSchedule;
begin
// Clear the structure stack
SetLength(FStructStack, 0);
FEvent := Event;
with Event do
begin
if not (State in [sesNotInitialized, sesEnded]) then
raise EJVCLException.CreateRes(@RsEScheduleIsActiveReadingANewSchedule);
OrgSchedule := Schedule;
try
Schedule := CreateSchedule;
// Begin of actual reading
if not IsStructured then
CheckSignature;
CheckBeginStruct(seskSchedule);
CheckVersion;
// Generic schedule info
RestoreScheduleStart;
CheckBeginStruct(seskScheduleRecurInfo);
RestoreScheduleRecurType;
if Schedule.RecurringType <> srkOneShot then
begin
CheckBeginStruct(seskScheduleEndInfo);
RestoreScheduleEndType;
if Schedule.EndType = sekDate then
RestoreScheduleEndDate
else
if Schedule.EndType in [sekTriggerCount, sekDayCount] then
RestoreScheduleEndCount;
CheckEndStruct; {seskScheduleEndInfo}
CheckBeginStruct(seskScheduleDayFreq);
RestoreFreqStart;
if not UsesIdentifiers or (NextItemKind = seikFreqEnd) then
begin
RestoreFreqEnd;
RestoreFreqInterval;
end;
CheckEndStruct; {seskScheduleDayFreq}
case Schedule.RecurringType of
srkDaily:
begin
CheckBeginStruct(seskScheduleDaily);
if not UsesIdentifiers or (NextItemKind = seikScheduleDailyWeekdays) then
RestoreScheduleDailyWeekdays;
if not UsesIdentifiers or (NextItemKind = seikScheduleDailyInterval) then
RestoreScheduleDailyInterval;
CheckEndStruct; {seskScheduleDaily}
end;
srkWeekly:
begin
CheckBeginStruct(seskScheduleWeekly);
RestoreScheduleWeeklyDays;
RestoreScheduleWeeklyInterval;
CheckEndStruct; {seskScheduleWeekly}
end;
srkMonthly:
begin
CheckBeginStruct(seskScheduleMonthly);
CheckBeginStruct(seskScheduleMonthlyIndex);
RestoreScheduleMonthlyIndexType;
if (Schedule as IJclMonthlySchedule).IndexKind <> sikNone then
RestoreScheduleMonthlyIndex;
CheckEndStruct; {seskScheduleMonthlyIndex}
if (Schedule as IJclMonthlySchedule).IndexKind = sikNone then
RestoreScheduleMonthlyDay;
RestoreScheduleMonthlyInterval;
CheckEndStruct; {seskScheduleMonthly}
end;
srkYearly:
begin
CheckBeginStruct(seskScheduleYearly);
CheckBeginStruct(seskScheduleYearlyIndex);
RestoreScheduleYearlyIndexType;
if (Schedule as IJclYearlySchedule).IndexKind <> sikNone then
RestoreScheduleYearlyIndex;
CheckEndStruct; {seskScheduleYearlyIndex}
if (Schedule as IJclYearlySchedule).IndexKind = sikNone then
RestoreScheduleYearlyDay;
RestoreScheduleYearlyMonth;
RestoreScheduleYearlyInterval;
CheckEndStruct; {seskScheduleYearly}
end;
end;
end;
CheckEndStruct; {seskScheduleRecurInfo}
CheckEndStruct; {seskSchedule}
// we succeeded in reading in the schedule.
except
{ uh-oh! reading of the schedule failed. Better restore the original
schedule so the end user won't miss it ;) }
Schedule := OrgSchedule;
raise;
end;
end;
end;
procedure TJvSchedEvtStore.SaveSchedule(const Event: TJvEventCollectionItem);
begin
// Clear the structure stack
SetLength(FStructStack, 0);
FEvent := Event;
with Event do
begin
if not (State in [sesNotInitialized, sesEnded, sesPaused]) then
raise EJVCLException.CreateRes(@RsEScheduleIsActiveStoringOfAScheduleC);
if not IsStructured then
StoreSignature;
BeginStruct(seskSchedule);
StoreVersion;
// Generic schedule info
StoreScheduleStart;
BeginStruct(seskScheduleRecurInfo);
StoreScheduleRecurType;
if Schedule.RecurringType <> srkOneShot then
begin
BeginStruct(seskScheduleEndInfo);
StoreScheduleEndType;
if Schedule.EndType = sekDate then
StoreScheduleEndDate
else
if Schedule.EndType in [sekTriggerCount, sekDayCount] then
StoreScheduleEndCount;
EndStruct; {seskScheduleEndInfo}
BeginStruct(seskScheduleDayFreq);
StoreFreqStart;
if not UsesIdentifiers or ((Schedule as IJclScheduleDayFrequency).Interval <> 0) then
begin
StoreFreqEnd;
StoreFreqInterval;
end;
EndStruct; {seskScheduleDayFreq}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -