Utilisation de données complexes dans un flux de travail

 

Date de publication : juillet 2016

<_caps3a_sxs _xmlns3a_caps="https://schemas.microsoft.com/build/caps/2013/11"><_caps3a_sxstarget locale="fr-FR">DynamicValue vous permet de créer, de stocker et d’utiliser des structures de données. Ces données peuvent être récursives : une valeur DynamicValue peut contenir d'autres valeurs DynamicValues. Les règles de composition d'une valeur DynamicValue sont très simples : ses propriétés peuvent être des primitives, des tableaux ou d'autres valeursDynamicValues semblables à un jeu de propriétés récursives ou au format de sérialisation JSON. Une valeur DynamicValue fournit un conteneur et un mécanisme de manipulation pour les données composées avec une surface de liaison de première classe pour WF.Stockage des données par une DynamicValueÀ la base, vous pouvez considérer une DynamicValue comme une liste récursive de paires clé-valeur. Le tableau suivant représente une DynamicValue simple :NomValeur de type de données primitives sous-jacentÂge42NomJohn DoeDans le tableau précédent, la DynamicValue possède deux propriétés : Age a la valeur 42 et Name a la valeur John Doe. Le nom d’une propriété DynamicValue est une chaîne, et sa valeur peut être d’un type figurant dans la liste suivante, ou la valeur null (Nothing en Visual Basic). Si un autre type est transmis à une DynamicValue, une exception est levée.ChaîneInt32DoubleGuidBooleanDateTimeTimeSpanIList<T>, où T est l'un des types figurant dans cette listeIDictionary<string, T>, où T est l'un des types figurant dans cette listeDynamicValueNotez que DynamicValue figure dans la liste des types pris en charge. Cela signifie que la valeur d’une DynamicValue peut être une autre DynamicValue, comme indiqué dans le tableau suivant.NomValeurClientNomValeurÂge42NomJohn DoeSociétéContoso CorporationCustomer contient une DynamicValue comme valeur, et cette DynamicValue contient Age et Name. Pour référencer la valeur de Name, vous pouvez utiliser Customer/Name. Si la valeur Customer/Name est désignée et qu’elle n’a pas encore été créée, celle-ci est ajoutée. Cela s’appelle un upsert.Une DynamicValue prend également en charge la notion de tableaux. Un tableau est un ensemble de valeurs primitives contenues dans une valeur associée à une DynamicValue. La principale différence conceptuelle entre une DynamicValue sous forme de tableau et une DynamicValue imbriquée réside dans le fait que les éléments du tableau n’ont pas de nom et font l’objet d’un accès par index. Notez que les tableaux peuvent contenir différents types. Dans la valeur de tableau correspondant à Numbers, les types sont Int32 et Double. Dans la valeur de tableau correspondant à Items, les valeurs sont une DynamicValue imbriquée et Int32.NomValeurNombres4633.142.71ItemsNomValeurPremière4Seconde56Valeurs d’adressage dans une DynamicValueLes valeurs sont définies et récupérées à partir d’une DynamicValue à l’aide d’une notation de chemin d’accès. Les chemins d’accès sont des chaînes de type Uri qui pointent vers une propriété donnée, ce qui ressemble à la représentation aplatie d’une structure. Les chemins d’accès sont formés en utilisant le nom d’une propriété, une chaîne ou un index contenu dans un élément au sein d’une valeur de tableau, représentée par un nombre entre parenthèses.Pour consulter des exemples d’utilisation de chemins d’accès DynamicValue, voir l’exemple Évaluateur de chemin d’accès d’une DynamicValuehttps://go.microsoft.com/fwlink/?LinkId=257469. L’exemple DynamicValue Path Evaluatorhttps://go.microsoft.com/fwlink/?LinkId=257469 vous permet d’entrer le point de terminaison d’un service REST qui renvoie JSON, et d’expérimenter et de vous familiariser avec une DynamicValue et les chemins d’accès des données renvoyées.Dans la section précédente, plusieurs exemples de DynamicValue ont été fournis. Le premier exemple concernait une DynamicValue avec deux valeurs, comme indiqué dans le tableau suivant.NomValeurÂge42NomJohn DoePour accéder à la première valeur, un chemin d’accès formé par Age est utilisé. La valeur 42 est renvoyée. Un chemin d’accès formé par Name renvoie la valeur John Doe.Le second exemple de la section précédente comportait des valeurs imbriquées, comme indiqué dans le tableau suivant.NomValeurClientNomValeurÂge42NomJohn DoeSociétéContoso CorporationLe chemin d’accès Customer renvoie une DynamicValue (qui contient elle-même deux valeurs). Le chemin d’accès Company renvoie Contoso Corporation. Afin d’accéder aux valeurs imbriquées, le caractère / est utilisé pour délimiter les propriétés. À l’aide de cette notation, le chemin d’accès Customer/Age renvoie la valeur 42, et Customer/Name renvoie John Doe.Pour accéder aux valeurs stockées dans un tableau, le chemin d’accès comporte des index. Le tableau suivant représente la DynamicValue de la section précédente, laquelle contenait des tableaux et des DynamicValues imbriquées.NomValeurNombres4633.142.71ItemsNomValeurPremière4Seconde56Dans la DynamicValue représentée par le tableau suivant, un chemin d'accès de Numbers renvoie le premier tableau. Les tableaux DynamicValue sont basés sur zéro ; Numbers(0) renvoie le premier élément du tableau et Numbers(3) renvoie le quatrième élément.Items renvoie le deuxième tableau et Items(0) renvoie le premier élément du tableau, qui est une DynamicValue. Pour accéder aux valeurs de ce DynamicArray imbriqué, les noms des propriétés sont combinés au chemin d'accès qui fournit le tableau.Items(0)/First renvoie la valeur 4, et Items(0)/Second renvoie la valeur 5.Vous pouvez utiliser les chemins d’accès pour créer de manière déclarative une structure de données composées. Les valeurs peuvent être connues au moment de la conception, ou liées de manière dynamique lors de l’exécution. L’exemple suivant illustre un ensemble de chemin d’accès et de valeurs représentant une composition d’un client disposant d’une adresse.Chemin d’accès (Vers)Valeur (Depuis)PrénomJohnNomDoeAddress/CityRedmondAddress/StateWALes chemins d’accès et les valeurs du tableau précédent permettent de créer la DynamicValue représentée par le tableau suivant.NomValeurPrénomJohnNomDoeAdresseNomValeurVilleRedmondÉtatWALe type de la DynamicValue fournit une méthode Parse qui permet d’analyser une chaîne JSON en une DynamicValue. En outre, il existe une activité ParseDynamicValue qui peut être utilisée dans les flux de travail pour analyser une chaîne JSON en une DynamicValue.Les activités Http peuvent également comprendre une DynamicValue. Si vous affectez une DynamicValue à la réponse d’une activité Http*, celle-ci récupérera les résultats sous forme JSON et créera une DynamicValue avec ce résultat. Si vous transmettez une DynamicValue au corps de la demande, ou si vous l’utilisez comme contenu de réponse, les en-têtes appropriés seront ajoutés pour indiquer que JSON est utilisé.Utilisation d’une DynamicValue dans les flux de travailEn plus du type DynamicValue, Workflow Manager 1.0 fournit également des activités permettant de créer et d’utiliser une DynamicValue dans les flux de travail.ActivitéDescriptionArgumentsT:Microsoft.Activities.BuildDynamicValueCrée une instance DynamicValue. Elle reçoit un dictionnaire des chemins d’accès et des valeurs en entrée, et renvoie la DynamicValue qui en résulte. Elle utilise une approche multi-affectation pour créer la DynamicValue (elle accepte plusieurs chemins d’accès et valeurs).Cette activité permet de créer une DynamicValue, ou d’en modifier une existante.InArgument<IDictionary<string,InArgument>> PropertiesInOutArgument<DynamicValue> ResultT:Microsoft.Activities.ContainsDynamicValuePropertyRenvoie la valeur true si une DynamicValue contient une propriété représentée par le chemin d’accès spécifié.InArgument<DynamicValue> SourceInArgument<DynamicValue> PropertyNameOutArgument<bool> ResultT:Microsoft.Activities.CopyDynamicValueCopie les propriétés d’une DynamicValue dans une autre DynamicValue.InArgument<IDictionary<string,string>> PropertyMappingInArgument<DynamicValue> SourceOutArgument<DynamicValue> ResultT:Microsoft.Activities.CountDynamicValueItemsRenvoie le nombre d’enfants dans un chemin d’accès DynamicValue.InArgument<DynamicValue> SourceOutArgument<int> ResultT:Microsoft.Activities.CreateDynamicValueCrée une instance d’une DynamicValue qui transmet un seul chemin d’accès et une seule valeur (aucune sémantique de multi-affectation).InArgument<string> PropertyNameInArgument PropertyValueOutArgument<DynamicValue> ResultT:Microsoft.Activities.CreateDynamicValueFromMessageCrée une DynamicValue à partir d’un message SOAP.InArgument<DynamicValue> HeadersInArgument<XElement> ValueInArgument<MessageVersion> VersionOutArgument<DynamicValue> ResultT:Microsoft.Activities.CreateMessageFromDynamicValueCrée un message SOAP à partir d’une DynamicValue spécialement mise en forme.InArgument<string> ActionInArgument<DynamicValue> HeadersInArgument<DynamicValue> BodyInArgument<MessageVersion> VersionOutArgument<XElement> ResultT:Microsoft.Activities.CreateUriFromDynamicValueCrée un URI à partir d’une DynamicValue.InArgument<DynamicValue> OptionsOutArgument<string> ResultT:Microsoft.Activities.GetDynamicValuePropertiesObtient plusieurs propriétés d’une DynamicValue existante. Avec une DynamicValue, un utilisateur peut interroger plusieurs propriétés (en transmettant plusieurs chemins d’accès) via une activité unique.InArgument<DynamicValue> SourceInArgument<IDictionary<string,OutArgument>> PropertiesT:Microsoft.Activities.GetDynamicValueProperty`1Obtient une propriété d’une DynamicValue, où T correspond à l’un des types figurant dans la liste précédemment fournie.InArgument<DynamicValue> SourceInArgument<string> PropertyNameOutArgument<T> ResultT:Microsoft.Activities.ParseDynamicValueAnalyse une chaîne JSON en une DynamicValue.InArgument<string> JSONOutArgument<DynamicValue> ResultUtilisation d’une DynamicValueUne DynamicValue et ses activités connexes permettent de représenter et de manipuler des données sans spécifier d’hôte. Par conséquent, la DynamicValue est une fonctionnalité de flux de travail qui peut être utilisée avec n’importe quel hôte de flux de travail. Elle n’est donc pas limitée à Workflow Manager 1.0. Elle peut être utilisée avec n’importe lequel des autres hôtes de flux de travail existants, par exemple, WorkflowInvoker, WorkflowApplication et WorkflowServiceHost.L’exemple Utilisation de données complexes dans un flux de travail à l’aide d’une DynamicValuehttps://go.microsoft.com/fwlink/?LinkId=257468 décrit comment utiliser la fonctionnalité avec WorkflowApplication. Plusieurs des autres exemples de la section Using DynamicValue décrivent comment utiliser une DynamicValue dans des flux de travail Workflow Manager 1.0. L'utilisation d'une DynamicValue est la même, quel que soit l'hôte. Toutefois, le mode de chargement des données dans une DynamicValue diffère pour tous les hôtes (par exemple, dans Workflow Manager 1.0, il est fréquent de créer la DynamicValue en tant que résultat d'une opération Http via des activités Http).Pour plus d'informations sur les exemples Workflow Manager 1.0 et où les trouver, voir Workflow 1.0 Beta Samples.<_caps3a_sxssource locale="en-US">DynamicValue allows you to create, store, and consume data structures. This data can be recursive, meaning that a DynamicValue can contain other DynamicValues.DynamicValue composition rules are very simple: its properties can be primitives, arrays, or other DynamicValues, similar to a recursive property bag or JSON serialization format.DynamicValue provides both a container and manipulation mechanism for compound data with first class binding surface for WF.How DynamicValue Stores its DataAt the very core, you can think of DynamicValue as a recursive list of key-value pairs. The following table represents a simple DynamicValue:NameValue of Underlying Primitive Data TypeAge42NameJohn DoeIn the previous table, the DynamicValue has two properties: Age has a value of 42 and Name has a value of John Doe. The name of a DynamicValue property is a string, and the value can be any one of the types in the following list, or null (Nothing in Visual Basic). If any other type is passed to a DynamicValue an exception will be thrown.StringInt32DoubleGuidBooleanDateTimeTimeSpanIList<T>, where T is one of the types in this listIDictionary<string, T>, where T is one of the types in this listDynamicValueNote that DynamicValue is in the list of supported types. This means that the value of a DynamicValue can be another DynamicValue, as shown in the following table.NameValueCustomerNameValueAge42NameJon DoeCompanyContoso CorporationCustomer contains a DynamicValue as its value, and that DynamicValue contains Age and Name. To reference the value for Name, you can use Customer/Name. If Customer/Name value is referred to and it has not yet been created, it will be added. This is referred to as an upsert.DynamicValue also supports the notion of arrays. An array is a set of primitive values contained as the value for a DynamicValue. The main conceptual difference between a DynamicValue as an array instead of nested DynamicValue is that the items in the array do not have a name and are accessed by index. Note that the arrays can contain different types. In the array value for Numbers, the types are Int32 and Double. In the array value for Items, the values are a nested DynamicValue and an Int32.NameValueNumbers4633.142.71ItemsNameValueFirst4Second56Addressing Values in a DynamicValueValues are set and retrieved from a DynamicValue using a path notation. Paths are Uri-like strings that point to a given property, similar to the flattened representation of a structure. Paths are composed using the name of a property, using a string, or an index into an item within an array value, using a number surrounded by parenthesis.To see examples of working with DynamicValue paths, see the DynamicValue Path Evaluatorhttps://go.microsoft.com/fwlink/?LinkId=257469 sample. The DynamicValue Path Evaluatorhttps://go.microsoft.com/fwlink/?LinkId=257469 sample allows you to enter the endpoint of a REST service that returns JSON, and experiment and become familiar with DynamicValue and paths of the returned data.In the previous section, several examples of DynamicValue were given. The first example was for a DynamicValue with two values, as shown in the following table.NameValueAge42NameJohn DoeTo access the first value, a path consisting of Age is used, which returns a value of 42. A path of Name returns the value John Doe.The second example from the previous section included some nested values, as shown in the following table.NameValueCustomerNameValueAge42NameJon DoeCompanyContoso CorporationThe path Customer returns a DynamicValue (which itself contains two values). The path of Company returns Contoso Corporation. In order to access nested values, a / is used to delineate properties. Using this notation, the path Customer/Age returns a value of 42, and Customer/Name returns John Doe.To access values stored in an array, indexes are used in the path. The following table represents the DynamicValue from the previous section that contained booth arrays and nested DynamicValues.NameValueNumbers4633.142.71ItemsNameValueFirst4Second56In the DynamicValue represented by the previous table, a path of Numbers returns the first array.DynamicValue arrays are zero based, and Numbers(0) returns the first element of the array, and Numbers(3) returns the fourth element of the array.Items returns the second array, and Items(0) returns the first item in the array, which is a DynamicValue. To access the values in that nested DynamicArray, the property names are combined with the path that yields the array.Items(0)/First returns 4 and Items(0)/Second returns 5.You can use paths to declaratively build a compound data structure. The values can be known at design time or dynamically bound at runtime. The following example shows a set of paths and values that represent a composition of a customer that has an address.Path (To)Value (From)FirstNameJohnLastNameDoeAddress/CityRedmondAddress/StateWAThe paths and values in the previous table would create the DynamicValue represented by the following table.NameValueFirstNameJohnLastNameDoeAddressNameValueCityRedmondStateWAThe DynamicValue type provides a Parse method that can be used to parse a JSON string into a DynamicValue. In addition, there is a ParseDynamicValue activity that can be used in workflows to parse a JSON string into a DynamicValue.Http activities can also understand DynamicValue. If you assign a DynamicValue to the response of an Http* activity, it will get the results as JSON and build a DynamicValue with that result. If you pass a DynamicValue to the request body or use it as the response content, the appropriate headers will be added to indicate that JSON is used.Using DynamicValue in WorkflowsIn addition to the DynamicValue type, Workflow Manager 1.0 also provides activities for creating and working with DynamicValue in workflows.ActivityDescriptionArgumentsT:Microsoft.Activities.BuildDynamicValueBuilds a DynamicValue instance. It receives a dictionary of paths and values as input and returns the resulting DynamicValue. It uses a multi-assign approach to build the DynamicValue (it accepts multiple paths and values).This activity can be used to create a new DynamicValue or to modify an existing one.InArgument<IDictionary<string,InArgument>> PropertiesInOutArgument<DynamicValue> ResultT:Microsoft.Activities.ContainsDynamicValuePropertyReturns true if a DynamicValue contains a property represented by the specified pathInArgument<DynamicValue> SourceInArgument<DynamicValue> PropertyNameOutArgument<bool> ResultT:Microsoft.Activities.CopyDynamicValueCopies properties from one DynamicValue to another DynamicValueInArgument<IDictionary<string,string>> PropertyMappingInArgument<DynamicValue> SourceOutArgument<DynamicValue> ResultT:Microsoft.Activities.CountDynamicValueItemsReturns the count of children in a DynamicValue pathInArgument<DynamicValue> SourceOutArgument<int> ResultT:Microsoft.Activities.CreateDynamicValueCreate an instance of a DynamicValue passing only one path and one value (no multi-assign semantics)InArgument<string> PropertyNameInArgument PropertyValueOutArgument<DynamicValue> ResultT:Microsoft.Activities.CreateDynamicValueFromMessageCreates a DynamicValue from a SOAP messageInArgument<DynamicValue> HeadersInArgument<XElement> ValueInArgument<MessageVersion> VersionOutArgument<DynamicValue> ResultT:Microsoft.Activities.CreateMessageFromDynamicValueCreates a SOAP message from a specially formatted DynamicValueInArgument<string> ActionInArgument<DynamicValue> HeadersInArgument<DynamicValue> BodyInArgument<MessageVersion> VersionOutArgument<XElement> ResultT:Microsoft.Activities.CreateUriFromDynamicValueCreates a URI from a DynamicValueInArgument<DynamicValue> OptionsOutArgument<string> ResultT:Microsoft.Activities.GetDynamicValuePropertiesGet several properties of an existing DynamicValue. Given a DynamicValue a user can query multiple properties (passing multiple paths) using a single activity.InArgument<DynamicValue> SourceInArgument<IDictionary<string,OutArgument>> PropertiesT:Microsoft.Activities.GetDynamicValueProperty`1Get one property of a DynamicValue, where T is one of the types in previously given list.InArgument<DynamicValue> SourceInArgument<string> PropertyNameOutArgument<T> ResultT:Microsoft.Activities.ParseDynamicValueParse a JSON string into a DynamicValueInArgument<string> JSONOutArgument<DynamicValue> ResultUsing DynamicValueDynamicValue and its supporting activities allow for representing and manipulating data in a host agnostic way. Hence, DynamicValue is a workflow feature that can be used with any workflow host, so it is not limited to Workflow Manager 1.0. It can be used with any of the other existing workflow hosts like WorkflowInvoker, WorkflowApplication, and WorkflowServiceHost.The Working with complex data in a workflow using DynamicValuehttps://go.microsoft.com/fwlink/?LinkId=257468 sample demonstrates how to use the feature with WorkflowApplication. Several of the other Using DynamicValue samples show how to use DynamicValue in Workflow Manager 1.0 workflows.DynamicValue usage is the same regardless of the host; what changes for every host is how the data is loaded into the DynamicValue (for example in Workflow Manager 1.0 it is very common to create the DynamicValue as the result of an Http operation using Http activities).For information about the Workflow Manager 1.0 samples and where to locate them, see Workflow 1.0 Beta Samples.