长话短说 - 通过ServiceStack.Text的JSON解析器跳转的日期会丢失时区信息.奇怪的是,DateTimeSerializerTests.DateTime_Is_Serialized_As_Utc_and_Deserialized_as_local()似乎期待这种行为,并DateTimeSerializer.Prepare()显式调用ToLocalTime()解析为UTC的每个日期时间对象!
这是一个示例测试用例(MSTest,但很容易在任何东西中运行).本地通行证,但UTC和未指定不通过 - DateTime对象返回的类型始终为"本地".
[TestMethod]
public void TestParseSingleDateTime_UTC()
{
// In canonical UTC format
var date = "2014-06-03T14:26:20.0030000Z";
var raw = new DateTime(2014, 6, 3, 14, 26, 20, 3, DateTimeKind.Utc);
var value = DateTimeSerializer.ParseShortestXsdDateTime(date);
Assert.AreEqual(DateTimeKind.Utc, value.Kind);
Assert.AreEqual(raw, value);
}
[TestMethod]
public void TestParseSingleDateTime_Local()
{
// In local time zone
var date = "2014-06-02T11:15:49.1480000-05:00";
var raw = new DateTime(2014, 6, 2, 11, 15, 49, 148, DateTimeKind.Local);
var value = DateTimeSerializer.ParseShortestXsdDateTime(date);
Assert.AreEqual(DateTimeKind.Local, value.Kind);
Assert.AreEqual(raw, …Run Code Online (Sandbox Code Playgroud) 我有一个消息处理程序,在Azure中运行以下签名:
public static void DispatchQueueMessage([QueueTrigger("bq")] string msg,
TextWriter tw)
Run Code Online (Sandbox Code Playgroud)
我想配置log4net以使用提供的TextWriter.
如果这一般不可能,我绝对会选择使用标准格式输出的单个ILog实例!
我最终做了(如下):
ILog log = LogManager.GetLogger(name);
var appender = new TextWriterAppender();
appender.Writer = tw;
appender.Threshold = log4net.Core.Level.Debug;
DynamicPatternLayout layout = new DynamicPatternLayout();
layout.ConversionPattern = "%d [%t] %-5p %m%n";
layout.ActivateOptions();
appender.Layout = layout;
appender.ActivateOptions();
((log4net.Repository.Hierarchy.Logger) log.Logger).AddAppender(appender);
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Configured = true;
return log;
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
我试图用Roslyn确定两个方法签名是否相等(忽略参数顺序).当方法包含通用参数时,它变得有些不重要.
我想检测AGenericMethod和AnotherGenericMethod下面有相同的签名:
public void AGenericMethod<X>(X someX, int someInt) where X : IEnumerable<int>
{
//...
}
public void AnotherGenericMethod<Y>(Y someY, int someInt) where Y : IEnumerable<int>
{
//...
}
Run Code Online (Sandbox Code Playgroud)
对于X和Y ,似乎.Equals()会返回false.ITypeParameterSymbols
Roslyn中是否存在任何用于将其归类ITypeParameterSymbols为"等效"的功能(具有相同的约束)?如果不是,那么实现这一点的最佳方法是什么(考虑到约束本身可能是类型参数)?
我有一个简单的项目在VS上运行,用于Android应用程序,目前只是研究.我想录制简短(无聊)的视频来记录执行任务的人.我做的一切都很好.我有android SDK,我有模拟器,我有在互联网上无处不在的股票代码.我已经下载了Android机器的配置文件.有关kitkat,marshmellow等的API 15,19,23
我在清单中拥有视频,音频,外部存储等权限.
我想除了视频没有"停止"按钮外,我都是goo.
我有相应的相机操作工作就像一个享受.
private void TakeAPicture(object sender, EventArgs eventArgs)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
App._file = new File(App._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(App._file));
StartActivityForResult(intent, 0);
}
Run Code Online (Sandbox Code Playgroud)
然后,当单击相机按钮时,所有内容都很好地拾取内容并存储它.
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode != Result.Ok)
{
// did not do what we wanted
return;
}
// blah, blah, blah
}
Run Code Online (Sandbox Code Playgroud)
等等等等等等.
我的问题是,当我使用任何模拟器并单击视频版本时,视频启动但永不停止.最终它超时并且我得到了android"等待或杀死"消息,当我杀死时,它在OnActivityResult中使用取消resultCode(这是好的)
我是否应该期望模拟器中的视频有效.我正在使用红色/绿色框弹跳的模拟视频.
这是我的代码,由标准按钮点击触发
private void TakeAVideo(object sender, EventArgs eventArgs)
{
Intent intent = new Intent(MediaStore.ActionVideoCapture);
App._file = …Run Code Online (Sandbox Code Playgroud) 因为我们被迫放弃stateclient并转移到自定义存储,在我的情况下是一个azure表存储.使用我的storageexplorer,我可以看到它已经在我的azure上保存了对话数据.如何更新我的ff代码以获取过去的聊天记录?在我使用IActivityLogger类来记录对话之前,现在我对如何更新它感到困惑.
全球Asax之前:
protected void Application_Start()
{
var builder = new ContainerBuilder();
builder.RegisterType<Logger>().AsImplementedInterfaces().InstancePerDependency();
builder.Update(Conversation.Container);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
Run Code Online (Sandbox Code Playgroud)
全球Asax之后:
protected void Application_Start()
{
Conversation.UpdateContainer(builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
});
GlobalConfiguration.Configure(WebApiConfig.Register);
}
Run Code Online (Sandbox Code Playgroud)
记录器类:
public class Logger:IActivityLogger
{
public static ConcurrentDictionary<string, List<IActivity>> Messages = new ConcurrentDictionary<string, List<IActivity>>();
public Task LogAsync(IActivity activity)
{
try
{
var list = new List<IActivity>() { activity };
Messages.AddOrUpdate(activity.Conversation.Id, list, (k, v) => { v.Add(activity); return v; }); …Run Code Online (Sandbox Code Playgroud) 我正在尝试RouteDataRequestCultureProvider在新的ASP.NET Core 2.2 MVC项目中使用。
我已经阅读了有关ASP.NET Core中路由的Microsoft文档,以了解2.2中引入的更改,但是我不明白为什么“文化”不被视为URL生成的环境值。
我ConfigureServices在Startup.cs中进行了更新,以包括以下设置:
var supportedCultres = new[] { new CultureInfo("en"), new CultureInfo("fr") };
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en");
options.SupportedCultures = supportedCultres;
options.SupportedUICultures = supportedCultres;
options.RequestCultureProviders = new[] { new RouteDataRequestCultureProvider { Options = options } };
});
Run Code Online (Sandbox Code Playgroud)
我修改了应用程序和默认路由Configure以使用“文化”路径段:
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(locOptions);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{culture:regex(^(en|fr)$)}/{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
HomeController.Index()当我按预期导航到/ en或/ fr时,此路线将解析为,但与锚定标记帮助器进行的其他操作的任何链接都将呈现为<a href="">(包括支架产生的“隐私”链接)。
关闭EnableEndpointRouting会导致锚标记助手再次工作:
services.AddMvc(opts => { opts.EnableEndpointRouting = false; …Run Code Online (Sandbox Code Playgroud) c# localization asp.net-core-mvc asp.net-core asp.net-core-routing
为什么编译器拒绝此代码并出现以下错误?(我用VS 2017用C# 7.3启用。)
CS0019运算符'=='不能应用于类型'T'和'T'的操作数
public class GenericTest<T> where T : Enum
{
public bool Compare(T a, T b)
{
return a == b;
}
}
Run Code Online (Sandbox Code Playgroud)
没有泛型的版本当然是完全有效的。
public enum A { ONE, TWO, THREE };
public class Test
{
public bool Compare(A a, A b)
{
return a == b;
}
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序中的MediaPlayer对象问题已经有一段时间了.基本上会发生什么:声音播放一段时间然后突然停止.这是我使用的两种方法.
protected virtual void playMovingSound()
{
movingSound.Open(new Uri(@"Music\walk.mp3", UriKind.Relative));
movingSound.Volume = 0.6 * ((GameVariables.ingameSoundOn) ? 1 : 0);
movingSound.Play();
}
protected void stopMovingSound()
{
movingSound.Stop();
}
Run Code Online (Sandbox Code Playgroud)
我不明白问题是什么.即使我在播放声音之前调用MediaPlayer的构造函数,问题仍然存在.
此外,MediaPlayer的其他实例也会同时停止播放.
方法stopMovingSound()和playMovingSound()每秒触发一次.
Edit1:类构造函数如下所示:
protected MediaPlayer movingSound = null;
public PlayerControlledObject(some params...) : base()
{
//...
movingSound = new MediaPlayer();
}
Run Code Online (Sandbox Code Playgroud)
和makeStep方法一样
public virtual void makeStep(double stepUnit)
{
double loopSteps = 100;
double littleStepX, littleStepY;
littleStepX = (angle == 0 ? 1 : angle == 180 ? -1 : 0) * stepUnit / loopSteps; …Run Code Online (Sandbox Code Playgroud) 我正在使用Xamarin开发一个Android应用程序,在将Xamarin升级到它的最新版本之后,我的WebRequest中抛出了以下异常:
{System.Net.WebException:获取响应流时出错(ReadDone1):ReceiveFailure ---> System.IO.IOException:EndRead failure ---> System.Net.Sockets.SocketException:System.Net.Sockets上的peer重置连接.Socket.EndReceive(IAsyncResult结果)[0x00000] in:0在System.Net.Sockets.NetworkStream.EndRead(IAsyncResult ar)[0x00000] in:0 ---内部异常堆栈跟踪结束---在System.Net .Sockets.NetworkStream.EndRead(IAsyncResult ar)[0x00000] in:0 at Mono.Security.Protocol.Tls.SslStreamBase.InternalReadCallback(IAsyncResult result)[0x00000] in:0 ---内部异常堆栈跟踪结束---在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)[0x00000] in:0 in System.Threading.Tasks.TaskFactory1 [System.Net.WebResponse] .InnerInvoke(System.Threading.Tasks.TaskCompletionSource1 tcs,System.Func)
2 endMethod,IAsyncResult l)[0x00000] in:0 ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x00000] in:0 at System. Runtime.CompilerServices.TaskAwaiter 1 [System.Net.WebResponse] .GetResult()[0x00000] in:0 at modulo.CICC.Chat.Core.ConnectionFactory.WebServices + d _32.MoveNext()[0x000db] in c:\ Users\Raphael Alvarenga\Documents\Projects\SESGE\Modulo.CICC.Chat\Modulo.CICC.Chat.Core\ConnectionFactory\WebServices.cs:205}
这是代码:
try
{
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
string data = "access_token=" + System.Web.HttpUtility.UrlEncode(accessToken) + "&refresh_token=" + System.Web.HttpUtility.UrlEncode(refreshToken);
WebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url + "?" + data);
myWebRequest.Method = method;
myWebRequest.ContentLength = data.Length;
myWebRequest.ContentType …Run Code Online (Sandbox Code Playgroud) 我正在AsyncEventingBasicConsumer使用以下代码尝试RabbitMQ :
static void Main(string[] args)
{
Console.Title = "Consumer";
var factory = new ConnectionFactory() { DispatchConsumersAsync = true };
const string queueName = "myqueue";
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queueName, true, false, false, null);
// consumer
var consumer = new AsyncEventingBasicConsumer(channel);
consumer.Received += Consumer_Received;
channel.BasicConsume(queueName, true, consumer);
// publisher
var props = channel.CreateBasicProperties();
int i = 0;
while (true)
{
var messageBody = Encoding.UTF8.GetBytes($"Message {++i}");
channel.BasicPublish("", queueName, props, messageBody);
Thread.Sleep(50);
} …Run Code Online (Sandbox Code Playgroud) c# ×10
android ×2
asp.net-core ×1
asynchronous ×1
azure ×1
botframework ×1
chatbot ×1
emulation ×1
enums ×1
generics ×1
localization ×1
log4net ×1
rabbitmq ×1
roslyn ×1
servicestack ×1
webrequest ×1
wpf ×1
xamarin ×1