/// <summary>
        /// Initializes a new instance of the SearchIndexClient class.
        /// </summary>
        /// <param name='searchServiceName'>
        /// Required. Gets or sets the name of the Azure Search service.
        /// </param>
        /// <param name='indexName'>
        /// Required. Gets or sets the name of the Azure Search index.
        /// </param>
        /// <param name='credentials'>
        /// Required. Gets or sets the credentials used to authenticate to an
        /// Azure Search service.  (see
        /// https://msdn.microsoft.com/library/azure/dn798935.aspx for more
        /// information)
        /// </param>
        /// <param name='baseUri'>
        /// Optional. Gets the URI used as the base for all cloud service
        /// requests.
        /// </param>
        /// <param name='httpClient'>
        /// The Http client
        /// </param>
        public SearchIndexClient(string searchServiceName, string indexName, SearchCredentials credentials, Uri baseUri, HttpClient httpClient)
            : this(httpClient)
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }
            if (indexName == null)
            {
                throw new ArgumentNullException("indexName");
            }
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (baseUri == null)
            {
                throw new ArgumentNullException("baseUri");
            }
            this._searchServiceName = searchServiceName;
            this._indexName         = indexName;
            this._credentials       = credentials;
            this._baseUri           = baseUri;

            this.Credentials.InitializeServiceClient(this);
        }
 /// <summary>
 /// Initializes a new instance of the SearchServiceClient class.
 /// </summary>
 /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
 /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
 /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx" />
 /// </param>
 /// <param name='rootHandler'>
 /// Optional. The http client handler used to handle http transport.
 /// </param>
 /// <param name='handlers'>
 /// Optional. The set of delegating handlers to insert in the http
 /// client pipeline.
 /// </param>
 public SearchServiceClient(
     string searchServiceName,
     SearchCredentials credentials,
     HttpClientHandler rootHandler,
     params DelegatingHandler[] handlers) : this(rootHandler, handlers)
 {
     Initialize(searchServiceName, credentials);
 }
 public SearchIndexClient GetClient(string indexName)
 {
     // Argument checking is done by the SearchCredentials and SearchIndexClient constructors.
     // Note that HttpClient can't be shared in case it has already been used (SearchIndexClient will attempt
     // to set the Timeout property on it).
     var credentials = new SearchCredentials(_client.Credentials.ApiKey);
     return new SearchIndexClient(_client.SearchServiceName, indexName, credentials);
 }
Ejemplo n.º 4
0
        private void Initialize(string searchServiceName, string indexName, SearchCredentials credentials)
        {
            Throw.IfArgumentNull(credentials, "credentials");

            this.SetBaseUri(searchServiceName, indexName);

            this.Credentials = credentials;
            this.Credentials.InitializeServiceClient(this);
        }
        public SearchIndexClient GetClient(string indexName)
        {
            // Argument checking is done by the SearchCredentials and SearchIndexClient constructors.
            // Note that HttpClient can't be shared in case it has already been used (SearchIndexClient will attempt
            // to set the Timeout property on it).
            var credentials = new SearchCredentials(_client.Credentials.ApiKey);

            return(new SearchIndexClient(_client.SearchServiceName, indexName, credentials));
        }
        private void Initialize(string searchServiceName, SearchCredentials credentials)
        {
            Throw.IfArgumentNull(credentials, nameof(credentials));
            ValidateSearchServiceName(searchServiceName);

            Credentials       = credentials;
            SearchServiceName = searchServiceName;

            Credentials.InitializeServiceClient(this);
        }
        private void Initialize(string searchServiceName, SearchCredentials credentials)
        {
            var validatedSearchServiceName = new SearchServiceName(searchServiceName);

            Throw.IfArgumentNull(credentials, "credentials");

            this.Credentials = credentials;
            this.BaseUri     = validatedSearchServiceName.BuildBaseUri();

            this.Credentials.InitializeServiceClient(this);
        }
        /// <summary>
        /// Initializes a new instance of the SearchServiceClient class.
        /// </summary>
        /// <param name='credentials'>
        /// Required. Gets the credentials used to authenticate to an Azure
        /// Search service.  (see
        /// https://msdn.microsoft.com/library/azure/dn798935.aspx for more
        /// information)
        /// </param>
        /// <param name='baseUri'>
        /// Required. Gets the URI used as the base for all cloud service
        /// requests.
        /// </param>
        /// <param name='httpClient'>
        /// The Http client
        /// </param>
        public SearchServiceClient(SearchCredentials credentials, Uri baseUri, HttpClient httpClient)
            : this(httpClient)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (baseUri == null)
            {
                throw new ArgumentNullException("baseUri");
            }
            this._credentials = credentials;
            this._baseUri     = baseUri;

            this.Credentials.InitializeServiceClient(this);
        }
        /// <summary>
        /// Initializes a new instance of the SearchServiceClient class.
        /// </summary>
        /// <param name='searchServiceName'>
        /// Required. Gets or sets the name of the Azure Search service.
        /// </param>
        /// <param name='credentials'>
        /// Required. Gets or sets the credentials used to authenticate to an
        /// Azure Search service.  (see
        /// https://msdn.microsoft.com/library/azure/dn798935.aspx for more
        /// information)
        /// </param>
        /// <param name='httpClient'>
        /// The Http client
        /// </param>
        public SearchServiceClient(string searchServiceName, SearchCredentials credentials, HttpClient httpClient)
            : this(httpClient)
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            this._searchServiceName = searchServiceName;
            this._credentials       = credentials;
            this._baseUri           = TypeConversion.TryParseUri("https://" + this.SearchServiceName + ".search.windows.net/");

            this.Credentials.InitializeServiceClient(this);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the SearchServiceClient class.
        /// </summary>
        /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
        /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
        /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx"/>
        /// </param>
        public SearchServiceClient(string searchServiceName, SearchCredentials credentials)
            : this()
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }

            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            this._credentials = credentials;
            this._baseUri     = BuildBaseUriForService(searchServiceName);

            this.Credentials.InitializeServiceClient(this);
        }
        /// <summary>
        /// Initializes a new instance of the SearchServiceClient class.
        /// </summary>
        /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
        /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
        /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx"/>
        /// </param>
        public SearchServiceClient(string searchServiceName, SearchCredentials credentials)
            : this()
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }

            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            
            this._credentials = credentials;
            this._baseUri = BuildBaseUriForService(searchServiceName);

            this.Credentials.InitializeServiceClient(this);
        }
        /// <summary>
        /// Initializes a new instance of the SearchIndexClient class.
        /// </summary>
        /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
        /// <param name='indexName'>Required. The name of the Azure Search index.</param>
        /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
        /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx" />
        /// </param>
        /// <param name='httpClient'>The Http client</param>
        public SearchIndexClient(string searchServiceName, string indexName, SearchCredentials credentials, HttpClient httpClient)
            : this(httpClient)
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }
            
            if (indexName == null)
            {
                throw new ArgumentNullException("indexName");
            }
            
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            
            this._credentials = credentials;
            this._baseUri = BuildBaseUriForIndex(searchServiceName, indexName);

            this.Credentials.InitializeServiceClient(this);
        }
        /// <summary>
        /// Initializes a new instance of the SearchIndexClient class.
        /// </summary>
        /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
        /// <param name='indexName'>Required. The name of the Azure Search index.</param>
        /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
        /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx" />
        /// </param>
        /// <param name='httpClient'>The Http client</param>
        public SearchIndexClient(string searchServiceName, string indexName, SearchCredentials credentials, HttpClient httpClient)
            : this(httpClient)
        {
            if (searchServiceName == null)
            {
                throw new ArgumentNullException("searchServiceName");
            }

            if (indexName == null)
            {
                throw new ArgumentNullException("indexName");
            }

            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            this._credentials = credentials;
            this._baseUri     = BuildBaseUriForIndex(searchServiceName, indexName);

            this.Credentials.InitializeServiceClient(this);
        }
 /// <summary>
 /// Initializes a new instance of the SearchServiceClient class.
 /// </summary>
 /// <param name='searchServiceName'>Required. The name of the Azure Search service.</param>
 /// <param name='credentials'>Required. The credentials used to authenticate to an Azure Search service.
 /// <see href="https://msdn.microsoft.com/library/azure/dn798935.aspx"/>
 /// </param>
 public SearchServiceClient(string searchServiceName, SearchCredentials credentials)
     : this()
 {
     Initialize(searchServiceName, credentials);
 }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            string searchServiceName = args[0];
            var credentials = new SearchCredentials(args[1]);
            var searchClient = new SearchServiceClient(searchServiceName, credentials);
            try
            {
                IndexDefinitionResponse getResponse = searchClient.Indexes.Get(IndexName);
                if (getResponse?.Index != null)
                {
                    Console.WriteLine("Deleting and recreating index " + IndexName);
                    searchClient.Indexes.Delete(IndexName);
                }
            }
            catch (CloudException)
            {
                // We expect this if the index does not yet exist.
            }

            IndexDefinitionResponse createIndexResponse = searchClient.Indexes.Create(new Index(
                IndexName,
                new[]
                {
                    new Field("ItemId", DataType.String) { IsKey = true },
                    new Field("Title", DataType.String) { IsSearchable = true },
                    new Field("Content", DataType.String) { IsSearchable = true },
                    new Field("CommentThreadId", DataType.Int32),
                    new Field("TimelineEntryId", DataType.Int32),
                    new Field("MediaAlbumId", DataType.Int32),
                    new Field("UserMediaId", DataType.Int32)
                }));

            Index index = createIndexResponse.Index;
            var indexClient = new SearchIndexClient(searchServiceName, IndexName, credentials);
            using (var dbContext = new ApplicationDbContext(args[2]))
            {
                IEnumerable<TimelineEntry> timelineEntries = dbContext.TimelineEntries
                    .Include(te => te.Message)
                    .Include(te => te.CommentThread.Comments.Select(c => c.Text));

                foreach (TimelineEntry entry in timelineEntries)
                {
                    var batchActions = new List<IndexAction<MessageIndexEntry>>();

                    batchActions.Add(new IndexAction<MessageIndexEntry>(
                        IndexActionType.Upload,
                        new MessageIndexEntry
                        {
                            ItemId = "timeline-" + entry.TimelineEntryId,
                            Content = entry.Message.Content,
                            TimelineEntryId = entry.TimelineEntryId
                        }));

                    if (entry.CommentThread != null)
                    {
                        foreach (Comment comment in entry.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction<MessageIndexEntry>(
                                IndexActionType.Upload,
                                new MessageIndexEntry
                                {
                                    ItemId = "comment-" + comment.CommentId,
                                    Content = comment.Text.Content,
                                    TimelineEntryId = entry.TimelineEntryId,
                                    CommentThreadId = comment.CommentThreadId
                                }));
                        }
                    }
                    var batch = new IndexBatch<MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }

                IEnumerable<MediaAlbum> albums = dbContext.MediaAlbums
                    .Include(a => a.CommentThread.Comments.Select(c => c.Text));

                foreach (MediaAlbum album in albums)
                {
                    var batchActions = new List<IndexAction<MessageIndexEntry>>();

                    batchActions.Add(new IndexAction<MessageIndexEntry>(
                        IndexActionType.Upload,
                        new MessageIndexEntry
                        {
                            ItemId = "album-" + album.MediaAlbumId,
                            Title = album.Title,
                            Content = album.Description,
                            MediaAlbumId = album.MediaAlbumId
                        }));

                    if (album.CommentThread != null)
                    {
                        foreach (Comment comment in album.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction<MessageIndexEntry>(
                                IndexActionType.Upload,
                                new MessageIndexEntry
                                {
                                    ItemId = "comment-" + comment.CommentId,
                                    Content = comment.Text.Content,
                                    MediaAlbumId = album.MediaAlbumId,
                                    CommentThreadId = comment.CommentThreadId
                                }));
                        }
                    }
                    var batch = new IndexBatch<MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }


                IEnumerable<UserMedia> medias = dbContext.UserMedias
                    .Include(m => m.Description)
                    .Include(m => m.CommentThread.Comments.Select(c => c.Text));

                foreach (UserMedia media in medias)
                {
                    var batchActions = new List<IndexAction<MessageIndexEntry>>();

                    batchActions.Add(new IndexAction<MessageIndexEntry>(
                        IndexActionType.Upload,
                        new MessageIndexEntry
                        {
                            ItemId = "media-" + media.UserMediaId,
                            Title = media.Title,
                            Content = media.Description?.Content,
                            UserMediaId = media.UserMediaId,
                            MediaAlbumId = media.MediaAlbumId
                        }));

                    if (media.CommentThread != null)
                    {
                        foreach (Comment comment in media.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction<MessageIndexEntry>(
                                IndexActionType.Upload,
                                new MessageIndexEntry
                                {
                                    ItemId = "comment-" + comment.CommentId,
                                    Content = comment.Text.Content,
                                    UserMediaId = media.UserMediaId,
                                    MediaAlbumId = media.MediaAlbumId,
                                    CommentThreadId = comment.CommentThreadId
                                }));
                        }
                    }
                    var batch = new IndexBatch<MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }
            }
        }