GoogleCloudSamples.AuthSample.MainFunction C# (CSharp) Метод

MainFunction() приватный Метод

private MainFunction ( string args ) : void
args string
Результат void
        void MainFunction(string[] args)
        {
            AuthSample sample = new AuthSample();
            string bucket = null;
            if (args.Length == 0)
            {
                Console.WriteLine(usage);
                return;
            }
            bucket = args[0];
            // Create a new Cloud Storage client authorized via Application 
            // Default Credentials
            StorageService storage = CreateAuthorizedClient();

            try
            {
                // Use the Cloud Storage client to get a list of objects for the
                // given bucket name
                Objects result = ListBucketContents(storage, bucket);

                // Get enumerator to loop through list of objects
                var resultsList = result.Items.GetEnumerator();

                Console.WriteLine(
                    "======= Listing Cloud Storage Bucket's contents =======");
                Console.WriteLine();

                // Loop through objects list, output object name and timestamp
                while (resultsList.MoveNext())
                {
                    if (!resultsList.Current.Equals(null))
                    {
                        // Output object name and creation timestamp
                        Console.WriteLine(resultsList.Current.Name.ToString());
                        Console.WriteLine(
                            resultsList.Current.TimeCreated.ToString());
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException ||
                    ex is Google.GoogleApiException)
                {
                    // No contents found for given bucket
                    Console.WriteLine("No contents found for given bucket. "
                        + "Sign in to the Google Developers Console");
                    Console.WriteLine(
                        "at: https://console.developers.google.com/storage ");
                    Console.WriteLine("to confirm your bucket name is valid "
                        + "and to upload some files to your bucket.");
                }
            }
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
    }

Usage Example

Пример #1
0
        // [END list_storage_bucket_contents]

        private static void Main(string[] args)
        {
            SamplesUtil.InvokeMain(() =>
            {
                var sample = new AuthSample();
                sample.MainFunction(args);
            });
        }
All Usage Examples Of GoogleCloudSamples.AuthSample::MainFunction