我正在使用自定义DateTimeToString:IValueConverter
在我的ConvertBack方法中,我在转换失败时抛出异常,但它没有显示为验证失败(这是一个未处理的应用程序异常),我想将其显示为验证问题(红色边框).
简而言之,我希望它在DateTime + Texbox中显示验证消息("输入字符串格式不正确"),但使用我的自定义IValueConverter.
假设,我想扩展(添加更多框)一些WCF服务.这看起来很简单,设置负载均衡器,使用例如循环算法在多个盒子上调用WCF服务.
但是如何处理WCF服务有回调契约的情况.当客户端连接到某个特定的框时,它会接收仅由此计算机WCF服务实例引发的事件.我希望客户端接收由组(集群)中的任何WCF服务实例引发的事件.
使WCF服务了解其他WCF服务实例引发的事件的最佳方法是什么?
一些想法:多播,广播,WCF NetPeerTcpBinding,订阅集群中所有WCF服务的单个服务器(充当事件聚合).
更新:我已设法创建测试系统,使用NetPeerTCPBinding作为跨服务器共享事件的机制.我还没有做过基准测试,但我觉得WCF P2P对于这个巨大的东西很重要,我将实现基于UDP广播的事件共享系统.
首先,我没有生气,因为我MVVM在WinForms中使用 - )我知道MVP(Model View Presenter)模式及其变体.当我开始这个项目时,我将学习WPF并使用它,但我不得不急于开发程序,并且没有时间学习WPF,所以我必须在WinForms中编写它,我很清楚.
所以简而言之,我有一个面向数据的大型智能客户端应用程序,接近完成,我已完成所有模型和ViewModel(基础设施,域,演示完成)UI也已完成,现在我只需要将UI连接到ViewModels.
首先,我开始使用标准winforms方式(BindingSources和简单的数据绑定)连接它,但是当我做了30-50%的绑定时,我发现我的程序运行速度很慢,到目前为止,我总共有100-150个绑定属性,30它们是域根实体(聚合根)绑定到其EditForm.因此数据绑定在这种情况下不能很好地工作,许多不必要的更新,当小的变化,不清楚的行为和其他丑陋的东西时,整个视图的级联更新.它闻起来像非常不可靠的代码,我几乎无法控制.
所以我开始重写布线作为纯粹干净的WinForms代码(订阅PropertyChange和ListChanged事件,并从UI自己设置ViewModels属性).很多代码要写,但它的工作速度要快得多,我对此完全控制,感觉更可靠.
那么你对这些家伙的想法是什么?谁有过这样的经历?您对"To DataBind与否"的判断是什么?
在我的对象转换代码中,我有很多:
try
{
NativeObject.Property1= int.Parse(TextObject.Property1);
}
catch (Exception e)
{
Trace.WriteLineIf(ConverterSwitch.TraceVerbose, e);
}
try
{
NativeObject.Property2= DateTime.Parse(TextObject.Property2);
}
catch (Exception e)
{
Trace.WriteLineIf(ConverterSwitch.TraceVerbose, e);
}
Run Code Online (Sandbox Code Playgroud)
等等...我不希望所有转换都失败导致某些属性因此我不能将所有这些放在一个try块中,但我需要记录一些事情是否失败并继续..
有没有办法压缩所有这尝试抓东西?
可惜我们不能用C#编写代码:
try
{
int num = int.Parse("3");
decimal num2 = decimal.Parse("3.4");
}
catch (Exception e)
{
Trace.Write(e);
continue; //continue execution from the point we left. (line 2)
}
Run Code Online (Sandbox Code Playgroud) 我在50%的WinXP SP3机器上遇到此例外.我知道大约260个字符的路径长度限制,但可以做什么?
我已经将文件命名为只有2个字符,没有任何子目录,但在一半的WinXP机器上,IsolatedStorage的路径已超过260个字符.
我正在尝试在我的项目中使用ProtoBuf-NET(它主要是Silverlight 4项目).
我在序列化我的模型集合时遇到了困难,它们都是这样定义的:
private List<T> _itemsSet;
public IEnumerable<T> TSet
{
get {return _itemsSet;}
set {_itemsSet = value == null ? new List<T>() : new List<T>(value);}
}
public void AddT(T item)
{
//Do my logic here
_itemsSet.Add(item);
}
Run Code Online (Sandbox Code Playgroud)
更新:首先我不能序列化它 - No serializer defined for type: System.Collections.Generic.IEnumerable1 [MyType]`.其次,我认为我将无法根据手动和protobuf-net源代码分析来绝对它.
ProtoMember(1, OverwriteList=true)不起作用?它不是要覆盖收集而不应该关心Add<T>()方法吗?为什么它只是不尝试将此属性设置为T [] List<T>或任何可分配的设置IEnumerable<T>?public interface IReflectable{ object GetValue(FieldInfo field); void SetValue(FieldInfo field, object value);
}使用私有字段.我使用这种方法与Db4o的私有字段一起工作:http://community.versant.com/Forums/tabid/98/aft/10881/Default.aspxMyTypeCollection<T> : …我有一个返回的ASP.NET MVC Web API控制器 public IEnumerable<IMessage> Get()
它抛出异常,我需要注册从IMessage传递给已知类型集合派生的类型DataContractSerializer.
如何注册"已知类型"为使用DataContractSerializer和DataContractJSONSerializer在MVC的Web API项目?
KnownType属性不能放在接口上.
保存组合的新的和修改的分离POCO实体的正确和快速方法是什么?
我在想这些方法:
private void Method_2(IList<Entity> entities) //detached entities
{
//This method is using SELECT to check if entity exist
using (var context = new ModelContainer())
{
foreach (Entity entity in entities)
{
var foundEntity = context.CreateObjectSet<Entity>().SingleOrDefault(t => t.Id == entity.Id);
context.Detach(foundEntity); //Remove it from ObjectStateManager
if (foundEntity != null)//It is modified entity
{
context.AttachTo("EntitySet", entity); //Attach our entity
context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); //We know it exists
}
else//It is new entity
{
context.CreateObjectSet<Entity>().AddObject(entity);
}
}
context.SaveChanges();
}
}
private void Method_1(IList<Entity> entities) …Run Code Online (Sandbox Code Playgroud) 我有一个视图,其中@model声明为FullModel类型;
public class FullModel
{
public IList<Record> SomeRecords {get;set;}
public Record NewRecord {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
此视图呈现SomeRecords,并且还将用于将NewRecord发布到控制器方法的Form呈现为:
public ActionResult CreateNew(Record record)
{
...
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西:
@using (@Html.BeginForm("CreateNew", "RecordController"))
{
@Html.TextBoxFor(x => x.NewRecord.SomeProp)
...
}
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,因为路径从root开始FullModel,所以POST数据变为NewRecord.SomeProp和控制器期望Record为root,路径应该是SomeProp
什么是通常\正确的方法来处理这个?
我有使用PRISM 4的silverlight 4应用程序,我正在使用MEF.
我的Shell定义了一个加载模块的主要区域,我希望模块有自己的RegionManager,因此它们定义的区域是本地RegionManager而不是global的位置.并且我想在模块内部通过容器(对于类型IRegionManager)解析此本地RegionManager.
但是来自文档的方法:
IRegion detailsRegion = this.regionManager.Regions["DetailsRegion"];
View view = new View();
bool createRegionManagerScope = true;
IRegionManager detailsRegionManager = detailsRegion.Add(view, null,
createRegionManagerScope);
Run Code Online (Sandbox Code Playgroud)
对我来说不起作用,当从子视图中解析IRegionManager时,我仍然得到GlobalRegionManager.
c# ×9
silverlight ×4
.net ×3
asp.net-mvc ×2
data-binding ×1
exception ×1
mef ×1
mvvm ×1
poco ×1
prism ×1
protobuf-net ×1
razor ×1
try-catch ×1
wcf ×1
windows-xp ×1
winforms ×1