我正在尝试使用JsonPath for .NET(http://code.google.com/p/jsonpath/downloads/list),我无法找到如何解析Json字符串和JsonPath字符串的示例得到一个结果.
有没有人用过这个?
我将跟踪由Unity容器管理的服务中发生的每个操作作为文件系统中的日志.我想我可以定义一个名为IService的接口,所有其他接口或实现都应该继承自己.另一方面,我想开发一个自定义拦截行为或调用处理程序来将日志保存到文件中.
不幸的是,我发现使用此代码对我不起作用
IUnityContainer unity = new UnityContainer();
//Interception
unity.AddNewExtension<Interception>();
Interception interception = unity.Configure<Interception>();
unity.RegisterType<IService>(
new DefaultInterceptor(new InterfaceInterceptor()),
new DefaultInterceptionBehavior(new LoggingBehavior()));
string[] configFiles = Directory.GetFiles(".", "*.config");
foreach (string configFile in configFiles)
{
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFile };
System.Configuration.Configuration configuration =
ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
var unitySection = (UnityConfigurationSection)
configuration.GetSection("unity");
unity = unitySection.Configure(unity);
}
IGateway imapGW = unity.Resolve<IGateway>("ImapGateway");
Run Code Online (Sandbox Code Playgroud)
在Unity中使用拦截器对我有什么误解吗?如何在不为每项服务配置拦截器的情况下自动记录所有内容?
我正在使用Interop通过Outlook发送电子邮件,但我无法指定From电子邮件地址.
我想向来自同一发件人(来自)的多个用户发送邮件.我需要提一下电子邮件地址.但是,我找不到使用Intellisense的属性,允许我指定它.
请帮忙.
Microsoft.Office.Interop.Outlook.Application olkApp1 =
new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem olkMail1 =
(MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
olkMail1.To = txtpsnum.Text;
olkMail1.CC = "";
olkMail1.Subject = "Assignment note";
olkMail1.Body = "Assignment note";
olkMail1.Attachments.Add(AssignNoteFilePath,
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1,
"Assignment_note");
olkMail1.Save();
//olkMail.Send();
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用StackOverflow的搜索API来搜索问题.
我正在使用此操作来执行解析:
public ActionResult StackExchange(string sq)
{
string url = "http://api.stackoverflow.com/1.1/search?intitle=" + sq + "&order=desc";
var client = new WebClient();
var response = client.DownloadString(new Uri(url));
JObject o = JObject.Parse(response);// ERROR
int total = (int)o["total"];
return View(total);
}
Run Code Online (Sandbox Code Playgroud)
这是我试图解析的JSON URL:
http://api.stackoverflow.com/1.1/search?intitle=asp.net%20custom%20404&order=desc
我试图提取以下数据:
`"total": 3` ,
`"question_timeline_url": "/questions/10868557/timeline",`
`"title": "Asp.net custom 404 not working using Intelligencia rewriter"`
Run Code Online (Sandbox Code Playgroud)
给出错误为:Newtonsoft.Json.JsonReaderException:解析值时遇到意外的字符:.路径'',第0行,第0位.
什么是例外的原因?我之前使用过相同的方法,但效果很好.
请建议.
我正在尝试动态声明一个ImageButton.
我声明它并为其分配ID和图像,如下所示:
ImageButton btn = new ImageButton();
btn.ImageUrl = "img/Delete.png";
btn.ID = oa1[i] + "_" + i;
btn.OnClick = "someMethod";
Run Code Online (Sandbox Code Playgroud)
但是当我尝试为按钮分配OnClick处理程序时,它会抛出以下异常:
System.Web.UI.WebControls.ImageButton.OnClick is inaccessible due to protection level
Run Code Online (Sandbox Code Playgroud) 我正在使用Se7enSoft的MozNet插件.这是FireFox 3.6的WebBrowser控件.它使用XulRunner.
我要做的第一件事是执行Initialize(...)方法.
var binDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
var xulRuntimeDirectory = Path.Combine(binDirectory, "xul");
Se7enSoft.MozNet.Xpcom.Initialize(xulRuntimeDirectory, null);
Run Code Online (Sandbox Code Playgroud)
我必须将它传递给我们安装XulRunner的目录.此插件的Initialize方法在内部使用以下DLLImport.
[DllImport("xpcom", CharSet = CharSet.Ansi,
EntryPoint = "NS_CStringContainerFinish",
CallingConvention = CallingConvention.Cdecl)]
internal static extern int Moz_CStringContainerFinish(ACString container);
Run Code Online (Sandbox Code Playgroud)
XulRunner的xpcom.dll中的NS_CStringContainerFinish方法是必需的.
就在第一次调用此方法之前,MozNet插件会临时更改PATH环境变量.
Environment.SetEnvironmentVariable("path",
Environment.GetEnvironmentVariable("path") + ";" +
binDirectory, EnvironmentVariableTarget.Process);
Run Code Online (Sandbox Code Playgroud)
XulRunner的位置暂时添加到PATH环境变量中,以确保它可以解析xpcom.dll(和其他).
但它仍然无法找到它.我收到以下异常.
Unable to load DLL 'xpcom': Cannot find method.
(Exception from HRESULT: 0x8007007F)
at Se7enSoft.MozNet.Native.MozNativeMethods.Moz_CStringContainerInit(
ACString container)
at Se7enSoft.MozNet.Xpcom.XpCom_Init()
at Se7enSoft.MozNet.Xpcom.Initialize(String mozPath, String profPath)
Run Code Online (Sandbox Code Playgroud)
此问题仅发生在3台PC上(Windows 2000和XP).适用于数百个其他人.
如果我调试并跳过Environment.SetEnvironmentVariable(...)方法,我可以重现该问题.
SetEnvironmentVariable是否存在任何可能阻止其更改PATH环境变量的问题?
在与支付终端通信的一些遗留代码中出现了错误.
在新付款开始之前,代码会尝试清除SerialPort的内部读取缓冲区.
我将代码调整到最低限度.它使用.NET SerialPort类型.设置读取超时50ms.然后它读取512个字节并继续这样做,直到不再读取字节或抛出TimeoutException为止.
我们添加了一堆日志记录,它显示对第一个Read(...)方法的调用有时需要10到15分钟,即使超时为50ms.然后抛出TimeoutException并继续应用程序.但在Read(...)期间应用程序挂起.
这并不总是发生,Windows 2000机器出于某种原因似乎更容易出现此错误.
public class Terminal
{
private SerialPort _serialPort = new SerialPort();
public void ClearReadBuffer()
{
try
{
_serialPort.ReadTimeout = 50;
int length;
do
{
var buffer = new byte[512];
length = _serialPort.Read(buffer, 0, 512);
} while (length > 0);
}
catch (TimeoutException) {}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
PS:大多数错误报告来自W2K机器,其中设备连接到EdgePort,EdgePort模拟一堆虚拟COM端口.它的驱动程序创建了一堆(大约8个)本地COM端口.
但是我们也有来自Windows 7的报告.如果我们直接将设备连接到PC(没有EdgePort),我们也可以重现这个问题.然而不是经常发生,当它发生时延迟不是10分钟,而是更像是1 - 2分钟.
更新:尝试了很多东西来解决这个问题.难以重现,但在现场经常发生,因为它分布在数千台PC上.实际上用另一个开源版本替换了.NET 2.0 SerialPort类型.在一台PC上没有问题的地方工作,我们实际上可以像60-70%的时间那样重现它.但是,在生产中的试点测试中,问题仍然存在.
付款终端的代码是在几年前编写的,我把它移植到另一个应用程序中.在端口期间,我重新考虑了一些代码,但保留了原始功能.与终端通信时,代码将:
同时主线程有一个while循环,其中包含一个Thread.Sleep(50)和一个Application.DoEvents()调用(yuck!).我重构了整个"等待循环",并使用了WaitHandle(AutoResetEvent/ManualResetEvent).我只是等到这个句柄设置好了.工作没有问题,但在某些PC上,所有串口通信都会冻结几分钟,直到触发它为止.重新启用Application.DoEvents()工作方式,问题就消失了.
不幸的是,它仍然存在于我之中,为什么在这里需要它以及为什么它会导致如此严重的副作用.这些应用程序支持其他5种类型的串行端口设备.与这些设备通信从不需要这样的东西.