/// <summary> /// Find out the state services. /// </summary> public void GetServiceState(Logging logging) { // Check if Radish running? try { using (var conn = ConnectionMultiplexer.Connect("localhost")) { // YES - Redis running. RedisIsStarted = true; conn.Close(); } } catch (RedisException ex) { logging.ProcessingException(ex); // NO - Redis is not running. RedisIsStarted = false; // Cached database initialization form (-2 seconds). var cacheMap = new Thread(CacheThreadMap); cacheMap.Start(); var cacheStorage1 = new Thread(CacheThreadStorage1); cacheStorage1.Start(); var cacheStorage2 = new Thread(CacheThreadStorage2); cacheStorage2.Start(); var cacheStorage3 = new Thread(CacheThreadStorage3); cacheStorage3.Start(); var cacheStorage4 = new Thread(CacheThreadStorage4); cacheStorage4.Start(); } // Check if running Sphinx? try { var connection = new SphinxQLConnection(@"Data Source=localhost;Port=9306"); connection.Open(); // YES - Sphinx running. SphinxIsStarted = true; connection.Close(); } catch (SphinxQLException ex) { logging.ProcessingException(ex); // NO - Sphinx NOT running. SphinxIsStarted = false; } }
/// <summary> /// Event: information search (using a search form). /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event Args</param> override protected void btnSearch_Click(object sender, RoutedEventArgs e) { txtSearchResult.Text = string.Empty; var ds = new DataSet(); try { using (var connection = new SphinxQLConnection(@"Data Source=localhost;Port=9306")) { var selectCommand = new SphinxQLCommand(connection); // We shape our query string. var commandText = new StringBuilder(); if (txtSearchFirstName.Text != string.Empty) { selectCommand.Parameters.Add("@matchFirstName", txtSearchFirstName.Text); commandText.Append(@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE MATCH(@matchFirstName);"); } if (txtSearchLastName.Text != string.Empty) { selectCommand.Parameters.Add("@matchLastName", txtSearchLastName.Text); commandText.Append(@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE MATCH(@matchLastName);"); } if (txtSearchAge.Text != string.Empty) { switch (cmbSearchAge.SelectedIndex) { case 0: commandText.Append( $@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE AGE > {txtSearchAge.Text};"); break; case 1: commandText.Append( $@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE AGE < {txtSearchAge.Text};"); break; case 2: commandText.Append( $@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE AGE = {txtSearchAge.Text};"); break; } } if (txtSearchCountry.Text != string.Empty) { selectCommand.Parameters.Add("@matchCountry", txtSearchCountry.Text); commandText.Append(@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE MATCH(@matchCountry);"); } if (txtSearchCity.Text != string.Empty) { selectCommand.Parameters.Add("@matchCity", txtSearchCity.Text); commandText.Append(@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE MATCH(@matchCity);"); } if (txtSearchBio.Text != string.Empty) { selectCommand.Parameters.Add("@matchBio", txtSearchBio.Text); commandText.Append(@"SELECT * FROM indexstore1, indexstore2, indexstore3, indexstore4, indexstore5 WHERE MATCH(@matchBio);"); } selectCommand.CommandText = commandText.ToString().Substring(0, commandText.Length - 1); var dataAdapter = new SphinxQLDataAdapter {SelectCommand = selectCommand}; dataAdapter.Fill(ds); } } catch (SphinxQLException ex) { _logging.ProcessingException(ex); } // Parsing XML. using (var reader = XmlReader.Create(new StringReader(ds.GetXml()))) { while (reader.Read()) { if (!reader.IsStartElement()) continue; switch (reader.Name) { case "NewDataSet": break; case "Table": break; case "id": break; case "first_name": if (reader.Read()) txtSearchResult.Text += $"First Name: {reader.Value.Trim()}\n"; break; case "last_name": if (reader.Read()) txtSearchResult.Text += $"Second Name: {reader.Value.Trim()}\n"; break; case "age": if (reader.Read()) txtSearchResult.Text += $"Age: {reader.Value.Trim()}\n"; break; case "bio": if (reader.Read()) txtSearchResult.Text += $"Bio: {reader.Value.Trim()}\n"; break; case "country": if (reader.Read()) txtSearchResult.Text += $"Country: {reader.Value.Trim()}\n"; break; case "city": if (reader.Read()) txtSearchResult.Text += $"City: {reader.Value.Trim()}\n\n"; break; } } } }