| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Search.Models |
| | 6 | | { |
| | 7 | | using Common; |
| | 8 | | using System; |
| | 9 | |
|
| | 10 | | public partial class DataSource : IResourceWithETag |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Creates a new DataSource to connect to an Azure SQL database. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="name">The name of the datasource.</param> |
| | 16 | | /// <param name="sqlConnectionString">The connection string for the Azure SQL database.</param> |
| | 17 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 18 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 19 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 20 | | /// <returns>A new DataSource instance.</returns> |
| | 21 | | public static DataSource AzureSql( |
| | 22 | | string name, |
| | 23 | | string sqlConnectionString, |
| | 24 | | string tableOrViewName, |
| | 25 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 26 | | string description = null) |
| | 27 | | { |
| 90 | 28 | | return CreateSqlDataSource(name, sqlConnectionString, tableOrViewName, description, null, deletionDetectionP |
| | 29 | | } |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Creates a new DataSource to connect to an Azure SQL database with change detection enabled. |
| | 33 | | /// </summary> |
| | 34 | | /// <param name="name">The name of the datasource.</param> |
| | 35 | | /// <param name="sqlConnectionString">The connection string for the Azure SQL database.</param> |
| | 36 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 37 | | /// <param name="changeDetectionPolicy">The change detection policy for the datasource.</param> |
| | 38 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 39 | | /// <returns>A new DataSource instance.</returns> |
| | 40 | | public static DataSource AzureSql( |
| | 41 | | string name, |
| | 42 | | string sqlConnectionString, |
| | 43 | | string tableOrViewName, |
| | 44 | | DataChangeDetectionPolicy changeDetectionPolicy, |
| | 45 | | string description = null) |
| | 46 | | { |
| 8 | 47 | | Throw.IfArgumentNull(changeDetectionPolicy, nameof(changeDetectionPolicy)); |
| 8 | 48 | | return CreateSqlDataSource(name, sqlConnectionString, tableOrViewName, description, changeDetectionPolicy); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Creates a new DataSource to connect to an Azure SQL database with change detection and deletion detection en |
| | 53 | | /// </summary> |
| | 54 | | /// <param name="name">The name of the datasource.</param> |
| | 55 | | /// <param name="sqlConnectionString">The connection string for the Azure SQL database.</param> |
| | 56 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 57 | | /// <param name="changeDetectionPolicy">The change detection policy for the datasource. Note that only high wate |
| | 58 | | /// allowed for Azure SQL when deletion detection is enabled.</param> |
| | 59 | | /// <param name="deletionDetectionPolicy">The data deletion detection policy for the datasource.</param> |
| | 60 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 61 | | /// <returns>A new DataSource instance.</returns> |
| | 62 | | public static DataSource AzureSql( |
| | 63 | | string name, |
| | 64 | | string sqlConnectionString, |
| | 65 | | string tableOrViewName, |
| | 66 | | HighWaterMarkChangeDetectionPolicy changeDetectionPolicy, |
| | 67 | | DataDeletionDetectionPolicy deletionDetectionPolicy, |
| | 68 | | string description = null) |
| | 69 | | { |
| 8 | 70 | | Throw.IfArgumentNull(changeDetectionPolicy, nameof(changeDetectionPolicy)); |
| 8 | 71 | | Throw.IfArgumentNull(deletionDetectionPolicy, nameof(deletionDetectionPolicy)); |
| | 72 | |
|
| 8 | 73 | | return CreateSqlDataSource(name, sqlConnectionString, tableOrViewName, description, changeDetectionPolicy, d |
| | 74 | | } |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// Creates a new DataSource to connect to a VM-hosted SQL Server database. |
| | 78 | | /// </summary> |
| | 79 | | /// <param name="name">The name of the datasource.</param> |
| | 80 | | /// <param name="sqlConnectionString">The connection string for the SQL Server database.</param> |
| | 81 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 82 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 83 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 84 | | /// <returns>A new DataSource instance.</returns> |
| | 85 | | public static DataSource SqlServerOnAzureVM( |
| | 86 | | string name, |
| | 87 | | string sqlConnectionString, |
| | 88 | | string tableOrViewName, |
| | 89 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 90 | | string description = null) |
| | 91 | | { |
| 8 | 92 | | return AzureSql(name, sqlConnectionString, tableOrViewName, deletionDetectionPolicy, description); |
| | 93 | | } |
| | 94 | |
|
| | 95 | | /// <summary> |
| | 96 | | /// Creates a new DataSource to connect to a VM-hosted SQL Server database with change detection enabled. |
| | 97 | | /// </summary> |
| | 98 | | /// <param name="name">The name of the datasource.</param> |
| | 99 | | /// <param name="sqlConnectionString">The connection string for the SQL Server database.</param> |
| | 100 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 101 | | /// <param name="changeDetectionPolicy">The change detection policy for the datasource.</param> |
| | 102 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 103 | | /// <returns>A new DataSource instance.</returns> |
| | 104 | | public static DataSource SqlServerOnAzureVM( |
| | 105 | | string name, |
| | 106 | | string sqlConnectionString, |
| | 107 | | string tableOrViewName, |
| | 108 | | DataChangeDetectionPolicy changeDetectionPolicy, |
| | 109 | | string description = null) |
| | 110 | | { |
| 4 | 111 | | return AzureSql(name, sqlConnectionString, tableOrViewName, changeDetectionPolicy, description); |
| | 112 | | } |
| | 113 | |
|
| | 114 | | /// <summary> |
| | 115 | | /// Creates a new DataSource to connect to a VM-hosted SQL Server database with change detection and deletion de |
| | 116 | | /// </summary> |
| | 117 | | /// <param name="name">The name of the datasource.</param> |
| | 118 | | /// <param name="sqlConnectionString">The connection string for the SQL Server database.</param> |
| | 119 | | /// <param name="tableOrViewName">The name of the table or view from which to read rows.</param> |
| | 120 | | /// <param name="changeDetectionPolicy">The change detection policy for the datasource. Note that only high wate |
| | 121 | | /// allowed for SQL Server when deletion detection is enabled.</param> |
| | 122 | | /// <param name="deletionDetectionPolicy">The data deletion detection policy for the datasource.</param> |
| | 123 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 124 | | /// <returns>A new DataSource instance.</returns> |
| | 125 | | public static DataSource SqlServerOnAzureVM( |
| | 126 | | string name, |
| | 127 | | string sqlConnectionString, |
| | 128 | | string tableOrViewName, |
| | 129 | | HighWaterMarkChangeDetectionPolicy changeDetectionPolicy, |
| | 130 | | DataDeletionDetectionPolicy deletionDetectionPolicy, |
| | 131 | | string description = null) |
| | 132 | | { |
| 4 | 133 | | return AzureSql(name, sqlConnectionString, tableOrViewName, changeDetectionPolicy, deletionDetectionPolicy, |
| | 134 | | } |
| | 135 | |
|
| | 136 | | /// <summary> |
| | 137 | | /// Creates a new DataSource to connect to a CosmosDb database. |
| | 138 | | /// </summary> |
| | 139 | | /// <param name="name">The name of the datasource.</param> |
| | 140 | | /// <param name="cosmosDbConnectionString">The connection string for the CosmosDb database. It must follow this |
| | 141 | | /// "AccountName|AccountEndpoint=[your account name or endpoint];AccountKey=[your account key];Database=[your da |
| | 142 | | /// <param name="collectionName">The name of the collection from which to read documents.</param> |
| | 143 | | /// <param name="query">Optional. A query that is applied to the collection when reading documents.</param> |
| | 144 | | /// <param name="useChangeDetection">Optional. Indicates whether to use change detection when indexing. Default |
| | 145 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 146 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 147 | | /// <returns>A new DataSource instance.</returns> |
| | 148 | | public static DataSource CosmosDb( |
| | 149 | | string name, |
| | 150 | | string cosmosDbConnectionString, |
| | 151 | | string collectionName, |
| | 152 | | string query = null, |
| | 153 | | bool useChangeDetection = true, |
| | 154 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 155 | | string description = null) |
| | 156 | | { |
| 18 | 157 | | Throw.IfArgumentNullOrEmpty(name, nameof(name)); |
| 18 | 158 | | Throw.IfArgumentNullOrEmpty(collectionName, nameof(collectionName)); |
| 18 | 159 | | Throw.IfArgumentNullOrEmpty(cosmosDbConnectionString, nameof(cosmosDbConnectionString)); |
| | 160 | |
|
| 18 | 161 | | return new DataSource() |
| 18 | 162 | | { |
| 18 | 163 | | Type = DataSourceType.CosmosDb, |
| 18 | 164 | | Name = name, |
| 18 | 165 | | Description = description, |
| 18 | 166 | | Container = new DataContainer() |
| 18 | 167 | | { |
| 18 | 168 | | Name = collectionName, |
| 18 | 169 | | Query = query |
| 18 | 170 | | }, |
| 18 | 171 | | Credentials = new DataSourceCredentials(cosmosDbConnectionString), |
| 18 | 172 | | DataChangeDetectionPolicy = useChangeDetection ? new HighWaterMarkChangeDetectionPolicy("_ts") : null, |
| 18 | 173 | | DataDeletionDetectionPolicy = deletionDetectionPolicy |
| 18 | 174 | | }; |
| | 175 | | } |
| | 176 | |
|
| | 177 | | /// <summary> |
| | 178 | | /// Creates a new DataSource to connect to a DocumentDb database. |
| | 179 | | /// </summary> |
| | 180 | | /// <param name="name">The name of the datasource.</param> |
| | 181 | | /// <param name="documentDbConnectionString">The connection string for the DocumentDb database. It must follow t |
| | 182 | | /// "AccountName|AccountEndpoint=[your account name or endpoint];AccountKey=[your account key];Database=[your da |
| | 183 | | /// <param name="collectionName">The name of the collection from which to read documents.</param> |
| | 184 | | /// <param name="query">Optional. A query that is applied to the collection when reading documents.</param> |
| | 185 | | /// <param name="useChangeDetection">Optional. Indicates whether to use change detection when indexing. Default |
| | 186 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 187 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 188 | | /// <returns>A new DataSource instance.</returns> |
| | 189 | | [Obsolete("Use CosmosDb instead.")] |
| | 190 | | public static DataSource DocumentDb( |
| | 191 | | string name, |
| | 192 | | string documentDbConnectionString, |
| | 193 | | string collectionName, |
| | 194 | | string query = null, |
| | 195 | | bool useChangeDetection = true, |
| | 196 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 197 | | string description = null) |
| | 198 | | { |
| 0 | 199 | | Throw.IfArgumentNullOrEmpty(name, nameof(name)); |
| 0 | 200 | | Throw.IfArgumentNullOrEmpty(collectionName, nameof(collectionName)); |
| 0 | 201 | | Throw.IfArgumentNullOrEmpty(documentDbConnectionString, nameof(documentDbConnectionString)); |
| | 202 | |
|
| 0 | 203 | | return new DataSource() |
| 0 | 204 | | { |
| 0 | 205 | | Type = DataSourceType.DocumentDb, |
| 0 | 206 | | Name = name, |
| 0 | 207 | | Description = description, |
| 0 | 208 | | Container = new DataContainer() |
| 0 | 209 | | { |
| 0 | 210 | | Name = collectionName, |
| 0 | 211 | | Query = query |
| 0 | 212 | | }, |
| 0 | 213 | | Credentials = new DataSourceCredentials(documentDbConnectionString), |
| 0 | 214 | | DataChangeDetectionPolicy = useChangeDetection ? new HighWaterMarkChangeDetectionPolicy("_ts") : null, |
| 0 | 215 | | DataDeletionDetectionPolicy = deletionDetectionPolicy |
| 0 | 216 | | }; |
| | 217 | | } |
| | 218 | |
|
| | 219 | | /// <summary> |
| | 220 | | /// Creates a new DataSource to connect to an Azure Blob container. |
| | 221 | | /// </summary> |
| | 222 | | /// <param name="name">The name of the datasource.</param> |
| | 223 | | /// <param name="storageConnectionString">The connection string for the Azure Storage account. It must follow th |
| | 224 | | /// "DefaultEndpointsProtocol=https;AccountName=[your storage account];AccountKey=[your account key];" Note that |
| | 225 | | /// <param name="containerName">The name of the container from which to read blobs.</param> |
| | 226 | | /// <param name="pathPrefix">Optional. If specified, the datasource will include only blobs with names starting |
| | 227 | | /// useful when blobs are organized into "virtual folders", for example.</param> |
| | 228 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 229 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 230 | | /// <returns>A new DataSource instance.</returns> |
| | 231 | | public static DataSource AzureBlobStorage( |
| | 232 | | string name, |
| | 233 | | string storageConnectionString, |
| | 234 | | string containerName, |
| | 235 | | string pathPrefix = null, |
| | 236 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 237 | | string description = null) |
| | 238 | | { |
| 10 | 239 | | Throw.IfArgumentNullOrEmpty(name, nameof(name)); |
| 10 | 240 | | Throw.IfArgumentNullOrEmpty(containerName, nameof(containerName)); |
| 10 | 241 | | Throw.IfArgumentNullOrEmpty(storageConnectionString, nameof(storageConnectionString)); |
| | 242 | |
|
| 10 | 243 | | return new DataSource() |
| 10 | 244 | | { |
| 10 | 245 | | Type = DataSourceType.AzureBlob, |
| 10 | 246 | | Name = name, |
| 10 | 247 | | Description = description, |
| 10 | 248 | | Container = new DataContainer() |
| 10 | 249 | | { |
| 10 | 250 | | Name = containerName, |
| 10 | 251 | | Query = pathPrefix |
| 10 | 252 | | }, |
| 10 | 253 | | Credentials = new DataSourceCredentials(storageConnectionString), |
| 10 | 254 | | DataDeletionDetectionPolicy = deletionDetectionPolicy |
| 10 | 255 | | }; |
| | 256 | | } |
| | 257 | |
|
| | 258 | | /// <summary> |
| | 259 | | /// Creates a new DataSource to connect to an Azure Table. |
| | 260 | | /// </summary> |
| | 261 | | /// <param name="name">The name of the datasource.</param> |
| | 262 | | /// <param name="storageConnectionString">The connection string for the Azure Storage account. It must follow th |
| | 263 | | /// "DefaultEndpointsProtocol=https;AccountName=[your storage account];AccountKey=[your account key];" Note that |
| | 264 | | /// <param name="tableName">The name of the table from which to read rows.</param> |
| | 265 | | /// <param name="query">Optional. A query that is applied to the table when reading rows.</param> |
| | 266 | | /// <param name="deletionDetectionPolicy">Optional. The data deletion detection policy for the datasource.</para |
| | 267 | | /// <param name="description">Optional. Description of the datasource.</param> |
| | 268 | | /// <returns>A new DataSource instance.</returns> |
| | 269 | | public static DataSource AzureTableStorage( |
| | 270 | | string name, |
| | 271 | | string storageConnectionString, |
| | 272 | | string tableName, |
| | 273 | | string query = null, |
| | 274 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null, |
| | 275 | | string description = null) |
| | 276 | | { |
| 8 | 277 | | Throw.IfArgumentNullOrEmpty(name, nameof(name)); |
| 8 | 278 | | Throw.IfArgumentNullOrEmpty(tableName, nameof(tableName)); |
| 8 | 279 | | Throw.IfArgumentNullOrEmpty(storageConnectionString, nameof(storageConnectionString)); |
| | 280 | |
|
| 8 | 281 | | return new DataSource() |
| 8 | 282 | | { |
| 8 | 283 | | Type = DataSourceType.AzureTable, |
| 8 | 284 | | Name = name, |
| 8 | 285 | | Description = description, |
| 8 | 286 | | Container = new DataContainer() |
| 8 | 287 | | { |
| 8 | 288 | | Name = tableName, |
| 8 | 289 | | Query = query |
| 8 | 290 | | }, |
| 8 | 291 | | Credentials = new DataSourceCredentials(storageConnectionString), |
| 8 | 292 | | DataDeletionDetectionPolicy = deletionDetectionPolicy |
| 8 | 293 | | }; |
| | 294 | | } |
| | 295 | |
|
| | 296 | | private static DataSource CreateSqlDataSource( |
| | 297 | | string name, |
| | 298 | | string sqlConnectionString, |
| | 299 | | string tableOrViewName, |
| | 300 | | string description, |
| | 301 | | DataChangeDetectionPolicy changeDetectionPolicy = null, |
| | 302 | | DataDeletionDetectionPolicy deletionDetectionPolicy = null) |
| | 303 | | { |
| 106 | 304 | | Throw.IfArgumentNullOrEmpty(name, nameof(name)); |
| 106 | 305 | | Throw.IfArgumentNullOrEmpty(tableOrViewName, nameof(tableOrViewName)); |
| 106 | 306 | | Throw.IfArgumentNullOrEmpty(sqlConnectionString, nameof(sqlConnectionString)); |
| | 307 | |
|
| 106 | 308 | | return new DataSource() |
| 106 | 309 | | { |
| 106 | 310 | | Type = DataSourceType.AzureSql, |
| 106 | 311 | | Name = name, |
| 106 | 312 | | Description = description, |
| 106 | 313 | | Container = new DataContainer() |
| 106 | 314 | | { |
| 106 | 315 | | Name = tableOrViewName |
| 106 | 316 | | }, |
| 106 | 317 | | Credentials = new DataSourceCredentials(sqlConnectionString), |
| 106 | 318 | | DataChangeDetectionPolicy = changeDetectionPolicy, |
| 106 | 319 | | DataDeletionDetectionPolicy = deletionDetectionPolicy |
| 106 | 320 | | }; |
| | 321 | | } |
| | 322 | | } |
| | 323 | | } |