本文整理汇总了C#中SolrNet.Impl.SolrConnection.Post方法的典型用法代码示例。如果您正苦于以下问题:C# SolrConnection.Post方法的具体用法?C# SolrConnection.Post怎么用?C# SolrConnection.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolrNet.Impl.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.Post方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public void Post()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
var response = mocks.DynamicMock<IHttpWebResponse>();
With.Mocks(mocks).Expecting(delegate {
Expect.Call(request.GetRequestStream())
.Repeat.Once()
.Return(new MemoryStream());
Expect.Call(reqFactory.Create(new Uri("https://pepe")))
.Repeat.Once()
.Return(request);
request.Method = HttpWebRequestMethod.POST;
LastCall.On(request).Repeat.Once();
Expect.Call(request.GetResponse())
.Repeat.Once()
.Return(response);
Expect.Call(response.Headers)
.Repeat.Any()
.Return(new WebHeaderCollection());
Expect.Call(response.GetResponseStream())
.Repeat.Once()
.Return(new MemoryStream());
}).Verify(delegate {
var conn = new SolrConnection("https://pepe", reqFactory);
conn.Post("", "");
});
}
示例2: Main
private static void Main(string[] args)
{
var connection = new SolrConnection(solrURL);
Startup.Init<Product>(connection);
var p = new Product
{
Id = "SP2514N",
Manufacturer = "Samsung Electronics Co. Ltd.",
Categories = new[]
{
"electronics",
"hard drive333333333111",
},
Price = 92,
InStock = true,
};
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
solr.Add(p);
solr.Commit();
p = new Product
{
Id = "SP2514N2",
Manufacturer = "AAA Electronics Co. Ltd.",
Categories = new[]
{
"electronics",
"hard 777777777",
},
Price = 92,
InStock = true,
};
solr.Add(p);
solr.Commit();
var results = solr.Query(new SolrQueryByField("id", "SP2514N"));
Console.WriteLine(results[0].Price);
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string archiveFolder = Path.Combine(baseDirectory, "docs");
try
{
solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
solr.Delete(SolrQuery.All);
connection = (SolrConnection) ServiceLocator.Current.GetInstance<ISolrConnection>();
foreach (var file in Directory.GetFiles(archiveFolder, "*.xml"))
{
connection.Post("/update", File.ReadAllText(file, Encoding.UTF8));
}
solr.Commit();
solr.BuildSpellCheckDictionary();
}
catch (SolrConnectionException e)
{
throw new Exception(string.Format("Couldn't connect to Solr. Please make sure that Solr is running on '{0}' or change the address in your web.config, then restart the application.", solrURL), e);
}
}
示例3: InvalidHostPost_ShouldThrowException
public void InvalidHostPost_ShouldThrowException()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
With.Mocks(mocks).Expecting(delegate {
Expect.Call(request.GetRequestStream())
.Repeat.Once()
.Throw(new WebException());
Expect.Call(reqFactory.Create(new Uri("http://lalala:12345/update")))
.IgnoreArguments()
.Repeat.Once()
.Return(request);
}).Verify(delegate {
var conn = new SolrConnection("http://lalala:12345", reqFactory);
conn.Post("/update", "");
});
}
示例4: InvalidHostPost_ShouldThrowException
public void InvalidHostPost_ShouldThrowException() {
var reqFactory = new Mocks.HttpWebRequestFactory {
create = _ => new Mocks.HttpWebRequest {
getRequestStream = () => { throw new WebException(); },
requestUri = () => new Uri("http://lalala:12345/update"),
}
};
var conn = new SolrConnection("http://lalala:12345") { HttpWebRequestFactory = reqFactory };
conn.Post("/update", "");
}