예제 #1
0
        //This will be removed for the final version, we use it for testing
        public List <GoogleGlossary> GetProjectGlossaries(IMtTranslationOptions options)
        {
            var googleGlosaries = new List <GoogleGlossary>();
            var request         = new ListGlossariesRequest
            {
                ParentAsLocationName = new LocationName(options.ProjectName, options.ProjectLocation),
                PageSize             = 50,
            };

            try
            {
                var response = _translationServiceClient.ListGlossaries(request);
                var test     = response.AsRawResponses();

                foreach (var glossaryResponse in test)
                {
                    foreach (var glossary in glossaryResponse)
                    {
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error($"{MethodBase.GetCurrentMethod().Name}: {e}");
                throw;
            }
            return(googleGlosaries);
        }
예제 #2
0
        public List <string> ListGlossaries()
        {
            ListGlossariesRequest request = new ListGlossariesRequest
            {
                ParentAsLocationName = new LocationName(projectId, locaionId),
            };
            var response = client.ListGlossaries(request);

            // Iterate over glossaries and display each glossary's details.

            return(response.Select(x =>
                                   $"name: {x.Name}, Entry count: {x.EntryCount}, Input URI: {x.InputConfig.GcsSource.InputUri}").ToList());
        }
        /// <summary>Snippet for ListGlossariesAsync</summary>
        public async Task ListGlossariesAsync_RequestObject()
        {
            // Snippet: ListGlossariesAsync(ListGlossariesRequest,CallSettings)
            // Create client
            TranslationServiceClient translationServiceClient = await TranslationServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListGlossariesRequest request = new ListGlossariesRequest
            {
                ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListGlossariesResponse, Glossary> response =
                translationServiceClient.ListGlossariesAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Glossary item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListGlossariesResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Glossary item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int             pageSize   = 10;
            Page <Glossary> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Glossary item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
예제 #4
0
        /// <summary>
        /// Lists all the glossaries for a given project.
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project ID.</param>
        public static void ListGlossariesSample(string projectId = "[Google Cloud Project ID]")
        {
            TranslationServiceClient translationServiceClient = TranslationServiceClient.Create();
            ListGlossariesRequest    request = new ListGlossariesRequest
            {
                ParentAsLocationName = new LocationName(projectId, "us-central1"),
            };
            PagedEnumerable <ListGlossariesResponse, Glossary> response = translationServiceClient.ListGlossaries(request);

            // Iterate over glossaries and display each glossary's details.
            foreach (Glossary item in response)
            {
                Console.WriteLine($"Glossary name: {item.Name}");
                Console.WriteLine($"Entry count: {item.EntryCount}");
                Console.WriteLine($"Input URI: {item.InputConfig.GcsSource.InputUri}");
            }
        }
예제 #5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListGlossariesRequest request;

            try
            {
                request = new ListGlossariesRequest
                {
                    CatalogId           = CatalogId,
                    DisplayName         = DisplayName,
                    DisplayNameContains = DisplayNameContains,
                    LifecycleState      = LifecycleState,
                    TimeCreated         = TimeCreated,
                    TimeUpdated         = TimeUpdated,
                    CreatedById         = CreatedById,
                    UpdatedById         = UpdatedById,
                    Fields       = Fields,
                    SortBy       = SortBy,
                    SortOrder    = SortOrder,
                    Limit        = Limit,
                    Page         = Page,
                    OpcRequestId = OpcRequestId
                };
                IEnumerable <ListGlossariesResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.GlossaryCollection, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListGlossariesRequest request;

            try
            {
                request = new ListGlossariesRequest
                {
                    CatalogId           = CatalogId,
                    DisplayName         = DisplayName,
                    DisplayNameContains = DisplayNameContains,
                    LifecycleState      = LifecycleState,
                    TimeCreated         = TimeCreated,
                    TimeUpdated         = TimeUpdated,
                    CreatedById         = CreatedById,
                    UpdatedById         = UpdatedById,
                    Fields       = Fields,
                    SortBy       = SortBy,
                    SortOrder    = SortOrder,
                    Limit        = Limit,
                    Page         = Page,
                    OpcRequestId = OpcRequestId
                };
                IEnumerable <ListGlossariesResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.GlossaryCollection, true);
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }