示例#1
0
 /// <summary>Snippet for CreateSubmission</summary>
 public void CreateSubmissionRequestObject()
 {
     // Snippet: CreateSubmission(CreateSubmissionRequest, CallSettings)
     // Create client
     WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.Create();
     // Initialize request argument(s)
     CreateSubmissionRequest request = new CreateSubmissionRequest
     {
         ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
         Submission          = new Submission(),
     };
     // Make the request
     Submission response = webRiskServiceClient.CreateSubmission(request);
     // End snippet
 }
示例#2
0
        /// <summary>Snippet for CreateSubmissionAsync</summary>
        public async Task CreateSubmissionRequestObjectAsync()
        {
            // Snippet: CreateSubmissionAsync(CreateSubmissionRequest, CallSettings)
            // Additional: CreateSubmissionAsync(CreateSubmissionRequest, CancellationToken)
            // Create client
            WebRiskServiceClient webRiskServiceClient = await WebRiskServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateSubmissionRequest request = new CreateSubmissionRequest
            {
                ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
                Submission          = new Submission(),
            };
            // Make the request
            Submission response = await webRiskServiceClient.CreateSubmissionAsync(request);

            // End snippet
        }
示例#3
0
        public void CreateSubmissionResourceNames()
        {
            moq::Mock <WebRiskService.WebRiskServiceClient> mockGrpcClient = new moq::Mock <WebRiskService.WebRiskServiceClient>(moq::MockBehavior.Strict);
            CreateSubmissionRequest request = new CreateSubmissionRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
                Submission          = new Submission(),
            };
            Submission expectedResponse = new Submission {
                Uri = "uri3db70593",
            };

            mockGrpcClient.Setup(x => x.CreateSubmission(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            WebRiskServiceClient client   = new WebRiskServiceClientImpl(mockGrpcClient.Object, null);
            Submission           response = client.CreateSubmission(request.ParentAsProjectName, request.Submission);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#4
0
        public async stt::Task CreateSubmissionResourceNamesAsync()
        {
            moq::Mock <WebRiskService.WebRiskServiceClient> mockGrpcClient = new moq::Mock <WebRiskService.WebRiskServiceClient>(moq::MockBehavior.Strict);
            CreateSubmissionRequest request = new CreateSubmissionRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
                Submission          = new Submission(),
            };
            Submission expectedResponse = new Submission {
                Uri = "uri3db70593",
            };

            mockGrpcClient.Setup(x => x.CreateSubmissionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Submission>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            WebRiskServiceClient client = new WebRiskServiceClientImpl(mockGrpcClient.Object, null);
            Submission           responseCallSettings = await client.CreateSubmissionAsync(request.ParentAsProjectName, request.Submission, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Submission responseCancellationToken = await client.CreateSubmissionAsync(request.ParentAsProjectName, request.Submission, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
示例#5
0
        private static void Submissions(OAuthAuthenticationStrategy auth)
        {
            var client = new SubmissionApiClient <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>(auth, projectId, "1e65ee5c-2555-4fd4-8305-56228ee3a0dd");

            var itemId = Guid.NewGuid().ToString();

            // List translation requests
            var query = new Dictionary <string, string>();

            query.Add("state", "In Progress|Translated|Completed");
            foreach (var s in client.GetPage(query, 100, 0).items)
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
                foreach (var sub in s.translationSubmissions)
                {
                    Console.WriteLine("  " + sub.state + sub.targetLocaleId);
                }
            }

            // Sample code to process items in bulk
            foreach (var item in client.GetAll(string.Empty, string.Empty))
            {
                var r = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();
                if (item.translationSubmissions == null || item.translationSubmissions.Where(x => x.state != "Deleted").Count() == 0)
                {
                    continue;
                }

                r.translationSubmissions = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >();
                foreach (TranslationSubmission <SampleTargetAssetKey, SampleCustomSubmissionData> s in item.translationSubmissions)
                {
                    r.translationSubmissions.Add(new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>
                    {
                        translationSubmissionUid = s.translationSubmissionUid,
                        state = "Deleted"
                    });
                }

                var ur = client.UpdateTranslationRequest(r, item.translationRequestUid);
            }

            var singleRequest = client.Get("27c4b81d8d52");

            // Create translation request
            var createTranslationRequest = new CreateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData>();

            createTranslationRequest.contentHash      = Guid.NewGuid().ToString().Substring(0, 32);
            createTranslationRequest.fileUri          = Guid.NewGuid().ToString();
            createTranslationRequest.originalAssetKey = new SampleOriginalAssetKey()
            {
                Key = itemId
            };
            createTranslationRequest.originalLocaleId   = "en";
            createTranslationRequest.title              = "test";
            createTranslationRequest.customOriginalData = new SampleCustomTranslationRequestData()
            {
                ItemId = itemId, Path = "content/home"
            };

            var request = client.CreateTranslationRequest(createTranslationRequest);

            // Search submissions
            var searchResult = client.GetPage("originalAssetKey.Key", itemId, 100, 0);

            searchResult = client.GetPage("translationRequestUid", "2e3b50ec4de3", 100, 0);

            query = new Dictionary <string, string>();
            query.Add("state", "Translated|Completed");
            query.Add("customTranslationData", "{\"MediaContent\": false }");
            // query.Add("customOriginalData", "{\"Path\": \"/sitecore/content/Home/Team/Chris-Castle\" }");
            searchResult = client.GetPage(query, 100, 0);

            // Create subsmission
            var submission = new CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>();

            submission.state          = "Deleted";
            submission.submitterName  = "test";
            submission.targetLocaleId = "ru-RU";
            submission.targetAssetKey = new SampleTargetAssetKey()
            {
                Key = Guid.NewGuid().ToString()
            };
            submission.customTranslationData = new SampleCustomSubmissionData()
            {
                Revision = Guid.NewGuid().ToString(), Locked = false, MediaContent = false
            };

            request = client.CreateSubmission(request.translationRequestUid, new List <CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >()
            {
                submission
            });

            // Update submission
            var updateRequest = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();

            updateRequest.customOriginalData      = request.customOriginalData;
            updateRequest.customOriginalData.Path = "newpath";
            updateRequest.translationSubmissions  = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> > {
                new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> {
                    translationSubmissionUid = request.translationSubmissions[0].translationSubmissionUid,
                    state            = "In Progress",
                    lastExportedDate = DateTime.UtcNow
                }
            };

            var updatedRequest = client.UpdateTranslationRequest(updateRequest, request.translationRequestUid);

            // List translation requests
            foreach (var s in client.GetAll("state", "In Progress"))
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
            }
        }
示例#6
0
 public Task <ApiResponse> CreateAsync(CreateSubmissionRequest request)
 => _client.PostAsync(Path, request);