Asynchronous calls to browser extensions and external components

Trendy tendencies

The traits within the improvement of browsers result in the truth that the share of “asynchrony” within the platform is growing increasingly. Step one was to desert modality. Now there are asynchronous requirements working with cryptography extensions, working with recordsdata and exterior parts.

The explanation for the subsequent motion in the direction of asynchrony was that the builders of the Google Chrome browser refused to assist the previous NPAPI expertise (Netscape Plugin Software Programming Interface). This expertise was used to attach external modules – extensions to the browser.

Such extensions are utilized by 1C: Enterprise to work with cryptography, to work with recordsdata and to attach exterior parts. That is a relatively strong performance. Cryptography is being used in digital doc administration, and because of external components, purposes can work with barcode scanners and different retail gear.

And now, as a substitute for the previous, synchronous NPAPI expertise, the builders of Google Chrome have created brand new expertise referred to as Native Messaging. At the same time, they are enormously instrumental in that each extension builder does not use the previous knowledge. As a result, it won’t be supported.

Without going into particulars, the brand new expertise is healthier and safer. That is good. However, one among its essential variations is that it offers purely asynchronous interplay with browser extensions. And this requires a radical change in all strategies of working with attachments and exterior parts that exist in 1C: Enterprise. As a result, they’re all based primarily on synchronous communication.

Asynchronous Strategies

We solved this drawback with the identical approach as the issue modal calls… We’ve created their asynchronous counterparts for all synchronous strategies utilizing NPAPI expertise. Principally, they differ within the presence of the Begin prefix and in the truth that the primary parameter is a Notification Description, from which the execution of this system code will proceed after the completion of the referred to as motion.

For instance, as a substitute of the Encrypt () technique, we now advocate utilizing the Begin Encryption () technique:

МенеджерКриптографии.Зашифровать(<ИсходныеДанные>, <Получатели>)
МенеджерКриптографии.НачатьШифрование(<ОписаниеОповещения>, <ИсходныеДанные>, <Получатели>)

As an alternative of the GetFiles () – StartFiles () technique:

ПолучитьФайлы(<ПолучаемыеФайлы>, <ПолученныеФайлы>,  <РасположениеФайлов>, <Интерактивно>)
НачатьПолучениеФайлов((<ОписаниеОповещения>, <ПолучаемыеФайлы>,  <РасположениеФайлов>, <Интерактивно>)

As an alternative of InstallExternalComponent () – StartInstallExternalComponent ():

УстановитьВнешнююКомпоненту(<Местоположение>)
НачатьУстановкуВнешнейКомпоненты(<ОписаниеОповещенияОЗавершении>, <Местоположение>)

And so on. For a whole checklist of the brand new asynchronous strategies and their correspondence to the previous strategies, see the V8Update.htm file (which comes with the platform), the documentation, and the syntax helper.

Actually, by and enormous, every little thing is similar to what we did earlier than once we removed modality. However, the functioning of the latest asynchronous strategies has a vital function that methods that decision modeless dialogues shouldn’t have.

After we name a modeless dialogue asynchronously, we count on some consumer response and nothing else, within the sense that nothing sudden can occur.

And exceptions can happen within the technique of calling asynchronous strategies for working with extensions and parts. The attachment didn’t set up, and the element didn’t load, and so on.

You usually present dealing with such exceptions within the software code and utilizing the Try … Exception operator. However, now this turns unattainable; due to the time of the asynchronous name, the appliance code shouldn’t be executed. Accordingly, the Try … Exception operator doesn’t work.

To unravel this drawback, we added two optionally available properties to the Alert Description object:

  • ErrorsHandlingProcedureName;
  • Error Dealing with Module.

If the asynchronous name “one thing goes mistaken” and an exception happens, the process pointed to by these properties shall be executed. It is sensible to use these two properties solely in asynchronous strategies for working with extensions. You do not want these properties when invoking modeless dialogues.

Configuration property

As within the case of abandoning modality, all the utilized answers as an entire should know “what it’s”. It’s both modal or modeless. It’s both synchronous and asynchronous.

Earlier, to resolve the difficulty with modality, we added a particular property to the configurations Modality use mode. Now, to handle the problem of synchrony, we’ve added a property comparable to the Mode of utilizing synchronous calls to extensions and exterior parts.

The essence of its use is as follows:

  • Don’t use is a brand new, asynchronous mode of operation. That is the default mode for brand spanking new configurations. Using previous synchronous strategies is prohibited. They don’t go syntactic management and aren’t within the context trace. An try and execute asynchronous technique throws an exception.
  • Use with a warning – This Mode is for the developer. It doesn’t preclude the usage of previous, synchronous strategies. However, each time the asynchronous technique is named on the consumer, it throws a warning message. We advocate utilizing this Mode in “recyclable” configurations. It’s handy for visible seek for synchronous calls and their management within the revision technique.
  • Use – a mode that ensures compatibility of the brand new platform model with previous configurations that use synchronous strategies for working with extensions and exterior parts.

All of the strategies and properties that we talked about are carried out in model 8.3.5.1383. It would help if you used them in your software options. And the builders BSP, for instance, will switch to the asynchronous operation of subsystems utilizing cryptography, file dealing with and exterior parts.

Naturally, as with modal calls, you most likely have a query. Do I have to redo my software answer? Ought to take advantage of these asynchronous strategies in my new software answer?

When is it wanted?

The reply to this query is identical as we gave earlier after they talked concerning the rejection of modality.

First, not each model of the expertise platform helps the Mode of asynchronous calls to extensions and exterior parts. This working model has existed since model 8.3.5.1383. Subsequently, if you are engaged on decrease variations of the platform, you can’t be puzzled by the rejection of synchronous strategies for now.

Secondly, not all utilized options should essentially use this Mode. Crucial are purposes that shall be operated utilizing the online consumer within the Google Chrome browser. Such purposes, in giant mass, are purposes that work in the service model… In case your software is not used on this model, chances are you’ll not abandon synchronous strategies for now.

Nonetheless, regardless of the primary and second factors, there are international traits that may affect your plans. We, 1C, develop all commonplace options to believe that they can be utilized in any available method. Subsequently, we’ll implement new utilized options, in addition to all of the libraries used in them, in a mode without utilizing synchronous calls.

So, you higher begin to grasp this Mode of operation now. Even when your software is probably not utilizing it, we advocate that if potential, start translating now. That being stated, we support that you just method this course creatively in the identical vein as when abandoning modality. There is no such thing as having to exchange synchronous strategies with asynchronous ones mechanically. At first, it’s helpful to consider whether or not it’s potential to vary the algorithm the state of affairs so that on this place to abandon the usage of synchronous strategies entirely?

Refactoring

On the one hand, if the configuration is giant and there are a lot of synchronous calls in it, then the “handbook” modification of such a configuration is usually a very time-consuming process.

However, from model 8.3.5.1068, the platform has tools that permit you to convert synchronous calls to their asynchronous counterparts.

Subsequently, we took these already current instruments, expanded them, and reoriented them from “shifting away from modality” to “shifting to asynchrony”. At its core, the transition to asynchronous strategies is much like the actions carried out when the modality is deserted. Previous, “not fancy”, synchronous (modal) calls must be changed with new, “fancy”, asynchronous calls that use AlertHandling.

On this up to date type, the refactoring instruments grew to become obtainable to you in model 8.3.6.1977.

Because the focus of those instruments has shifted in the direction of asynchrony, we’ve renamed a few of the instructions. The phrase “deprecated synchronous” is now used as a substitute for “modeless”:

As well as, we added a brand new Refactoring tab to the configurator settings. Each transformation is enabled by default. However, in case you want it, with its assistance, you possibly can carry out solely one of many forms of modifications throughout automated refactoring:

Facebook
Twitter
Pinterest
WhatsApp

Related Articles

Latest Articles