我正在尝试通过网络发送XML文档,但收到以下异常:
"MY LONG EMAIL STRING" was specified for the 'Body' element. ---> System.ArgumentException: '', hexadecimal value 0x02, is an invalid character.
at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int32 ch, Byte* pDst, Boolean entitize)
at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlUtf8RawTextWriterIndent.WriteString(String text)
at System.Xml.XmlRawWriter.WriteValue(String value)
at System.Xml.XmlWellFormedWriter.WriteValue(String value)
at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.WriteValue(String value, String name)
--- End of inner exception stack trace ---
Run Code Online (Sandbox Code Playgroud)
我无法控制我尝试发送的内容,因为字符串是从电子邮件中收集的.如何在保留非法字符的同时对我的字符串进行编码以使其成为有效的XML?
我想以这种或那种方式保留原始角色.
我正在寻找在我的控制之外远程调用服务的方法,直到连接成功为止.我也不想简单地设置一个定时器,每隔n秒/分钟执行一次动作,直到成功为止.经过一系列研究后,似乎断路器模式非常适合.
我发现了一个实现,它使用温莎城堡拦截弹,这看起来真棒.唯一的问题是我不知道如何使用它.从几篇文章,我发现关于该主题的唯一使用的例子,我能找到的就是简单地使用断路器只调用一个动作一次,这似乎不是很有用.从那看起来我需要简单地在while(true)循环中使用断路器来运行我的动作.
我如何使用Windsor拦截器执行一个动作来调用外部服务,直到它成功而不会关闭我们的服务器?
有人可以填写丢失的部分吗?
while(true)
{
try
{
service.Subscribe();
break;
}
catch (Exception e)
{
Console.WriteLine("Gotcha!");
Thread.Sleep(TimeSpan.FromSeconds(10));
}
}
Console.WriteLine("Success!");
public interface IService
{
void Subscribe();
}
public class Service : IService
{
private readonly Random _random = new Random();
public void Subscribe()
{
var a = _random.Next(0, 10) % 2421;
if(_random.Next(0, 10) % 2 != 0)
throw new AbandonedMutexException();
}
}
Run Code Online (Sandbox Code Playgroud)
基于此,我想我现在理解这个概念以及如何应用它.
c# design-patterns dependency-injection interceptor circuit-breaker
我已经实现了一个订阅/发布(为了我自己的享受)WCF服务,它运作得相当好.像我见过的所有博客和书籍一样,他们都OperationContext用来获取客户回调地址.经过一些阅读,由于很多人说不使用OperationContext,我发现自己无法创建适当的单元测试.然而,我还没有找到替代方案.我想订阅方法可以接受一个参数来提供它自己的地址吗?从集成测试站的角度来看,我可以看到代码是可测试的,但是不能用于单元测试,因为它OperationContext总是为空.
如何在不使用订阅我的服务的情况下获取客户端点OperationContext?
除了一点点,但在显示代码示例时,哪里有一个好的WCF资源并考虑了测试?有大量的博客在没有提供样本测试用例的情况下重复相同的代码.
谢谢.
我们有一个应用程序,它使用a StreamingSubscriptionConnection来读取发送到特定邮箱的每封电子邮件.我在开发过程中每天运行几次的问题我得到了例外{"'{square character}', hexadecimal value 0x1F, is an invalid character. Line 1, position 1."}.
这是堆栈跟踪:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Int32 pos, Char invChar)
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read()
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read(XmlNodeType nodeType)
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.InternalReadElement(XmlNamespace xmlNamespace, String localName, XmlNodeType nodeType)
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.ReadStartElement(XmlNamespace xmlNamespace, String localName)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)
Run Code Online (Sandbox Code Playgroud)
如何安全地阅读包含非法字符的EWS电子邮件?
经过一番搜索似乎它是可以解决这个问题,使用旧版本的EWS API的.但是,使用最新版本的托管API似乎没有人修复.
为什么这个简单的断言语句失败了?从我所读到的,我应该是.不幸的是,由于功能是如此基本,因此没有太多信息.
public interface IDummy{}
public class Dummy : IDummy {}
Assert.IsAssignableFrom<IDummy>(new Dummy());
Run Code Online (Sandbox Code Playgroud)
运行此测试产生
Expected: assignable from <Application.Tests.ViewModels.IDummy>
But was: <Application.Tests.ViewModels.Dummy>
Run Code Online (Sandbox Code Playgroud)
我试过交换界面和对象方无济于事.
处理EWS限制策略的有效方法是什么?
我正在尝试阅读邮箱中的每封电子邮件以及下载所有附件.我遇到的问题是Exchange经常会返回异常说The server cannot service this request right now. Try again later..似乎很明显,我必须达到我的极限.搜索我可以看到这个错误很可能是因为我每分钟花费多少时间来处理CAS.限制政策似乎是EWSPercentTimeInCAS.
由于每个查询只能收到1,000封电子邮件,因此我需要查询所有57,000封电子邮件.我怎样才能做到这一点?
请注意,我并没有试图规避限制政策.想到的唯一想法是Thread.Sleep(30000)每次检索1,000封电子邮件时发出声明(我的搜索结果限制).然而不理想应该工作,因为获取1,000个项目花费的时间要少得多.
此问题似乎源于下载附件.邮箱总共有7,000个附件.
可能重复:
如何设置wpf应用程序的默认字体?
来自Web开发背景我经常对如何为控件分配样式感到困惑.我想做的是为整个应用程序设置一个全局字体系列.
在我的App.xaml文件中,我有以下内容
<Style TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Helvetica, Arial" />
<Setter Property="FontSize" Value="13" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我已经尝试将目标类型更改为Control但是没有做任何事情.我希望,因为从技术上讲Window,一切都在一个控制中,一切都会按预期工作.
原来TextBlock控件不继承Control.我认为这是问题的主要原因,因为90%的文字都在TextBlock表格中.
在CSS中我会做这样的事情:
body {
font-family: Helvetica, Arial;
font-size: 13px;
}
Run Code Online (Sandbox Code Playgroud) 阅读这篇博文,它提到你可以让你的DI容器自动订阅它实现的事件IHandle<>.这正是我想要完成的.
这是我到目前为止所拥有的.
container.Register(Component
.For<MainWindowViewModel>()
.ImplementedBy<MainWindowViewModel>()
.LifeStyle.Transient
.OnCreate((kernel, thisType) => kernel.Resolve<IEventAggregator>().Subscribe(thisType)));
Run Code Online (Sandbox Code Playgroud)
虽然此代码成功订阅MainWindowViewModel以接收已发布的消息,但实际接收消息的时间没有任何反应.如果我按预期手动订阅所有工作.
这是我的MainWindowViewModel课.
public class MainWindowViewModel : IHandle<SomeMessage>
{
private readonly FooViewModel _fooViewModel;
private readonly IEventAggregator _eventAggregator;
public MainWindowViewModel(FooViewModel fooViewModel, IEventAggregator eventAggregator)
{
_fooViewModel = fooViewModel;
_eventAggregator = eventAggregator;
//_eventAggregator.Subscribe(this);
_fooViewModel.InvokeEvent();
}
public void Handle(SomeMessage message)
{
Console.WriteLine("Received message with text: {0}", message.Text);
}
}
Run Code Online (Sandbox Code Playgroud)
如果任何类继承,我如何告诉Windsor自动订阅IHandle<>?
我最终想出了这个订阅的自定义工具.
public class EventAggregatorFacility : AbstractFacility
{
protected override void Init()
{
Kernel.DependencyResolving += Kernel_DependencyResolving; …Run Code Online (Sandbox Code Playgroud) 在创建时设置列表容量的重要性是什么?
例如,说我知道肯定是我的名单将只包含ň其整个生命周期的项目.
这个问题只是为了满足我的兴趣。阅读“在类和结构之间进行选择”页面显示“它的实例大小小于 16 字节。”。
鉴于这个简单的不可变的struct。
public struct Coordinate
{
private readonly double _latitude;
private readonly double _longitude;
public Coordinate(double latitude, double longitude)
{
_latitude = latitude;
_longitude = longitude;
}
public double Latitude
{
get { return _latitude; }
}
public double Longitude
{
get { return _longitude; }
}
}
Run Code Online (Sandbox Code Playgroud)
属性是否也计入 16 字节限制?还是只有字段才算?
如果后者不会使用structMicrosoft 提供的指南,因为 double 是 8 个字节?两个双精度数将是 16 个字节,正好是 16 个字节,不能少于 16 个字节。