├── src
├── Common
│ ├── AdsApi.snk
│ ├── Lib
│ │ ├── Configurable.cs
│ │ ├── AdsService.cs
│ │ ├── GzipHeaderInspector.cs
│ │ ├── AdsClient.cs
│ │ ├── ContextStore.cs
│ │ ├── ServiceFactory.cs
│ │ └── AdsException.cs
│ ├── Logging
│ │ ├── SoapMessageDirection.cs
│ │ ├── DefaultTraceWriter.cs
│ │ ├── ITraceWriter.cs
│ │ ├── TraceFormatter.cs
│ │ ├── SoapListener.cs
│ │ ├── DefaultBodyFormatter.cs
│ │ ├── UrlEncodedBodyFormatter.cs
│ │ ├── KeyValueMessageFormatter.cs
│ │ ├── JsonBodyFormatter.cs
│ │ ├── ResponseInfo.cs
│ │ ├── SoapTraceFormatter.cs
│ │ └── RequestInfo.cs
│ ├── Util
│ │ ├── DefaultDateTimeProvider.cs
│ │ ├── DateTimeProvider.cs
│ │ ├── AdsHttpClientFactory.cs
│ │ ├── DeprecationUtilities.cs
│ │ ├── CsvException.cs
│ │ ├── XmlUtilities.cs
│ │ ├── TemporaryIdGenerator.cs
│ │ ├── CollectionUtilities.cs
│ │ ├── PreconditionUtilities.cs
│ │ └── Reports
│ │ │ └── ReportsException.cs
│ ├── Common.csproj
│ ├── OAuth
│ │ └── OAuthClientMessageInspector.cs
│ └── Config
│ │ └── ConfigSetting.cs
├── package_icon.png
└── AdManager
│ ├── Lib
│ ├── AdManagerAuthorizationMethod.cs
│ ├── AdManagerServiceSignature.cs
│ ├── AdManagerService.cs
│ ├── AdManagerException.cs
│ ├── AdManagerTraceListener.cs
│ └── AdManagerUser.cs
│ ├── Headers
│ ├── AdManagerSoapHeader.cs
│ ├── ResponseHeader.cs
│ └── RequestHeader.cs
│ └── AdManager.csproj
├── tests
├── Common
│ ├── Mocks
│ │ ├── MockAdsService.cs
│ │ ├── IMockAdsService.cs
│ │ ├── MockClock.cs
│ │ ├── MockDateTimeProvider.cs
│ │ ├── MockHttpClientFactory.cs
│ │ ├── MockAdsSoapClient.cs
│ │ ├── MockTraceWriter.cs
│ │ ├── MockHttpMessageHandler.cs
│ │ ├── MockServiceSignature.cs
│ │ ├── MockAdsUser.cs
│ │ ├── MockServiceFactory.cs
│ │ └── MockTraceListener.cs
│ ├── Common.Tests.csproj
│ ├── Lib
│ │ ├── ServiceFactoryTests.cs
│ │ ├── ServiceSignatureTests.cs
│ │ ├── AdsExceptionTests.cs
│ │ └── GzipHeaderInspectorTests.cs
│ ├── Config
│ │ └── ConfigSettingTests.cs
│ ├── Logging
│ │ ├── DefaultBodyFormatterTests.cs
│ │ ├── KeyValueMessageFormatterTests.cs
│ │ ├── JsonBodyFormatterTests.cs
│ │ ├── SoapTraceFormatterTests.cs
│ │ └── UrlEncodedBodyFormatterTests.cs
│ ├── TestUtils.cs
│ ├── HttpMessage.cs
│ └── Util
│ │ ├── CollectionUtilitiesTest.cs
│ │ ├── CsvFileTests.cs
│ │ ├── XmlUtilitiesTest.cs
│ │ └── TemporaryIdGeneratorTests.cs
└── AdManager
│ ├── BaseTests.cs
│ ├── AdManager.Tests.csproj
│ ├── EnumIntegrityTests.cs
│ └── Lib
│ └── AdManagerAppConfigTests.cs
├── utilities
└── OAuthTokenGenerator
│ └── OAuthTokenGenerator.csproj
├── .gitignore
├── examples
└── AdManager
│ └── CSharp
│ ├── AdManager.Examples.CSharp.csproj
│ ├── v202505
│ ├── UserService
│ │ ├── GetAllRoles.cs
│ │ └── GetCurrentUser.cs
│ ├── NetworkService
│ │ ├── GetAllNetworks.cs
│ │ └── GetCurrentNetwork.cs
│ ├── InventoryService
│ │ └── GetAllAdUnitSizes.cs
│ └── SiteService
│ │ └── CreateSites.cs
│ ├── v202508
│ ├── UserService
│ │ ├── GetAllRoles.cs
│ │ └── GetCurrentUser.cs
│ ├── NetworkService
│ │ ├── GetAllNetworks.cs
│ │ └── GetCurrentNetwork.cs
│ ├── InventoryService
│ │ └── GetAllAdUnitSizes.cs
│ └── SiteService
│ │ └── CreateSites.cs
│ ├── v202511
│ ├── UserService
│ │ ├── GetAllRoles.cs
│ │ └── GetCurrentUser.cs
│ ├── NetworkService
│ │ ├── GetAllNetworks.cs
│ │ └── GetCurrentNetwork.cs
│ ├── InventoryService
│ │ └── GetAllAdUnitSizes.cs
│ └── SiteService
│ │ └── CreateSites.cs
│ └── SampleBase.cs
└── CONTRIBUTING.md
/src/Common/AdsApi.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleads/googleads-dotnet-lib/HEAD/src/Common/AdsApi.snk
--------------------------------------------------------------------------------
/src/package_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleads/googleads-dotnet-lib/HEAD/src/package_icon.png
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockAdsService.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.ServiceModel;
3 |
4 | namespace Google.Api.Ads.Common.Tests.Mocks {
5 |
6 | ///
7 | /// A mock ads service for testing
8 | ///
9 | public class MockAdsService : ClientBase {
10 | public MockAdsService(BasicHttpBinding binding, EndpointAddress endpoint)
11 | : base(binding, endpoint) {
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/tests/Common/Mocks/IMockAdsService.cs:
--------------------------------------------------------------------------------
1 | using System.ServiceModel;
2 |
3 | namespace Google.Api.Ads.Common.Tests.Mocks {
4 |
5 | ///
6 | /// A mock service interface for testing.
7 | ///
8 | [System.ServiceModel.ServiceContractAttribute(Namespace = "https://www.google.com/", ConfigurationName = "IMockAdsService")]
9 | public interface IMockAdsService {
10 |
11 | [System.ServiceModel.OperationContractAttribute(Action = "GetMockData")]
12 | void GetMockData();
13 | }
14 | }
--------------------------------------------------------------------------------
/utilities/OAuthTokenGenerator/OAuthTokenGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 | namespace Google.Api.Ads.Common.Utilities.OAuthTokenGenerator
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # User-specific files
2 | *.suo
3 | *.user
4 | *.sln.docstates
5 |
6 | # Build results
7 | [Dd]ebug/
8 | [Dd]ebugPublic/
9 | [Rr]elease/
10 | x64/
11 | build/
12 | bld/
13 | [Bb]in/
14 | [Oo]bj/
15 |
16 | #NUNIT
17 | *.VisualState.xml
18 | TestResult.xml
19 |
20 | # Visual Studio profiler
21 | *.psess
22 | *.vsp
23 | *.vspx
24 |
25 | # ReSharper files
26 | _ReSharper*/
27 | *.[Rr]e[Ss]harper
28 | *.DotSettings.user
29 |
30 | # NuGet Packages Directory
31 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
32 | #packages/
33 | ## TODO: If the tool you use requires repositories.config, also uncomment the next line
34 | #!packages/repositories.config
35 |
36 | # Backup & report files from converting an old project file to a newer
37 | # Visual Studio version
38 | _UpgradeReport_Files/
39 | Backup*/
40 | UpgradeLog*.XML
41 | UpgradeLog*.htm
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerAuthorizationMethod.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | namespace Google.Api.Ads.AdManager.Lib
16 | {
17 | ///
18 | /// List of supported Authorization methods for Ad Manager API.
19 | ///
20 | public enum AdManagerAuthorizationMethod
21 | {
22 | ///
23 | /// OAuth 2.0 draft 10 API.
24 | ///
25 | OAuth2
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Common/Lib/Configurable.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2013, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 |
17 | namespace Google.Api.Ads.Common.Lib
18 | {
19 | ///
20 | /// Marks a class as configurable.
21 | ///
22 | public interface Configurable
23 | {
24 | ///
25 | /// Gets the application configuration class for this object.
26 | ///
27 | AppConfig Config { get; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockClock.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Apis.Util;
16 | using System;
17 |
18 | namespace Google.Api.Ads.Common.Tests.Mocks {
19 | ///
20 | /// Mock IClock for testing purposes.
21 | ///
22 | class MockClock : IClock {
23 | DateTime IClock.Now => new DateTime(2018, 1, 1, 1, 1, 1, DateTimeKind.Utc);
24 | DateTime IClock.UtcNow => new DateTime(2018, 1, 1, 1, 1, 1, DateTimeKind.Utc);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Common/Logging/SoapMessageDirection.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 |
17 | namespace Google.Api.Ads.Common.Lib
18 | {
19 | ///
20 | /// Direction of SOAP message.
21 | ///
22 | public enum SoapMessageDirection
23 | {
24 | ///
25 | /// Response from the server.
26 | ///
27 | IN,
28 |
29 | ///
30 | /// Request to the server.
31 | ///
32 | OUT
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockDateTimeProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using System;
18 |
19 | namespace Google.Api.Ads.Common.Tests.Mocks {
20 |
21 | ///
22 | /// Mock Date time provider for testing purposes.
23 | ///
24 | public class MockDateTimeProvider : DateTimeProvider {
25 |
26 | ///
27 | /// Gets the mocked time.
28 | ///
29 | public DateTime Now {
30 | get {
31 | return new DateTime(2014, 11, 3, 12, 25, 30);
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/tests/Common/Common.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp3.1
4 | Google.Ads.Common.Tests
5 | Google.Api.Ads.Common.Tests
6 | true
7 | 4
8 | full
9 | true
10 | true
11 | true
12 | $(ProjectDir)..\..\src\Common\AdsApi.snk
13 | true
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Common/Util/DefaultDateTimeProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 |
17 | namespace Google.Api.Ads.Common.Util
18 | {
19 | ///
20 | /// Default implementation of DateTimeProvider.
21 | ///
22 | public class DefaultDateTimeProvider : DateTimeProvider
23 | {
24 | ///
25 | /// Gets the current time.
26 | ///
27 | ///
28 | /// The current time.
29 | ///
30 | public DateTime Now
31 | {
32 | get { return DateTime.Now; }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Common/Util/DateTimeProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 |
17 | namespace Google.Api.Ads.Common.Util
18 | {
19 | ///
20 | /// Provides the current date and time, without depending directly on
21 | /// System.DateTime. This makes testing code that depends on timestamps
22 | /// easier.
23 | ///
24 | public interface DateTimeProvider
25 | {
26 | ///
27 | /// Gets the current time.
28 | ///
29 | ///
30 | /// The current time.
31 | ///
32 | DateTime Now { get; }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Common/Lib/AdsService.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Reflection;
18 |
19 | namespace Google.Api.Ads.Common.Lib
20 | {
21 | ///
22 | /// Lists all the services available through this library.
23 | ///
24 | public abstract class AdsService
25 | {
26 | ///
27 | /// Gets all service types defined in this service.
28 | ///
29 | /// The nested types that define service versions under this
30 | /// service.
31 | public abstract Type[] GetServiceTypes();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockHttpClientFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Apis.Http;
16 | using System.Net.Http;
17 |
18 | namespace Google.Api.Ads.Common.Tests.Mocks {
19 | ///
20 | /// Mock HttpClientFactory for testing purposes.
21 | ///
22 | class MockHttpClientFactory : HttpClientFactory {
23 |
24 | ///
25 | /// Gets or sets the message handler for testing purposes.
26 | ///
27 | public MockHttpMessageHandler messageHandler { get; set; }
28 |
29 | protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args) {
30 | return messageHandler;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Common/Logging/DefaultTraceWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | namespace Google.Api.Ads.Common.Logging
18 | {
19 | ///
20 | /// Default instance of TraceWriter, which just delegates to TraceUtilities.
21 | ///
22 | public class DefaultTraceWriter : ITraceWriter
23 | {
24 | void ITraceWriter.WriteDetailedRequestLogs(string message, bool isFailure)
25 | {
26 | TraceUtilities.WriteDetailedRequestLogs(message, isFailure);
27 | }
28 |
29 | void ITraceWriter.WriteSummaryRequestLogs(string message, bool isFailure)
30 | {
31 | TraceUtilities.WriteSummaryRequestLogs(message, isFailure);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockAdsSoapClient.cs:
--------------------------------------------------------------------------------
1 | // copyright 2017, google inc. all rights reserved.
2 | //
3 | // licensed under the apache license, version 2.0 (the "license");
4 | // you may not use this file except in compliance with the license.
5 | // you may obtain a copy of the license at
6 | //
7 | // http://www.apache.org/licenses/license-2.0
8 | //
9 | // unless required by applicable law or agreed to in writing, software
10 | // distributed under the license is distributed on an "as is" basis,
11 | // without warranties or conditions of any kind, either express or implied.
12 | // see the license for the specific language governing permissions and
13 | // limitations under the license.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using System.ServiceModel;
17 | using System.ServiceModel.Channels;
18 |
19 | namespace Google.Api.Ads.Common.Tests.Mocks {
20 | public class MockAdsSoapClient : AdsSoapClient where TChannel : class {
21 | ///
22 | /// Initializes a new instance of the MockAdsSoapClient class.
23 | ///
24 | /// The binding with which to make calls to the service.
25 | /// Remote address of the service.
26 | public MockAdsSoapClient(Binding binding, EndpointAddress remoteAddress)
27 | : base(binding, remoteAddress) {
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockTraceWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 |
17 | namespace Google.Api.Ads.Common.Tests.Mocks {
18 |
19 | class MockTraceWriter : ITraceWriter {
20 | internal string SummaryLog { get; set; }
21 | internal bool IsSummaryFailure { get; set; }
22 |
23 | internal string DetailedLog { get; set; }
24 | internal bool IsDetailedLogFailure { get; set; }
25 |
26 | void ITraceWriter.WriteDetailedRequestLogs(string message, bool isFailure) {
27 | this.DetailedLog = message;
28 | this.IsDetailedLogFailure = isFailure;
29 | }
30 |
31 | void ITraceWriter.WriteSummaryRequestLogs(string message, bool isFailure) {
32 | this.SummaryLog = message;
33 | this.IsSummaryFailure = isFailure;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/AdManager/Headers/AdManagerSoapHeader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.ServiceModel.Channels;
19 |
20 | namespace Google.Api.Ads.AdManager.Headers
21 | {
22 | ///
23 | /// Base class for Ad Manager API Soap headers.
24 | ///
25 | public abstract class AdManagerSoapHeader : MessageHeader
26 | {
27 | ///
28 | /// The API version the header should be namespaced to.
29 | ///
30 | public string Version { get; set; }
31 |
32 | ///
33 | /// Gets the namespace.
34 | ///
35 | /// The namespace.
36 | public override string Namespace
37 | {
38 | get { return "https://www.google.com/apis/ads/publisher/" + Version; }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/Common/Lib/ServiceFactoryTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Tests.Mocks;
17 |
18 | using NUnit.Framework;
19 |
20 | using System;
21 |
22 | namespace Google.Api.Ads.Common.Tests.Lib {
23 | ///
24 | /// Tests the ServiceFactory class.
25 | ///
26 | public class ServiceFactoryTests {
27 | ///
28 | /// The test configuration class.
29 | ///
30 | MockAppConfig config = new MockAppConfig();
31 |
32 | ///
33 | /// Tests the property setters and getters.
34 | ///
35 | [Test]
36 | [Category("Small")]
37 | public void TestProperties() {
38 | ServiceFactory serviceFactory = new MockServiceFactory();
39 | serviceFactory.Config = config;
40 | Assert.AreEqual(config, serviceFactory.Config);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Common/Logging/ITraceWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | namespace Google.Api.Ads.Common.Logging
16 | {
17 | ///
18 | /// Interface for SOAP trace log writers.
19 | ///
20 | public interface ITraceWriter
21 | {
22 | ///
23 | /// Writes detailed logs.
24 | ///
25 | /// The log content to write
26 | /// If the log is for a failed request.
27 | void WriteDetailedRequestLogs(string message, bool isFailure);
28 |
29 | ///
30 | /// Writes summary logs.
31 | ///
32 | /// The log content to write
33 | /// If the log is for a failed request.
34 | void WriteSummaryRequestLogs(string message, bool isFailure);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Common/Logging/TraceFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Collections.Generic;
16 |
17 | namespace Google.Api.Ads.Common.Logging
18 | {
19 | ///
20 | /// Formats a Trace message.
21 | ///
22 | public abstract class TraceFormatter
23 | {
24 | ///
25 | /// The mask pattern to be used when masking sensitive data in logs.
26 | ///
27 | public const string MASK_PATTERN = "REDACTED";
28 |
29 | ///
30 | /// Masks the contents of the traced message.
31 | ///
32 | /// The message body.
33 | /// The keys for which values should be masked
34 | /// in the message body.
35 | /// The formatted message body.
36 | public abstract string MaskContents(string body, ISet keysToMask);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/Common/Config/ConfigSettingTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Config;
16 | using NUnit.Framework;
17 |
18 | namespace Google.Api.Ads.Common.Tests.Config {
19 |
20 | ///
21 | /// Tests for class.
22 | ///
23 | public class ConfigSettingTests {
24 | public const string CONFIG_NAME = "TestSetting";
25 | public const int DEFAULT_VALUE = 42;
26 |
27 | ///
28 | /// Tests the method.
29 | ///
30 | [Test]
31 | [Category("Small")]
32 | public void TestTryParse() {
33 | ConfigSetting configSetting = new ConfigSetting(CONFIG_NAME, DEFAULT_VALUE);
34 |
35 | configSetting.TryParse("foo");
36 | Assert.AreEqual(DEFAULT_VALUE, configSetting.Value);
37 |
38 | configSetting.TryParse("52");
39 | Assert.AreEqual(52, configSetting.Value);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/AdManager/BaseTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 |
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Text;
20 | using System.Threading;
21 |
22 | namespace Google.Api.Ads.AdManager.Tests
23 | {
24 | ///
25 | /// Base class for all test suites.
26 | ///
27 | public class BaseTests
28 | {
29 | ///
30 | /// The AdManagerUser to be used for tests.
31 | ///
32 | protected AdManagerUser user = new AdManagerUser();
33 |
34 | ///
35 | /// Default public constructor.
36 | ///
37 | /// The constructor adds a 200 ms delay between running individual
38 | /// tests so that we don't hit the server frequently and cause quota errors.
39 | ///
40 | public BaseTests()
41 | {
42 | Thread.Sleep(200);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Common/Logging/SoapListener.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System.Xml;
18 |
19 | namespace Google.Api.Ads.Common.Logging
20 | {
21 | ///
22 | /// Listens to SOAP messages sent and received by this library.
23 | ///
24 | public interface SoapListener : Configurable
25 | {
26 | ///
27 | /// Initializes the listener for handling an API call.
28 | ///
29 | void InitForCall();
30 |
31 | ///
32 | /// Handles the request and response for a message.
33 | ///
34 | /// Request info.
35 | /// Response info.
36 | void HandleMessage(RequestInfo requestInfo, ResponseInfo responseInfo);
37 |
38 | ///
39 | /// Cleans up any resources after an API call.
40 | ///
41 | void CleanupAfterCall();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockHttpMessageHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Net.Http;
17 | using System.Threading;
18 | using System.Threading.Tasks;
19 |
20 | namespace Google.Api.Ads.Common.Tests.Mocks {
21 | ///
22 | /// Mock HttpMessageHandler for testing purposes.
23 | ///
24 | class MockHttpMessageHandler : HttpMessageHandler {
25 | internal String LastRequest { get; private set; }
26 | internal String Response { get; set; }
27 |
28 | protected override Task SendAsync(HttpRequestMessage request,
29 | CancellationToken cancellationToken) {
30 | FormUrlEncodedContent content = request.Content as FormUrlEncodedContent;
31 | LastRequest = request.Content.ReadAsStringAsync().Result;
32 | var taskCompletion = new TaskCompletionSource();
33 | taskCompletion.SetResult(new HttpResponseMessage() {
34 | Content = new StringContent(Response)
35 | });
36 | return taskCompletion.Task;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Common/Logging/DefaultBodyFormatterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 | using Google.Api.Ads.Common.Util;
17 |
18 | using NUnit.Framework;
19 |
20 | using System.Collections.Generic;
21 |
22 | namespace Google.Api.Ads.Common.Tests.Util {
23 |
24 | ///
25 | /// UnitTests for class.
26 | ///
27 | [TestFixture]
28 | public class DefaultBodyFormatterTests {
29 | ///
30 | /// The request body to be used for testing.
31 | ///
32 | private const string BODY = "KEY1=foo;KEY2=bar";
33 |
34 | ///
35 | /// The keys to be masked in the request.
36 | ///
37 | private ISet KEYS = new HashSet() { "KEY1", "KEY2" };
38 |
39 | ///
40 | /// Test for DefaultBodyFormatter.MaskContents method.
41 | ///
42 | [Test]
43 | public void TestMaskContents() {
44 | Assert.AreEqual(BODY, new DefaultBodyFormatter().MaskContents(BODY, KEYS));
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockServiceSignature.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 |
19 | namespace Google.Api.Ads.Common.Tests.Mocks {
20 | ///
21 | /// Implements a mock version of the ServiceSignature class for testing
22 | /// purposes.
23 | ///
24 | public class MockServiceSignature : ServiceSignature {
25 | ///
26 | /// Initializes a new instance of the
27 | /// class.
28 | ///
29 | /// The version.
30 | /// Name of the service.
31 | /// The protocols.
32 | public MockServiceSignature(string version, string serviceName, SupportedProtocols protocols)
33 | : base(version, serviceName, protocols) {
34 | }
35 |
36 | ///
37 | /// Gets the type of service.
38 | ///
39 | public override Type ServiceType {
40 | get {
41 | return null;
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/AdManager/Headers/ResponseHeader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Runtime.Serialization;
16 |
17 | namespace Google.Api.Ads.AdManager.Headers
18 | {
19 | ///
20 | /// SOAP Response header for DFP API services.
21 | ///
22 | [DataContract(Name = "ResponseHeader", Namespace = PLACEHOLDER_NAMESPACE)]
23 | public class ResponseHeader
24 | {
25 | ///
26 | /// A placeholder namespace for deserializing response headers from different API versions.
27 | ///
28 | public const string PLACEHOLDER_NAMESPACE =
29 | "https://www.google.com/ads/api/publisher/version";
30 |
31 | ///
32 | /// Gets or sets the request id for this API call.
33 | ///
34 | [DataMember(Order = 0)]
35 | public string requestId { get; set; }
36 |
37 | ///
38 | /// Gets or sets the response time for this API call.
39 | ///
40 | [DataMember(Order = 1)]
41 | public long responseTime { get; set; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/AdManager.Examples.CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net6.0
4 | Google.Api.Ads.AdManager.Examples.CSharp
5 | Google.AdManager.Examples.CSharp
6 | Exe
7 | Google.Api.Ads.AdManager.Examples.CSharp.Program
8 | true
9 | $(ProjectDir)..\..\..\src\Common\AdsApi.snk
10 | pdbonly
11 | true
12 | true
13 | true
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
25 |
27 |
28 |
29 |
31 | App.config
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/Common/Logging/DefaultBodyFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Collections.Generic;
16 |
17 | namespace Google.Api.Ads.Common.Logging
18 | {
19 | ///
20 | /// Default instance of TraceFormatter. This class doesn't do any formatting
21 | /// transformation.
22 | ///
23 | public class DefaultBodyFormatter : TraceFormatter
24 | {
25 | ///
26 | /// Initializes a new instance of the
27 | /// class.
28 | ///
29 | public DefaultBodyFormatter() : base()
30 | {
31 | }
32 |
33 | ///
34 | /// Masks the contents of the traced message.
35 | ///
36 | /// The message body.
37 | /// The keys for which values should be masked
38 | /// in the message body.
39 | ///
40 | /// The formatted message body.
41 | ///
42 | public override string MaskContents(string body, ISet keysToMask)
43 | {
44 | return body;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerServiceSignature.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.Globalization;
19 |
20 | namespace Google.Api.Ads.AdManager.Lib
21 | {
22 | ///
23 | /// Service creation params for DFP API family of services.
24 | ///
25 | public class AdManagerServiceSignature : ServiceSignature
26 | {
27 | ///
28 | /// Gets the type of service.
29 | ///
30 | public override Type ServiceType
31 | {
32 | get
33 | {
34 | return Type.GetType(string.Format(CultureInfo.InvariantCulture,
35 | "Google.Api.Ads.AdManager.{0}.{1}", Version, ServiceName));
36 | }
37 | }
38 |
39 | ///
40 | /// Public constructor.
41 | ///
42 | /// Service version.
43 | /// Service name.
44 | public AdManagerServiceSignature(string version, string serviceName)
45 | : base(version, serviceName, SupportedProtocols.SOAP)
46 | {
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockAdsUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Logging;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.Common.Tests.Mocks {
21 | ///
22 | /// Implments a mock version of AdsUser class for testing purposes.
23 | ///
24 | class MockAdsUser : AdsUser {
25 | ///
26 | /// Overloaded constructor.
27 | ///
28 | /// The configuration class.
29 | public MockAdsUser(MockAppConfig config)
30 | : base(config) {
31 | }
32 |
33 | ///
34 | /// Gets all the service types to be registered against this user.
35 | ///
36 | ///
37 | /// The type of all service classes to be registered.
38 | ///
39 | public override Type[] GetServiceTypes() {
40 | return null;
41 | }
42 |
43 | ///
44 | /// Gets the default listeners.
45 | ///
46 | ///
47 | /// A list of default listeners
48 | ///
49 | public override SoapListener[] GetDefaultListeners() {
50 | return new SoapListener[] {new MockTraceListener(this.Config)};
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/Common/TestUtils.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2013, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using NUnit.Framework;
16 |
17 | using System;
18 | using System.Reflection;
19 |
20 | namespace Google.Api.Ads.Common.Tests {
21 | ///
22 | /// Support utility methods for running test cases.
23 | ///
24 | public class TestUtils {
25 | ///
26 | /// Validates whether an ArgumentNullException is called whenever a required
27 | /// property in targetObject is null, and testDelegate is invoked.
28 | ///
29 | /// The target object.
30 | /// The property names to be checked for null
31 | /// values.
32 | /// The test delegate.
33 | public static void ValidateRequiredParameters(object targetObject, string[] propertyNames,
34 | TestDelegate testDelegate) {
35 | foreach (string propertyName in propertyNames) {
36 | PropertyInfo propInfo = targetObject.GetType().GetProperty(propertyName);
37 | object oldValue = propInfo.GetValue(targetObject, null);
38 | if (propInfo.CanWrite) {
39 | propInfo.SetValue(targetObject, null, null);
40 | Assert.Throws(testDelegate);
41 | propInfo.SetValue(targetObject, oldValue, null);
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributor License Agreements
2 |
3 | We'd love to accept your code patches! However, before we can take them, we have to clear a couple
4 | of legal hurdles.
5 |
6 | - Please fill out either the individual or corporate Contributor License Agreement.
7 | - If you are an individual writing original source code and are sure you own the intellectual
8 | property, then you'll need to sign an individual CLA available at
9 | https://developers.google.com/open-source/cla/individual.
10 | - If you work for a company that wants to allow you to contribute your work to this client
11 | library, then you'll need to sign a corporate CLA available at
12 | https://developers.google.com/open-source/cla/corporate.
13 |
14 | Follow either of the two links above to access the appropriate CLA and instructions on how to sign
15 | and return it. Once we receive the CLA, we'll add you to the official list of contributors and
16 | will be able to accept your patches.
17 |
18 | # Submitting Patches
19 |
20 | - Sign a Contributor License Agreement (see above).
21 | - Join the appropriate product discussion forum.
22 | - AdWords API: https://developers.google.com/adwords/api/community/
23 | - DFP API: https://developers.google.com/doubleclick-publishers/community
24 | - Create an issue on the library issue tracker if there isn't one already. Use this issue to
25 | co-ordinate the changes with the library maintainer.
26 | - Fork the library, make the changes and send a
27 | [pull request](https://help.github.com/articles/using-pull-requests).
28 | - The library maintainer will work with you to review and apply the patch.
29 |
30 | # If you can't become a contributor
31 |
32 | If you can't become a contributor, but wish to share some code that illustrates an issue /
33 | shows how an issue may be fixed, then you can attach your changes on the issue tracker. We will
34 | use this code to troubleshoot the issue and fix it, but will not use this code in the library
35 | unless the steps to submit patches are done.
36 |
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerService.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Reflection;
20 |
21 | namespace Google.Api.Ads.AdManager.Lib
22 | {
23 | ///
24 | /// Lists all the services available through this library.
25 | ///
26 | public partial class AdManagerService : AdsService
27 | {
28 | ///
29 | /// Creates a service creation parameter for defining a DFP service.
30 | ///
31 | /// Service version.
32 | /// Service name.
33 | /// A service creation parameter defining this service.
34 | protected static ServiceSignature MakeServiceSignature(string version, string serviceName)
35 | {
36 | return new AdManagerServiceSignature(version, serviceName);
37 | }
38 |
39 | ///
40 | /// Gets all service types defined in this service.
41 | ///
42 | /// The nested types that define service versions under this
43 | /// service.
44 | public override Type[] GetServiceTypes()
45 | {
46 | return MethodInfo.GetCurrentMethod().DeclaringType.GetNestedTypes();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/Common/Lib/ServiceSignatureTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Tests.Mocks;
17 |
18 | using NUnit.Framework;
19 |
20 | using System;
21 |
22 | namespace Google.Api.Ads.Common.Tests.Lib {
23 | ///
24 | /// Tests the ServiceSignature class.
25 | ///
26 | public class ServiceSignatureTests {
27 | ///
28 | /// The test version string.
29 | ///
30 | const string VERSION = "TEST_VERSION";
31 |
32 | ///
33 | /// The test service name string.
34 | ///
35 | const string SERVICE_NAME = "SERVICE_NAME";
36 |
37 | ///
38 | /// The test protocol.
39 | ///
40 | const ServiceSignature.SupportedProtocols PROTOCOLS = ServiceSignature.SupportedProtocols.SOAP;
41 |
42 | ///
43 | /// Tests the property setters and getters.
44 | ///
45 | [Test]
46 | [Category("Small")]
47 | public void TestProperties() {
48 | MockServiceSignature signature = new MockServiceSignature(VERSION, SERVICE_NAME, PROTOCOLS);
49 | Assert.AreEqual(VERSION, signature.Version);
50 | Assert.AreEqual(SERVICE_NAME, signature.ServiceName);
51 | Assert.AreEqual(PROTOCOLS, signature.SupportedProtocol);
52 | Assert.NotNull(signature.Id);
53 | Assert.Null(signature.ServiceType);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/AdManager/AdManager.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp3.1
4 | Google.AdManager.Tests
5 | Google.Api.Ads.AdManager.Tests
6 | true
7 | 4
8 | full
9 | true
10 | true
11 | true
12 | true
13 | $(ProjectDir)..\..\src\Common\AdsApi.snk
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | App.config
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | True
38 | True
39 | Resources.resx
40 |
41 |
42 |
43 |
44 | ResXFileCodeGenerator
45 | Resources.Designer.cs
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/tests/Common/HttpMessage.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | namespace Google.Api.Ads.Common.Tests {
16 | ///
17 | /// Represents an HTTP request / response pair to be mocked.
18 | ///
19 | public class HttpMessage {
20 | ///
21 | /// Request body.
22 | ///
23 | string request;
24 |
25 | ///
26 | /// Response body.
27 | ///
28 | string response;
29 |
30 | ///
31 | /// Response type.
32 | ///
33 | string responseType;
34 |
35 | ///
36 | /// Overloaded constructor.
37 | ///
38 | /// The request body.
39 | /// The response body.
40 | /// The response type.
41 | public HttpMessage(string request, string response, string responseType) {
42 | this.request = request;
43 | this.response = response;
44 | this.responseType = responseType;
45 | }
46 |
47 | ///
48 | /// Gets the request.
49 | ///
50 | public string Request {
51 | get {
52 | return request;
53 | }
54 | }
55 |
56 | ///
57 | /// Gets the response.
58 | ///
59 | public string Response {
60 | get {
61 | return response;
62 | }
63 | }
64 |
65 | ///
66 | /// Gets the response type.
67 | ///
68 | public string ResponseType {
69 | get {
70 | return responseType;
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Common/Lib/GzipHeaderInspector.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.ServiceModel.Dispatcher;
17 | using System.ServiceModel.Channels;
18 | using System.ServiceModel;
19 |
20 | namespace Google.Api.Ads.Common.Lib
21 | {
22 | ///
23 | /// OAuth2 client message inspector that adds encoding HTTP headers.
24 | ///
25 | public class GzipHeaderInspector : IClientMessageInspector
26 | {
27 | internal const string ENCODING_HEADER = "Accept-Encoding";
28 |
29 | internal readonly string[] ACCEPT_VALUES =
30 | {
31 | "gzip",
32 | "deflate"
33 | };
34 |
35 | ///
36 | /// Adds an Accept-Encoding header to outbound requests.
37 | ///
38 | public object BeforeSendRequest(ref Message request, IClientChannel channel)
39 | {
40 | object httpProp;
41 | if (!request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpProp))
42 | {
43 | httpProp = new HttpRequestMessageProperty();
44 | request.Properties.Add(HttpRequestMessageProperty.Name, httpProp);
45 | }
46 |
47 | ((HttpRequestMessageProperty) httpProp).Headers.Add(ENCODING_HEADER,
48 | string.Join(", ", ACCEPT_VALUES));
49 | return null;
50 | }
51 |
52 | ///
53 | /// A no-op for this inspector.
54 | ///
55 | public void AfterReceiveReply(ref Message reply, object correlationState)
56 | {
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Common/Lib/AdsClient.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Net;
17 |
18 | using Google.Api.Ads.Common.Lib;
19 |
20 | namespace Google.Api.Ads.Common.Lib
21 | {
22 | ///
23 | /// This interface defines a client protocol (SOAP, WSE, REST, etc.)
24 | /// supported by the library.
25 | ///
26 | public interface AdsClient
27 | {
28 | ///
29 | /// The timeout for the request.
30 | ///
31 | int Timeout { get; set; }
32 |
33 | ///
34 | /// The url endpoint for the service.
35 | ///
36 | string Url { get; set; }
37 |
38 | ///
39 | /// Gets or sets whether gzip compression is enabled.
40 | ///
41 | bool EnableDecompression { get; set; }
42 |
43 | ///
44 | /// Gets or sets proxy information for making a service request through
45 | /// a firewall.
46 | ///
47 | IWebProxy Proxy { get; set; }
48 |
49 | ///
50 | /// Gets or sets the value for the user agent header that is sent with each
51 | /// request.
52 | ///
53 | string UserAgent { get; set; }
54 |
55 | ///
56 | /// Gets or sets the AdsUser object that created this
57 | /// service.
58 | ///
59 | AdsUser User { get; set; }
60 |
61 | ///
62 | /// Gets or sets the signature for this service.
63 | ///
64 | ServiceSignature Signature { get; set; }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Common/Logging/UrlEncodedBodyFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Collections.Generic;
16 | using System.Collections.Specialized;
17 | using System.Web;
18 |
19 | namespace Google.Api.Ads.Common.Logging
20 | {
21 | ///
22 | /// Formats a URL encoded HTTP trace message by masking out sensitive fields.
23 | ///
24 | public class UrlEncodedBodyFormatter : TraceFormatter
25 | {
26 | ///
27 | /// Masks the contents of the traced message.
28 | ///
29 | /// The message body.
30 | /// The keys for which values should be masked
31 | /// in the message body.
32 | ///
33 | /// The formatted message body.
34 | ///
35 | public override string MaskContents(string body, ISet keysToMask)
36 | {
37 | NameValueCollection collection = HttpUtility.ParseQueryString(body);
38 |
39 | foreach (string key in keysToMask)
40 | {
41 | if (keysToMask.Contains(key))
42 | {
43 | collection[key] = MASK_PATTERN;
44 | }
45 | }
46 |
47 | List encodedParams = new List();
48 | foreach (string key in collection.Keys)
49 | {
50 | encodedParams.Add(string.Format("{0}={1}", HttpUtility.UrlEncode(key),
51 | HttpUtility.UrlEncode(collection[key])));
52 | }
53 |
54 | return string.Join("&", encodedParams.ToArray());
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Common/Lib/ContextStore.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Collections.Concurrent;
16 |
17 | namespace Google.Api.Ads.Common.Lib
18 | {
19 | ///
20 | /// This class provides an environment agnostic context store.
21 | ///
22 | public static class ContextStore
23 | {
24 | private static ConcurrentDictionary store =
25 | new ConcurrentDictionary();
26 |
27 | ///
28 | /// Adds a key-value pair to the context store.
29 | ///
30 | /// The key for the value being stored.
31 | /// The value being stored.
32 | public static void AddKey(string key, object value)
33 | {
34 | store.AddOrUpdate(key, value, (k, v) => value);
35 | }
36 |
37 | ///
38 | /// Removes a stored value from the context store.
39 | ///
40 | /// The key for the value to be removed.
41 | public static void RemoveKey(string key)
42 | {
43 | store.TryRemove(key, out object ignored);
44 | }
45 |
46 | ///
47 | /// Gets the value of an item stored in the context store.
48 | ///
49 | /// The key for which value should be retrieved.
50 | /// The object's value, or null if the key is missing.
51 | public static object GetValue(string key)
52 | {
53 | return store.TryGetValue(key, out object value) ? value : null;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/Common/Logging/KeyValueMessageFormatterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 |
17 | using NUnit.Framework;
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Util {
22 |
23 | ///
24 | /// UnitTests for class.
25 | ///
26 | [TestFixture]
27 | public class KeyValueMessageFormatterTests {
28 | private const string KEY1 = "KEY1";
29 | private const string KEY2 = "KEY2";
30 | private const string KEY3 = "KEY3";
31 |
32 | private const string VALUE1 = "VALUE1";
33 | private const string VALUE2 = "VALUE2";
34 | private const string VALUE3 = "VALUE3";
35 |
36 | ///
37 | /// The request body to be used for testing.
38 | ///
39 | private readonly string BODY = string.Format("{0}={1}\r\n{2}={3}\r\n{4}={5}",
40 | KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3);
41 |
42 | private readonly string FORMATTED_BODY = string.Format("{0}={1}\r\n{2}={3}\r\n{4}={5}",
43 | KEY1, KeyValueMessageFormatter.MASK_PATTERN, KEY2, KeyValueMessageFormatter.MASK_PATTERN,
44 | KEY3, VALUE3);
45 | ///
46 | /// The keys to be masked in the request.
47 | ///
48 | private ISet KEYS = new HashSet() { KEY1, KEY2 };
49 |
50 | ///
51 | /// Test for KeyValueMessageFormatter.MaskContents method.
52 | ///
53 | [Test]
54 | public void TestMaskContents() {
55 | string maskedBody = new KeyValueMessageFormatter().MaskContents(BODY, KEYS);
56 | Assert.AreEqual(FORMATTED_BODY, maskedBody);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockServiceFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using System;
17 |
18 | namespace Google.Api.Ads.Common.Tests.Mocks {
19 | ///
20 | /// Implements a mock version of the ServiceFactory interface for testing
21 | /// purposes.
22 | ///
23 | public class MockServiceFactory : ServiceFactory {
24 | ///
25 | /// Create a service object.
26 | ///
27 | /// Signature of the service being created.
28 | /// The user for which the service is being created.
29 | /// The server to which the API calls should be
30 | /// made.
31 | ///
32 | ///
33 | /// An object of the desired service type.
34 | ///
35 | public override AdsClient CreateService(ServiceSignature signature, AdsUser user,
36 | Uri serverUrl) {
37 | return null;
38 | }
39 |
40 | ///
41 | /// Reads the headers from App.config.
42 | ///
43 | /// The configuration class.
44 | protected override void ReadHeadersFromConfig(AppConfig config) {
45 | return;
46 | }
47 |
48 | ///
49 | /// Checks preconditions of the service signature and throws and exception if the service
50 | /// cannot be generated.
51 | ///
52 | /// the service signature for generating the service
53 | protected override void CheckServicePreconditions(ServiceSignature signature) {
54 | return;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/Common/Util/CollectionUtilitiesTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2016, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using NUnit.Framework;
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Util
22 | {
23 | ///
24 | /// UnitTests for class.
25 | ///
26 | [TestFixture]
27 | public class CollectionUtilitiesTest
28 | {
29 | const long value = long.MinValue;
30 | const string invalidKey = "INVALID_KEY";
31 | const string validKey = "VALID_KEY";
32 |
33 | Dictionary dictionary;
34 |
35 | ///
36 | /// Inits this instance.
37 | ///
38 | [SetUp]
39 | public void Init() {
40 | dictionary = new Dictionary() {
41 | {validKey, value}
42 | };
43 | }
44 |
45 | ///
46 | /// Test for CollectionUtilities.TryGetValue()
47 | ///
48 | [Test]
49 | public void TestTryGetValue() {
50 | // Ensure that requesting an invalid key with no default specified returns the default
51 | // value for that type.
52 | Assert.AreEqual(0L, CollectionUtilities.TryGetValue(dictionary, invalidKey));
53 |
54 | long validValue = dictionary[validKey];
55 |
56 | // Ensure requesting a valid key returns the expected value.
57 | Assert.AreEqual(validValue, CollectionUtilities.TryGetValue(dictionary, validKey));
58 |
59 | // Ensure requesting an invalid key with a default specified returns the specified default.
60 | Assert.AreEqual(validValue,
61 | CollectionUtilities.TryGetValue(dictionary, invalidKey, validValue));
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Common/Common.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Ads API Dotnet Common Library
5 | 9.5.3
6 | This library provides you with common functionality to access Google's Ads APIs.
7 | See https://github.com/googleads/googleads-dotnet-lib/blob/main/ChangeLog
8 | AdWords DFP DoubleClick Google
9 | package_icon.png
10 | Copyright 2012, Google Inc. All Rights Reserved.
11 | https://github.com/AnashOommen, https://github.com/ChristopherSeeley, https://github.com/jimper
12 | Apache-2.0
13 | Google.Ads.Common
14 | true
15 |
16 |
17 |
18 |
19 | netstandard2.0
20 | Google.Ads.Common
21 | Google.Api.Ads.Common
22 | true
23 | $(ProjectDir)..\Common\AdsApi.snk
24 | portable
25 | true
26 | snupkg
27 | true
28 | true
29 | true
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/tests/Common/Logging/JsonBodyFormatterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 | using Newtonsoft.Json;
17 | using NUnit.Framework;
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Util {
22 |
23 | ///
24 | /// UnitTests for class.
25 | ///
26 | [TestFixture]
27 | public class JsonBodyFormatterTests {
28 | private const string KEY1 = "KEY1";
29 | private const string KEY2 = "KEY2";
30 | private const string KEY3 = "KEY3";
31 |
32 | private const string VALUE1 = "VALUE1";
33 | private const string VALUE2 = "VALUE2";
34 | private const string VALUE3 = "VALUE3";
35 |
36 | ///
37 | /// The request body to be used for testing.
38 | ///
39 | private readonly string BODY = string.Format("{{'{0}': '{1}', '{2}': '{3}', '{4}': '{5}'}}",
40 | KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3);
41 |
42 | ///
43 | /// The keys to be masked in the request.
44 | ///
45 | private ISet KEYS = new HashSet() { KEY1, KEY2 };
46 |
47 | ///
48 | /// Test for JsonBodyFormatter.MaskContents method.
49 | ///
50 | [Test]
51 | public void TestMaskContents() {
52 | string maskedBody = new JsonBodyFormatter().MaskContents(BODY, KEYS);
53 | Dictionary jsonDict =
54 | JsonConvert.DeserializeObject>(maskedBody);
55 |
56 | Assert.AreEqual(jsonDict[KEY1], TraceFormatter.MASK_PATTERN);
57 | Assert.AreEqual(jsonDict[KEY2], TraceFormatter.MASK_PATTERN);
58 | Assert.AreEqual(jsonDict[KEY3], VALUE3);
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/src/Common/Logging/KeyValueMessageFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Collections.Specialized;
18 |
19 | namespace Google.Api.Ads.Common.Logging
20 | {
21 | ///
22 | /// Formats a Key-value collection message by masking out sensitive fields.
23 | ///
24 | public class KeyValueMessageFormatter : TraceFormatter
25 | {
26 | ///
27 | /// Masks the contents of the traced message.
28 | ///
29 | /// The message body.
30 | /// The keys for which values should be masked
31 | /// in the message body.
32 | ///
33 | /// The formatted message body.
34 | ///
35 | public override string MaskContents(string body, ISet keysToMask)
36 | {
37 | string[] splits = body.Split(new char[]
38 | {
39 | '\r',
40 | '\n'
41 | }, StringSplitOptions.RemoveEmptyEntries);
42 | for (int i = 0; i < splits.Length; i++)
43 | {
44 | string split = splits[i];
45 | int delim = split.IndexOf('=');
46 | if (delim != -1)
47 | {
48 | string key = split.Substring(0, delim);
49 | if (keysToMask.Contains(key))
50 | {
51 | split = string.Format("{0}={1}", key, MASK_PATTERN);
52 | }
53 | }
54 |
55 | splits[i] = split;
56 | }
57 |
58 | return string.Join("\r\n", splits);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/Common/Util/AdsHttpClientFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Apis.Http;
17 |
18 | using System.Net.Http;
19 |
20 | namespace Google.Api.Ads.Common.Util
21 | {
22 | ///
23 | /// An implementation that allows setting proxy server.
24 | ///
25 | internal class AdsHttpClientFactory : HttpClientFactory
26 | {
27 | ///
28 | /// The configuration class for obtaining proxy instance.
29 | ///
30 | private AppConfig config;
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | /// The configuration instance.
36 | internal AdsHttpClientFactory(AppConfig config) : base()
37 | {
38 | this.config = config;
39 | }
40 |
41 | ///
42 | /// Creates a HTTP message handler. Override this method to mock a message handler.
43 | ///
44 | ///
45 | ///
46 | protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args)
47 | {
48 | if (config.Proxy != null)
49 | {
50 | HttpClientHandler webRequestHandler = new HttpClientHandler()
51 | {
52 | UseProxy = true,
53 | Proxy = config.Proxy,
54 | UseCookies = false
55 | };
56 |
57 | return webRequestHandler;
58 | }
59 | else
60 | {
61 | return base.CreateHandler(args);
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Common/Util/DeprecationUtilities.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2013, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Reflection;
17 |
18 | namespace Google.Api.Ads.Common.Util
19 | {
20 | ///
21 | /// Utility class to display deprecation message at runtime.
22 | ///
23 | public class DeprecationUtilities
24 | {
25 | ///
26 | /// Writes a deprecation message to Trace stream.
27 | ///
28 | /// Details of the deprecated member.
29 | /// The member corresponding to memberInfo should be annotated with
30 | /// an ObsoleteAttribute.
31 | public static void ShowDeprecationMessage(MemberInfo memberInfo)
32 | {
33 | if (memberInfo == null)
34 | {
35 | throw new NullReferenceException("MemberInfo cannot be null.");
36 | }
37 |
38 | TraceUtilities.WriteDeprecationWarnings(GetDeprecationMessage(memberInfo));
39 | }
40 |
41 | ///
42 | /// Gets the deprecation message to be displayed.
43 | ///
44 | /// Details of the deprecated member.
45 | /// The deprecation message as found on the ObsoleteAttribute
46 | /// decoration for this member, or null otherwise.
47 | private static string GetDeprecationMessage(MemberInfo memberInfo)
48 | {
49 | object[] attributes = memberInfo.GetCustomAttributes(typeof(ObsoleteAttribute), false);
50 |
51 | if (attributes.Length > 0)
52 | {
53 | return ((ObsoleteAttribute) attributes[0]).Message;
54 | }
55 |
56 | return null;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/AdManager/Headers/RequestHeader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.Xml;
19 | using System.ServiceModel.Channels;
20 |
21 |
22 | namespace Google.Api.Ads.AdManager.Headers
23 | {
24 | ///
25 | /// Soap Request header for DFP API services.
26 | ///
27 | public class RequestHeader : AdManagerSoapHeader, ICloneable
28 | {
29 | ///
30 | /// The name of the element to be used when serializing.
31 | ///
32 | public override string Name
33 | {
34 | get { return "RequestHeader"; }
35 | }
36 |
37 | ///
38 | /// Gets or sets the network code.
39 | ///
40 | public string networkCode { get; set; }
41 |
42 | ///
43 | /// Gets or sets the application name.
44 | ///
45 | public string applicationName { get; set; }
46 |
47 | ///
48 | /// Creates a new object that is a copy of the current instance.
49 | ///
50 | public object Clone()
51 | {
52 | return new RequestHeader()
53 | {
54 | networkCode = this.networkCode,
55 | applicationName = this.applicationName,
56 | Version = this.Version
57 | };
58 | }
59 |
60 | ///
61 | /// Serlalizes the RequestHeader for the SOAP XML request.
62 | ///
63 | protected override void OnWriteHeaderContents(XmlDictionaryWriter writer,
64 | MessageVersion messageVersion)
65 | {
66 | writer.WriteElementString("networkCode", networkCode);
67 | writer.WriteElementString("applicationName", applicationName);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Common/Util/CsvException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.IO;
19 | using System.Text;
20 | using System.Runtime.Serialization;
21 | using System.Security.Permissions;
22 | using System.Xml.Serialization;
23 |
24 | namespace Google.Api.Ads.Common.Util
25 | {
26 | ///
27 | /// Custom exception class for handling csv errors.
28 | ///
29 | [Serializable]
30 | public class CsvException : AdsException
31 | {
32 | ///
33 | /// Public constructor.
34 | ///
35 | public CsvException() : base()
36 | {
37 | }
38 |
39 | ///
40 | /// Public constructor.
41 | ///
42 | /// Error message for this API exception.
43 | public CsvException(string message) : base(message)
44 | {
45 | }
46 |
47 | ///
48 | /// Public constructor.
49 | ///
50 | /// Error message for this API exception.
51 | /// Inner exception, if any.
52 | public CsvException(string message, Exception innerException) : base(message,
53 | innerException)
54 | {
55 | }
56 |
57 | ///
58 | /// Protected constructor. Used by serialization frameworks while
59 | /// deserializing an exception object.
60 | ///
61 | /// Info about the serialization context.
62 | /// A streaming context that represents the
63 | /// serialization stream.
64 | protected CsvException(SerializationInfo info, StreamingContext context) : base(info,
65 | context)
66 | {
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.IO;
19 | using System.Runtime.Serialization;
20 | using System.Security.Permissions;
21 | using System.Text;
22 | using System.Xml.Serialization;
23 |
24 | namespace Google.Api.Ads.AdManager.Lib
25 | {
26 | ///
27 | /// Base class for all exceptions specific to DFP.
28 | ///
29 | [Serializable]
30 | public class AdManagerException : AdsException
31 | {
32 | ///
33 | /// Public constructor.
34 | ///
35 | public AdManagerException() : base()
36 | {
37 | }
38 |
39 | ///
40 | /// Public constructor.
41 | ///
42 | /// Error message for this API exception.
43 | public AdManagerException(string message) : base(message)
44 | {
45 | }
46 |
47 | ///
48 | /// Public constructor.
49 | ///
50 | /// Error message for this API exception.
51 | /// Inner exception, if any.
52 | public AdManagerException(string message, Exception innerException)
53 | : base(message, innerException)
54 | {
55 | }
56 |
57 | ///
58 | /// Protected constructor. Used by serialization frameworks while
59 | /// deserializing an exception object.
60 | ///
61 | /// Info about the serialization context.
62 | /// A streaming context that represents the
63 | /// serialization stream.
64 | protected AdManagerException(SerializationInfo info, StreamingContext context)
65 | : base(info, context)
66 | {
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/tests/Common/Util/CsvFileTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using NUnit.Framework;
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.IO;
22 | using System.Xml;
23 |
24 | namespace Google.Api.Ads.Common.Tests.Util {
25 | ///
26 | /// UnitTests for class.
27 | ///
28 | [TestFixture]
29 | public class CsvFileTests {
30 | ///
31 | /// Test for CsvFile.Write() and CsvFile.Read()
32 | ///
33 | [Test]
34 | public void TestCsvReadWrite() {
35 | string fileName = Path.GetTempFileName();
36 |
37 | CsvFile csvDoc = new CsvFile();
38 | csvDoc.Headers.AddRange(new string[] {"item1", "item2"});
39 | csvDoc.Records.Add(new string[] {"a", "1"});
40 | csvDoc.Records.Add(new string[] {"b,c", "2"});
41 | csvDoc.Records.Add(new string[] {"\"d\", \"e\"", "3"});
42 | Assert.DoesNotThrow(
43 | delegate() {
44 | csvDoc.Write(fileName);
45 | },
46 | "CsvFile.Write() should not throw an exception.");
47 |
48 | // Downloaded report should be a valid csv.
49 | csvDoc = new CsvFile();
50 | Assert.DoesNotThrow(
51 | delegate() {
52 | csvDoc.Read(fileName, true);
53 | },
54 | "CsvFile should not throw an exception.");
55 |
56 | Assert.AreEqual(csvDoc.Headers.Count, 2);
57 | Assert.AreEqual(csvDoc.Headers[0], "item1");
58 | Assert.AreEqual(csvDoc.Headers[1], "item2");
59 |
60 | Assert.AreEqual(csvDoc.Records.Count, 3);
61 |
62 | Assert.AreEqual(csvDoc.Records[0][0], "a");
63 | Assert.AreEqual(csvDoc.Records[0][1], "1");
64 | Assert.AreEqual(csvDoc.Records[1][0], "b,c");
65 | Assert.AreEqual(csvDoc.Records[1][1], "2");
66 | Assert.AreEqual(csvDoc.Records[2][0], "\"d\", \"e\"");
67 | Assert.AreEqual(csvDoc.Records[2][1], "3");
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/tests/Common/Mocks/MockTraceListener.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Logging;
17 |
18 | using System;
19 | using System.Collections.Generic;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Mocks {
22 | ///
23 | /// Implements a mock version of the TraceListener class for testing purposes.
24 | ///
25 | class MockTraceListener : TraceListener {
26 |
27 | ///
28 | /// The last ResponseInfo that was handled.
29 | ///
30 | public ResponseInfo LastResponseInfo { get; set; }
31 |
32 | ///
33 | /// The last RequestInfo that was handled.
34 | ///
35 | public RequestInfo LastRequestInfo { get; set; }
36 |
37 | ///
38 | /// Initializes a new instance of the class.
39 | ///
40 | /// The config class.
41 | public MockTraceListener(AppConfig config) : base(config) {
42 | this.DateTimeProvider = new MockDateTimeProvider();
43 | }
44 |
45 | ///
46 | /// Gets a list of fields to be masked in xml logs.
47 | ///
48 | ///
49 | /// The list of fields to be masked.
50 | ///
51 | protected override ISet GetFieldsToMask() {
52 | return new HashSet(new string[] { "authToken", "developerToken" },
53 | StringComparer.OrdinalIgnoreCase);
54 | }
55 |
56 | ///
57 | /// Writes summary logs.
58 | ///
59 | /// The log content to write
60 | /// If the log is for a failed request.
61 | public override void HandleMessage(RequestInfo requestInfo, ResponseInfo responseInfo) {
62 | this.LastRequestInfo = requestInfo;
63 | this.LastResponseInfo = responseInfo;
64 | base.HandleMessage(requestInfo, responseInfo);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/tests/Common/Logging/SoapTraceFormatterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 | using Google.Api.Ads.Common.Util;
17 |
18 | using NUnit.Framework;
19 |
20 | using System.Collections.Generic;
21 | using System.Xml;
22 |
23 | namespace Google.Api.Ads.Common.Tests.Util {
24 |
25 | ///
26 | /// UnitTests for class.
27 | ///
28 | [TestFixture]
29 | public class SoapTraceFormatterTests {
30 | ///
31 | /// The keys to be masked in the request.
32 | ///
33 | private ISet KEYS = new HashSet() { "KEY1", "KEY2" };
34 |
35 | ///
36 | /// Test for SoapTraceFormatter.MaskContents method.
37 | ///
38 | [Test]
39 | public void TestMaskContents() {
40 | string maskedBody = new SoapTraceFormatter().MaskContents(Resources.SoapRequest, KEYS);
41 | XmlDocument xDoc = XmlUtilities.CreateDocument(maskedBody);
42 | XmlNamespaceManager xmlns = new XmlNamespaceManager(xDoc.NameTable);
43 | xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
44 | xmlns.AddNamespace("cm", "https://adwords.google.com/api/adwords/cm/v201409");
45 |
46 | // Test masking on header nodes.
47 | XmlNodeList childNodes = xDoc.SelectNodes(
48 | "soap:Envelope/soap:Header/cm:RequestHeader/child::*", xmlns);
49 | foreach (XmlElement childNode in childNodes) {
50 | if (KEYS.Contains(childNode.LocalName)) {
51 | Assert.AreEqual(childNode.InnerText, SoapTraceFormatter.MASK_PATTERN);
52 | }
53 | }
54 |
55 | // Test masking on body nodes.
56 | childNodes = xDoc.SelectNodes("soap:Envelope/soap:Body/cm:get/child::*", xmlns);
57 | foreach (XmlElement childNode in childNodes) {
58 | if (KEYS.Contains(childNode.LocalName)) {
59 | Assert.AreEqual(childNode.InnerText, SoapTraceFormatter.MASK_PATTERN);
60 | }
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/tests/Common/Logging/UrlEncodedBodyFormatterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 |
17 | using NUnit.Framework;
18 |
19 | using System.Collections.Generic;
20 | using System.Web;
21 |
22 | namespace Google.Api.Ads.Common.Tests.Util {
23 |
24 | ///
25 | /// UnitTests for class.
26 | ///
27 | [TestFixture]
28 | public class UrlEncodedBodyFormatterTests {
29 | private const string KEY1 = "KEY1";
30 | private const string KEY2 = "KEY2";
31 | private const string KEY3 = "KEY3";
32 |
33 | private const string VALUE1 = "VALUE1";
34 | private const string VALUE2 = "VALUE2";
35 | private const string VALUE3 = "VALUE3";
36 |
37 | ///
38 | /// The request body to be used for testing.
39 | ///
40 | private readonly string BODY = string.Format("{0}={1}&{2}={3}&{4}={5}",
41 | HttpUtility.UrlEncode(KEY1),
42 | HttpUtility.UrlEncode(VALUE1),
43 | HttpUtility.UrlEncode(KEY2),
44 | HttpUtility.UrlEncode(VALUE2),
45 | HttpUtility.UrlEncode(KEY3),
46 | HttpUtility.UrlEncode(VALUE3));
47 |
48 | private readonly string FORMATTED_BODY = string.Format("{0}={1}&{2}={3}&{4}={5}",
49 | HttpUtility.UrlEncode(KEY1),
50 | KeyValueMessageFormatter.MASK_PATTERN,
51 | HttpUtility.UrlEncode(KEY2),
52 | KeyValueMessageFormatter.MASK_PATTERN,
53 | HttpUtility.UrlEncode(KEY3),
54 | HttpUtility.UrlEncode(VALUE3));
55 | ///
56 | /// The keys to be masked in the request.
57 | ///
58 | private ISet KEYS = new HashSet() { KEY1, KEY2 };
59 |
60 | ///
61 | /// Test for KeyValueMessageFormatter.MaskContents method.
62 | ///
63 | [Test]
64 | public void TestMaskContents() {
65 | string maskedBody = new UrlEncodedBodyFormatter().MaskContents(BODY, KEYS);
66 | Assert.AreEqual(FORMATTED_BODY, maskedBody);
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/UserService/GetAllRoles.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202505;
17 | using Google.Api.Ads.AdManager.v202505;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
22 | {
23 | ///
24 | /// This example gets all roles.
25 | ///
26 | public class GetAllRoles : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all roles."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllRoles codeExample = new GetAllRoles();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get roles. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (UserService userService = user.GetService())
59 | {
60 | Role[] roles = userService.getAllRoles();
61 |
62 | // Print out some information for each role.
63 | int i = 0;
64 | foreach (Role role in roles)
65 | {
66 | Console.WriteLine("{0}) Role with ID {1} and name \"{2}\" was found.", i++,
67 | role.id, role.name);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", roles.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/UserService/GetAllRoles.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202508;
17 | using Google.Api.Ads.AdManager.v202508;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
22 | {
23 | ///
24 | /// This example gets all roles.
25 | ///
26 | public class GetAllRoles : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all roles."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllRoles codeExample = new GetAllRoles();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get roles. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (UserService userService = user.GetService())
59 | {
60 | Role[] roles = userService.getAllRoles();
61 |
62 | // Print out some information for each role.
63 | int i = 0;
64 | foreach (Role role in roles)
65 | {
66 | Console.WriteLine("{0}) Role with ID {1} and name \"{2}\" was found.", i++,
67 | role.id, role.name);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", roles.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/UserService/GetAllRoles.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202511;
17 | using Google.Api.Ads.AdManager.v202511;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
22 | {
23 | ///
24 | /// This example gets all roles.
25 | ///
26 | public class GetAllRoles : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all roles."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllRoles codeExample = new GetAllRoles();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get roles. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (UserService userService = user.GetService())
59 | {
60 | Role[] roles = userService.getAllRoles();
61 |
62 | // Print out some information for each role.
63 | int i = 0;
64 | foreach (Role role in roles)
65 | {
66 | Console.WriteLine("{0}) Role with ID {1} and name \"{2}\" was found.", i++,
67 | role.id, role.name);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", roles.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Common/OAuth/OAuthClientMessageInspector.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.ServiceModel.Dispatcher;
16 | using System.ServiceModel.Channels;
17 | using System.ServiceModel;
18 |
19 | using Google.Api.Ads.Common.Lib;
20 |
21 | namespace Google.Api.Ads.Common.OAuth
22 | {
23 | ///
24 | /// OAuth2 client message inspector that adds authorization HTTP headers.
25 | ///
26 | public class OAuthClientMessageInspector : IClientMessageInspector
27 | {
28 | internal const string AUTHORIZATION_HEADER = "Authorization";
29 |
30 | AdsOAuthProvider oauthProvider;
31 |
32 | ///
33 | /// Initializes a new instance of the OAuth2ClientMessageInspector class.
34 | ///
35 | public OAuthClientMessageInspector(AdsOAuthProvider oauthProvider)
36 | {
37 | this.oauthProvider = oauthProvider;
38 | }
39 |
40 | ///
41 | /// Adds an OAuth2 authorization header to outbound requests.
42 | ///
43 | public object BeforeSendRequest(ref Message request, IClientChannel channel)
44 | {
45 | if (this.oauthProvider == null)
46 | {
47 | throw new AdsOAuthException("OAuth provider cannot be null");
48 | }
49 |
50 | object httpProp;
51 | if (!request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpProp))
52 | {
53 | httpProp = new HttpRequestMessageProperty();
54 | request.Properties.Add(HttpRequestMessageProperty.Name, httpProp);
55 | }
56 |
57 | ((HttpRequestMessageProperty) httpProp).Headers.Add(AUTHORIZATION_HEADER,
58 | this.oauthProvider.GetAuthHeader());
59 | return null;
60 | }
61 |
62 | ///
63 | /// Performs any operations after receiving the SOAP response.
64 | ///
65 | public void AfterReceiveReply(ref Message reply, object correlationState)
66 | {
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerTraceListener.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Logging;
16 |
17 | using System;
18 | using System.Collections.Generic;
19 |
20 | namespace Google.Api.Ads.AdManager.Lib
21 | {
22 | ///
23 | /// Listens to SOAP messages sent and received by this library.
24 | ///
25 | public class AdManagerTraceListener : TraceListener
26 | {
27 | ///
28 | /// The singleton instance.
29 | ///
30 | protected static AdManagerTraceListener instance = new AdManagerTraceListener();
31 |
32 | ///
33 | /// Protected constructor.
34 | ///
35 | protected AdManagerTraceListener() : base(new AdManagerAppConfig())
36 | {
37 | }
38 |
39 | ///
40 | /// Gets the singleton instance.
41 | ///
42 | public static SoapListener Instance
43 | {
44 | get { return instance; }
45 | }
46 |
47 | ///
48 | /// Parses the body of the request and populates fields in the request info.
49 | ///
50 | /// The request info for this SOAP call.
51 | protected override void PopulateRequestInfo(ref RequestInfo info)
52 | {
53 | base.PopulateRequestInfo(ref info);
54 |
55 | // Set the network code.
56 | info.IdentifierName = "networkCode";
57 | info.IdentifierValue = ((AdManagerAppConfig) this.Config).NetworkCode;
58 | }
59 |
60 | ///
61 | /// Gets a list of fields to be masked in xml logs.
62 | ///
63 | /// The list of fields to be masked.
64 | protected override ISet GetFieldsToMask()
65 | {
66 | return new HashSet(new string[]
67 | {
68 | "authToken",
69 | "token",
70 | "Authorization"
71 | }, StringComparer.OrdinalIgnoreCase);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Common/Logging/JsonBodyFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Collections.Specialized;
18 |
19 | using Newtonsoft.Json;
20 |
21 |
22 | namespace Google.Api.Ads.Common.Logging
23 | {
24 | ///
25 | /// Formats a JSON trace message by masking out sensitive fields.
26 | ///
27 | public class JsonBodyFormatter : TraceFormatter
28 | {
29 | ///
30 | /// Masks the contents of the traced message.
31 | ///
32 | /// The message body.
33 | /// The keys for which values should be masked
34 | /// in the message body.
35 | ///
36 | /// The formatted message body.
37 | ///
38 | public override string MaskContents(string body, ISet keysToMask)
39 | {
40 | Dictionary jsonDict = null;
41 |
42 | try
43 | {
44 | jsonDict = JsonConvert.DeserializeObject>(body);
45 | }
46 | catch
47 | {
48 | // This block could be hit if
49 | // - ArgumentException is thrown. This happens if the body being passed
50 | // here is not a JSON text.
51 | // - ArgumentNullException if body is null.
52 | // In both cases, it makes sense to return body unaltered.
53 | return body;
54 | }
55 |
56 | if (jsonDict != null)
57 | {
58 | foreach (string key in keysToMask)
59 | {
60 | if (jsonDict.ContainsKey(key))
61 | {
62 | jsonDict[key] = MASK_PATTERN;
63 | }
64 | }
65 |
66 | return JsonConvert.SerializeObject(jsonDict);
67 | }
68 | else
69 | {
70 | return body;
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Common/Util/XmlUtilities.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2016, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 |
16 | using System.IO;
17 | using System.Text;
18 | using System.Xml;
19 |
20 | namespace Google.Api.Ads.Common.Util
21 | {
22 | ///
23 | /// Utilities for working with XML.
24 | ///
25 | public class XmlUtilities
26 | {
27 | ///
28 | /// Loads a string into an XML document that that has XXE disabled.
29 | ///
30 | /// The XML document contents as a text.
31 | /// An XML Document object, with the contents loaded into the
32 | /// DOM.
33 | public static XmlDocument CreateDocument(string contents)
34 | {
35 | return CreateDocument(Encoding.UTF8.GetBytes(contents));
36 | }
37 |
38 | ///
39 | /// Loads the contents of a byte array into an XML document that
40 | /// has XXE disabled.
41 | ///
42 | /// The XML document contents as a byte array.
43 | /// An XML Document object, with the contents loaded into the
44 | /// DOM.
45 | public static XmlDocument CreateDocument(byte[] contents)
46 | {
47 | return CreateDocument(new MemoryStream(contents));
48 | }
49 |
50 | ///
51 | /// Loads the contents of a stream into an XML document that has XXE
52 | /// disabled.
53 | ///
54 | /// The content stream.
55 | /// An XML Document object, with the contents loaded into the
56 | /// DOM.
57 | public static XmlDocument CreateDocument(Stream stream)
58 | {
59 | XmlReaderSettings settings = new XmlReaderSettings()
60 | {
61 | DtdProcessing = DtdProcessing.Prohibit
62 | };
63 | XmlReader reader = XmlReader.Create(stream, settings);
64 | XmlDocument doc = new XmlDocument();
65 | doc.Load(reader);
66 | return doc;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/SampleBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Uncomment this key and recompile to make all the samples interactive
16 | // instead of manually replacing the INSERT_XXX fields in samples.
17 |
18 | #define INTERACTIVE
19 |
20 | using Google.Api.Ads.AdManager.Lib;
21 |
22 | using System;
23 | using System.Threading;
24 |
25 | namespace Google.Api.Ads.AdManager.Examples.CSharp
26 | {
27 | ///
28 | /// This abstract class represents a code example.
29 | ///
30 | public abstract class SampleBase
31 | {
32 | ///
33 | /// Returns a description about the code example.
34 | ///
35 | public abstract string Description { get; }
36 |
37 | ///
38 | /// Retrieves a user provided sample value.
39 | ///
40 | ///
41 | /// A prompt to display (when in interactive mode), or the value to be returned.
42 | ///
43 | ///
44 | /// When called in interactive mode, presents the provided string as a prompt to the user
45 | /// and returns the user provided input. Otherwise, returns the provided string exactly.
46 | ///
47 | protected static string _T(string prompt)
48 | {
49 | #if INTERACTIVE
50 | Console.Write(prompt + " : ");
51 | return Console.ReadLine();
52 | #else
53 | return prompt;
54 | #endif
55 | }
56 |
57 | ///
58 | /// Gets the current time stamp.
59 | ///
60 | /// The current timestamp as a string.
61 | /// You can use this method to generate a random string for use
62 | /// with various entities that need a unique name. The method adds a 100ms
63 | /// delay to prevent closely placed calls from generating the same
64 | /// timestamp.
65 | protected string GetTimeStamp()
66 | {
67 | Thread.Sleep(100);
68 | return (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds.ToString();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Common/Logging/ResponseInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Net;
16 |
17 | namespace Google.Api.Ads.Common.Logging
18 | {
19 | ///
20 | /// Stores the details of an HTTP response being logged.
21 | ///
22 | public class ResponseInfo
23 | {
24 | ///
25 | /// The HTTP response headers.
26 | ///
27 | public WebHeaderCollection Headers { get; set; }
28 |
29 | ///
30 | /// The HTTP response body.
31 | ///
32 | public string Body { get; set; }
33 |
34 | ///
35 | /// The HTTP status code of the response.
36 | ///
37 | public HttpStatusCode StatusCode { get; set; }
38 |
39 | ///
40 | /// The ID of the preceeding request.
41 | ///
42 | public string RequestId { get; set; }
43 |
44 | ///
45 | /// The count of operations included in the preceeding request.
46 | ///
47 | public long OperationCount { get; set; }
48 |
49 | ///
50 | /// The response time in milliseconds.
51 | ///
52 | public long ResponseTimeMs { get; set; }
53 |
54 | ///
55 | /// The error message associated with this response.
56 | ///
57 | public string ErrorMessage { get; set; }
58 |
59 | ///
60 | /// Initializes a new instance of the class.
61 | ///
62 | public ResponseInfo()
63 | {
64 | }
65 |
66 | ///
67 | /// Initializes a new instance of the class.
68 | ///
69 | /// The HTTP response.
70 | /// The HTTP response body.
71 | public ResponseInfo(WebResponse response, string body)
72 | {
73 | this.Headers = response != null ? response.Headers : new WebHeaderCollection();
74 | this.Body = body;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/NetworkService/GetAllNetworks.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202505;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
21 | {
22 | ///
23 | /// This example gets all networks.
24 | ///
25 | public class GetAllNetworks : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets all networks."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetAllNetworks codeExample = new GetAllNetworks();
41 | Console.WriteLine(codeExample.Description);
42 | try
43 | {
44 | codeExample.Run(new AdManagerUser());
45 | }
46 | catch (Exception e)
47 | {
48 | Console.WriteLine("Failed to get networks. Exception says \"{0}\"", e.Message);
49 | }
50 | }
51 |
52 | ///
53 | /// Run the code example.
54 | ///
55 | public void Run(AdManagerUser user)
56 | {
57 | using (NetworkService networkService = user.GetService())
58 | {
59 | Network[] networks = networkService.getAllNetworks();
60 |
61 | // Print out some information for each network.
62 | int i = 0;
63 | foreach (Network network in networks)
64 | {
65 | Console.WriteLine(
66 | "{0}) Network with code \"{1}\" and display name \"{2}\" was found.", i++,
67 | network.networkCode, network.displayName);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", networks.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/NetworkService/GetAllNetworks.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202508;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
21 | {
22 | ///
23 | /// This example gets all networks.
24 | ///
25 | public class GetAllNetworks : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets all networks."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetAllNetworks codeExample = new GetAllNetworks();
41 | Console.WriteLine(codeExample.Description);
42 | try
43 | {
44 | codeExample.Run(new AdManagerUser());
45 | }
46 | catch (Exception e)
47 | {
48 | Console.WriteLine("Failed to get networks. Exception says \"{0}\"", e.Message);
49 | }
50 | }
51 |
52 | ///
53 | /// Run the code example.
54 | ///
55 | public void Run(AdManagerUser user)
56 | {
57 | using (NetworkService networkService = user.GetService())
58 | {
59 | Network[] networks = networkService.getAllNetworks();
60 |
61 | // Print out some information for each network.
62 | int i = 0;
63 | foreach (Network network in networks)
64 | {
65 | Console.WriteLine(
66 | "{0}) Network with code \"{1}\" and display name \"{2}\" was found.", i++,
67 | network.networkCode, network.displayName);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", networks.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/NetworkService/GetAllNetworks.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202511;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
21 | {
22 | ///
23 | /// This example gets all networks.
24 | ///
25 | public class GetAllNetworks : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets all networks."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetAllNetworks codeExample = new GetAllNetworks();
41 | Console.WriteLine(codeExample.Description);
42 | try
43 | {
44 | codeExample.Run(new AdManagerUser());
45 | }
46 | catch (Exception e)
47 | {
48 | Console.WriteLine("Failed to get networks. Exception says \"{0}\"", e.Message);
49 | }
50 | }
51 |
52 | ///
53 | /// Run the code example.
54 | ///
55 | public void Run(AdManagerUser user)
56 | {
57 | using (NetworkService networkService = user.GetService())
58 | {
59 | Network[] networks = networkService.getAllNetworks();
60 |
61 | // Print out some information for each network.
62 | int i = 0;
63 | foreach (Network network in networks)
64 | {
65 | Console.WriteLine(
66 | "{0}) Network with code \"{1}\" and display name \"{2}\" was found.", i++,
67 | network.networkCode, network.displayName);
68 | }
69 |
70 | Console.WriteLine("Number of results found: {0}", networks.Length);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/NetworkService/GetCurrentNetwork.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202505;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
21 | {
22 | ///
23 | /// This code example gets the current network that you can make requests
24 | /// against.
25 | ///
26 | public class GetCurrentNetwork : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get
34 | {
35 | return "This code example gets the current network that you can make requests " +
36 | "against.";
37 | }
38 | }
39 |
40 | ///
41 | /// Main method, to run this code example as a standalone application.
42 | ///
43 | public static void Main()
44 | {
45 | GetCurrentNetwork codeExample = new GetCurrentNetwork();
46 | Console.WriteLine(codeExample.Description);
47 | codeExample.Run(new AdManagerUser());
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user)
54 | {
55 | using (NetworkService networkService = user.GetService())
56 | {
57 | try
58 | {
59 | // Get the current network.
60 | Network network = networkService.getCurrentNetwork();
61 |
62 | Console.WriteLine(
63 | "Current network has network code \"{0}\" and display name \"{1}\".",
64 | network.networkCode, network.displayName);
65 | }
66 | catch (Exception e)
67 | {
68 | Console.WriteLine("Failed to get current network. Exception says \"{0}\"",
69 | e.Message);
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/NetworkService/GetCurrentNetwork.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202508;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
21 | {
22 | ///
23 | /// This code example gets the current network that you can make requests
24 | /// against.
25 | ///
26 | public class GetCurrentNetwork : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get
34 | {
35 | return "This code example gets the current network that you can make requests " +
36 | "against.";
37 | }
38 | }
39 |
40 | ///
41 | /// Main method, to run this code example as a standalone application.
42 | ///
43 | public static void Main()
44 | {
45 | GetCurrentNetwork codeExample = new GetCurrentNetwork();
46 | Console.WriteLine(codeExample.Description);
47 | codeExample.Run(new AdManagerUser());
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user)
54 | {
55 | using (NetworkService networkService = user.GetService())
56 | {
57 | try
58 | {
59 | // Get the current network.
60 | Network network = networkService.getCurrentNetwork();
61 |
62 | Console.WriteLine(
63 | "Current network has network code \"{0}\" and display name \"{1}\".",
64 | network.networkCode, network.displayName);
65 | }
66 | catch (Exception e)
67 | {
68 | Console.WriteLine("Failed to get current network. Exception says \"{0}\"",
69 | e.Message);
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/NetworkService/GetCurrentNetwork.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202511;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
21 | {
22 | ///
23 | /// This code example gets the current network that you can make requests
24 | /// against.
25 | ///
26 | public class GetCurrentNetwork : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get
34 | {
35 | return "This code example gets the current network that you can make requests " +
36 | "against.";
37 | }
38 | }
39 |
40 | ///
41 | /// Main method, to run this code example as a standalone application.
42 | ///
43 | public static void Main()
44 | {
45 | GetCurrentNetwork codeExample = new GetCurrentNetwork();
46 | Console.WriteLine(codeExample.Description);
47 | codeExample.Run(new AdManagerUser());
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user)
54 | {
55 | using (NetworkService networkService = user.GetService())
56 | {
57 | try
58 | {
59 | // Get the current network.
60 | Network network = networkService.getCurrentNetwork();
61 |
62 | Console.WriteLine(
63 | "Current network has network code \"{0}\" and display name \"{1}\".",
64 | network.networkCode, network.displayName);
65 | }
66 | catch (Exception e)
67 | {
68 | Console.WriteLine("Failed to get current network. Exception says \"{0}\"",
69 | e.Message);
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/tests/Common/Util/XmlUtilitiesTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2016, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using NUnit.Framework;
18 |
19 | using System.Collections.Generic;
20 | using System.IO;
21 | using System.Text;
22 | using System.Xml;
23 |
24 | namespace Google.Api.Ads.Common.Tests.Util {
25 | ///
26 | /// UnitTests for class.
27 | ///
28 | [TestFixture]
29 | public class XmlUtilitiesTest {
30 |
31 | ///
32 | /// Inits this instance.
33 | ///
34 | [SetUp]
35 | public void Init() {
36 | }
37 |
38 | ///
39 | /// Tests that XmlDocument created with XmlUtililites doesn't resolve
40 | /// External Xml Entities.
41 | ///
42 | [Test]
43 | [Category("Small")]
44 | public void TestNoXxeTranslation() {
45 | Assert.Throws(delegate() {
46 | XmlDocument xDoc = XmlUtilities.CreateDocument(Resources.XxeExample);
47 | });
48 | }
49 |
50 | ///
51 | /// Tests that XmlDocument created with XmlUtililites can load an XML with
52 | /// UTF-8 BOM mark from a byte array or string.
53 | ///
54 | [Test]
55 | [Category("Small")]
56 | public void TestCanLoadXmlFromDiskWithUtf8BomInMemory() {
57 | Assert.DoesNotThrow(delegate() {
58 | XmlUtilities.CreateDocument(Resources.Utf8Bom);
59 | XmlUtilities.CreateDocument(Encoding.UTF8.GetBytes(Resources.Utf8Bom));
60 | });
61 | }
62 |
63 | ///
64 | /// Tests that XmlDocument created with XmlUtililites can load an XML with
65 | /// UTF-8 BOM mark from a file.
66 | ///
67 | [Test]
68 | [Category("Small")]
69 | public void TestCanLoadXmlFromDiskWithUtf8Bom() {
70 | string path = Path.GetTempFileName();
71 | using (FileStream fs = File.Create(path)) {
72 | byte[] bytes = Encoding.UTF8.GetBytes(Resources.Utf8Bom);
73 | fs.Write(bytes, 0, bytes.Length);
74 | }
75 | using (FileStream fs = File.OpenRead(path)) {
76 | Assert.DoesNotThrow(delegate() {
77 | XmlUtilities.CreateDocument(fs);
78 | });
79 | }
80 | }
81 | }
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/src/Common/Logging/SoapTraceFormatter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using System.Collections.Generic;
18 | using System.Text;
19 | using System.Xml;
20 |
21 | namespace Google.Api.Ads.Common.Logging
22 | {
23 | ///
24 | /// Formats a SOAP message.
25 | ///
26 | public class SoapTraceFormatter : TraceFormatter
27 | {
28 | private static readonly XmlWriterSettings XmlWriterSettings = new XmlWriterSettings()
29 | {
30 | Encoding = Encoding.UTF8,
31 | Indent = true
32 | };
33 |
34 | ///
35 | /// Masks the contents of the traced message.
36 | ///
37 | /// The message body.
38 | /// The keys for which values should be masked
39 | /// in the message body.
40 | ///
41 | /// The formatted message body.
42 | ///
43 | public override string MaskContents(string body, ISet keysToMask)
44 | {
45 | if (keysToMask.Count == 0)
46 | {
47 | return body;
48 | }
49 |
50 | XmlDocument xDoc = XmlUtilities.CreateDocument(body);
51 | XmlNamespaceManager xmlns = new XmlNamespaceManager(xDoc.NameTable);
52 | xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
53 |
54 | foreach (string key in keysToMask)
55 | {
56 | string xPath =
57 | string.Format("soap:Envelope/descendant::*[local-name()='{0}']", key);
58 | XmlNodeList nodes = xDoc.SelectNodes(xPath, xmlns);
59 | foreach (XmlElement node in nodes)
60 | {
61 | node.InnerText = MASK_PATTERN;
62 | }
63 | }
64 |
65 | // Pretty-print the XML.
66 | StringBuilder sb = new StringBuilder();
67 | using (XmlWriter xmlWriter = XmlWriter.Create(sb, XmlWriterSettings))
68 | {
69 | xDoc.WriteContentTo(xmlWriter);
70 | }
71 |
72 | return sb.ToString();
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/Common/Util/TemporaryIdGeneratorTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2013, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Util;
16 |
17 | using NUnit.Framework;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Util {
22 |
23 | ///
24 | /// Tests for class.
25 | ///
26 | [TestFixture]
27 | internal class TemporaryIdGeneratorTests {
28 |
29 | ///
30 | /// Tests the Next method with default values.
31 | ///
32 | [Test]
33 | [Category("Small")]
34 | public void TestNextWithDefaultValues() {
35 | TemporaryIdGenerator generator = new TemporaryIdGenerator();
36 | Assert.That(generator.Next == Int32.MinValue);
37 | Assert.That(generator.Next == Int32.MinValue + 1);
38 | }
39 |
40 | ///
41 | /// Tests the Next method when a start ID is provided.
42 | ///
43 | [Test]
44 | [Category("Small")]
45 | public void TestNextWithStartId() {
46 | int startId = -20;
47 | TemporaryIdGenerator generator = new TemporaryIdGenerator(startId);
48 |
49 | Assert.That(generator.Next == startId);
50 | Assert.That(generator.Next == startId + 1);
51 | }
52 |
53 | ///
54 | /// Tests that an exception is thrown when a positive start ID is provided.
55 | ///
56 | [Test]
57 | [Category("Small")]
58 | public void TestThrowsExceptionWithPositiveStartId() {
59 | int startId = 20;
60 | Assert.Throws(delegate() {
61 | TemporaryIdGenerator generator = new TemporaryIdGenerator(startId);
62 | });
63 |
64 | startId = 0;
65 | Assert.Throws(delegate() {
66 | TemporaryIdGenerator generator = new TemporaryIdGenerator(startId);
67 | });
68 | }
69 |
70 | ///
71 | /// Tests that an exception is thrown if a positive number gets generated.
72 | ///
73 | [Test]
74 | [Category("Small")]
75 | public void TestDoesNotGeneratePositiveId() {
76 | int startId = -1;
77 | TemporaryIdGenerator generator = new TemporaryIdGenerator(startId);
78 | Assert.Throws(delegate() {
79 | long next = generator.Next;
80 | });
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/UserService/GetCurrentUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202505;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
21 | {
22 | ///
23 | /// This code example gets current user. To create users, run CreateUsers.cs.
24 | ///
25 | public class GetCurrentUser : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets current user. To create users, run CreateUsers.cs."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetCurrentUser codeExample = new GetCurrentUser();
41 | Console.WriteLine(codeExample.Description);
42 | codeExample.Run(new AdManagerUser());
43 | }
44 |
45 | ///
46 | /// Run the code example.
47 | ///
48 | public void Run(AdManagerUser user)
49 | {
50 | using (UserService userService = user.GetService())
51 | {
52 | try
53 | {
54 | // Get the current user.
55 | User usr = userService.getCurrentUser();
56 |
57 | if (usr != null)
58 | {
59 | Console.WriteLine(
60 | "User with ID = '{0}', email = '{1}', and role = '{2}' is the " +
61 | "current user.", usr.id, usr.email, usr.roleName);
62 | }
63 | else
64 | {
65 | Console.WriteLine("The current user could not be retrieved.");
66 | }
67 | }
68 | catch (Exception e)
69 | {
70 | Console.WriteLine("Failed to get current user. Exception says \"{0}\"",
71 | e.Message);
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/UserService/GetCurrentUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202508;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
21 | {
22 | ///
23 | /// This code example gets current user. To create users, run CreateUsers.cs.
24 | ///
25 | public class GetCurrentUser : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets current user. To create users, run CreateUsers.cs."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetCurrentUser codeExample = new GetCurrentUser();
41 | Console.WriteLine(codeExample.Description);
42 | codeExample.Run(new AdManagerUser());
43 | }
44 |
45 | ///
46 | /// Run the code example.
47 | ///
48 | public void Run(AdManagerUser user)
49 | {
50 | using (UserService userService = user.GetService())
51 | {
52 | try
53 | {
54 | // Get the current user.
55 | User usr = userService.getCurrentUser();
56 |
57 | if (usr != null)
58 | {
59 | Console.WriteLine(
60 | "User with ID = '{0}', email = '{1}', and role = '{2}' is the " +
61 | "current user.", usr.id, usr.email, usr.roleName);
62 | }
63 | else
64 | {
65 | Console.WriteLine("The current user could not be retrieved.");
66 | }
67 | }
68 | catch (Exception e)
69 | {
70 | Console.WriteLine("Failed to get current user. Exception says \"{0}\"",
71 | e.Message);
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/UserService/GetCurrentUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202511;
17 |
18 | using System;
19 |
20 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
21 | {
22 | ///
23 | /// This code example gets current user. To create users, run CreateUsers.cs.
24 | ///
25 | public class GetCurrentUser : SampleBase
26 | {
27 | ///
28 | /// Returns a description about the code example.
29 | ///
30 | public override string Description
31 | {
32 | get { return "This example gets current user. To create users, run CreateUsers.cs."; }
33 | }
34 |
35 | ///
36 | /// Main method, to run this code example as a standalone application.
37 | ///
38 | public static void Main()
39 | {
40 | GetCurrentUser codeExample = new GetCurrentUser();
41 | Console.WriteLine(codeExample.Description);
42 | codeExample.Run(new AdManagerUser());
43 | }
44 |
45 | ///
46 | /// Run the code example.
47 | ///
48 | public void Run(AdManagerUser user)
49 | {
50 | using (UserService userService = user.GetService())
51 | {
52 | try
53 | {
54 | // Get the current user.
55 | User usr = userService.getCurrentUser();
56 |
57 | if (usr != null)
58 | {
59 | Console.WriteLine(
60 | "User with ID = '{0}', email = '{1}', and role = '{2}' is the " +
61 | "current user.", usr.id, usr.email, usr.roleName);
62 | }
63 | else
64 | {
65 | Console.WriteLine("The current user could not be retrieved.");
66 | }
67 | }
68 | catch (Exception e)
69 | {
70 | Console.WriteLine("Failed to get current user. Exception says \"{0}\"",
71 | e.Message);
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Common/Logging/RequestInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Net;
17 |
18 | namespace Google.Api.Ads.Common.Logging
19 | {
20 | ///
21 | /// Stores the details of an HTTP request being logged.
22 | ///
23 | public class RequestInfo
24 | {
25 | ///
26 | /// The request URI.
27 | ///
28 | public Uri Uri { get; set; }
29 |
30 | ///
31 | /// The HTTP request method.
32 | ///
33 | public string HttpMethod { get; set; }
34 |
35 | ///
36 | /// The HTTP request headers.
37 | ///
38 | public WebHeaderCollection Headers { get; set; }
39 |
40 | ///
41 | /// The HTTP request body.
42 | ///
43 | public string Body { get; set; }
44 |
45 | ///
46 | /// The service being requested.
47 | ///
48 | public string Service { get; set; }
49 |
50 | ///
51 | /// The method being requested.
52 | ///
53 | public string Method { get; set; }
54 |
55 | ///
56 | /// The identifier associated with this request.
57 | ///
58 | public string IdentifierName { get; set; }
59 |
60 | ///
61 | /// The value of the identifier associated with this request.
62 | ///
63 | public string IdentifierValue { get; set; }
64 |
65 | ///
66 | /// Initializes a new instance of the class.
67 | ///
68 | public RequestInfo()
69 | {
70 | }
71 |
72 | ///
73 | /// Initializes a new instance of the class.
74 | ///
75 | /// The HTTP request being logged.
76 | /// The HTTP request body.
77 | public RequestInfo(WebRequest request, string body)
78 | {
79 | this.Uri = request.RequestUri;
80 | this.HttpMethod = request.Method;
81 | this.Headers = request.Headers;
82 | this.Body = body;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/tests/AdManager/EnumIntegrityTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2016, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Tests;
16 | using Google.Api.Ads.AdManager.Lib;
17 |
18 | using NUnit.Framework;
19 |
20 | using System.Collections.Generic;
21 |
22 | namespace Google.Api.Ads.AdManager.Tests
23 | {
24 | ///
25 | /// UnitTests for service creation.
26 | ///
27 | [TestFixture]
28 | [Category("Smoke")]
29 | public class EnumIntegrityTests : BaseTests
30 | {
31 | private const string ROOT_NAMESPACE = "Google.Api.Ads.AdManager.";
32 |
33 | ///
34 | /// Default public constructor.
35 | ///
36 | public EnumIntegrityTests() : base()
37 | {
38 | }
39 |
40 | ///
41 | /// Test whether enum values are same across versions.
42 | ///
43 | [Test]
44 | public void TestEnumValues()
45 | {
46 | Dictionary lookup = new Dictionary();
47 |
48 | // Enumerate through each of the enums and their fields.
49 | StubIntegrityTestHelper.EnumerateEnumFields(ROOT_NAMESPACE,
50 |
51 | // For each matching enum and field, process it.
52 | delegate(string hashedFieldName, int enumValue)
53 | {
54 | // If this key exists in the lookup table, then the value of that
55 | // entry should match the value of the enum field we are examining.
56 | int existingEnumValue = 0;
57 | if (lookup.TryGetValue(hashedFieldName, out existingEnumValue))
58 | {
59 | Assert.AreEqual(existingEnumValue, enumValue,
60 | string.Format(
61 | "Enum value of {0} doesn't match. Old value: {1}, new value: {2}",
62 | hashedFieldName, existingEnumValue, enumValue));
63 | }
64 | else
65 | {
66 | // Otherwise, this is a new enum type / field. Add it to the lookup map.
67 | lookup[hashedFieldName] = enumValue;
68 | }
69 | });
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Common/Util/TemporaryIdGenerator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Linq;
18 |
19 | namespace Google.Api.Ads.Common.Util
20 | {
21 | ///
22 | /// Generates a sequence of temporary negative IDs.
23 | ///
24 | public class TemporaryIdGenerator
25 | {
26 | ///
27 | /// The number generation sequence.
28 | ///
29 | private IEnumerator sequence;
30 |
31 | ///
32 | /// Initializes a new instance of the class.
33 | ///
34 | public TemporaryIdGenerator() : this(Int32.MinValue)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the class.
40 | ///
41 | /// The ID to start generating the sequence from.
42 | /// If startId is a positive value.
43 | /// The IDs are generated in the increasing order from the
44 | /// .
45 | public TemporaryIdGenerator(int startId)
46 | {
47 | if (startId >= 0)
48 | {
49 | throw new ArgumentException("ID cannot be positive.");
50 | }
51 |
52 | int count = -1 - startId;
53 | sequence = Enumerable.Range(startId, count).GetEnumerator();
54 | }
55 |
56 | ///
57 | /// Returns the next ID in the list.
58 | ///
59 | ///
60 | public long Next
61 | {
62 | get
63 | {
64 | if (sequence.MoveNext())
65 | {
66 | return sequence.Current;
67 | }
68 | else
69 | {
70 | throw new ApplicationException("No more IDs to generate.");
71 | }
72 | }
73 | }
74 |
75 | ///
76 | /// Gets the sequence of numbers.
77 | ///
78 | public IEnumerator Sequence
79 | {
80 | get { return sequence; }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/Common/Util/CollectionUtilities.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2016, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.Collections.Generic;
16 |
17 | namespace Google.Api.Ads.Common.Util
18 | {
19 | ///
20 | /// Provides utility methods for working with collections.
21 | ///
22 | public static class CollectionUtilities
23 | {
24 | ///
25 | /// Attempts to retrieve a value associated with the specified key from the specified
26 | /// Dictionary.
27 | /// The dictionary to query.
28 | /// The key to retrieve a value for.
29 | ///
30 | /// The value associated with the spcified key, or the default value for that type if none
31 | /// could be found.
32 | public static T TryGetValue(Dictionary dictionary, S key)
33 | {
34 | return TryGetValue(dictionary, key, default(T));
35 | }
36 |
37 | ///
38 | /// Attempts to retrieve a value associated with the specified key from the specified
39 | /// Dictionary.
40 | /// The dictionary to query.
41 | /// The key to retrieve a value for.
42 | /// The value to return if none could be found.
43 | ///
44 | /// The value associated with the spcified key, or defaultValue if none could be found.
45 | ///
46 | public static T TryGetValue(Dictionary dictionary, S key, T defaultValue)
47 | {
48 | T value;
49 | return dictionary.TryGetValue(key, out value) ? value : defaultValue;
50 | }
51 |
52 | ///
53 | /// Expands an array and adds a value to it.
54 | ///
55 | /// Type of the array.
56 | /// The old array.
57 | /// The new value.
58 | /// The expanded array.
59 | public static T[] AddValueToArray(T[] oldArray, T newValue)
60 | {
61 | List retval = oldArray == null ? new List() : new List(oldArray);
62 | retval.Add(newValue);
63 | return retval.ToArray();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Common/Util/PreconditionUtilities.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Text;
18 |
19 | namespace Google.Api.Ads.Common.Util
20 | {
21 | ///
22 | /// Provides utility methods for checking preconditions.
23 | ///
24 | public class PreconditionUtilities
25 | {
26 | ///
27 | /// Utility method for null checking arguments.
28 | ///
29 | /// The Object to check
30 | /// The name of the argument being checked
31 | public static void CheckArgumentNotNull(object value, string argument)
32 | {
33 | if (value == null)
34 | {
35 | throw new ArgumentNullException(argument);
36 | }
37 | }
38 |
39 | ///
40 | /// Utility method for null checking arguments.
41 | ///
42 | /// The Object to check
43 | /// The name of the argument being checked
44 | public static void CheckArgument(bool condition, string message)
45 | {
46 | if (!condition)
47 | {
48 | throw new ArgumentException(message);
49 | }
50 | }
51 |
52 | ///
53 | /// Utility method for checking values.
54 | ///
55 | /// The Object to check
56 | /// The error message if the Object is null
57 | public static void CheckNotNull(object value, string message)
58 | {
59 | if (value == null)
60 | {
61 | throw new NullReferenceException(message);
62 | }
63 | }
64 |
65 | ///
66 | /// Utility method for checking the state of a class or method.
67 | ///
68 | /// The condition to check.
69 | /// The error message to use if the condition check
70 | /// fails.
71 | public static void CheckState(bool condition, string message)
72 | {
73 | if (!condition)
74 | {
75 | throw new InvalidOperationException(message);
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/InventoryService/GetAllAdUnitSizes.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202505;
17 | using Google.Api.Ads.AdManager.v202505;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
22 | {
23 | ///
24 | /// This example gets all ad unit sizes.
25 | ///
26 | public class GetAllAdUnitSizes : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all ad unit sizes."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllAdUnitSizes codeExample = new GetAllAdUnitSizes();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (InventoryService inventoryService = user.GetService())
59 | {
60 | // Create a statement to select ad unit sizes.
61 | StatementBuilder statementBuilder = new StatementBuilder();
62 |
63 | AdUnitSize[] adUnitSizes =
64 | inventoryService.getAdUnitSizesByStatement(statementBuilder.ToStatement());
65 |
66 | // Print out some information for each ad unit size.
67 | int i = 0;
68 | foreach (AdUnitSize adUnitSize in adUnitSizes)
69 | {
70 | Console.WriteLine("{0}) Ad unit size with dimensions \"{1}\" was found.", i++,
71 | adUnitSize.fullDisplayString);
72 | }
73 |
74 | Console.WriteLine("Number of results found: {0}", adUnitSizes.Length);
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202505/SiteService/CreateSites.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202505;
17 |
18 | using System;
19 | using System.Linq;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202505
22 | {
23 | ///
24 | /// This code example creates new sites.
25 | ///
26 | public class CreateSites : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This code example creates new sites."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | CreateSites codeExample = new CreateSites();
42 | Console.WriteLine(codeExample.Description);
43 |
44 | string childNetworkCode = _T("INSERT_CHILD_NETWORK_CODE_HERE");
45 | string url = _T("INSERT_URL_HERE");
46 |
47 | codeExample.Run(new AdManagerUser(), childNetworkCode, url);
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user, string childNetworkCode, string url)
54 | {
55 | using (SiteService siteService = user.GetService())
56 | {
57 | Site site = new Site() {
58 | childNetworkCode = childNetworkCode,
59 | url = url
60 | };
61 |
62 | try
63 | {
64 | // Create the sites on the server.
65 | Site[] sites = siteService.createSites(new Site[] { site });
66 |
67 | foreach (Site createdSite in sites)
68 | {
69 | Console.WriteLine("A site with ID \"{0}\" and URL \"{1}\" was created.",
70 | createdSite.id, createdSite.url);
71 | }
72 | }
73 | catch (Exception e)
74 | {
75 | Console.WriteLine("Failed to create sites. Exception says \"{0}\"",
76 | e.Message);
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/InventoryService/GetAllAdUnitSizes.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202508;
17 | using Google.Api.Ads.AdManager.v202508;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
22 | {
23 | ///
24 | /// This example gets all ad unit sizes.
25 | ///
26 | public class GetAllAdUnitSizes : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all ad unit sizes."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllAdUnitSizes codeExample = new GetAllAdUnitSizes();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (InventoryService inventoryService = user.GetService())
59 | {
60 | // Create a statement to select ad unit sizes.
61 | StatementBuilder statementBuilder = new StatementBuilder();
62 |
63 | AdUnitSize[] adUnitSizes =
64 | inventoryService.getAdUnitSizesByStatement(statementBuilder.ToStatement());
65 |
66 | // Print out some information for each ad unit size.
67 | int i = 0;
68 | foreach (AdUnitSize adUnitSize in adUnitSizes)
69 | {
70 | Console.WriteLine("{0}) Ad unit size with dimensions \"{1}\" was found.", i++,
71 | adUnitSize.fullDisplayString);
72 | }
73 |
74 | Console.WriteLine("Number of results found: {0}", adUnitSizes.Length);
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202508/SiteService/CreateSites.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202508;
17 |
18 | using System;
19 | using System.Linq;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202508
22 | {
23 | ///
24 | /// This code example creates new sites.
25 | ///
26 | public class CreateSites : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This code example creates new sites."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | CreateSites codeExample = new CreateSites();
42 | Console.WriteLine(codeExample.Description);
43 |
44 | string childNetworkCode = _T("INSERT_CHILD_NETWORK_CODE_HERE");
45 | string url = _T("INSERT_URL_HERE");
46 |
47 | codeExample.Run(new AdManagerUser(), childNetworkCode, url);
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user, string childNetworkCode, string url)
54 | {
55 | using (SiteService siteService = user.GetService())
56 | {
57 | Site site = new Site() {
58 | childNetworkCode = childNetworkCode,
59 | url = url
60 | };
61 |
62 | try
63 | {
64 | // Create the sites on the server.
65 | Site[] sites = siteService.createSites(new Site[] { site });
66 |
67 | foreach (Site createdSite in sites)
68 | {
69 | Console.WriteLine("A site with ID \"{0}\" and URL \"{1}\" was created.",
70 | createdSite.id, createdSite.url);
71 | }
72 | }
73 | catch (Exception e)
74 | {
75 | Console.WriteLine("Failed to create sites. Exception says \"{0}\"",
76 | e.Message);
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/InventoryService/GetAllAdUnitSizes.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.Util.v202511;
17 | using Google.Api.Ads.AdManager.v202511;
18 |
19 | using System;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
22 | {
23 | ///
24 | /// This example gets all ad unit sizes.
25 | ///
26 | public class GetAllAdUnitSizes : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This example gets all ad unit sizes."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | GetAllAdUnitSizes codeExample = new GetAllAdUnitSizes();
42 | Console.WriteLine(codeExample.Description);
43 | try
44 | {
45 | codeExample.Run(new AdManagerUser());
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine("Failed to get ad unit sizes. Exception says \"{0}\"", e.Message);
50 | }
51 | }
52 |
53 | ///
54 | /// Run the code example.
55 | ///
56 | public void Run(AdManagerUser user)
57 | {
58 | using (InventoryService inventoryService = user.GetService())
59 | {
60 | // Create a statement to select ad unit sizes.
61 | StatementBuilder statementBuilder = new StatementBuilder();
62 |
63 | AdUnitSize[] adUnitSizes =
64 | inventoryService.getAdUnitSizesByStatement(statementBuilder.ToStatement());
65 |
66 | // Print out some information for each ad unit size.
67 | int i = 0;
68 | foreach (AdUnitSize adUnitSize in adUnitSizes)
69 | {
70 | Console.WriteLine("{0}) Ad unit size with dimensions \"{1}\" was found.", i++,
71 | adUnitSize.fullDisplayString);
72 | }
73 |
74 | Console.WriteLine("Number of results found: {0}", adUnitSizes.Length);
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/AdManager/CSharp/v202511/SiteService/CreateSites.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 | using Google.Api.Ads.AdManager.v202511;
17 |
18 | using System;
19 | using System.Linq;
20 |
21 | namespace Google.Api.Ads.AdManager.Examples.CSharp.v202511
22 | {
23 | ///
24 | /// This code example creates new sites.
25 | ///
26 | public class CreateSites : SampleBase
27 | {
28 | ///
29 | /// Returns a description about the code example.
30 | ///
31 | public override string Description
32 | {
33 | get { return "This code example creates new sites."; }
34 | }
35 |
36 | ///
37 | /// Main method, to run this code example as a standalone application.
38 | ///
39 | public static void Main()
40 | {
41 | CreateSites codeExample = new CreateSites();
42 | Console.WriteLine(codeExample.Description);
43 |
44 | string childNetworkCode = _T("INSERT_CHILD_NETWORK_CODE_HERE");
45 | string url = _T("INSERT_URL_HERE");
46 |
47 | codeExample.Run(new AdManagerUser(), childNetworkCode, url);
48 | }
49 |
50 | ///
51 | /// Run the code example.
52 | ///
53 | public void Run(AdManagerUser user, string childNetworkCode, string url)
54 | {
55 | using (SiteService siteService = user.GetService())
56 | {
57 | Site site = new Site() {
58 | childNetworkCode = childNetworkCode,
59 | url = url
60 | };
61 |
62 | try
63 | {
64 | // Create the sites on the server.
65 | Site[] sites = siteService.createSites(new Site[] { site });
66 |
67 | foreach (Site createdSite in sites)
68 | {
69 | Console.WriteLine("A site with ID \"{0}\" and URL \"{1}\" was created.",
70 | createdSite.id, createdSite.url);
71 | }
72 | }
73 | catch (Exception e)
74 | {
75 | Console.WriteLine("Failed to create sites. Exception says \"{0}\"",
76 | e.Message);
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Common/Lib/ServiceFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.ComponentModel;
18 | using System.Text;
19 |
20 | namespace Google.Api.Ads.Common.Lib
21 | {
22 | ///
23 | /// Interface to a factory which can create a particular group of services.
24 | /// For every new service supported, you need an implementation of this
25 | /// interface.
26 | ///
27 | public abstract class ServiceFactory : Configurable
28 | {
29 | ///
30 | /// An App.config reader suitable for this factory.
31 | ///
32 | private AppConfig config;
33 |
34 | ///
35 | /// Gets an App.config reader suitable for this factory.
36 | ///
37 | public AppConfig Config
38 | {
39 | get { return config; }
40 | set
41 | {
42 | config = value;
43 | config.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
44 | {
45 | ReadHeadersFromConfig(config);
46 | };
47 | ReadHeadersFromConfig(config);
48 | }
49 | }
50 |
51 | ///
52 | /// Create a service object.
53 | ///
54 | /// Signature of the service being created.
55 | /// The user for which the service is being created.
56 | /// The server to which the API calls should be
57 | /// made.
58 | /// An object of the desired service type.
59 | public abstract AdsClient CreateService(ServiceSignature signature, AdsUser user,
60 | Uri serverUrl);
61 |
62 | ///
63 | /// Reads the headers from App.config.
64 | ///
65 | /// The configuration class.
66 | protected abstract void ReadHeadersFromConfig(AppConfig config);
67 |
68 | ///
69 | /// Checks preconditions of the service signature and throws and exception if the service
70 | /// cannot be generated.
71 | ///
72 | /// the service signature for generating the service
73 | protected abstract void CheckServicePreconditions(ServiceSignature signature);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/AdManager/Lib/AdManagerAppConfigTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2018, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.AdManager.Lib;
16 |
17 | using NUnit.Framework;
18 | using System;
19 |
20 | using System.Collections.Generic;
21 |
22 | namespace Google.Api.Ads.AdManager.Tests.Lib
23 | {
24 |
25 | internal class MockAdManagerAppConfig : AdManagerAppConfig
26 | {
27 |
28 | ///
29 | /// Allows the test cases to call ReadSettings method for testing purposes.
30 | ///
31 | /// The configuration settings.
32 | /// AppConfigBase class loads its settings from App.config, and the
33 | /// framework calls ReadSettings method to load the values. However, this is
34 | /// a protected method, so we expose ReadSettings in the mock version to
35 | /// allow easier configuration of AppConfig while running test cases.
36 | ///
37 | public void MockReadSettings(Dictionary dictSettings) =>
38 | base.ReadSettings(dictSettings);
39 | }
40 |
41 | ///
42 | /// Test cases for AdManagerAppConfig.
43 | ///
44 | internal class AdManagerAppConfigTests
45 | {
46 |
47 | ///
48 | /// The dictionary to hold the test data.
49 | ///
50 | private Dictionary dictSettings = new Dictionary()
51 | {
52 | { "NetworkCode", "1234567890" },
53 | { "ApplicationName", "TEST_APPLICATION_NAME" },
54 | { "AdManagerApi.Server", "TEST_ADMANAGER_SERVER" },
55 | { "AuthorizationMethod", "OAuth2" },
56 | };
57 |
58 | ///
59 | /// Tests that various settings are read correctly.
60 | ///
61 | [Test]
62 | [Category("Small")]
63 | public void TestReadSettings()
64 | {
65 | MockAdManagerAppConfig config = new MockAdManagerAppConfig();
66 | config.MockReadSettings(dictSettings);
67 |
68 | Assert.AreEqual(dictSettings["NetworkCode"], config.NetworkCode);
69 | Assert.AreEqual(dictSettings["ApplicationName"], config.ApplicationName);
70 | Assert.AreEqual(dictSettings["AdManagerApi.Server"], config.AdManagerApiServer);
71 | Assert.AreEqual(dictSettings["AuthorizationMethod"],
72 | config.AuthorizationMethod.ToString());
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/Common/Lib/AdsException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.IO;
18 | using System.Runtime.Serialization;
19 | using System.Text;
20 | using System.Xml.Serialization;
21 |
22 | namespace Google.Api.Ads.Common.Lib
23 | {
24 | ///
25 | /// Base class for all exceptions thrown by the library related
26 | /// to an Ads API call.
27 | ///
28 | [Serializable]
29 | public abstract class AdsException : Exception
30 | {
31 | ///
32 | /// Protected constructor.
33 | ///
34 | protected AdsException() : base()
35 | {
36 | }
37 |
38 | ///
39 | /// Protected constructor.
40 | ///
41 | /// Error message for this API exception.
42 | protected AdsException(string message) : base(message)
43 | {
44 | }
45 |
46 | ///
47 | /// Protected constructor.
48 | ///
49 | /// Error message for this API exception.
50 | /// Inner exception, if any.
51 | protected AdsException(string message, Exception innerException)
52 | : base(message, innerException)
53 | {
54 | }
55 |
56 | ///
57 | /// Protected constructor, used by serialization frameworks while
58 | /// deserializing an exception object.
59 | ///
60 | /// Info about the serialization context.
61 | /// A streaming context that represents the
62 | /// serialization stream.
63 | protected AdsException(SerializationInfo info, StreamingContext context)
64 | : base(info, context)
65 | {
66 | }
67 |
68 | ///
69 | /// Gets a specified field from serialization stream.
70 | ///
71 | /// The type of field.
72 | /// The serialization context.
73 | /// The serialization field name.
74 | /// The deserialized value of field.
75 | protected T GetValue(SerializationInfo info, string fieldName)
76 | {
77 | return (T) info.GetValue(fieldName, typeof(T));
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/Common/Util/Reports/ReportsException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 |
17 | using System;
18 | using System.Runtime.Serialization;
19 | using System.Security.Permissions;
20 |
21 | namespace Google.Api.Ads.Common.Util.Reports
22 | {
23 | ///
24 | /// Custom exception class for handling reporting errors.
25 | ///
26 | [Serializable]
27 | public class AdsReportsException : AdsException
28 | {
29 | ///
30 | /// Public constructor.
31 | ///
32 | public AdsReportsException() : base()
33 | {
34 | }
35 |
36 | ///
37 | /// Public constructor.
38 | ///
39 | /// Error message for this API exception.
40 | public AdsReportsException(string message) : base(message)
41 | {
42 | }
43 |
44 | ///
45 | /// Public constructor.
46 | ///
47 | /// Error message for this API exception.
48 | /// Inner exception, if any.
49 | public AdsReportsException(string message, Exception innerException)
50 | : base(message, innerException)
51 | {
52 | }
53 |
54 | ///
55 | /// Protected constructor. Used by serialization frameworks while
56 | /// deserializing an exception object.
57 | ///
58 | /// Info about the serialization context.
59 | /// A streaming context that represents the
60 | /// serialization stream.
61 | protected AdsReportsException(SerializationInfo info, StreamingContext context)
62 | : base(info, context)
63 | {
64 | }
65 |
66 | ///
67 | /// This method is called by serialization frameworks while serializing
68 | /// an exception object.
69 | ///
70 | /// Info about the serialization context.
71 | /// A streaming context that represents the
72 | /// serialization stream.
73 | [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
74 | public override void GetObjectData(SerializationInfo info, StreamingContext context)
75 | {
76 | base.GetObjectData(info, context);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Common/Config/ConfigSetting.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Util;
17 |
18 | using System.ComponentModel;
19 |
20 | namespace Google.Api.Ads.Common.Config
21 | {
22 | ///
23 | /// A config setting, to be used with and derived classes.
24 | ///
25 | public abstract class ConfigSetting
26 | {
27 | ///
28 | /// Gets the name of the setting.
29 | ///
30 | public string Name { get; protected set; }
31 |
32 | ///
33 | /// Tries to parse a value.
34 | ///
35 | /// The value text.
36 | public abstract void TryParse(string valueText);
37 | }
38 |
39 | ///
40 | /// A config setting of a specified type, to be used with
41 | /// and derived classes.
42 | ///
43 | /// The type of the setting.
44 | public class ConfigSetting : ConfigSetting
45 | {
46 | ///
47 | /// Gets or sets the value of the setting.
48 | ///
49 | public T Value { get; set; }
50 |
51 | ///
52 | /// Gets the default value of the setting.
53 | ///
54 | public T DefaultValue { get; private set; }
55 |
56 | ///
57 | /// Initializes a new instance of the class.
58 | ///
59 | /// Name of the setting.
60 | /// The default value.
61 | public ConfigSetting(string name, T defaultValue)
62 | {
63 | Name = name;
64 | DefaultValue = defaultValue;
65 | Value = defaultValue;
66 | }
67 |
68 | ///
69 | /// Tries to parse a value.
70 | ///
71 | /// The value text.
72 | public override void TryParse(string valueText)
73 | {
74 | TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
75 | try
76 | {
77 | Value = (T) converter.ConvertFromInvariantString(valueText);
78 | }
79 | catch
80 | {
81 | TraceUtilities.WriteGeneralWarnings(
82 | string.Format(CommonErrorMessages.ConfigSettingParseError, Name, valueText));
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/AdManager/AdManager.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Google's Ad Manager API Dotnet Client Library
5 | Google.Dfp
6 | 24.33.0
7 | This library provides you with functionality to access the Google's Ad Manager API.
8 | See https://github.com/googleads/googleads-dotnet-lib/blob/main/ChangeLog
9 | DFP Google
10 | package_icon.png
11 | Copyright 2011, Google Inc. All Rights Reserved.
12 | https://github.com/AnashOommen, https://github.com/ChristopherSeeley, https://github.com/jimper
13 | Apache-2.0
14 | Google
15 | git
16 | https://github.com/googleads/googleads-dotnet-lib
17 | true
18 |
19 |
20 |
21 | netstandard2.0
22 | Google.AdManager
23 | Google.Api.Ads.AdManager
24 | true
25 | ..\Common\AdsApi.snk
26 | pdbonly
27 | true
28 | snupkg
29 | true
30 | true
31 | true
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | True
55 | True
56 | AdManagerErrorMessages.resx
57 |
58 |
59 |
60 |
61 | ResXFileCodeGenerator
62 | AdManagerErrorMessages.Designer.cs
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/tests/Common/Lib/AdsExceptionTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2012, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Tests.Mocks;
17 |
18 | using NUnit.Framework;
19 |
20 | using System;
21 | using System.IO;
22 | using System.Runtime.Serialization.Formatters.Binary;
23 |
24 | namespace Google.Api.Ads.Common.Tests.Lib {
25 | ///
26 | /// Coverage tests for AdsException class.
27 | ///
28 | public class AdsExceptionTests {
29 | ///
30 | /// Message to be used for running tests.
31 | ///
32 | private string message = "This is a test message";
33 |
34 | ///
35 | /// Inner exception to be used for running tests.
36 | ///
37 | private ApplicationException innerException = new ApplicationException();
38 |
39 | ///
40 | /// Tests the default constructor.
41 | ///
42 | [Test]
43 | [Category("Small")]
44 | public void TestContructor1() {
45 | Assert.DoesNotThrow(delegate() {
46 | AdsException exception = new MockAdsException();
47 | });
48 | }
49 |
50 | ///
51 | /// Tests the overloaded constructors.
52 | ///
53 | [Test]
54 | [Category("Small")]
55 | public void TestContructor2() {
56 | AdsException exception = new MockAdsException(message);
57 | Assert.AreEqual(message, exception.Message);
58 | Assert.Null(exception.InnerException);
59 | }
60 |
61 | ///
62 | /// Tests the overloaded constructors.
63 | ///
64 | [Test]
65 | [Category("Small")]
66 | public void TestContructor3() {
67 | AdsException exception = new MockAdsException(message, innerException);
68 | Assert.AreEqual(message, exception.Message);
69 | Assert.AreEqual(innerException, exception.InnerException);
70 | }
71 |
72 | ///
73 | /// Tests the protected serialization constructor.
74 | ///
75 | [Test]
76 | [Category("Small")]
77 | public void TestContructor4() {
78 | Assert.DoesNotThrow(delegate() {
79 | MockAdsException exception = new MockAdsException();
80 | exception.MockProperty = 2;
81 | BinaryFormatter formatter = new BinaryFormatter();
82 | MemoryStream memStream = new MemoryStream();
83 | formatter.Serialize(memStream, exception);
84 | memStream.Seek(0, SeekOrigin.Begin);
85 | MockAdsException exception1 = (MockAdsException) formatter.Deserialize(memStream);
86 | memStream.Dispose();
87 | Assert.AreEqual(2, exception1.MockProperty);
88 | });
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/tests/Common/Lib/GzipHeaderInspectorTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2017, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System.ServiceModel;
16 | using System.ServiceModel.Channels;
17 | using Google.Api.Ads.Common.Lib;
18 | using Google.Api.Ads.Common.Tests.Mocks;
19 | using NUnit.Framework;
20 |
21 | namespace Google.Api.Ads.Common.Tests.Lib {
22 |
23 | ///
24 | /// UnitTests for class.
25 | ///
26 | [TestFixture]
27 | public class GzipHeaderInspectorTests {
28 | ///
29 | /// The service to test applying headers to.
30 | ///
31 | IClientChannel channel;
32 |
33 | ///
34 | /// The request Message for testing.
35 | ///
36 | private Message request;
37 |
38 | ///
39 | /// The test message version.
40 | ///
41 | readonly MessageVersion TestMessageVersion =
42 | MessageVersion.CreateVersion(EnvelopeVersion.Soap11);
43 |
44 | ///
45 | /// Initialize this test class instance.
46 | ///
47 | [SetUp]
48 | public void Init() {
49 | EndpointAddress endpoint = new EndpointAddress("http://www.google.com");
50 | BasicHttpBinding binding = new BasicHttpBinding();
51 | this.channel = new MockAdsService(binding, endpoint).InnerChannel;
52 | this.request = Message.CreateMessage(TestMessageVersion, "", "request body");
53 | }
54 |
55 | ///
56 | /// Test that the message state is valid and can be read
57 | /// after the inspector is applied.
58 | ///
59 | [Test]
60 | public void TestMessageIsValidState() {
61 | GzipHeaderInspector inspector = new GzipHeaderInspector();
62 | inspector.BeforeSendRequest(ref request, channel);
63 | inspector.AfterReceiveReply(ref request, channel);
64 | Assert.AreEqual(MessageState.Created, request.State);
65 | }
66 |
67 | ///
68 | /// Test that an appropriate Accept-Encoding HTTP header is added.
69 | ///
70 | [Test]
71 | public void TestAcceptEncodingHeaderApplied() {
72 | GzipHeaderInspector inspector = new GzipHeaderInspector();
73 | inspector.BeforeSendRequest(ref request, channel);
74 |
75 | object properties;
76 | request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out properties);
77 | HttpRequestMessageProperty httpProps = (HttpRequestMessageProperty)properties;
78 |
79 | Assert.AreEqual(1, httpProps.Headers.Count);
80 | Assert.AreEqual("Accept-Encoding", httpProps.Headers.GetKey(0));
81 | Assert.AreEqual("gzip, deflate", httpProps.Headers.Get(0));
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/src/AdManager/Lib/AdManagerUser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2011, Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using Google.Api.Ads.Common.Lib;
16 | using Google.Api.Ads.Common.Logging;
17 |
18 | using System;
19 | using System.Linq;
20 | using System.Collections.Generic;
21 |
22 | namespace Google.Api.Ads.AdManager.Lib
23 | {
24 | ///
25 | /// Represents an Ad Manager API user.
26 | ///
27 | public partial class AdManagerUser : AdsUser
28 | {
29 | ///
30 | /// Public constructor. Use this version if you want the library to
31 | /// use all settings from App.config.
32 | ///
33 | public AdManagerUser() : base(new AdManagerAppConfig())
34 | {
35 | }
36 |
37 | ///
38 | /// Parameterized constructor. Use this version if you want to construct
39 | /// a AdManagerUser with a custom set of headers.
40 | ///
41 | /// The custom set of headers.
42 | public AdManagerUser(Dictionary headers) : base(new AdManagerAppConfig(),
43 | headers)
44 | {
45 | }
46 |
47 | ///
48 | /// Public constructor. Use this version if you want to construct
49 | /// a AdManagerUser with a custom configuration.
50 | ///
51 | public AdManagerUser(AdManagerAppConfig config) : base(config)
52 | {
53 | }
54 |
55 | ///
56 | /// Gets all the service types to be registered against this user.
57 | ///
58 | /// The type of all service classes to be registered.
59 | public override Type[] GetServiceTypes()
60 | {
61 | return new AdManagerService().GetServiceTypes();
62 | }
63 |
64 | ///
65 | /// Gets the default listeners.
66 | ///
67 | /// A list of default listeners
68 | public override SoapListener[] GetDefaultListeners()
69 | {
70 | return new SoapListener[]
71 | {
72 | AdManagerTraceListener.Instance
73 | };
74 | }
75 |
76 | ///
77 | /// Creates a service of the given type.
78 | ///
79 | public T GetService() where T : AdsClient
80 | {
81 | Type serviceType = typeof(T);
82 | string version = serviceType.Namespace.Split('.').Last();
83 | AdManagerServiceSignature serviceSignature =
84 | new AdManagerServiceSignature(version, serviceType.Name);
85 | return (T) GetService(serviceSignature);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------