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

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("applications", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.Applications = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("nextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListApplicationsResponse response = new ListApplicationsResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("ApplicationSummaries", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ApplicationSummary, ApplicationSummaryUnmarshaller>(ApplicationSummaryUnmarshaller.Instance);
                    response.ApplicationSummaries = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("HasMoreApplications", targetDepth))
                {
                    var unmarshaller = BoolUnmarshaller.Instance;
                    response.HasMoreApplications = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemplo n.º 3
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonApplicationInsightsConfig config = new AmazonApplicationInsightsConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonApplicationInsightsClient client = new AmazonApplicationInsightsClient(creds, config);

            ListApplicationsResponse resp = new ListApplicationsResponse();

            do
            {
                ListApplicationsRequest req = new ListApplicationsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListApplications(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.ApplicationInfoList)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        public static ListApplicationsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            ListApplicationsResponse listApplicationsResponse = new ListApplicationsResponse();

            listApplicationsResponse.HttpResponse = _ctx.HttpResponse;
            listApplicationsResponse.RequestId    = _ctx.StringValue("ListApplications.RequestId");
            listApplicationsResponse.Message      = _ctx.StringValue("ListApplications.Message");
            listApplicationsResponse.ErrorCode    = _ctx.StringValue("ListApplications.ErrorCode");
            listApplicationsResponse.Code         = _ctx.StringValue("ListApplications.Code");
            listApplicationsResponse.Success      = _ctx.BooleanValue("ListApplications.Success");

            ListApplicationsResponse.ListApplications_Data data = new ListApplicationsResponse.ListApplications_Data();
            data.PageSize    = _ctx.IntegerValue("ListApplications.Data.PageSize");
            data.CurrentPage = _ctx.IntegerValue("ListApplications.Data.CurrentPage");
            data.TotalSize   = _ctx.IntegerValue("ListApplications.Data.TotalSize");

            List <ListApplicationsResponse.ListApplications_Data.ListApplications_Application> data_applications = new List <ListApplicationsResponse.ListApplications_Data.ListApplications_Application>();

            for (int i = 0; i < _ctx.Length("ListApplications.Data.Applications.Length"); i++)
            {
                ListApplicationsResponse.ListApplications_Data.ListApplications_Application application = new ListApplicationsResponse.ListApplications_Data.ListApplications_Application();
                application.Instances         = _ctx.IntegerValue("ListApplications.Data.Applications[" + i + "].Instances");
                application.ScaleRuleEnabled  = _ctx.BooleanValue("ListApplications.Data.Applications[" + i + "].ScaleRuleEnabled");
                application.AppDescription    = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].AppDescription");
                application.AppId             = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].AppId");
                application.RunningInstances  = _ctx.IntegerValue("ListApplications.Data.Applications[" + i + "].RunningInstances");
                application.RegionId          = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].RegionId");
                application.NamespaceId       = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].NamespaceId");
                application.ScaleRuleType     = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].ScaleRuleType");
                application.AppDeletingStatus = _ctx.BooleanValue("ListApplications.Data.Applications[" + i + "].AppDeletingStatus");
                application.AppName           = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].AppName");

                List <ListApplicationsResponse.ListApplications_Data.ListApplications_Application.ListApplications_TagsItem> application_tags = new List <ListApplicationsResponse.ListApplications_Data.ListApplications_Application.ListApplications_TagsItem>();
                for (int j = 0; j < _ctx.Length("ListApplications.Data.Applications[" + i + "].Tags.Length"); j++)
                {
                    ListApplicationsResponse.ListApplications_Data.ListApplications_Application.ListApplications_TagsItem tagsItem = new ListApplicationsResponse.ListApplications_Data.ListApplications_Application.ListApplications_TagsItem();
                    tagsItem._Value = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].Tags[" + j + "].Value");
                    tagsItem.Key    = _ctx.StringValue("ListApplications.Data.Applications[" + i + "].Tags[" + j + "].Key");

                    application_tags.Add(tagsItem);
                }
                application.Tags = application_tags;

                data_applications.Add(application);
            }
            data.Applications             = data_applications;
            listApplicationsResponse.Data = data;

            return(listApplicationsResponse);
        }
Exemplo n.º 5
0
        public void ListApplicationValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(@"{ 'value':[{
                    'id': 'foo',
                    'allowUpdates': 'true',
                    'displayName' : 'DisplayName',
                    'defaultVersion' : 'beta',
                    'packages':[
                        {'version':'version1', 'state':'pending', 'format': 'beta', 'lastActivationTime': '" + utcNow.ToString("o") + @"'},
                        {'version':'version2', 'state':'pending', 'format': 'alpha', 'lastActivationTime': '" + utcNow.ToString("o") + @"'}],

                    }]}")
            };


            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = GetBatchManagementClient(handler);

            ListApplicationsResponse result = client.Applications.List("resourceGroupName", "acctName", new ListApplicationsParameters());

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            Application application = result.Applications.First();

            Assert.Equal("foo", application.Id);
            Assert.Equal(true, application.AllowUpdates);
            Assert.Equal("beta", application.DefaultVersion);
            Assert.Equal("DisplayName", application.DisplayName);
            Assert.Equal(application.ApplicationPackages.Count, 2);
            Assert.Equal("beta", application.ApplicationPackages.First().Format);
            Assert.Equal(PackageState.Pending, application.ApplicationPackages.First().State);
            Assert.Equal("version1", application.ApplicationPackages.First().Version);
            Assert.Equal(utcNow, application.ApplicationPackages.First().LastActivationTime);
        }
Exemplo n.º 6
0
        public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync(string appPackageName, string applicationVersion)
        {
            string accountName       = TestCommon.Configuration.BatchAccountName;
            string resourceGroupName = TestCommon.Configuration.BatchAccountResourceGroup;

            using (BatchManagementClient mgmtClient = TestCommon.OpenBatchManagementClient())
            {
                ListApplicationsResponse applicationSummaries = await mgmtClient.Applications.ListAsync(resourceGroupName, accountName, new ListApplicationsParameters());

                bool testPackageAlreadyUploaded = applicationSummaries.Applications.Any(a =>
                                                                                        string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase) &&
                                                                                        string.Equals(applicationVersion, a.DefaultVersion, StringComparison.OrdinalIgnoreCase));

                if (!testPackageAlreadyUploaded)
                {
                    await UploadTestApplicationAndActivateAsync(appPackageName, applicationVersion, resourceGroupName, accountName).ConfigureAwait(false);
                }
            }
        }
        public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync(
            string appPackageName,
            string applicationVersion,
            string accountName,
            string resourceGroupName)
        {
            using (BatchManagementClient mgmtClient = TestCommon.OpenBatchManagementClient())
            {
                ListApplicationsResponse applicationSummaries =
                    await mgmtClient.Applications.ListAsync(resourceGroupName, accountName, new ListApplicationsParameters()).ConfigureAwait(false);

                bool testPackageAlreadyUploaded =
                    applicationSummaries.Applications.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase));

                if (!testPackageAlreadyUploaded)
                {
                    const string format = "zip";

                    var addResponse =
                        await
                        mgmtClient.Applications.AddApplicationPackageAsync(resourceGroupName, accountName, appPackageName, applicationVersion)
                        .ConfigureAwait(false);

                    var storageUrl = addResponse.StorageUrl;

                    await TestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false);

                    await
                    mgmtClient.Applications.ActivateApplicationPackageAsync(
                        resourceGroupName,
                        accountName,
                        appPackageName,
                        applicationVersion,
                        new ActivateApplicationPackageParameters { Format = format }).ConfigureAwait(false);
                }
            }
        }