Passo a passo
Crie um projeto com a opção Serviço do Windows
Crie as tabelas
Crie a procedure global
exemplo
Procedure Servico_SMS()
sComando is string = CommandLine()
SWITCH sComando
CASE 1
ReplicarSMS()
CASE 666
EndService(esStop)
OTHER CASE
ReplicarSMS()
END
Multitask(5s)
Crie agora procedure que será disparada a cada 5s
Procedure ReplicarSMS()
ok is boolean = False
ok = HOpenConnection(MyHfsqlClassic)
HChangeConnection(T000_SMS_CALLBACK,MyHfsqlClassic)
IF ok = False
INIWrite("Servico","Sms_erro_00",TimeSys(),"c:\temp\log.ini")
END
SQLCODIGO is SQL Query =
[
SELECT
T000_SMS_CALLBACK.T000_ID,
T000_SMS_CALLBACK.T000_MOBILE,
T000_SMS_CALLBACK.T000_SHORTCODE,
T000_SMS_CALLBACK.T000_ACCOUNT,
T000_SMS_CALLBACK.T000_BODY,
T000_SMS_CALLBACK.T000_RECEIVED,
T000_SMS_CALLBACK.T000_CORRELATED_MSG_ID,
T000_SMS_CALLBACK.T000_DATAHORASMS,
T000_SMS_CALLBACK.T000_DATAHORACAD,
T000_SMS_CALLBACK.T000_REPLICADO
FROM T000_SMS_CALLBACK
WHERE T000_SMS_CALLBACK.T000_REPLICADO <> 1
]
IF HExecuteSQLQuery(SQLCODIGO) = True
FOR EACH SQLCODIGO
IF HFound(SQLCODIGO) = True AND SQLCODIGO.T000_REPLICADO <> 1 THEN
ok = HOpenConnection(CONN_INFOTST)
HChangeConnection(T071_SMS_CALLBACK,CONN_INFOTST)
IF ok = False
INIWrite("Servico","Sms_erro_01",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
END
T071_SMS_CALLBACK.T071_MOBILE = SQLCODIGO.T000_MOBILE
T071_SMS_CALLBACK.T071_SHORTCODE = SQLCODIGO.T000_SHORTCODE
T071_SMS_CALLBACK.T071_ACCOUNT = SQLCODIGO.T000_ACCOUNT
T071_SMS_CALLBACK.T071_BODY = SQLCODIGO.T000_BODY
T071_SMS_CALLBACK.T071_RECEIVED = SQLCODIGO.T000_RECEIVED
T071_SMS_CALLBACK.T071_CORRELATED_MSG_ID = SQLCODIGO.T000_CORRELATED_MSG_ID
T071_SMS_CALLBACK.T071_DATAHORACAD = SQLCODIGO.T000_DATAHORASMS
ok = HAdd(T071_SMS_CALLBACK)
IF ok = True
INIWrite("Servico","Sms_Add",TimeSys(),"c:\temp\log.ini")
ELSE
INIWrite("Servico","Sms_erro_1.1",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
END
IF ok = True
HReset(T000_SMS_CALLBACK)
IF HReadSeek(T000_SMS_CALLBACK,T000_ID,SQLCODIGO.T000_ID,hIdentical) = True AND T000_SMS_CALLBACK.T000_REPLICADO <> 1
T000_SMS_CALLBACK.T000_DATAHORACAD = DateSys() + TimeSys()
T000_SMS_CALLBACK.T000_REPLICADO = 1
ok = HModify(T000_SMS_CALLBACK)
IF ok = True
INIWrite("Servico","Sms_modify",TimeSys(),"c:\temp\log.ini")
ELSE
INIWrite("Servico","Sms_erro_02",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
END
END
ELSE
INIWrite("Servico","Sms_erro_03",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
ok = False
END
ELSE
INIWrite("Servico","Sms_erro_04",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
ok = False
END
END
ELSE
INIWrite("Servico","Sms_erro_05",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
ok = False
END
ok = HCloseConnection(CONN_INFOTST)
IF ok = False THEN
INIWrite("Servico","Sms_erro_06",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
END
ok = HCloseConnection(MyHfsqlClassic)
IF ok = False THEN
INIWrite("Servico","Sms_erro_07",TimeSys()+"---"+ErrorInfo(),"c:\temp\log.ini")
END
Exemplo com fonte está no repositório oficial
https://repository.windev.com/resource.awp…
https://repository.windev.com/resource.awp?file_id=281474976710857;exemplo-microservico-servico-windows
--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/