什么正则表达式模式需要传递给java.lang.String.split()方法,使用所有空格字符('','\ t','\n'等)作为分隔符将String拆分为子串数组?
我遇到了几个我打电话的问题,但里面还有flatten另一个问题!这显然意味着它们正在链中传播并被卷入另一个链中.有没有办法递归展平所有内部AggregateExceptions?通常,我将使用句柄委托处理这些,但如果有另一个内部AggregateExceeption,则返回false.我没有妥善处理这些问题吗?AggregateExceptionAggregateExceptionAggregateException
编辑:既然我已经打电话展平,看来问题是,它没有被抓住,直到后来方式在调用堆栈.这是我正在调用Flatten()的代码.要在堆栈跟踪中使用,此方法称为WriteExceptionRecord(string,FileInfo):
do
{
try
{
using (var stream = file.Open(FileMode.Append, FileAccess.Write, FileShare.None))
{
using (StreamWriter writer = new StreamWriter(stream))
{
await writer.WriteLineAsync(data);
}
}
}
catch (AggregateException ex)
{
ex.Flatten().Handle((x) =>
{
if (x is IOException)
{
retryNeeded = true;
retryLeft--;
Thread.Sleep(500);
return true;
}
logger.ErrorException("Could not write to exception file: " + data, ex);
return false;
});
}
}
while (retryNeeded && retryLeft > 0);
Run Code Online (Sandbox Code Playgroud)
但是,堆栈跟踪显示它没有被捕获.相反,它会在调用堆栈之后被捕获.以下是出于安全原因删除了一些识别信息的跟踪:
System.AggregateException: One or more errors occurred. ---> …Run Code Online (Sandbox Code Playgroud) 我需要Jquery的scrollTo函数来为这个网站工作:http://cinicraft.com/Silverman/index.html
我尝试了以下内容
$(document).ready(function()
{
$("div.btnLp3").click(function(){
$('body,html').scrollTo('#target-examples', 800, {easing:'elasout'});
});
});
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个:
$(document).ready(function()
{
$("div.btnLp3").click(function(){
$('html, body').animate({ scrollTop: $(window.location.hash).offset().top}, 1000);
});
});
Run Code Online (Sandbox Code Playgroud)
我似乎无法开始scrollTo工作.有没有人有任何想法?这是我导入的内容:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"> </script>
Run Code Online (Sandbox Code Playgroud) 我知道ShouldSerialize*模式和*Specified模式以及它们是如何工作的,但两者之间有什么区别吗?
当某些事情应该有条件地序列化时,是否有任何"陷阱"使用一种方法而不是另一种方法?
此问题仅供使用XmlSerializer,但也欢迎有关此主题的一般信息.
关于这个主题的信息非常少,因此可能是因为它们执行完全相同的目的而且它是一种风格选择.然而,看起来奇怪的是.NET实现者会通过反射来分析类,并查找其中一个/两个模式来确定生成的序列化程序的行为,因为它会减慢序列化程序的生成速度,除非它只是一个向后兼容性工件.
编辑: 对于那些不熟悉这两个模式的人,如果*Specified属性或ShouldSerialize*方法返回true,则该属性被序列化.
public string MyProperty { get; set; }
//*Specified Pattern
[XmlIgnore]
public bool MyPropertySpecified { get{ return !string.IsNullOrWhiteSpace(this.MyProperty); } }
//ShouldSerialize* Pattern
public bool ShouldSerializeMyProperty()
{
return !string.IsNullOrWhiteSpace(this.MyProperty);
}
Run Code Online (Sandbox Code Playgroud) 我在使用RestSharp时遇到问题我需要将REST API用于我正在进行的项目.我需要发出的请求分为三部分:头API密钥,要上传的文件和一堆JSON格式的数据.API要求使用表单字段名称"data"发送数据部分.由于某种原因,这会导致问题,因为它在请求正文中命名字段"data".
我的代码如下:
var request = new RestRequest(UPLOAD_DOC_URLSEGMENT, Method.POST)
{
RequestFormat = DataFormat.Json,
AlwaysMultipartFormData = true,
JsonSerializer = new RestSharpJsonDotNetSerializer(customSerializer)
};
if (doc is DocA)
request.AddParameter("data",doc as DocA,ParameterType.RequestBody);
//request.AddBody(doc as DocA);
else
request.AddParameter("data", doc as DocB,ParameterType.RequestBody);
//request.AddBody(doc as DocB);
request.AddFile("file", doc.File.FullName);
Run Code Online (Sandbox Code Playgroud)
如您所见,我试图同时使用request.AddBody(doc)方法和request.AddParameter(name, object, type)方法.它们似乎都没有正确发送数据,因为我收到服务器的响应,说明缺少必需的参数.使用fiddler,我可以看到二进制数据,但从不使用这两种方法的JSON数据.我已经浏览了RestSharp文档,但我找不到任何允许我将特定"字段"名称指定为表单数据体的"数据"的内容,这是我认为导致我遇到的问题.我在这做错了什么?
编辑:进一步检查fiddler后,它似乎没有将我的JSON数据添加到HTTP请求的主体.但是,在上传(执行命令)之前有一个断点,我可以在参数列表(和文件列表)中看到所有序列化的内容.当用Fiddler检查时,我看到文件二进制数据,然后是多部分/表格数据边界,然后什么都没有.我认为这是我的数据应该是......
我正在使用JSON.NET来序列化我的对象以连接到REST API.我的对象中需要序列化为JSON的属性之一具有动态属性名称.如果此属性的struct中包含的值是数值,则JSON属性为"type_id",但如果此值为字符串值,则JSON属性名称为"type_code".我尝试使用自定义JsonConverter,但是JsonWriterException当我尝试序列化时,我收到了这条消息:
"状态属性中的Token PropertyName将导致无效的JSON对象.路径''."
下面是我的对象的子集,如下所示我没有在我的对象中指定属性名称,因为:
[JsonProperty("title",Required=Required.Always,Order=1)]
public string Title { get; set; }
[JsonProperty("date",Order=3)]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTime Date { get; set; }
[JsonProperty(Order=2)]
[JsonConverter(typeof(TypeIdentifierJsonConverter))]
public TypeIdentifier DocTypeIdentifier { get; set; }
Run Code Online (Sandbox Code Playgroud)
在TypeIdentifier类中,我在WriteJson()方法中有以下内容:
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
TypeIdentifier docTypeId;
id= (TypeIdentifier) value;
writer.WritePropertyName(id.ParameterName);
writer.WriteValue(id.Value);
}
Run Code Online (Sandbox Code Playgroud)
但是,我假设它默认为对象属性的名称而不是我的自定义属性,导致JSON字符串中的单个值的两个属性名称.如何为此动态设置属性名称,因为JsonPropertyAttribute标记在未明确指定时会显示拉取对象的属性名称?
注意:此对象永远不需要从此应用程序反序列化.
编辑: 此对象标记有[JsonObject(MemberSerialization.OptIn)]属性
如何在不使用?的情况下将其转换为F#中Int64的Int32类型Microsoft.FSharp.Compatibility.Int32.of_int64?
我这样做是因为当我尝试时,交互式似乎不起作用:
open Microsoft.FSharp.Compatibility
Run Code Online (Sandbox Code Playgroud)
随着FSharp.PowerPack加入作为参考,它说:
错误FS0039:未定义名称空间"兼容性".
编辑:有人有问题的答案吗?关于int类型的建议是有用的和信息性的,但我在F#interactive中打开powerpack命名空间时遇到了同样的问题.
使用2012年6月的Azure SDK,我有一个服务总线主题,我正在添加订阅.
我想过滤该订阅.如果我根据我添加到BrokeredMessage Properties包中的一个项目执行此操作,那么这样可以正常工作:
// Send the message:
BrokeredMessage message = new BrokeredMessage(serializableObject);
message.Properties.Add("MySessionId", "GUID");
getTopicClient("MY_TOPIC").Send(message); // method creates client. omitted here.
// Retrieve it:
SqlFilter myFilter = new SqlFilter(@"(MySessionId = ""GUID"")");
namespaceManager.CreateSubscription("MY_TOPIC", "MY_SUB", myFilter);
SubscriptionClient client = getSubscriptionClient("MY_TOPIC", "MY_SUB"); // method creates client. omitted here.
// This will work fine:
Message newMessage = client.Receive();
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做,但是将过滤器值添加到BrokeredMessage对象的某个直接属性(例如SessionId),则会失败:
// Send the message:
BrokeredMessage message = new BrokeredMessage(serializableObject);
message.SessionId = "GUID";
getTopicClient("MY_TOPIC").Send(message); // method creates client. omitted here.
// Retrieve it:
SqlFilter myFilter …Run Code Online (Sandbox Code Playgroud) 在ASP.NET MVC应用程序中,我收到了一个使用我的Entity Framework上下文的控制器方法的以下错误消息.
在先前的异步操作完成之前,在该上下文上开始第二操作.使用'await'确保在此上下文上调用另一个方法之前已完成任何异步操作.任何实例成员都不保证是线程安全的.
我知道你不能并行运行查询,所有东西似乎都在等待.如果我调试程序并逐步检查从EF返回的一些数据,那么它可以工作,可能是因为这会强制查询完成.
编辑 如果我在控制器方法的空检查中放置一个断点并检查shipmentDetail异常的数据是不是抛出.
这是代码的一部分:
控制器方法:
[Route("{id:int}/Deliveries")]
public async Task<ActionResult> DeliveryInfo(int id)
{
var shipmentDetail = await db.ShipmentDetails.SingleOrDefaultAsync(s => s.Id == id);
if (shipmentDetail == null)
return HttpNotFound(string.Format("No shipment detail found with id {0}", id));
var model = await DeliveryInfoModel.CreateModel(db, shipmentDetail);
return View("DeliveryInfo", model);
}
Run Code Online (Sandbox Code Playgroud)
CreateModel方法:
public static async Task<DeliveryInfoModel> CreateModel(Context db, ShipmentDetail shipment)
{
DeliveryInfoModel model = new DeliveryInfoModel()
{
ShipmentInfo = shipment
};
//initialize processing dictionary
Dictionary<int, bool> boxesProcessed = new …Run Code Online (Sandbox Code Playgroud) c# ×6
f# ×2
json ×2
.net ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
azure ×1
exception ×1
java ×1
jquery ×1
json.net ×1
rest ×1
restsharp ×1
scrollto ×1
servicebus ×1
split ×1
string ×1
whitespace ×1