我需要Style根据Silverlight中的某些配置值设置一个给定的控件.我想有可能Style从两种可用的样式(静态资源)中选择一个控件.我试图做一些像:
<TextBox Style="{Binding ABC}"/>
Run Code Online (Sandbox Code Playgroud)
哪里
public string ABC
{
get {return "{StaticResource MyStyle}";}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.
你有什么想法?
提前致谢!
干杯
我想知道,假设我有一个 ConcurrentBag 封装在这样的对象中
class Package
{
private ConcurrentBag<string> myList;
public string title {get; private set;}
public string description {get; private set;}
public Package(string title,string description)
{
myList = new ConcurrentBag<string>();
this.title = title;
this.description = description;
}
public override string ToString()
{
return title + " " + description;
}
}
Run Code Online (Sandbox Code Playgroud)
我将如何返回我的 ConcurrentBag 的只读版本?
下面是使用 MVVM LightSet方法的基本模式:
public class MyViewModel : ViewModelBase
{
private string _text;
public Text
{
get{ return _text; }
set{ Set(()=>Text, ref _text, value); }
}
}
Run Code Online (Sandbox Code Playgroud)
但是在我的项目中,我将字段保留在 DataModel 类中,这对于克隆数据和复制取消修改非常有用:
public class MyDataModel
{
public string Text;
}
public class MyViewModel : ViewModelBase
{
private MyDataModel data;
public Text
{
get{ return data.Text; }
set{ data.Text = value; RaisePropertyChanged(()=>Text); }
}
}
Run Code Online (Sandbox Code Playgroud)
但是在这种情况下我不能使用该Set方法,因为它的第二个参数是ref并且我不能data.Text用作ref参数。
Set( ()=>Text, ref data.Text, value ); // …Run Code Online (Sandbox Code Playgroud) 我有以下代码,我正在尝试模拟它,但我的单元测试失败了。
代码:
await _someDataRepository.GetSomeDataAsync(false)
.Where(r => r.Code == statusCode)
.FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
嘲笑:
Mock<SomeDataRepository> _someDataRepositoryMock = new Mock<SomeDataRepository>();
_someDataRepositoryMock.Setup(s => s.GetSomeDataAsync(It.IsAny<bool>()))
.Returns<List<Domain.Student.Entities.SectionRegistrationStatusItem>>(
i => Task.FromResult(
i.Where(sr => sr.Code == It.IsAny<string>())
)
);
Run Code Online (Sandbox Code Playgroud)
我将如何模拟链式语句?
我有一个POCO课程:
public class SomeEntity {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想在SomeEntity类中使用不同的值测试其他一些类.问题是我需要测试许多属性的不同组合.例如:
所以在每个测试中我想创建这样的测试对象:
// test that someOtherObject always return the same result
// for testObject with ID = 1 and accepts any values from range of
// values for FirstName and …Run Code Online (Sandbox Code Playgroud) 我正在创建一个客户端服务器应用程 服务器已经设计好并等待客户端的连接.现在在客户端部分,我希望在应用程序的整个生命周期中保持连接活动,并且只有在主客户端应用程序关闭或关闭或服务器关闭时才会关闭连接.
目前每10秒服务器关闭TCP连接.我尝试过
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, true);
Run Code Online (Sandbox Code Playgroud)
但它对我不起作用..下面是我的代码块
public TCPStreamDevice(string RemoteIPAddress, int RemotePort, string SourceIPAddress, int SourcePortNo)
{
mIpAddress = RemoteIPAddress;
mPort = RemotePort;
mClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Net.IPEndPoint LocalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(SourceIPAddress), SourcePortNo);
mClient.Bind(LocalEndPoint);
mDataReceivedCallback = new AsyncCallback(DataReceivedTCPCallback_Handler);
mBuffer = new byte[1024];
Description = new DeviceDescription();
}
Run Code Online (Sandbox Code Playgroud)
在我有的处理程序中:
private void DataReceivedTCPCallback_Handler(IAsyncResult ar)
{
try
{
Socket client = (Socket)ar.AsyncState;
int bytesReceived = client.EndReceive(ar);
if (bytesReceived > 0)
{
//to know transport level errors
//EngineInterface.reponseReceived(mBuffer, false);
ReceiveCallBackFunc(mBuffer, bytesReceived);
client.BeginReceive(mBuffer, …Run Code Online (Sandbox Code Playgroud) 我目前有一个AppDomain.CurrentDomain.UnhandledException处理程序,当应用程序崩溃时,它会通过电子邮件向我发送堆栈跟踪.这在大多数情况下工作正常,但是当我在MVVM光视图模型中得到异常时,堆栈跟踪可能相当神秘,并没有真正告诉我它们在哪里发生.有没有一种简单的方法将我的viewmodels包装在try catch语句中,然后我可以将一些更有用的信息注入异常,然后重新抛出它?
以下是堆栈跟踪的示例:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at GalaSoft.MvvmLight.Helpers.WeakAction.Execute() in d:\GalaSoft\mydotnet\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\Helpers\WeakAction.cs:line 269 at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter) in d:\GalaSoft\mydotnet\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\Command\RelayCommand.cs:line 167 at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, …
我是为WebAPI编写测试用例的新手。我曾经看过类似的问题,但没有得到回答,但是我想知道如果我的API ODataQueryOptions作为参数的一部分,我将如何测试它们。见下文:
public IQueryable<Item> GetByIdAndLocale(ODataQueryOptions opts,
Guid actionuniqueid,
string actionsecondaryid)
Run Code Online (Sandbox Code Playgroud)
我需要起订吗?如果是这样,看起来会如何?任何帮助,将不胜感激。
假设我的组件当前对我的接口有一个依赖关系,ICache并使用构造函数注入在基于DB的Cache实现中注册.像这样的东西:
container.Register(Component.For<ICache>()
.ImplementedBy<DatabaseCache>()
.LifeStyle.Singleton
.Named("dbcache"));
Run Code Online (Sandbox Code Playgroud)
然后我的组件注册它:
container.Register(Component.For<IRepository>()
.ImplementedBy<CoolRepository>()
.LifeStyle.Singleton
.Named("repo")
.DependsOn(Dependency.OnComponent(typeof(ICache), "dbcache")));
Run Code Online (Sandbox Code Playgroud)
但是如果我希望我的组件能够同时使用ICache不同类型的第二个依赖项呢?如何将2个不同的同一接口实现注入主组件?
我正在使用 MVVM 模式和 MVVM Light 将事件转换为命令,在我的 XAML 中,我有以下代码:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Padding="0,0,0,0" Height="Auto">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding MyCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中,我有以下代码:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Padding="0,0,0,0" Height="Auto">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding MyCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
但是点击事件不会被触发。但是,我对应用程序中的每个按钮都使用这种方式,当按钮进入用户控件或窗口时,将触发该事件。
谢谢。
我正在测试一个SignalR服务器(在控制台应用程序中自托管),它最终将构成数据记录系统的基础.测试客户端正在向集线器发出大约180个呼叫/秒,而消息本身非常小(只是一个名称/值对).
我正在使用Castle Windsor进行DI,使用自定义IHubActivator来解析Hub实例:
internal class WindsorHubActivator : IHubActivator
{
private readonly IWindsorContainer _container;
public WindsorHubActivator(IWindsorContainer container)
{
_container = container;
}
public IHub Create(HubDescriptor descriptor)
{
var hubType = descriptor.HubType;
return _container.Resolve(hubType) as IHub;
}
}
Run Code Online (Sandbox Code Playgroud)
这是集线器类:
public class TelemetryHub : Hub
{
private readonly TelemetryDataService _telemetryDataService;
public TelemetryHub(TelemetryDataService telemetryDataService)
{
_telemetryDataService = telemetryDataService;
}
public void LogTelemetryData(string name, double value)
{
_telemetryDataService.LogTelemetryData(name, value);
}
}
Run Code Online (Sandbox Code Playgroud)
当集线器类在Windsor注册为"瞬态"时,内存消耗量稳步攀升,直到达到2Gb然后因OOM异常而下降.如果我将Hub注册为"Singleton",那么应用程序内存消耗将保持非常低且一致.
该TelemetryDataService班是不是问题.我已经注释掉了hub的构造函数和方法代码,问题仍然存在.
出于好奇,我接着进一步改变了阶段,改变了WindsorHubActivator阶级,将温莎带出了等式:
internal class WindsorHubActivator : IHubActivator …Run Code Online (Sandbox Code Playgroud) c# ×9
moq ×3
mvvm ×3
mvvm-light ×3
unit-testing ×3
wpf ×3
.net ×1
button ×1
coding-style ×1
datagrid ×1
linq ×1
mocking ×1
nunit ×1
odata ×1
signalr ×1
signalr-hub ×1
silverlight ×1
tcp ×1
xaml ×1