Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ServerInternalFiles Access Location
#1
If I need to use the ServerInternalFiles how and where do I access them?
Reply
#2
Hi,

unit is IWServerInternalFiles.pas. It implements TIWServerInternalFiles class which handles a list of resources kept in streams (TMemoryStream instances).

It is accessible via gInternalFiles instance declared in the same unit.

You can add custom memory streams to the list like:

procedure AddStream(aStream: TMemoryStream; AResName, AFileName: string);

You need to provide a unique AResName and a AFileName which can be basically anything. Example:

gInternalFiles.AddStream(MyMemStream, 'MY_TEMPLATE', 'mytemplate');

then you retrieve it using ResourceAsStream Method like

myStream := gInternalFiles.ResourceasStream('MY_TEMPLATE');

You are responsible for freeing myStream instance. However, if you intend to use it in a template, it doessn't need to be freed (the tamplate engine frees it for you).

Please let me know if you need further help
Reply
#3
(08-02-2018, 11:41 PM)Alexandre Machado Wrote: Hi,

unit is IWServerInternalFiles.pas. It implements TIWServerInternalFiles class which handles a list of resources kept in streams (TMemoryStream instances).

It is accessible via gInternalFiles instance declared in the same unit.

You can add custom memory streams to the list like:

procedure AddStream(aStream: TMemoryStream; AResName, AFileName: string);

You need to provide a unique AResName and a AFileName which can be basically anything. Example:

gInternalFiles.AddStream(MyMemStream, 'MY_TEMPLATE', 'mytemplate');

then you retrieve it using ResourceAsStream Method like

myStream := gInternalFiles.ResourceasStream('MY_TEMPLATE');

You are responsible for freeing myStream instance. However, if you intend to use it in a template, it doessn't need to be freed (the tamplate engine frees it for you).

Please let me know if you need further help

Thanks.  I am working on a proof in concept and have been able to load a stream from a file to use in the template processor using the beforeProcess event; however, I can not seem to be able to load from the ServerInternalFiles.

Here is the code that I am trying to use but it just gives me a blank page.

procedure TMainForm.tpBeforeProcess(var VTemplate: TStream);
var
  lTemplateMemStream : TMemoryStream;
begin
      try
        lTemplateMemStream := TMemoryStream.Create;
        lTemplateMemStream.Position := 0;
        lTemplateMemStream.LoadFromFile('STEP_HTML.html');
        gInternalFiles.AddStream(lTemplateMemStream,'TEST_RES','test');

        VTemplate.Free;
        VTemplate := Tstream.Create;
        VTemplate := gInternalFiles.ResourceAsStream('TEST_RES');

      finally
        lTemplateMemStream.Free;
      end;

end;

The following code will load a template from a file into the template processor and works, but does not use the ServerInternalFiles.

procedure TMainForm.tpBeforeProcess(var VTemplate: TStream);
begin

        VTemplate.Free;
        VTemplate := TFileStream.Create('STEP_HTML.html', fmOpenRead + fmShareDenyWrite);
        TFileStream(VTemplate).Seek(0, soFromBeginning);

end;


Any help on what I am doing wrong on the first procedure would be appreciated.
Reply
#4
Updating with some conversation on this subject, lifted from Telegram (originators can clarify or updated as needed):

Eddy
very simple fast question: how do I overwrite the VTemplate: TStream inside

procedure TForm1.IWTemplateProcessorHTMLMainBeforeProcess(var VTemplate:
TStream);

Alex:
Load your template to TMemoryStream instances (1 for each template file) do whatever you want with them and add them to the ServerInternalFiles list. Use them from there instead of loading/processing it every time.
Then just use the BeforeProcess event to use your own stream. This way IW won't load it from file

but if you are following this, use the ServerController.OnConfig event

if you need to do some processment which is dependent on the request, then you need to do the processment using the BeforeProcess event anyway. You can still use the serverInternalFile to avoid having to load the template from file every time
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)