Application on TSD and communication with 1C: Enterprise 8.3 through HTTP-Service. Part 1.1 (Detailed Description of the API)

This part appeared after I started the full implementation. After combat operation, there was a need to change the structure of data exchange. It turned out to be very difficult to introduce TSD into the work. “1C mobile platform” was chosen as the software, as Kotlin was very hard. In this part, I will talk about how the exchange was implemented initially, and provide a code on the example of a single directory both on the server side and on the client side.

1. General description of the exchange algorithm.


On the server side, exchange plans with automatic change logging are used. Practice has shown that this is the least expensive way in terms of programming. On the TSD side, in each directory, a document, a props was added , in the registers a props with the same name was added .

The exchange itself is now split into two stages.

  1. We receive new data, we fix a sign of updating;
  2. We send confirmation that the data has been received. If the answer is yes, we remove the sign of the update;

Such a scheme appeared after the TSD began to leave the WiFi coverage area. Often it turned out that the data came, but the response was not sent.

To facilitate the entry of the TSD into operation, a directory with predefined values ​​has appeared, for each ( ).

2. As was implemented before.


The request was initiated by the TSD. Every 15 seconds there was a request for new data, for each directory, document, register. Data is collected in batches of 100 elements. Which imposed its limitations. If you complete the registration for the entire node, then the data is loaded about 30 minutes. Because in the current implementation, there was no mechanism for notifying the TSD about the presence of another pack.

A piece of code 1C on TSD
 () 
	
	.();
	.();

	.();
	.();
			
	.();
	.();
	
	.();
	.();
	
	.();
	.();


After the number of directories became more than five, a sad picture emerged: Each action on the server side is the same. The data request is different. But fixing changes for directories is one and the same. Let’s look at the example of OKEY. In short, then

  • We prepare the connection, take all of the constants.
  • We are preparing a request. Each directory lies in its own route. And then the command with parameters follows. something like this:
    localhost/ws/okeis/getNew&node=.
  • Prepare the response structure
  • We get the response and fill out the structure depending on the HTTP response code.
  • If successful, deploy JSON in 1C structures.
  • We start the transaction. We fix changes in the directory. Commit transaction
  • We call the function of committing changes on the server side
  • And now the fixation is exactly the same on the server side

Initially, each directory had its own fixing procedure, now it looks like this.

Lots of 1C code

	
 () 
HTTP = .HTTP();
	HTTP = .HTTP("okeis", "getAll?node="+(..()));
	
	 = HTTP.(HTTP);
	
	 =  ;
	.("", .);
	.("", .());

	 . = 200 
		 = .;
		 = .JSON();
		  .("") 
			();
			 = ;
			    .okeis 
				 = .code;
				 = .name;
				 = .fullName;
				 = .internationalReduction;
				
				 = ..();
				
				 () 
					 = .();
				
					 = ..();
				;
				
				. = ;
				. = ;
				. = ;
				. = ;
				. = ;
				
				
					.();
				
					 = ;
					;
				;
				
			;
			
			   
				();
			
				();
			;
		;			
	;




 get()
	
	 .URL.("") = "getAll" 
		
		(0,"  ");
		
		 = ..("node");
		
		 = ();
		 = HTTP(200, );
		
		(0,"  ");
		 ;
	;

	 = HTTP(400,  (",", , " "));
	 ;




 () 
	
	 =  ;
	. = "
	               |	.  
	               |
	               |	.  
	               |
	               |	.";
	
	 = .();
	 = .();
	
	 =  ;
	
	 .() 
		.( ("code", ..));
	;
	
	 =  ;
	.("okeis", );
	
	
	HTTP = .HTTP();
	HTTP = .HTTP("okeis", "dataObtained?node="+(..()));
	
	 = .();
	
	HTTP.();
	
	 = HTTP.(HTTP);
	
	 . = 200 
		();
		 = ;
				
		      
			 = ..(.code).();
			. = ;
			
				.();
			
				 = ;
				;
			;
				
		;
		
		   
			();
		
			();
		;
		
	;
	



 post()
	
	 = .URL.("");

	  = "dataObtained" 
		
		 = ..("node");
		 = ..("nameStructure");

		 = .();
		 = JSON();
		
		 =  ("", , , );
		
		  
			 = HTTP(200,  ("code", 0));
		
			 = HTTP(400,  ("code", 100));
		;
		
		 ;
	;
	 
	 = HTTP(400,  (",", , " "));
	 ;



 (, , , )
	
	 = ();
	
	();
	 = ;
	    [] 
		
		 = [].(.code);
		
		 () 
			
				.(,);
			
				 = ;
				;
			;	
		;
	;
	
	  
		();
		 ;
	
		();
		 ;
	;
	
	


This article discusses forehead implementation. Do not do this, unless you need to quickly assemble a prototype, and test it in battle.

If you like the article, in the next I’ll tell you how it is implemented now.

All Articles