Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                UserCredential credential;
                // Load client secrets.
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    /* The file token.json stores the user's access and refresh tokens, and is created
                     * automatically when the authorization flow completes for the first time. */
                    string credPath = "token.json";
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Vault API service.
                var service = new VaultService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });

                // Define request parameters.
                MattersResource.ListRequest request = service.Matters.List();
                request.PageSize = 10;

                // List matters.
                ListMattersResponse response = request.Execute();
                Console.WriteLine("Matters:");
                if (response.Matters == null || response.Matters.Count == 0)
                {
                    Console.WriteLine("No matters found.");
                    return;
                }
                foreach (var matter in response.Matters)
                {
                    Console.WriteLine("{0} ({1})", matter.Name, matter.MatterId);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/vault.googleapis.com-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Vault API service.
            var service = new VaultService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            MattersResource.ListRequest request = service.Matters.List();
            request.PageSize = 10;

            // List matters.
            ListMattersResponse response = request.Execute();

            Console.WriteLine("Matters:");
            if (response.Matters != null && response.Matters.Count > 0)
            {
                foreach (var matter in response.Matters)
                {
                    Console.WriteLine("{0} ({1})", matter.Name, matter.MatterId);
                }
            }
            else
            {
                Console.WriteLine("No matters found.");
            }
            Console.Read();
        }