Hello,
I'm converting an application from an equipment supplier, and he provided me with a C# source.
I tried to convert from C# to Cobol, using the "OpenText C# to Micro Focus Visual Cobol Translator" tool, but it is giving me an erro in one of the parts.
The original source:
public async Task<InitialResponse> InitiateOperationAsync(string baseUrl, PaymentRequest paymentRequest)
{
string payJson = JsonSerializer.Serialize(new
{
PAY = new
{
posto = paymentRequest.Posto,
operador = paymentRequest.Operador,
valor = paymentRequest.Valor
}
});
string requestUrl = $"{baseUrl}?PAY={payJson}";
try
{
HttpResponseMessage response = await _httpClient.GetAsync(requestUrl);
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<InitialResponse>(content);
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to initiate payment operation.", ex);
}
}
The result in cobol:
method-id InitiateOperationAsync (baseUrl as string, paymentRequest as type PaymentRequest) yielding return-value as type InitialResponse async final.
declare payJson as string = type JsonSerializer::Serialize(
PAY
posto paymentRequest::Posto
operador paymentRequest::Operador
valor paymentRequest::Valor
)
declare requestUrl as string = string::Format("{0}?PAY={1}", baseUrl, payJson)
try
declare response as type HttpResponseMessage = await _httpClient::GetAsync(requestUrl)
invoke response::EnsureSuccessStatusCode()
declare #content as string = await response::Content::ReadAsStringAsync()
set return-value to type JsonSerializer::Deserialize[type InitialResponse](#content)
goback
catch ex as type Exception
raise new InvalidOperationException("Failed to initiate payment operation.", ex)
end-try
end method.
Can you help me mor one time?
Best regards
Alberto Ferraz
------------------------------
Alberto Ferraz
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
The C# example is using an anonymous type which, to my knowledge, is not supported in Visual COBOL.
The following should do the same thing except the class PAY must be defined first.
I cannot test this using only the snippet so I am not sure if it works correctly but you can give it a try.
The Object definitions in the PAY class should be changed to the actual type of the parameters passed to it on the New method.
class-id MyClass.
method-id InitiateOperationAsync (baseUrl as string, paymentRequest as type PaymentRequest) yielding return-value as type InitialResponse async final.
declare payJson as string = type JsonSerializer::Serialize(new type PAY(paymentRequest::Posto, paymentRequest::Operador, paymentRequest::Valor))
declare requestUrl as string = string::Format("{0}?PAY={1}", baseUrl, payJson)
try
declare response as type HttpResponseMessage = await _httpClient::GetAsync(requestUrl)
invoke response::EnsureSuccessStatusCode()
declare #content as string = await response::Content::ReadAsStringAsync()
set return-value to type JsonSerializer::Deserialize[type InitialResponse](#content)
goback
catch ex as type Exception
raise new InvalidOperationException("Failed to initiate payment operation.", ex)
end-try
end method.
end class.
class-id PAY.
working-storage section.
01 posto type Object property. *> This should be changed to the actual type associated with paymentRequest.Posto
01 operador type Object property. *> This should be changed to the actual type associated with paymentRequest.Operador
01 valor type Object property. *> This should be changed to the actual type associated with paymentRequest.Valor
method-id New.
local-storage section.
procedure division using lnkPosto as type Object lnkOperador as type Object lnkValor as type Object.
set posto to lnkPosto
set operador to lnkOperador
set valor to lnkValor
goback.
end method.
end class.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
The C# example is using an anonymous type which, to my knowledge, is not supported in Visual COBOL.
The following should do the same thing except the class PAY must be defined first.
I cannot test this using only the snippet so I am not sure if it works correctly but you can give it a try.
The Object definitions in the PAY class should be changed to the actual type of the parameters passed to it on the New method.
class-id MyClass.
method-id InitiateOperationAsync (baseUrl as string, paymentRequest as type PaymentRequest) yielding return-value as type InitialResponse async final.
declare payJson as string = type JsonSerializer::Serialize(new type PAY(paymentRequest::Posto, paymentRequest::Operador, paymentRequest::Valor))
declare requestUrl as string = string::Format("{0}?PAY={1}", baseUrl, payJson)
try
declare response as type HttpResponseMessage = await _httpClient::GetAsync(requestUrl)
invoke response::EnsureSuccessStatusCode()
declare #content as string = await response::Content::ReadAsStringAsync()
set return-value to type JsonSerializer::Deserialize[type InitialResponse](#content)
goback
catch ex as type Exception
raise new InvalidOperationException("Failed to initiate payment operation.", ex)
end-try
end method.
end class.
class-id PAY.
working-storage section.
01 posto type Object property. *> This should be changed to the actual type associated with paymentRequest.Posto
01 operador type Object property. *> This should be changed to the actual type associated with paymentRequest.Operador
01 valor type Object property. *> This should be changed to the actual type associated with paymentRequest.Valor
method-id New.
local-storage section.
procedure division using lnkPosto as type Object lnkOperador as type Object lnkValor as type Object.
set posto to lnkPosto
set operador to lnkOperador
set valor to lnkValor
goback.
end method.
end class.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
Thanks for the answer and the help.
Effectively, there is no longer a compilation error in the lines, but it gives a structure error.
I don't think I managed to put things in the right way.
I am attaching the complete code that the supplier sent me, and then perhaps it will be easier to understand the general concept.
Best regards
Alberto Ferraz
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
Thanks for the answer and the help.
Effectively, there is no longer a compilation error in the lines, but it gives a structure error.
I don't think I managed to put things in the right way.
I am attaching the complete code that the supplier sent me, and then perhaps it will be easier to understand the general concept.
Best regards
Alberto Ferraz
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Here is a converted COBOL version of the C# program.
It compiles and runs but I cannot test it.
Since this was a console application there is a restriction on how the async/await syntax is used so I did it a different way. If you were calling these routines from a GUI application such as a Winform you could use the original syntax using await.
No guarantees but here you go...
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
The C# example is using an anonymous type which, to my knowledge, is not supported in Visual COBOL.
The following should do the same thing except the class PAY must be defined first.
I cannot test this using only the snippet so I am not sure if it works correctly but you can give it a try.
The Object definitions in the PAY class should be changed to the actual type of the parameters passed to it on the New method.
class-id MyClass.
method-id InitiateOperationAsync (baseUrl as string, paymentRequest as type PaymentRequest) yielding return-value as type InitialResponse async final.
declare payJson as string = type JsonSerializer::Serialize(new type PAY(paymentRequest::Posto, paymentRequest::Operador, paymentRequest::Valor))
declare requestUrl as string = string::Format("{0}?PAY={1}", baseUrl, payJson)
try
declare response as type HttpResponseMessage = await _httpClient::GetAsync(requestUrl)
invoke response::EnsureSuccessStatusCode()
declare #content as string = await response::Content::ReadAsStringAsync()
set return-value to type JsonSerializer::Deserialize[type InitialResponse](#content)
goback
catch ex as type Exception
raise new InvalidOperationException("Failed to initiate payment operation.", ex)
end-try
end method.
end class.
class-id PAY.
working-storage section.
01 posto type Object property. *> This should be changed to the actual type associated with paymentRequest.Posto
01 operador type Object property. *> This should be changed to the actual type associated with paymentRequest.Operador
01 valor type Object property. *> This should be changed to the actual type associated with paymentRequest.Valor
method-id New.
local-storage section.
procedure division using lnkPosto as type Object lnkOperador as type Object lnkValor as type Object.
set posto to lnkPosto
set operador to lnkOperador
set valor to lnkValor
goback.
end method.
end class.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
Thanks for the help. I have already managed to compile the program but, at run time, it gives me the following error:
Error: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.
The error that occurs is in the line marked with the arrow

If you want to test, just put this address in the line:
declare apiUrl as string = "http://icashserver.ddns.net:8889/VCASH"
This address is a simulator of the machine to which I have to connect the application.
Thanks again.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
Thanks for the help. I have already managed to compile the program but, at run time, it gives me the following error:
Error: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.
The error that occurs is in the line marked with the arrow

If you want to test, just put this address in the line:
declare apiUrl as string = "http://icashserver.ddns.net:8889/VCASH"
This address is a simulator of the machine to which I have to connect the application.
Thanks again.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I made a couple of changes, and I got it working like the C# example but there appears to be a problem with the C# example itself.
The way the code is now, a timeout exception will always be triggered.
That is because the source line:
throw new TimeoutException("A operação não foi concluída dentro do tempo limite.");
will always be executed.
I am not sure that this is the intent, but I created the COBOL program to behave the same way.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I made a couple of changes, and I got it working like the C# example but there appears to be a problem with the C# example itself.
The way the code is now, a timeout exception will always be triggered.
That is because the source line:
throw new TimeoutException("A operação não foi concluída dentro do tempo limite.");
will always be executed.
I am not sure that this is the intent, but I created the COBOL program to behave the same way.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Thanks again.
I've been trying out the "new version" and it gives me exactly the same error: "Error: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception".
I don't know if I'm creating the project correctly or if I'm missing something.
Regarding the issue of "a timeout exception will always be triggered", this should not be the intention but there could be an error in the test code that the supplier sent me.
The solution is to connect with a cash receiving machine (notes and coins).
The objective is to send several commands to the machine and receive the results of these commands.
For example, a command to know the status of the machine (http://icashserver.ddns.net:8889/VCASH?STATUS) If you try to do this in a browser you will get a response with the status of the machine.
If the status is "0" then it means that the machine is available and therefore a command can be sent with the amount to be paid (for example).
Then it is necessary to send several status requests to get the response that the process is finished.
Perhaps with this explanation you will be able to better understand what is necessary to implement the process.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Thanks again.
I've been trying out the "new version" and it gives me exactly the same error: "Error: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception".
I don't know if I'm creating the project correctly or if I'm missing something.
Regarding the issue of "a timeout exception will always be triggered", this should not be the intention but there could be an error in the test code that the supplier sent me.
The solution is to connect with a cash receiving machine (notes and coins).
The objective is to send several commands to the machine and receive the results of these commands.
For example, a command to know the status of the machine (http://icashserver.ddns.net:8889/VCASH?STATUS) If you try to do this in a browser you will get a response with the status of the machine.
If the status is "0" then it means that the machine is available and therefore a command can be sent with the amount to be paid (for example).
Then it is necessary to send several status requests to get the response that the process is finished.
Perhaps with this explanation you will be able to better understand what is necessary to implement the process.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
If it is easier to create this process in Windows Forms, there is no problem.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
If it is easier to create this process in Windows Forms, there is no problem.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I am attaching a new version of the program.
For me the program runs exactly like the C# version
The reason that the timeout error occurs in both the C# and COBOL versions is that the following condition is never true so the method is never exited. I cannot fix that as it seems to be a problem with the test data.
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
The COBOL project type should be a .NET Framework Console application.
The following references should be added:

------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I am attaching a new version of the program.
For me the program runs exactly like the C# version
The reason that the timeout error occurs in both the C# and COBOL versions is that the following condition is never true so the method is never exited. I cannot fix that as it seems to be a problem with the test data.
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
The COBOL project type should be a .NET Framework Console application.
The following references should be added:

------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I still have the same error. I think the problem is here:

When I do the step-by-step I notice that after this command, the application does not proceed to the next line and jumps to the next line

It should follow the order of the program to define all variables.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I still have the same error. I think the problem is here:

When I do the step-by-step I notice that after this command, the application does not proceed to the next line and jumps to the next line

It should follow the order of the program to define all variables.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Can you please zip up your project folders and upload them so that I can take a look?
I am using VC 10.0.
What VC version are you using?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Can you please zip up your project folders and upload them so that I can take a look?
I am using VC 10.0.
What VC version are you using?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I have already uploaded the folder I am using.
I'm using version 8.0.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I have already uploaded the folder I am using.
I'm using version 8.0.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
This seems to be a problem in Visual COBOL V8.0 which does not exist in V10.0.
I can reproduce the problem using 8.0 PU21 but the program works fine under 10.0.
Do you have access to the V10.0 product?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
This seems to be a problem in Visual COBOL V8.0 which does not exist in V10.0.
I can reproduce the problem using 8.0 PU21 but the program works fine under 10.0.
Do you have access to the V10.0 product?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I can try to install V10.0 but, with this redesign of the MicroFocus/Rocket website, I don't know where to download the new versions (I already looked but couldn't find it).
Can you get me the link to the download page?
Another question: for the program to be Windows Forms, will it need to change a lot?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I can try to install V10.0 but, with this redesign of the MicroFocus/Rocket website, I don't know where to download the new versions (I already looked but couldn't find it).
Can you get me the link to the download page?
Another question: for the program to be Windows Forms, will it need to change a lot?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
If you are looking to download a licensed copy of Visual COBOL and you are on maintenance, you would still use the OpenText support portal. If you are looking to download a copy of Visual COBOL Personal Edition, unfortunately this is not yet available.
I will try to get this to work under V8.0. I will test it from a WinForm program and see if the results are different.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
If you are looking to download a licensed copy of Visual COBOL and you are on maintenance, you would still use the OpenText support portal. If you are looking to download a copy of Visual COBOL Personal Edition, unfortunately this is not yet available.
I will try to get this to work under V8.0. I will test it from a WinForm program and see if the results are different.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
I've been doing some more experiments and I've already overcome the error I was making.
I updated the System.Text.Json version (I upgraded Nuget).
Now the application works but we have a new problem: the variable "content" that has the response from the "machine" is not being properly converted through "deserialize" (in C# and Cobol).
That's why the application tries 10 times and always comes out with the message "The operation was not completed within the time limit".
In C#

After "deserialize"

As the "Operation" variable is "null", the validation of "status Response.IDOperacao.HasValue" is always FALSE.
I've already done several tests and changes and I still can't figure out where the error is.
I don't know if in "WindowsForm" mode the problem will persist.
Thanks again
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I've been doing some more experiments and I've already overcome the error I was making.
I updated the System.Text.Json version (I upgraded Nuget).
Now the application works but we have a new problem: the variable "content" that has the response from the "machine" is not being properly converted through "deserialize" (in C# and Cobol).
That's why the application tries 10 times and always comes out with the message "The operation was not completed within the time limit".
In C#

After "deserialize"

As the "Operation" variable is "null", the validation of "status Response.IDOperacao.HasValue" is always FALSE.
I've already done several tests and changes and I still can't figure out where the error is.
I don't know if in "WindowsForm" mode the problem will persist.
Thanks again
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Alberto,
I pointed out that error in a previous post. You will have to contact the company from whom you received the test program.
Previous post:
"For me the program runs exactly like the C# version
The reason that the timeout error occurs in both the C# and COBOL versions is that the following condition is never true so the method is never exited. I cannot fix that as it seems to be a problem with the test data."
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Alberto,
I pointed out that error in a previous post. You will have to contact the company from whom you received the test program.
Previous post:
"For me the program runs exactly like the C# version
The reason that the timeout error occurs in both the C# and COBOL versions is that the following condition is never true so the method is never exited. I cannot fix that as it seems to be a problem with the test data."
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
I understood this issue with timeout and it is correct.
If there is a correct response from the machine in a timely manner, there is an exit method that prevents the application from reaching that message.

It ends up being the same as the solution you describe.
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
Now we just need to be able to "deserialize" the "#content" variable so that everything works.
Can you always "convert" the code to WindowsForm?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I understood this issue with timeout and it is correct.
If there is a correct response from the machine in a timely manner, there is an exit method that prevents the application from reaching that message.

It ends up being the same as the solution you describe.
// Verifica se a operação foi concluída
if (statusResponse.IDOperacao.HasValue)
{
return statusResponse;
}
Now we just need to be able to "deserialize" the "#content" variable so that everything works.
Can you always "convert" the code to WindowsForm?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
The problem is that it is trying to deserialize content into the FinalResponse object but the return string does not have those properties in it so there is nothing to deserialize. Look at content and you will see that it has three elements and one isnt even in the class:
{\\"STATUS\\":0,\\"MENSAGEM\\":\\"Caixeiro disponivel!!!!\\",\\"INVENTARIO\\":[{\\"especie...
IDOperacao which is the property which is supposed to contain a value does not appear.
Are you sure that the URL you provided to me is the correct one for this particular test?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
The problem is that it is trying to deserialize content into the FinalResponse object but the return string does not have those properties in it so there is nothing to deserialize. Look at content and you will see that it has three elements and one isnt even in the class:
{\\"STATUS\\":0,\\"MENSAGEM\\":\\"Caixeiro disponivel!!!!\\",\\"INVENTARIO\\":[{\\"especie...
IDOperacao which is the property which is supposed to contain a value does not appear.
Are you sure that the URL you provided to me is the correct one for this particular test?
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
The logic of the commands is this:
1st - send the PAY command with the amount to be paid
2nd - check the status of the machine until returning the IDOoperation
3rd - end the operation by showing the IDOperacao, the amount paid and the change (these last two amounts are not being returned by the simulator).

What you referred to as STATUS/MESSAGE/INVENTORY has to do with recording the status of the machine when it is at rest.
The simulator does not always work as it is shared by many people in tests.
I managed to get good results as there shouldn't be many people using it at this time.
This address is also available: http://icashserver.ddns.net:8888/VCASH
Tomorrow I should be able to do tests on a real machine, let's see how it works.
I send you news.
Thanks.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
The logic of the commands is this:
1st - send the PAY command with the amount to be paid
2nd - check the status of the machine until returning the IDOoperation
3rd - end the operation by showing the IDOperacao, the amount paid and the change (these last two amounts are not being returned by the simulator).

What you referred to as STATUS/MESSAGE/INVENTORY has to do with recording the status of the machine when it is at rest.
The simulator does not always work as it is shared by many people in tests.
I managed to get good results as there shouldn't be many people using it at this time.
This address is also available: http://icashserver.ddns.net:8888/VCASH
Tomorrow I should be able to do tests on a real machine, let's see how it works.
I send you news.
Thanks.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I changed one of the lines in the program that uses "deserialize".

Replaces the top line with the bottom line (Newtonsoft.Json).
With this change I now have access to the content of the "#content" type "FinalResponse" variable.
I'm waiting for the real machine to be available so I can do initial testing.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I changed one of the lines in the program that uses "deserialize".

Replaces the top line with the bottom line (Newtonsoft.Json).
With this change I now have access to the content of the "#content" type "FinalResponse" variable.
I'm waiting for the real machine to be available so I can do initial testing.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I finally managed to access a real machine and, after some more corrections and adaptations, I was able to access and carry out some payment operations.
I think that, in terms of communication, the main thing is done.
Now I have to integrate this process into my invoicing application (whenever the customer pays in cash this process has to be called).
I don't know the best way to do it.
The process has to be called from the billing application, and the amount to be paid is passed.
After the process, the status of the operation must be returned.
Do you think it could be a simple Cobol program?
I await your comments and would like to thank you once again for your help.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
I finally managed to access a real machine and, after some more corrections and adaptations, I was able to access and carry out some payment operations.
I think that, in terms of communication, the main thing is done.
Now I have to integrate this process into my invoicing application (whenever the customer pays in cash this process has to be called).
I don't know the best way to do it.
The process has to be called from the billing application, and the amount to be paid is passed.
After the process, the status of the operation must be returned.
Do you think it could be a simple Cobol program?
I await your comments and would like to thank you once again for your help.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
That is great news that you got it to work!
What type of application is your invoicing system?
Is it native code or managed, console, Winform, Web?
If it is managed code, then you could retool the demo program to be a callable class library that accepts and returns parameters.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
That is great news that you got it to work!
What type of application is your invoicing system?
Is it native code or managed, console, Winform, Web?
If it is managed code, then you could retool the demo program to be a callable class library that accepts and returns parameters.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
The application is in WPF but may have parts in WindowsForms (I have another program that is in WindowsForms).
I think that if it's a "normal" program in Cobol, I think it will work.
It is called and passes the parameter of the amount to be paid, runs the machine access procedure and returns the status.
Is it very complicated to "convert" the demo program to the Cobol program?
What would be your suggestion?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
Hi Chris,
The application is in WPF but may have parts in WindowsForms (I have another program that is in WindowsForms).
I think that if it's a "normal" program in Cobol, I think it will work.
It is called and passes the parameter of the amount to be paid, runs the machine access procedure and returns the status.
Is it very complicated to "convert" the demo program to the Cobol program?
What would be your suggestion?
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------
I would create a new Class Library project and create a method that can be invoked from your form event such as a button_click that would take the place of the main in the console application. You would have to remove the Console.Writeline calls and instead pass the status message or a code back to the invoking method.
Something like the following perhaps? (I have not tested this at all, it is just an example)
method-id button1_Click final private async-void.
procedure division using by value sender as object e as type System.EventArgs.
declare mycashObj as type cashClass.cashClass = new cashClass.cashClass
declare myamount as decimal = 123.45
declare mystatus as string
try
set mystatus = await mycashObj::makeTransaction(myamount)
catch ex as type Exception
set textBox1::Text to ex::Message
end-try
set textBox1::Text to mystatus
end method.
$set ilusing"System"
$set ilusing"System.Collections.Generic"
$set ilusing"System.Net.Http"
$set ilusing"System.Text.Json"
$set ilusing"System.Text"
$set ilusing"System.Threading"
$set ilusing"System.Threading.Tasks"
class-id cashClass.cashClass.
working-storage section.
01 _httpClient type HttpClient.
method-id makeTransaction async.
local-storage section.
procedure division using amount as decimal yielding ret-status as string.
set _httpClient = new HttpClient
declare paymentRequest = new PaymentRequest
set paymentRequest::Posto = "1"
set paymentRequest::Operador = "XPTO"
set paymentRequest::Valor = 1230
declare apiUrl as string = "http://icashserver.ddns.net:8889/VCASH"
try
*> Inicia a operação
declare initialResponse = await InitiateOperationAsync(apiUrl, paymentRequest)
if initialResponse::Status = 0
continue
else
set ret-status to "Erro ao iniciar operação:" & initialResponse::Message
exit method
end-if
*> Monitora o status até a conclusão
declare finalResponse = await MonitorStatusAsync(apiUrl)
set ret-status to "Complete"
*> Exibe o resultado final
*>set textBox1::Text to "ID Operação: " & finalResponse::IDOperacao
*>set textBox1::Text to "Valor Entregue: " & finalResponse::Entregue
*>set textBox1::Text to "Troco: " & finalResponse::Troco
catch ex as type Exception
set ret-status to "Erro: " & ex::Message
end-try
end method.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
I would create a new Class Library project and create a method that can be invoked from your form event such as a button_click that would take the place of the main in the console application. You would have to remove the Console.Writeline calls and instead pass the status message or a code back to the invoking method.
Something like the following perhaps? (I have not tested this at all, it is just an example)
method-id button1_Click final private async-void.
procedure division using by value sender as object e as type System.EventArgs.
declare mycashObj as type cashClass.cashClass = new cashClass.cashClass
declare myamount as decimal = 123.45
declare mystatus as string
try
set mystatus = await mycashObj::makeTransaction(myamount)
catch ex as type Exception
set textBox1::Text to ex::Message
end-try
set textBox1::Text to mystatus
end method.
$set ilusing"System"
$set ilusing"System.Collections.Generic"
$set ilusing"System.Net.Http"
$set ilusing"System.Text.Json"
$set ilusing"System.Text"
$set ilusing"System.Threading"
$set ilusing"System.Threading.Tasks"
class-id cashClass.cashClass.
working-storage section.
01 _httpClient type HttpClient.
method-id makeTransaction async.
local-storage section.
procedure division using amount as decimal yielding ret-status as string.
set _httpClient = new HttpClient
declare paymentRequest = new PaymentRequest
set paymentRequest::Posto = "1"
set paymentRequest::Operador = "XPTO"
set paymentRequest::Valor = 1230
declare apiUrl as string = "http://icashserver.ddns.net:8889/VCASH"
try
*> Inicia a operação
declare initialResponse = await InitiateOperationAsync(apiUrl, paymentRequest)
if initialResponse::Status = 0
continue
else
set ret-status to "Erro ao iniciar operação:" & initialResponse::Message
exit method
end-if
*> Monitora o status até a conclusão
declare finalResponse = await MonitorStatusAsync(apiUrl)
set ret-status to "Complete"
*> Exibe o resultado final
*>set textBox1::Text to "ID Operação: " & finalResponse::IDOperacao
*>set textBox1::Text to "Valor Entregue: " & finalResponse::Entregue
*>set textBox1::Text to "Troco: " & finalResponse::Troco
catch ex as type Exception
set ret-status to "Erro: " & ex::Message
end-try
end method.
------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------
Hi Chris,
Thank you for your programming lines.
I have already created a WPF project and combined Class.cbl with the content you sent me.
I have already made the necessary adaptations and carried out some tests.
Apparently everything will be working.
Now I have to improve some features to be 100% effective.
There is a situation that I will have to implement but I haven't been able to see how yet.
I have to find a way to cancel the process (CANCEL) while I'm in the machine query cycle to see if it's already finished.
I have a window with an AMOUNT field, a PAY button and a CANCEL button.
I enter the amount and click PAY. While the machine is waiting for the customer to enter the money, I may have to cancel the process.
Considering that the CANCEL button is in the main program, if I click on CANCEL, will the program detect this CANCEL?
Thank again.
------------------------------
Alberto Ferraz
Sr
E.S.I.C. - Serviços De Informática, Lda
Massamá PT
------------------------------