/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListPackagesResponse response = new ListPackagesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Packages", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <PackageListItem, PackageListItemUnmarshaller>(PackageListItemUnmarshaller.Instance);
                    response.Packages = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public void EncryptedDataCanBeSetAndRetrieved()
        {
            var request  = new ListPackagesResponse();
            var packages = new List <PackageDetails>();

            request.Packages = packages;
            Assert.AreEqual(packages, request.Packages);
        }
        public void RequestConstructorInitialisesTheValues()
        {
            var request  = new EncryptedRequest();
            var response = new ListPackagesResponse(request);

            // Only check one property is set, since the properties are set by the base class
            Assert.AreEqual(request.Identifier, response.RequestIdentifier);
        }
        public void FullConstructorInitialisesTheValues()
        {
            var response1 = new ListPackagesResponse();

            response1.RequestIdentifier = "12345";
            var response2 = new ListPackagesResponse(response1);

            // Only check one property is set, since the properties are set by the base class
            Assert.AreEqual(response1.RequestIdentifier, response2.RequestIdentifier);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inspects all DAML packages that are registered on the ledger and returns the id of the package that contains the PingPong module.
        /// This is useful during development when the DAML model changes a lot, so that the package id doesn't need to be updated manually
        /// after each change.
        /// </summary>
        /// <param name="channel">the gRPC channel to use for services</param>
        /// <param name="ledgerId">the ledger id to use for requests</param>
        /// <returns>the package id of the example DAML module</returns>
        private static string DetectPingPongPackageId(Channel channel, String ledgerId)
        {
            var packageService = new PackageService.PackageServiceClient(channel);

            // fetch a list of all package ids available on the ledger
            ListPackagesResponse packagesResponse = packageService.ListPackages(new ListPackagesRequest {
                LedgerId = ledgerId
            });

            // find the package that contains the PingPong module
            foreach (string packageId in packagesResponse.PackageIds)
            {
                var packageResponse = packageService.GetPackage(new GetPackageRequest {
                    LedgerId = ledgerId, PackageId = packageId
                });

                try
                {
                    // parse the archive payload
                    var payload = Com.DigitalAsset.Daml_Lf_1_8.DamlLf.ArchivePayload.Parser.ParseFrom(packageResponse.ArchivePayload);

                    // get the DAML LF package
                    Package lfPackage = payload.DamlLf1;

                    var moduleDottedNames = lfPackage.GetModuleNameDNames();

                    if (moduleDottedNames.Count == 1 && moduleDottedNames[0] == "PingPong")
                    {
                        return(packageId);
                    }
                }
                catch (Google.Protobuf.InvalidProtocolBufferException ex)
                {
                    throw new ApplicationException($"Querying Package Service payload", ex);
                }
            }

            // No package on the ledger contained the PingPong module
            throw new ApplicationException("Module PingPong is not available on the ledger");
        }