Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Search] Upgrade data plane to latest AutoRest and split into 4 packages #4104

Merged
merged 6 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/SDKs/Search/DataPlane/AssemblyInfo.Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using System.Reflection;
using System.Resources;

[assembly: AssemblyVersion("5.0.0.0")]
[assembly: AssemblyFileVersion("5.0.0.0")]

[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Microsoft Azure .NET SDK")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
10 changes: 10 additions & 0 deletions src/SDKs/Search/DataPlane/AzSearch.DataPlane.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PackageTags>Microsoft Azure Search;Search</PackageTags>
<VersionPrefix>5.0.0-preview</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net452;netstandard1.4</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brjohnstmsft looks like the bug has been fixed that allows you specify Fx Version common for projects.
In that case, we will apply target Fx version from a common file and at that point, this line will be deleted from here (of course you will be involved in the PR), just as an FYI

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static class CloudExceptionExtensions
/// </summary>
/// <param name="exception">The exception to check.</param>
/// <returns>true if the exception is a failed access condition (HTTP 412 Precondition Failed), false otherwise.</returns>
public static bool IsAccessConditionFailed(this CloudException exception)
{
return exception?.Response?.StatusCode == HttpStatusCode.PreconditionFailed;
}
public static bool IsAccessConditionFailed(this CloudException exception) =>
exception?.Response?.StatusCode == HttpStatusCode.PreconditionFailed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

namespace Microsoft.Azure.Search.Common
{
using System;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// Defines extension methods for IEnumerable that are used in the implementation of the Azure Search
/// .NET SDK.
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
/// Converts the elements of a collection to strings and concatenates them into a comma-separated list,
/// or returns null for null or empty collections.
/// </summary>
/// <typeparam name="T">The type of elements that will be converted to strings.</typeparam>
/// <param name="enumerable">The collection to turn into a comma-separated string.</param>
/// <returns>A comma-separated string, or null if enumerable is null or empty.</returns>
public static string ToCommaSeparatedString<T>(this IEnumerable<T> enumerable)
{
if (enumerable == null || !enumerable.Any())
{
return null;
}

return String.Join(",", enumerable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

namespace Microsoft.Azure.Search.Common
{
using System;

/// <summary>
/// Defines utility methods for validating arguments.
/// </summary>
public static class Throw
{
/// <summary>
/// Throws ArgumentException with the given parameter name and optional message if the given Boolean
/// value is true.
/// </summary>
/// <param name="isInvalid">The flag to test. This method throws if it's true and does nothing if
/// it's false.</param>
/// <param name="paramName">The name of the parameter being validated. This is passed to the
/// ArgumentException constructor.</param>
/// <param name="message">An optional error message to include in the ArgumentException. The default
/// message is "Invalid argument."</param>
public static void IfArgument(bool isInvalid, string paramName, string message = null)
{
if (isInvalid)
{
message = message ?? "Invalid argument.";
throw new ArgumentException(message, paramName);
}
}

/// <summary>
/// Throws ArgumentNullException with the given parameter name and optional message if the given
/// reference is null.
/// </summary>
/// <typeparam name="T">The type of value to test. Must be a reference type.</typeparam>
/// <param name="value">The reference to test for null.</param>
/// <param name="paramName">The name of the parameter being validated. This is passed to the
/// ArgumentNullException constructor.</param>
/// <param name="message">An optional error message to include in the ArgumentNullException.</param>
public static void IfArgumentNull<T>(T value, string paramName, string message = null) where T : class
{
if (value == null)
{
if (message == null)
{
throw new ArgumentNullException(paramName);
}
else
{
throw new ArgumentNullException(paramName, message);
}
}
}

/// <summary>
/// Throws ArgumentNullException or ArgumentException with the given parameter name and optional message
/// if the given string is null or empty, respectively.
/// </summary>
/// <param name="value">The string to test for null or empty.</param>
/// <param name="paramName">The name of the parameter being validated. This is passed to the
/// ArgumentNullException or ArgumentException constructor.</param>
/// <param name="message">An optional error message to include in the ArgumentNullException
/// or ArgumentException.</param>
public static void IfArgumentNullOrEmpty(string value, string paramName, string message = null)
{
IfArgumentNull(value, paramName, message);

message = message ?? "Argument cannot be an empty string.";
IfArgument(value.Length == 0, paramName, message);
}

/// <summary>
/// Throws ArgumentNullException or ArgumentException with a pre-determined message if the given search
/// service name is null or empty, respectively.
/// </summary>
/// <param name="searchServiceName">The search service name to validate.</param>
public static void IfNullOrEmptySearchServiceName(string searchServiceName) =>
IfArgumentNullOrEmpty(
searchServiceName,
nameof(searchServiceName),
"Invalid search service name. Name cannot be null or an empty string.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Search.Models
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Common;

/// <summary>
/// Abstract base class for types that act like enums, but can be extended with arbitrary string values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ namespace Microsoft.Azure.Search.Models
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class SerializePropertyNamesAsCamelCaseAttribute : Attribute
{
internal static bool IsDefinedOnType<T>()
{
return typeof(T)
/// <summary>
/// Indicates whether the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute.
/// </summary>
/// <typeparam name="T">The type to test.</typeparam>
/// <returns>true if the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute,
/// false otherwise.</returns>
public static bool IsDefinedOnType<T>() =>
typeof(T)
.GetTypeInfo()
.GetCustomAttributes(typeof(SerializePropertyNamesAsCamelCaseAttribute), inherit: true)
.Any();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace Microsoft.Azure.Search
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Rest;
using Common;
using Rest;

/// <summary>
/// Credentials used to authenticate to an Azure Search service.
Expand All @@ -28,14 +29,14 @@ public class SearchCredentials : ServiceClientCredentials
public SearchCredentials(string apiKey)
{
Throw.IfArgumentNullOrEmpty(apiKey, "apiKey");
this.ApiKey = apiKey;
ApiKey = apiKey;
}

/// <summary>
/// api-key used to authenticate to an Azure Search service. Can be either a query key for querying only, or
/// an admin key that enables index and document management as well.
/// </summary>
public string ApiKey { get; private set; }
public string ApiKey { get; }

/// <summary>
/// Adds the credentials to the given HTTP request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Search.Serialization
{
using System;
using System.Reflection;
using Common;
using Models;
using Newtonsoft.Json;

Expand All @@ -22,7 +23,7 @@ namespace Microsoft.Azure.Search.Serialization
/// that they have well-known values, but they are extensible with new values and the values are based on strings
/// instead of integers.
/// </summary>
public class ExtensibleEnumConverter<T> : ConverterBase where T : ExtensibleEnum<T>
public class ExtensibleEnumConverter<T> : JsonConverter where T : ExtensibleEnum<T>
{
private ExtensibleEnumValueFactory<T> _enumValueFactory;

Expand Down Expand Up @@ -86,7 +87,7 @@ public override object ReadJson(
return null;
}

return _enumValueFactory(Expect<string>(reader, JsonToken.String));
return _enumValueFactory(reader.Expect<string>(JsonToken.String));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Microsoft.Azure.Search.Serialization
using Newtonsoft.Json;

/// <summary>
/// Base class for custom JsonConverters.
/// Defines extension methods for JsonReader that make it easier to implement a custom JsonConverter.
/// </summary>
public abstract class ConverterBase : JsonConverter
public static class JsonReaderExtensions
{
/// <summary>
/// Asserts that the given JSON reader is positioned on a token with the expected type. Optionally asserts
Expand All @@ -22,16 +22,16 @@ public abstract class ConverterBase : JsonConverter
/// <param name="reader">The JSON reader.</param>
/// <param name="expectedToken">The JSON token on which the reader is expected to be positioned.</param>
/// <param name="expectedValue">Optional; The expected value of the current JSON token.</param>
protected void ExpectAndAdvance(JsonReader reader, JsonToken expectedToken, object expectedValue = null)
{
ExpectAndAdvance<object>(reader, expectedToken, expectedValue);
}
public static void ExpectAndAdvance(
this JsonReader reader,
JsonToken expectedToken,
object expectedValue = null) => ExpectAndAdvance<object>(reader, expectedToken, expectedValue);

/// <summary>
/// Asserts that the given JSON reader is positioned on a token with the expected type and retrieves the value
/// of the token, if any. Optionally asserts that the value of the token matches a given expected value. If
/// any of the assertions fail, this method throws a JsonSerializationException. Otherwise, this method
/// attempts to advance the JSON reader to the next position.
/// Asserts that the given JSON reader is positioned on a token with the expected type and retrieves the
/// value of the token, if any. Optionally asserts that the value of the token matches a given expected
/// value. If any of the assertions fail, this method throws a JsonSerializationException. Otherwise, this
/// method attempts to advance the JSON reader to the next position.
/// </summary>
/// <typeparam name="TValue">The expected type of the value of the current JSON token.</typeparam>
/// <param name="reader">The JSON reader.</param>
Expand All @@ -40,7 +40,10 @@ protected void ExpectAndAdvance(JsonReader reader, JsonToken expectedToken, obje
/// <returns>
/// The value of the JSON token before advancing the reader, or default(TValue) if the token has no value.
/// </returns>
protected TValue ExpectAndAdvance<TValue>(JsonReader reader, JsonToken expectedToken, object expectedValue = null)
public static TValue ExpectAndAdvance<TValue>(
this JsonReader reader,
JsonToken expectedToken,
object expectedValue = null)
{
TValue result = Expect<TValue>(reader, expectedToken, expectedValue);
Advance(reader);
Expand All @@ -55,15 +58,13 @@ protected TValue ExpectAndAdvance<TValue>(JsonReader reader, JsonToken expectedT
/// <param name="reader">The JSON reader.</param>
/// <param name="expectedToken">The JSON token on which the reader is expected to be positioned.</param>
/// <param name="expectedValue">Optional; The expected value of the current JSON token.</param>
protected void Expect(JsonReader reader, JsonToken expectedToken, object expectedValue = null)
{
public static void Expect(this JsonReader reader, JsonToken expectedToken, object expectedValue = null) =>
Expect<object>(reader, expectedToken, expectedValue);
}

/// <summary>
/// Asserts that the given JSON reader is positioned on a token with the expected type and retrieves the value
/// of the token, if any. Optionally asserts that the value of the token matches a given expected value. If
/// any of the assertions fail, this method throws a JsonSerializationException.
/// Asserts that the given JSON reader is positioned on a token with the expected type and retrieves the
/// value of the token, if any. Optionally asserts that the value of the token matches a given expected
/// value. If any of the assertions fail, this method throws a JsonSerializationException.
/// </summary>
/// <typeparam name="TValue">The expected type of the value of the current JSON token.</typeparam>
/// <param name="reader">The JSON reader.</param>
Expand All @@ -72,7 +73,10 @@ protected void Expect(JsonReader reader, JsonToken expectedToken, object expecte
/// <returns>
/// The value of the current JSON token, or default(TValue) if the current token has no value.
/// </returns>
protected TValue Expect<TValue>(JsonReader reader, JsonToken expectedToken, object expectedValue = null)
public static TValue Expect<TValue>(
this JsonReader reader,
JsonToken expectedToken,
object expectedValue = null)
{
if (reader.TokenType != expectedToken)
{
Expand Down Expand Up @@ -116,7 +120,7 @@ protected TValue Expect<TValue>(JsonReader reader, JsonToken expectedToken, obje
/// Advances the given JSON reader, or throws a JsonSerializationException if it cannot be advanced.
/// </summary>
/// <param name="reader">The JSON reader to advance.</param>
protected void Advance(JsonReader reader)
public static void Advance(this JsonReader reader)
{
if (!reader.Read())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// <auto-generated>
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace Microsoft.Azure.Search.Models
{
using Azure;
using Search;
using Newtonsoft.Json;
using System.Linq;

Expand All @@ -21,7 +21,10 @@ public partial class SearchRequestOptions
/// <summary>
/// Initializes a new instance of the SearchRequestOptions class.
/// </summary>
public SearchRequestOptions() { }
public SearchRequestOptions()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the SearchRequestOptions class.
Expand All @@ -31,15 +34,20 @@ public SearchRequestOptions() { }
public SearchRequestOptions(System.Guid? clientRequestId = default(System.Guid?))
{
ClientRequestId = clientRequestId;
CustomInit();
}

/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();

/// <summary>
/// Gets or sets the tracking ID sent with the request to help with
/// debugging.
/// </summary>
[JsonProperty(PropertyName = "")]
[Newtonsoft.Json.JsonIgnore]
public System.Guid? ClientRequestId { get; set; }

}
}

Loading