Example #1
0
        private void Button_Connect_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder sb = new StringBuilder(1024);

            try
            {
                // read account settings, dump
                AccountSettings accountSettings = SampleHelpers.LoadAccountSettings();
                sb.AppendLine("--- accountSettings ---");
                sb.AppendLine(accountSettings.ToString());

                // read job settings, dump
                JobSettings jobSettings = SampleHelpers.LoadJobSettings();
                sb.AppendLine("--- jobSettings ---");
                sb.AppendLine(jobSettings.ToString());

                // connect to batch, dump status
                BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(
                    accountSettings.BatchServiceUrl,
                    accountSettings.BatchAccountName,
                    accountSettings.BatchAccountKey
                    );

                sb.AppendLine($"credentials created: {cred.AccountName},{cred.BaseUrl}");

                using (BatchClient client = BatchClient.Open(cred))
                {
                    sb.AppendLine($"batchclient opened successfully");
                    // enumerate pools
                    sb.AppendLine("--- pools ---");
                    foreach (var pool in client.PoolOperations.ListPools())
                    {
                        sb.AppendLine($"pool found: id:{pool.Id} vmsize:{pool.VirtualMachineSize} state:{pool.State.ToString()}");
                    }
                    sb.AppendLine("--- applications ---");
                    foreach (var app in client.ApplicationOperations.ListApplicationSummaries())
                    {
                        sb.AppendLine($"application found: {app.Id} {app.Versions[0]}");
                    }
                } // batchclient
            }
            catch (AggregateException ae)
            {
                sb.AppendLine("aggregate exception caught");
                sb.AppendLine(SampleHelpers.AggregateExceptionDump(ae.Flatten()));
                System.Diagnostics.Trace.Write(sb.ToString(), "ERROR");
            }
            catch (Exception ex)
            {
                sb.AppendLine("exception caught");
                sb.AppendLine(ex.ToString());
                System.Diagnostics.Trace.Write(sb.ToString(), "ERROR");
            }

            TextBlock_Out.Text = sb.ToString();
        }