PSG Client SDK-for VFP 9.0: © 2012 Programming Solutions Group
PSG Client SDK-for VFP 9.0: © 2012 Programming Solutions Group
All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the
written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered trademarks of the
respective owners. The publisher and the author make no claim to these trademarks.
While every precaution has been taken in the preparation of this document, the publisher and the author assume no
responsibility for errors or omissions, or for damages resulting from the use of information contained in this document
or from the use of programs and source code that may accompany it. In no event shall the publisher and the author be
liable for any loss of profit or any other commercial damage caused or alleged to have been caused directly or
indirectly by this document.
Publisher
...enter name...
Technical Editors
...enter name...
I PSG Client SDK- for VFP 9.0
Table of Contents
Part I Introduction 2
1 Technical
...................................................................................................................................
view 3
2 About ................................................................................................................................... 6
Index 0
Part
I
Introduction 2
1 Introduction
PSG platform allows database applications to efficiently perform over Internet or Intranet. It
enables easy loading of thousands of records instantly, using them locally and updating secured
server. It builds rich Internet applications operating as good and efficient as any desktop
applications using different programming languages. Among them .NET, Visual FoxPro or Java
using PSG as an intermediate communication layer that's secured by default.
PSG 2.0 enables faster development of application compared with other solutions.
The system provides a series of facilities by default, simplifying the development of complex
applications, reducing developing time with 40 to 60 percent:
- user management and user access rights per user and users groups
- integrated powerful reporting engine
- templates and classes
- integrated simple help system (as HTML pages)
Maintenance costs
- For the client the maintenance cost is close to zero, same as a Web Browser maintenance.
- Client application will be automatically updated with the last releases from the server.
- Database server should be administrated by a specialist according to size and complexity (like
any other application database servers)
- for small databases (few hundreds Mb) might be that there is be nothing to be done
- medium and big databases need maintenance depending on the database server
specifications (ie. some databases like Oracle require a database administrator as Oracle is
generally used for complex databases).
PSG is a platform used to develop and run client server database applications based on REST
services model.
The platform is built on a 4-tier architecture model.
PSG is based on a HTTPS WEB server and client for data exchange. The communication layer
optimizes the data transfer between the client application and the database server, enabling
PSG to serve also as WEB static and dynamic pages.
While PSG serves also WEB static and dynamic pages the first option is to optimize the data
transfer between the client application and the database server as a communication layer.
The platform offers an easy way to implement new services in minutes given the REST used
technology.
- international toolkit
The PSG server internally supports secure communication (SSL). Basic principle of such
communication requires that both client and server have their private and public keys. During
the process those two export their public keys to each other, and any data sent from one side to
another is encrypted using those keys. ONLY other side is able to decrypt the data (with private
key), and therefore transmissions like this are secure. In case that a third part is logging
information sent from one side to another would be unable to decrypt it alone in a reasonable
amount of time (could take few years to do that).
By using MD5 files checksum PSG implements a very strict control of modules that can run
client side. Client software modules are first downloaded from the server, being then stored into
the local cache. They can be used only if the MD5 checksum matches the server records, which
means that only approved versions can run. Each user group or individual user can have their
own access rights on modules making this security measure also useful for software updates.
When adding the new module on server updates for all clients are done automatically.
PSG can serve up to thousands users, depending on server hardware. More PSG servers can be
configured to offer access to the same database cluster.
PSG platform is open to extend the capabilities on server and client side. The server accepted
services can be easily customized and enhanced to fit all needs. To start programming an
Intranet/Internet application in days, only basic programming knowledge is needed. Database
applications are developed fast in the preferred programming language.
Client side programming. By using common development tools as .NET C#, Visual FoxPro or
JAVA IDE's, applications can be built faster. Classes and templates that handle all
communication processes are provided.
PSG solutions are highly scalable. An enterprise solution could provide services to hundred
thousands users in different system configuration.
1.2 About
Copyright Ó
WEB www.psgsdk.com
vfp.psgsdk.com
csharp.psgsdk.com
Support [email protected]
2011 - September - client side support for running several applications in the same time.
- C# script programming server side
2009 - September - the communication engine changes from TCP/IP proprietary socket secured
protocol to standard HTTPS communication protocol.
Part
II
Programming using VFP 8
Client side applications can be created using almost any well known programming language, the
PSG team offers support only for C#, VFP and JAVA (please check the www.psgsdk.com for an
updated list).
PSG client developent SDK's provided by psgsdk.com are free, but other providers for different
PSG SDK's may charge for a fee.
PSGSDK.COM provides free tools for the following languages (please check www.psgsdk.com
for more information):
- .NET C#
- VFP
- JAVA (NetBeans)
Source code may be available on request, please send the request to [email protected] .
Visual FoxPro was the first programming language used client side by PSG from 2004.
Building network database applications becomes faster and easier when using PSG platform and
VFP.
All PSG applications can be operated over Internet.
2.1 Overview
PSG platform is a complex structure, but the development of an application follows a very simple
procedure.
Developing n-tier client/server application involves writing code on both sides client and server.
Visual FoxPro 9.0 service pack 2 can help to create PSG applications.
The PSG services editor is available on server configuration utility in "Utils" page.
Services can be saved as XML files to be used as backup or to export to other server.
PSGCON is used for communications. Based on this all controls are implemented as easy as
possible.
The PSGCON object is instantiated into the main application. PSGCON is part of the
communication layer of PSG platform and it is coordinating all communications with the server
such as services, uploads and downloads.
A custom main application to serve a specific purpose could be created using the default one as
a sample.
The PSGCON object uses third party components for HTTPS communication and encryption,
royalty free licensed with the main application. Source code is provided for free, but additional
components should be licensed from third party vendors to be used for development.
In order to develop PSG applications there is no need for the additional licenses until you need to
redesign the main user interface.
_screen.server_ip
_screen.server_port
_screen.logincode
_screen.loginname
_screen.loginpass
_screen.company
_screen.appname
2.3 PSGCON
PSGCON deals with all the communication forms between the client and the PSG server. With its
server corespondent creates the communication layer of PSG platform.
- access PSG services
- download files
- upload files
The PSG client server communication is asynchronous. The server can not send any data to the
client until requested.
One PSG service responds with one answer and optional parameters. The answer can be a
command to be executed locally by the client application.
Some of the commands implemented into the PSGCON deal with usual functionality of the client.
In order to extend the client side functionality or to accept new custom commands client side, a
new object is used into each module code (see GETDATA object).
Combining server services with local commands the communication becomes slightly complex,
however first communication is initiated by the client.
PSGCON Object:
Methods:
run used to properly check and run an application module, used by the
main application menu
getinfo used to check a module licence code (when modules are licensed
separately)
loadhelp loads the help engine with the help page set - could provide help
context
Sample:
like
psgcon.send_command('ECHO#"HELLO"',thisform)
server service in the sample is ECHO and the parameter of ECHO is HELLO.
"thisform" object as a second parameters is provided, the response will be interpreted by the
object sent as parameter and the embedded GETDATA methods .
Properties:
m.usrcode = psgcon.usrcode
Server side, a WEB HTTP server listens on the server port minus ten. (Ex: server port 25010; ie
help port 25000)
Help is provided as a WEB site that can be created using any available tools. We recommend
Help & Manual from www.helpandmanual.com
The help start page should be "index.htm". Help is available by pressing F1 key.
In order to provide context help, the psgcon.help_page property should be set to the context page
whenever is needed. Do not forget to set it back to "index.htm" when the module/object is
released.
PSG client could embed the light release of NET Reports 3.0, limited to work with one database
only (the application main database).
NET Reports it is not mandatory, it works like an add on for the PSG Platform.
The NET Reports information is not part of this documentation. Please check the NET Reports
help file for more information.
The reports access rights can be set per individual user or user groups.
Available reports are:
- Export files
- Print reports (classic reports)
- CrossTab reports - drill down
- Ms. Excel PivotTable report
- Ms. Excel list
- Dashboard (uses graphs, drill down cross tabs, tables and text created from different data
cursors)
Application main menu & modules are simple and easy to use.
The application main menu is declared server side using the server config utility/ "Installed
documents" tab..
Document = single file that launches an application part (a VFP project compiled into an exe file).
When a bar is selected the "document" will be checked for MD5 conformity and executed.
If one pad has only one document it will activate the document in the same way as a bar when
selected.
For each "document" we can have dependencies or auxiliary files that are needed to run the
"document". These files will be also checked for MD5 checksum before use.
If one document or auxiliary file is not found client side or the MD5 checksum is not the correct
one, the file will be downloaded from the server.
This serves the security roles but also as the client application update mechanism.
Please check also USERS MANAGEMENT to see how to allocate users rights to use documents.
Application documents are projects build as executable files that can run on top of the main
application interface and use the PSG functionality.
This is a recommended basic scenario, but not limiting the possible "documents" to be created.
One could do anything in a project in order to achieve the application goals. But almost anytime
will deal with data load, show and modify. PSG services should be used given the fact that a lot
of jobs could be implemented server side as well.
See the application main menu for "documents" integration into the application.
Each "document" is a VFP project, that spares the application in small pieces easier to maintain
and update.
To be able to use a "document" it is mandatory that it is published on the server after it is
created.
Please check the PSG SDK for VFP for samples and templates.
The loading form is a special form that prepares the command for data request and finally
receives and loads the dataset.
PARAMETERS CE_,report_code
THIS.Name = m.CE_
this.interface_class = 'creport'
this.interface_container = 'usrcontrol2'
this.getdata.addtable('report')
this.getdata.addparameter(m.report_code)
this.getdata.addtable('rrep_details')
this.getdata.addparameter(m.report_code)
this.getdata.addtable('reports_databases')
this.getData.gettables()
In the INIT method, the GETDATA object prepares the PSG DATA service request in an easy and
convenient way.
Here is set the user interface to be used by the form after data loading. (interface class and
container)
The DATA command is sent to the server and a zip file with the dataset tables is prepared server
side. See DATA command /service.
For VFP a database container with the tables is prepared in order to preserve the eventually long
names for fields.
If JAVA or .NET are used, the server will prepare XML files. DBF method is faster as no xml
parser is used.
When download done event occurs the GETDATA object fires the form LOAD_DATA method.
The data tables are opened and the user interface is loaded.
Please see the templates and samples for details. Source code is available.
All controls embeds code that deals with PSG data communication using the PSGCON object.
Just fill in the boxes and configure some parameters.
Check also the samples form the SDK files.
Grids could be used by replacing columns base controls with the modified classes.
To insert a new class into a grid column (designer mode);
- edit the grid to the desired column (open the properties window and position to the
column).
- drop the control to the grid column
- position to the previous control in the properties window and close the properties
window
- press delete - this will remove the previous used control.
- open the properties window on column and set the SPARSE property to .T.
- set the PSG control properties as described
A basic container class has only INIT method code, generally used to position the window into the
screen.
The container should be populated with all necessary controls. The controls are set into the
container at design time instead on form, as the form is loaded before we have any data to be
used by controls. The form LOAD_DATA method actually opens the used tables.
If one control is not properly configured one error message will be shown into the application and
the form LOAD_DATA method stops.
thisform.Height = this.Height + 2
thisform.Width = this.Width + 2
thisform.Refresh
2.7.2.2 TextBox
psgtext.vcx
Used for character,numeric, integer, date and date-time fields; can edit up to 200 character sized
text fields, for larger fields use the EDITBOX instead.
New properties:
Modified methods:
2.7.2.3 EditBox
psgedit.vcx
New properties:
Modified methods:
2.7.2.4 CheckBox
psgcheck.vcx
New properties:
Modified methods:
2.7.2.5 ComboBox
psgcombo.vcx
New properties:
Modified methods:
2.7.2.6 Spinner
psgspinner.vcx
New properties:
Modified methods:
2.7.2.7 OptionBox
psgoption.vcx
New properties:
Modified methods:
2.7.2.8 Label
Used as a replacement for base class for international applications.
Depending on selected language will load the actual caption for the label.
Check the label class code and use the same code for grid headers and other captions in the
application.
2.7.2.9 PSGInsert
Stored in PSGDATA.VCX
Used method:
INSERT
PARAMETERS table_,remote_table,prim_key
Sample:
All fields that need to be inserted must have a declared variable with the same name. The method
checks for all fields in the local table and search for corresponding declared variable to be use in
the insert.
Keep in mind that some database servers like MS.SQL or PostgreSQL do not accept empty date
and datetime fields.
2.7.2.10 PSGDelete
Stored in PSGDATA.VCX
Used method:
DELETE
PARAMETERS table_name,key_name,record_id,local_table
2.7.2.11 GetData
Used by the loading form to prepare and send the DATA command.
DATA sends the instructions to the server to prepare the needed local tables.
Another purpose is to extend the client capabilities giving the power to respond to custom
commands that come from the server.
If the template is not used and the form is built from scratch:
- drop the class to the form or container
- change its name to "getdata" (by default will have "getdata1"
Methods:
gettables .getdata.gettables()
it prepares and sends a DATA command to the server which prepares
the local tables to be sent (server side).
psgcon.send_command(<command>,[object])
If the "object" is sent to the PSGCON, the accept method will fire on
the object set as default.
The PSG services could access some server objects and properties. Please check the PSG
SERVER SDK for a complete documentation.
The services scripts could use VFP, C#, VB script, Javascript as programming language. The
PSG base implemented services are written using VFP.
One service should use one programming language, but on the same server there can be
services written with different programming languages.
They all offer the same functionality.
Services could be managed from an editor application that starts from Utils tab of PSG server
config application or as standalone PSGCOMMAND.EXE in the server directory.
Services scripts are stored into a SQLITE database named psgcommand.db
New categories could be added, taking into account that a service name is unique on server.
One PSG service can use another service. Samples to be found in DATA service.
Generally, the services should respond as soon as possible (in few seconds). In case a lengthy
process should be used it is recommended to launch it out of service process and check later for
a response. REPORTS_RUN launches an external program, and the client will check
ISREPORTDATA in order to see if the job is completed. Sample are available in Reports.
<servicename>#<parameter1>,<parameter2>,...,<loginname>
Each service should have at least one parameter, the user login name that is added by the PSG
server automatically.
Each service should return a string as result.
The result string could be also a command to the client application (see the client GETDATA
accept method).
Ex:
RETURN "DONE#OK"
RETURN 'ECHO#'+test_value
ECHO#"Echo check"
Most common services, are generally used by the PSG templates classes.
PARAMETERS new_password,loginname
parses the fields values from the "insert_command" and sends the
INSERT command to the database server
some servers do not accept empty fields for date and datetime
fields
returns OK/NOK
MULTICOMMAND used to fire more than one service at the same time
UPDATETEXT updates a text field in the database (more than 240 characters )
Generally one service can't fail if the initial conditions are the same from development (database
structures, connections and others).
The development time errors that could be encountered when working with a service are:
ERROR 1000 - invalid command format (the command do not respect the standard syntax - ie.
the '#' mark or the name is incompatible (only alphanumeric and no spaces).
ERROR 1001 - command not found, the service is not set server side
ERROR 1002 - error in command, there are errors in the service that should be solved.
Data services command is prepared by GETDATA class and used by the loading form.
It is a special kind of services, one that uses other services to accomplish its task.
In order to develop PSG applications the base services cover almost all task required by the
usual requests.
However each application uses a different database and different datasets at one time.
The request of datasets or temporary cursors to be sent client side are solved by services.
There are services that are called only by the DATA service.
To call a service the ACCEPT method of the connection object is used:
.accept(<service name>#<parameters>)
Each table request prepared by GETDATA has a corresponding service here. The DATA service
will not be modified.
There is no general service while each request could have a different number of parameters.
However one could implement that if needed.
DATA receive the request for tables/XML files, prepare the files into one ZIP archive and send a
DATA command back to the client:
RETURN 'DATA#'+de_ret
The client main interface downloads the file, sends a command to delete the temporary ZIP
archive on server and fires the "DOWNLOADDONE" command in GETDATA ACCEPT method.
The loading form opens the tables to be used into the application. Table names are unique, but
the alias will have the name of the requested table to be used later.
Sample:
If we need to create an invoice form (a form that loads one invoice from an invoices list)
- tables to be used
- invoice (invoice header) - filtered by invoice_id
- invoice details - filtered by invoice_id
- customers list (to populate a combo box, only few fields and customer ID)
- products list
- other look up tables if needed.
The command to be sent to the server is prepared by GETDATA like the following:
invoice_id = "ID00234"
this.getdata.addtable('invoice')
this.getdata.addparameter(m.invoice_id)
this.getdata.addtable('invoice_details')
this.getdata.addparameter(m.invoice_id)
this.getdata.addtable('customers_list')
this.getdata.addtable('products_list')
this.getData.gettables()
DATA#"DBF","invoice|0,'ID00234'^invoice_details|0,'ID00234'^customers_list|0^products_list|0^"
- There is no need to construct this as it is parsed by the GETDATA into the command.
invoice
invoice_details
customers_list
products_list
----
INVOICE service script:
----
PARAMETERS re_,invoice_id,temp_file,loginname && re_ is used for backward compatibility, in
previous command 0 is used all the time.
&& temp_file,loginname are automatically added by the data service command
.connect(server.main_connection)
.sqlcon.cname = 'invoice'
.sqlcon.sqlcommand = .getsqlstring('invoice') && set the SQL script to be used from the SQL's
list
* or use next
* .sqlcon.sqlcommand = "select * from invoice where invoice_id = ?m.invoice_id"
* not recommended to select all fields, only necessary to avoid additional data traffic even the
data is compressed
RETURN .returnsql(temp_file) && execute the SQL statement and return the cursor
----
Please check demo applications and tutorials available in the PSG VFP Client SDK for samples
and tutorials.
The actual PSG SQL editor cannot check for script errors. The scripts should be verified with the
database server management tools.
Ms.SQL any
MySQL any
Oracle any
The database server can be changed any time. It is only required to check if stored SQL scripts
work properly with the new server.
The database connection string should be set using the server config utility in "Server" tab.
PSG includes an international toolkit able to translate captions to different languages and which
can be used with one application.
Check the LABEL class to see how it can be useful.
Client side the user can set the language to be used by using "System" from the menu.
Part
III
Users management 32
3 Users management
"Users management" section is available only for administrator in the client interface under
"Admin".
Next step - set the users groups, add users per groups and rights to users groups.
Part
IV
Distributing the application 36
The ZIP file could be used for server installation using the PSG server manager utility. (check the
SERVER SDK manual)
The server database distribution should be solved separately depending on the database server
provider:
- instructions to install a database server
- instructions to create the application database from a backup file
- the application database backup file
Client side only the PSG client application should be installed, distributed as MSI file.
A dedicated PSG installation kit for one application could be build if a personalized one is needed.
One PSG client could be used to connect more servers.
Files to be distributed:
- PSG server manager installation kit as MSI file
- PSG client installation kit as MSI file
- application PSG server ZIP file
Check also the PSG server SDK manual for server installation.
PSG Client installation kit will install all required components and the PSG client application and
shortcuts.
Administrator rights are required when installing the kit for proper installation of all components,
the PSG client will create local files for each computer user profile.
To connect a PSG server use the "setup" button into the "login" interface and set the server
address (IP/NAME/DOMAIN and port).