Changeset 51


Ignore:
Timestamp:
Apr 2, 2012, 3:59:58 PM (12 years ago)
Author:
chronos
Message:
  • Added: Unfinished installable module management.
Location:
trunk/Client
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Client/Application/Clients/UChronisClientMySQL.pas

    r46 r51  
    175175
    176176procedure TChronisClientMySQL.TypeUndefine(AType: TChronisType);
    177 begin
    178 
     177var
     178  DbRows: TDbRows;
     179  I: Integer;
     180  Query: string;
     181  RefType: TChronisType;
     182begin
     183  try
     184    DbRows := TDbRows.Create;
     185    Query := 'DROP TABLE IF EXISTS `' + AType.Name + '`';
     186    Database.Query(DbRows, Query);
     187  finally
     188    DbRows.Free;
     189  end;
    179190end;
    180191
  • trunk/Client/Application/UApplicationInfo.pas

    r49 r51  
    5050  Name := 'ChronIS';
    5151  Identification := 1;
    52   ReleaseDate := EncodeDate(2012, 3, 21);
     52  ReleaseDate := EncodeDate(2012, 4, 2);
    5353  MajorVersion := 0;
    5454  MinorVersion := 1;
  • trunk/Client/Application/UChronisModule.pas

    r29 r51  
    66
    77uses
    8   Classes, SysUtils;
     8  Classes, SysUtils, SpecializedList, UChronisClient;
    99
    1010type
     
    1414  TChronisModule = class
    1515    System: TObject; // TChronisSystem;
     16    SysName: string;
    1617    Name: string;
     18    Version: string;
     19    Creator: string;
     20    License: string;
     21    HomePage: string;
     22    Dependencies: TStringList;
     23    function IsInstalled: Boolean;
    1724    procedure Install; virtual;
    1825    procedure Uninstall; virtual;
    1926    constructor Create; virtual;
     27    destructor Destroy; override;
    2028  end;
    2129
    2230  TChronisModuleClass = class of TChronisModule;
     31
    2332
    2433implementation
     
    2736  USystem;
    2837
     38
    2939{ TChronisModule }
    3040
     41function TChronisModule.IsInstalled: Boolean;
     42var
     43  List: TListProxy;
     44begin
     45  List := TListProxy.Create;
     46  List.Client := TChronisBase(System).Client;
     47  List.SchemaName := TChronisBase(System).Client.Schema;
     48  List.ObjectName := SystemModuleObject;
     49  List.Condition := '(SysName="' + SysName + '") AND (Installed=1)';
     50  List.Load;
     51  Result := List.Objects.Count > 0;
     52  List.Free;
     53end;
     54
    3155procedure TChronisModule.Install;
     56var
     57  NewObject: TObjectProxy;
     58  List: TListProxy;
    3259begin
    33 
     60  List := TListProxy.Create;
     61  List.Client := TChronisBase(System).Client;
     62  List.SchemaName := TChronisBase(System).Client.Schema;
     63  List.ObjectName := SystemModuleObject;
     64  List.Condition := 'SysName="' + SysName + '"';
     65  List.Load;
     66  if List.Objects.Count > 0 then begin
     67    NewObject := TObjectProxy.Create;
     68    NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id']);
     69    NewObject.Client := TChronisBase(System).Client;
     70    NewObject.SchemaName := TChronisBase(System).Client.Schema;
     71    NewObject.ObjectName := SystemModuleObject;
     72    NewObject.Properties.Add('Installed', '1');
     73    NewObject.Save;
     74    NewObject.Free;
     75  end;
     76  List.Free;
    3477end;
    3578
    3679procedure TChronisModule.Uninstall;
     80var
     81  NewObject: TObjectProxy;
     82  List: TListProxy;
    3783begin
    38 
     84  List := TListProxy.Create;
     85  List.Client := TChronisBase(System).Client;
     86  List.SchemaName := TChronisBase(System).Client.Schema;
     87  List.ObjectName := SystemModuleObject;
     88  List.Condition := 'SysName="' + SysName + '"';
     89  List.Load;
     90  if List.Objects.Count > 0 then begin
     91    NewObject := TObjectProxy.Create;
     92    NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id']);
     93    NewObject.Client := TChronisBase(System).Client;
     94    NewObject.SchemaName := TChronisBase(System).Client.Schema;
     95    NewObject.ObjectName := SystemModuleObject;
     96    NewObject.Properties.Add('Installed', '0');
     97    NewObject.Save;
     98    NewObject.Free;
     99  end;
     100  List.Free;
    39101end;
    40102
    41103constructor TChronisModule.Create;
    42104begin
     105  Dependencies := TStringList.Create;
     106end;
    43107
     108destructor TChronisModule.Destroy;
     109begin
     110  Dependencies.Free;
     111  inherited Destroy;
    44112end;
    45113
  • trunk/Client/Forms/UFormMenu.lfm

    r49 r51  
    11object FormMenu: TFormMenu
    2   Left = 269
     2  Left = 333
    33  Height = 487
    4   Top = 72
     4  Top = 70
    55  Width = 262
    66  Caption = 'Navigation'
  • trunk/Client/Module/UModuleSystem.pas

    r46 r51  
    2222    destructor Destroy; override;
    2323  end;
     24
    2425
    2526implementation
  • trunk/Client/Module/UModuleUser.pas

    r46 r51  
    1010type
    1111
    12   { TModuleSystem }
     12  { TModuleUser }
    1313
    14   TModuleSystem = class(TChronisModule)
     14  TModuleUser = class(TChronisModule)
    1515  public
    1616    procedure Install; override;
     
    2323implementation
    2424
    25 { TModuleSystem }
     25{ TModuleUser }
    2626
    27 procedure TModuleSystem.Install;
     27procedure TModuleUser.Install;
    2828begin
    2929  inherited Install;
    3030end;
    3131
    32 procedure TModuleSystem.Uninstall;
     32procedure TModuleUser.Uninstall;
    3333begin
    3434  inherited Uninstall;
    3535end;
    3636
    37 constructor TModuleSystem.Create;
     37constructor TModuleUser.Create;
    3838begin
    3939  Name := 'User';
     
    4141end;
    4242
    43 destructor TModuleSystem.Destroy;
     43destructor TModuleUser.Destroy;
    4444begin
    4545  inherited Destroy;
  • trunk/Client/USystem.pas

    r46 r51  
    1111
    1212const
     13  SystemModuleObject = 'SystemModule';
    1314  ObjectGroupTable = 'ObjectGroup';
    1415  ObjectTable = 'Object';
     
    3637  vtTime, vtDate, vtColor, vtHyperlink, vtRelationOne, vtRelationMany, vtPassword);
    3738
    38   TChronisType = class;
    3939  TChronisObject = class;
    4040  TChronisBase = class;
     
    8888  end;
    8989
    90   TChronisType = class
    91   private
    92     ParentId: Integer;
    93   public
    94     Id: Integer;
    95     DbType: string;
    96     TypeIndex: Integer;
    97   end;
    98 
    99   { TChronisTypeList }
    100 
    101   TChronisTypeList = class(TListObject)
    102     function FindById(Id: Integer): TChronisType;
    103     function FindByTypeIndex(Id: Integer): TChronisType;
     90  { TChronisModuleList }
     91
     92  TChronisModuleList = class(TListObject) // TListObject<TChronisModule>
     93    Base: TChronisBase;
     94    procedure UpdateList;
     95    procedure Install;
     96    procedure Uninstall;
    10497  end;
    10598
     
    113106    Types: TChronisTypeList;
    114107    Client: TChronisClient;
    115     Modules: TListObject; // TListObject<TChronisModule>
     108    Modules: TChronisModuleList;
    116109    ModuleSystem: TChronisModule;
    117110    procedure RegisterModule(ModuleClass: TChronisModuleClass);
     
    168161end;
    169162
    170 { TChronisTypeList }
    171 
    172 function TChronisTypeList.FindById(Id: Integer): TChronisType;
    173 var
    174   I: Integer;
    175 begin
    176   I := 0;
    177   while (I < Count) and (TChronisType(Items[I]).Id <> Id) do Inc(I);
    178   if I < Count then Result := TChronisType(Items[I])
    179     else Result := nil;
    180 end;
    181 
    182 function TChronisTypeList.FindByTypeIndex(Id: Integer): TChronisType;
    183 var
    184   I: Integer;
    185 begin
    186   I := 0;
    187   while (I < Count) and (TChronisType(Items[I]).TypeIndex <> Id) do Inc(I);
    188   if I < Count then Result := TChronisType(Items[I])
    189     else Result := nil;
    190 end;
    191 
    192163{ TReportLine }
    193164
     
    277248    Client.Connect;
    278249    if Client.Connected then begin
    279       if IsDatabaseEmpty then ModuleSystem.Install;
     250      if not ModuleSystem.IsInstalled then ModuleSystem.Install;
    280251      LoadTypes;
    281252    end else FActive := False;
     
    697668begin
    698669  Types := TChronisTypeList.Create;
    699   Modules := TListObject.Create;
     670  Modules := TChronisModuleList.Create;
     671  Modules.Base := Self;
    700672end;
    701673
     
    775747end;
    776748
     749{ TChronisModuleList }
     750
     751procedure TChronisModuleList.UpdateList;
     752var
     753  I: Integer;
     754  NewObject: TObjectProxy;
     755  List: TListProxy;
     756begin
     757  List := TListProxy.Create;
     758  List.Client := Base.Client;
     759  List.SchemaName := Base.Client.Schema;
     760  NewObject := TObjectProxy.Create;
     761  NewObject.Client := Base.Client;
     762  for I := 0 to Count - 1 do
     763  with TChronisModule(Items[I]) do begin
     764    List.Condition := 'SysName="' + SysName + '"';
     765    List.Load;
     766    if List.Objects.Count > 0 then
     767      NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id'])
     768      else NewObject.Id := 0;
     769    NewObject.SchemaName := Base.Client.Schema;
     770    NewObject.ObjectName := SystemModuleObject;
     771    NewObject.Properties.Add('SysName', SysName);
     772    NewObject.Properties.Add('Name', Name);
     773    NewObject.Properties.Add('Version', Version);
     774    NewObject.Properties.Add('License', License);
     775    NewObject.Properties.Add('Creator', Creator);
     776    NewObject.Properties.Add('HomePage', HomePage);
     777    NewObject.Save;
     778  end;
     779  NewObject.Free;
     780  List.Free;
     781end;
     782
     783procedure TChronisModuleList.Install;
     784var
     785  NewType: TChronisType;
     786begin
     787  NewType := TChronisType.Create;
     788  NewType.Client := Base.Client;
     789  NewType.Name := SystemModuleObject;
     790  NewType.Properties.Add('SysName', 'String');
     791  NewType.Properties.Add('Name', 'String');
     792  NewType.Properties.Add('Version', 'String');
     793  NewType.Properties.Add('License', 'String');
     794  NewType.Properties.Add('Creator', 'String');
     795  NewType.Properties.Add('HomePage', 'String');
     796  NewType.Properties.Add('Installed', 'Boolean');
     797  NewType.Define;
     798end;
     799
     800procedure TChronisModuleList.Uninstall;
     801var
     802  NewType: TChronisType;
     803begin
     804  NewType := TChronisType.Create;
     805  NewType.Client := Base.Client;
     806  NewType.Name := SystemModuleObject;
     807  NewType.Undefine;
     808end;
     809
     810
    777811end.
    778812
  • trunk/Client/chronis.lpi

    r50 r51  
    3030          <SearchPaths>
    3131            <IncludeFiles Value="$(ProjOutDir)"/>
    32             <Libraries Value="/usr/lib/mysql/;/usr/lib64/mysql/"/>
     32            <Libraries Value="/usr/lib/mysql;/usr/lib64/mysql"/>
    3333            <OtherUnitFiles Value="Common;Forms"/>
    3434            <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
     
    284284    <SearchPaths>
    285285      <IncludeFiles Value="$(ProjOutDir)"/>
    286       <Libraries Value="/usr/lib/mysql/;/usr/lib64/mysql/"/>
     286      <Libraries Value="/usr/lib/mysql;/usr/lib64/mysql"/>
    287287      <OtherUnitFiles Value="Common;Forms;Application;Module;Application/Clients"/>
    288288      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
Note: See TracChangeset for help on using the changeset viewer.