使用自定义事件源时,例如:
\n\n[EventSource(Name = "MyEventSource")]\npublic partial class CustomEventSource : EventSource\n{\n}\nRun Code Online (Sandbox Code Playgroud)\n\nEventSource 类中有一个 IsEnabled 方法:
\n\nEventSource.IsEnabled(eventLevel,\xe2\x80\x82eventKeywords)\nRun Code Online (Sandbox Code Playgroud)\n\nhttps://msdn.microsoft.com/en-us/library/hh393402(v=vs.110).aspx
\n\n此方法如何确定该事件对于级别和关键字是否“已启用”?似乎没有任何关于此的可靠文档。在我的实现中,该方法返回 false,我不确定需要做什么才能使其返回 true。
\n我正在测试 Serilog 并且遇到了一些字段名称问题。
我想添加日志条目,其中一个字段包含在消息模板中,而其他字段仅存储在日志中以供查询。
我想做一些简单的事情:
logger.Debug("Recalculation performed for operation {OperationId}",
operationId, operationTypeId, otherId, anotherId);
Run Code Online (Sandbox Code Playgroud)
但这会导致字段名称没有被赋予友好名称,因为它们不在消息模板中:
{
"@timestamp":"2016-10-20T16:57:02.0623798+01:00",
"level":"Debug",
"messageTemplate":"Recalculation performed for operation {OperationId}",
"fields":{
"OperationId":1024,
"__1":16,
"__2":32,
"__3":256,
"SourceContext":"SerilogTest.Worker"
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将所有字段放入一个类中并使用 ForContext 方法将它们包含在日志条目中:
internal class OperationData
{
public int OperationId { get; set; }
public int OperationTypeId { get; set; }
public int OtherId { get; set; }
public int AnotherId { get; set; }
}
var operationData = new OperationData
{
OperationId = 1024,
OperationTypeId = 16,
OtherId …Run Code Online (Sandbox Code Playgroud) 我有一个 webApi 项目,在部署到开发环境后,我需要编辑 web.config 并将与数据库的连接从生产配置更改为开发配置,如果需要部署到生产配置,则返回。如何在我的项目中使用的发布或调试中为选定的开发或生产自动设置 webconfig?
我正在调用TryParse一个我要解析的字符串DateTime.简单的东西.当格式符合我的预期时,一切正常.但是,当日期的每个组件/某些组件都是单个数字时,解析将失败.
例:
var dateFormat = "yyyy-dd-MM hh:mm:ss";
var dateString = "2006-4-1 2:3:5";
DateTime.TryParseExact(dateString, dateFormat,
CultureInfo.InvariantCulture, DateTimeStyles.None, out result)
Run Code Online (Sandbox Code Playgroud)
如果我改变dateString了"2006-04-01 02:03:05",它解析得很好.
我如何告诉解析器解释2为02以上解析成功?
手动填充日期时间的每个部分以确保其符合格式.这样可行,但感觉不是很优雅.这是唯一的方法吗?
我也试过使用一种格式m而不是成功,但没有成功mm.
我有一个带有列表作为数据源的组合框。此列表包含具有其属性(名称,地址等)的对象(客户)。当我选择组合框的一个项目时,我想将信息(地址,邮政编码...)传递给表单上的某些文本框。在我的测试1tier应用程序中,这是正确的。但是我正在开发的主要应用程序是基于MVP的(我对此有自己的看法)。我面临的问题是铸造。由于我的看法不了解我的模型,因此不应允许我使用(客户)。string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
1层测试代码:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//getCustomers((int)comboBox1.SelectedValue);
//txtAddress.Text =Convert.ToString( comboBox1.SelectedValue);
Customers p = (Customers)comboBox1.SelectedItem;
string s = comboBox1.SelectedItem.ToString();
string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
txtAddress1.Text = address;
}
private void Form3_Load(object sender, EventArgs e)
{
using (var emp = new EmployerEFEntities())
{
var query = from customers in emp.Customers
select customers;
comboBox1.DisplayMember = "CustomerName";
comboBox1.ValueMember = "CustomerID";
comboBox1.DataSource = query.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经研究了几天,但没有成功。我希望有人能给我正确的方向。
实际应用程序的代码:
视图:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtName.Text = comboBox1.SelectedValue.ToString(); …Run Code Online (Sandbox Code Playgroud) 我在 UWP 中遇到了 TextBox.Text 绑定的一些问题。我多年来一直在做 WPF 并且通常知道我在 XAML 中在做什么,但无法让这个绑定工作......
我在 XAML 中的同一范围内有一个 TextBox 和一个 Button
<StackPanel Orientation="Horizontal"
Margin="0,10,0,0">
<TextBox Width="200" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"/>
<Button Margin="10,0,0,0"
Command="{Binding SearchBusCommand}">Go</Button>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
并且绑定的属性在 ViewModel 中的作用域相同
public ICommand SearchBusCommand { get; }
public string SearchText { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是,当我在 TextBox 中键入文本并点击 Button 时,命令会执行并且 SearchText 值为空...
我的期望是,当我在 TextBox 中键入文本时,SearchText 属性会更新为 Text 值。
如果我从 ViewModel 设置 SearchText 属性的值,它会出现在 TextBox 中。
我想在Android谷歌地图v2中获取经纬度的地址,但它有误.
这是我的代码:
case PLACES_DETAILS :
final HashMap<String, String> hm = result.get(0);
final double latitude = Double.parseDouble(hm.get("lat"));
final double longitude = Double.parseDouble(hm.get("lng"));
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
final LatLng point = new LatLng(latitude, longitude);
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLngZoom(point, 10);
CameraUpdate cameraZoom = CameraUpdateFactory.zoomBy(5);
googleMap.moveCamera(cameraPosition);
googleMap.animateCamera(cameraZoom);
googleMap.getCameraPosition();
//Log.e("Lat", String.valueOf(googleMap.getCameraPosition().target.latitude));
//Log.e("Long", String.valueOf(googleMap.getCameraPosition().target.latitude));
//googleMap.setOnMyLocationChangeListener(myLocationChangeListener);
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.e("Lat", String.valueOf(googleMap.getCameraPosition().target.latitude));
Log.e("Long", String.valueOf(googleMap.getCameraPosition().target.longitude));
}
});
Run Code Online (Sandbox Code Playgroud) 我正在调查更新我们的应用程序以使用Firebird以外的数据库服务器的可能性.我们依靠"STARTING WITH"来访问我们的分层数据.没有它,我看不出如何在没有经过一些严肃的重新设计的情况下迁移到另一个数据库.
如果您不熟悉"STARTS WITH",它只是检查字符串字段是否以特定字符串开头,例如......
WHERE 'This is a test' STARTS WITH 'This is' ...
Run Code Online (Sandbox Code Playgroud)
会回归真实.如果列已建立索引,则索引将用于比较.
其他数据库服务器(尤其是Oracle/MSSQL)是否支持"STARTING WITH"(或"STARTS WITH")?
我有一个MapControlUWP:
<maps:MapControl x:Name="BikeMap" ZoomLevel="17" Center="{Binding CenterPoint, Mode=TwoWay}">
<maps:MapItemsControl x:Name="MapItems" ItemsSource="{Binding BikePoints}"
ItemTemplate="{StaticResource BikePointTemplate}"/>
</maps:MapControl>
Run Code Online (Sandbox Code Playgroud)
我正在使用XAML数据模板添加MapElements,我的ItemsSource是一个简单对象列表.
但是,UWP似乎并没有提供一种方式来指定DataType的DataTemplate和MapItemsControl没有设置一个属性DataTemplateSelector.
有谁知道我如何使用MapItemsControl的多个数据模板,并根据ItemsSource中的对象类型选择相关的数据模板?