/// <summary> /// Initializes a new instance of the DataSource class with required arguments. /// </summary> /// <param name="name">The name of the datasource.</param> /// <param name="type">The data type of the datasource.</param> /// <param name="credentials">Credentials to connect to the datasource.</param> /// <param name="container">Information about the entity (such as Azure SQL table or /// DocumentDb collection) that will be indexed.</param> public DataSource( string name, DataSourceType type, DataSourceCredentials credentials, DataContainer container) { if (name == null) { throw new ArgumentNullException("name"); } if (type == null) { throw new ArgumentNullException("type"); } if (credentials == null) { throw new ArgumentNullException("credentials"); } if (container == null) { throw new ArgumentNullException("container"); } Name = name; Type = type; Credentials = credentials; Container = container; }
/// <summary> /// Initializes a new instance of the DataSource class with required arguments. /// </summary> /// <param name="name">The name of the datasource.</param> /// <param name="type">The data type of the datasource.</param> /// <param name="credentials">Credentials to connect to the datasource.</param> /// <param name="container">Information about the entity (such as Azure SQL table or /// DocumentDb collection) that will be indexed.</param> public DataSource( string name, DataSourceType type, DataSourceCredentials credentials, DataContainer container) { if (name == null) { throw new ArgumentNullException("name"); } if (type == null) { throw new ArgumentNullException("type"); } if (credentials == null) { throw new ArgumentNullException("credentials"); } if (container == null) { throw new ArgumentNullException("container"); } Name = name; Type = type; Credentials = credentials; Container = container; }
/// <summary> /// Initializes a new instance of the DataSource class. /// </summary> public DataSource(string name, DataSourceType type, DataSourceCredentials credentials, DataContainer container, string description = default(string), DataChangeDetectionPolicy dataChangeDetectionPolicy = default(DataChangeDetectionPolicy), DataDeletionDetectionPolicy dataDeletionDetectionPolicy = default(DataDeletionDetectionPolicy), string eTag = default(string)) { Name = name; Description = description; Type = type; Credentials = credentials; Container = container; DataChangeDetectionPolicy = dataChangeDetectionPolicy; DataDeletionDetectionPolicy = dataDeletionDetectionPolicy; ETag = eTag; }
private static void CreateAndSyncIndexer() { // Create a new indexer and sync it try { var creds = new DataSourceCredentials("Server=tcp:azs-playground.database.windows.net,1433;Database=usgs;User ID=reader;Password=EdrERBt3j6mZDP;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"); DataSource ds = new DataSource("usgs-datasource", DataSourceType.AzureSql, creds, new DataContainer("GeoNamesRI")); ds.Description = "USGS Dataset"; Indexer idx = new Indexer(); idx.Name = "usgs-indexer"; idx.Description = "USGS data indexer"; idx.DataSourceName = "usgs-datasource"; idx.TargetIndexName = "geonames"; idx.Parameters = new IndexingParameters(); idx.Parameters.MaxFailedItems = 10; idx.Parameters.MaxFailedItemsPerBatch = 5; idx.Parameters.Base64EncodeKeys = false; //Delete indexer and datasource if it existed _searchClient.DataSources.Delete("usgs-datasource"); _searchClient.Indexers.Delete("usgs-indexer"); //Create indexer and datasource _searchClient.DataSources.Create(ds); _searchClient.Indexers.Create(idx); //Launch the sync and then monitor progress until complete AzureOperationResponse response = _searchClient.Indexers.Run("usgs-indexer"); IndexerGetStatusResponse statusResponse; bool running = true; Console.WriteLine("{0}", "Synchronization running...\n"); while (running) { statusResponse = _searchClient.Indexers.GetStatus("usgs-indexer"); if (statusResponse.StatusCode != HttpStatusCode.OK) { Console.WriteLine("Error polling for indexer status. Status Code: {0}", response.StatusCode.ToString()); return; } if (statusResponse.ExecutionInfo.LastResult != null) { switch (statusResponse.ExecutionInfo.LastResult.Status.ToString()) { case "InProgress": Console.WriteLine("{0}", "Synchronization running...\n"); Thread.Sleep(3000); break; case "Success": running = false; Console.WriteLine("Synchronized {0} rows...\n", statusResponse.ExecutionInfo.LastResult.ItemCount.ToString()); break; default: running = false; Console.WriteLine("Synchronization failed: {0}\n", statusResponse.ExecutionInfo.LastResult.ErrorMessage.ToString()); break; } } } } catch (Exception ex) { Console.WriteLine("Error creating indexer: {0}: \n", ex.Message.ToString()); } }
private static void CreateAndSyncIndexer(string dbConnectionString, string dataSourceName, string dataSourceDescription, string targetCollection, string indexName, string indexerName, string indexerDescription) { // Create a new indexer and sync it try { var creds = new DataSourceCredentials(dbConnectionString); DataSource ds = new DataSource(dataSourceName, DataSourceType.DocumentDb, creds, new DataContainer(targetCollection)); ds.Description = dataSourceDescription; Indexer idx = new Indexer(); idx.Name = indexerName; idx.Description = indexerDescription; idx.DataSourceName = dataSourceName; idx.TargetIndexName = indexName; idx.Parameters = new IndexingParameters(); idx.Parameters.MaxFailedItems = 10; idx.Parameters.MaxFailedItemsPerBatch = 5; idx.Parameters.Base64EncodeKeys = false; //Delete indexer and datasource if it existed _searchClient.DataSources.Delete(dataSourceName); _searchClient.Indexers.Delete(indexerName); //Create indexer and datasource _searchClient.DataSources.Create(ds); _searchClient.Indexers.Create(idx); //Launch the sync and then monitor progress until complete AzureOperationResponse response = _searchClient.Indexers.Run(indexerName); IndexerGetStatusResponse statusResponse; bool running = true; Console.WriteLine("{0}", "Synchronization running...\n"); while (running) { statusResponse = _searchClient.Indexers.GetStatus(indexerName); if (statusResponse.StatusCode != HttpStatusCode.OK) { Console.WriteLine("Error polling for indexer status. Status Code: {0}", response.StatusCode.ToString()); return; } if (statusResponse.ExecutionInfo.LastResult != null) { switch (statusResponse.ExecutionInfo.LastResult.Status.ToString()) { case "InProgress": Console.WriteLine("{0}", "Synchronization running...\n"); Thread.Sleep(3000); break; case "Success": running = false; Console.WriteLine("Synchronized {0} rows...\n", statusResponse.ExecutionInfo.LastResult.ItemCount.ToString()); break; default: running = false; Console.WriteLine("Synchronization failed: {0}\n", statusResponse.ExecutionInfo.LastResult.ErrorMessage.ToString()); break; } } } } catch (Exception ex) { Console.WriteLine("Error creating indexer: {0}: \n", ex.Message.ToString()); } }