可以任何人告诉我为什么以下:
['a', 'b'].inject({}) {|m,e| m[e] = e }
Run Code Online (Sandbox Code Playgroud)
抛出错误:
IndexError: string not matched
from (irb):11:in `[]='
from (irb):11:in `block in irb_binding'
from (irb):11:in `each'
from (irb):11:in `inject'
from (irb):11
from C:/Ruby192/bin/irb:12:in `<main>'
Run Code Online (Sandbox Code Playgroud)
而以下工作?
a = {}
a["str"] = "str"
Run Code Online (Sandbox Code Playgroud) 我想让用户能够取消正在运行的查询.查询真的很慢.(查询优化除此之外.)这主要是出于好奇心.
MSDN说:
如果没有什么可以取消,则不会发生任何事情 但是,如果正在处理命令,并且尝试取消失败,则不会生成异常.
这就是我所拥有的:
var t = new Thread(AbortThread);
t.Start();
void AbortThread()
{
LongQuery.Current.Cmd.Cancel();
LongQuery.Current.Cmd.Dispose();
LongQuery.Current.DA.Dispose();
LongQuery.Current.Conn.Close();
LongQuery.Current.Conn.Dispose();
LongQuery.Current.Cmd = null;
LongQuery.Current.DA = null;
LongQuery.Current.Conn = null;
CurrentSearch.Abort();
CurrentSearch.Join();
CurrentSearch = null;
}
Run Code Online (Sandbox Code Playgroud)
我注意到这CurrentSearch.Abort()是阻塞,这就是为什么我把它包装在一个线程中,这可能意味着线程仍在工作.
最后,除了这个我可以做什么来取消查询?实际上是否可以从.NET取消这么长的查询?
我想知道是否有一个好的ORM可以自动完成我现在必须做的一些手工工作.我们的应用程序大量使用存储过程,这意味着与数据库的任何交互都通过存储过程.
现在,我必须以传统方式调用存储过程,这非常繁琐.是否有一个ORM在处理存储过程方面做得很好:
我们选择使用的NuGet管理私有(.NET)库,但版本已经DLL文件的越来越无聊.
假设我们在两个项目中有以下共享库:
然后,在每个具体项目中,我们有:
我们现在的问题是,这是很困难的测试在一个特定项目要Shared_BLL所做的更改.目前,我们必须:
这是非常困难和巨大的开销.
我们尝试了另一种方法,即临时删除DLL引用并用直接引用修改后的DLL替换它们.但是,您必须撤消对项目的所有更改,这不是特别好.
我在这里错过了什么吗?如果你在开发生命周期中使用NuGet,你如何处理DLL?
更新:对于面临同样问题的人,我们已经远离nuget,直到将其整理出来,并依赖于将DLL放在特定文件夹中,并在每个项目文件中使用HintPath中的绝对路径.构建事件会更新已定义目录中的DLL,并且可以调试Shared和Project.
我的本地用户帐户位于Administrators组中,我想简单地弄清楚Windows窗体项目将如何确定我是否在管理员组中.所以,我启动了一个Windows窗体项目,并尝试了以下内容:
[STAThread]
static void Main()
{
string adminGroup1 = @"BUILTIN\Administrators";
string adminGroup2 = Environment.MachineName + @"\Administrators";
string adminGroup3 = Environment.MachineName.ToLower() + @"\Administrators";
string adminGroup4 = "Administrators";
string adminGroup5 = "administrators";
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal currentUser1 = (WindowsPrincipal)Thread.CurrentPrincipal;
bool IsAdmin1_1 = currentUser1.IsInRole(adminGroup1); // false
bool IsAdmin1_2 = currentUser1.IsInRole(adminGroup2); // false
bool IsAdmin1_3 = currentUser1.IsInRole(adminGroup3); // false
bool IsAdmin1_4 = currentUser1.IsInRole(adminGroup4); // false
bool IsAdmin1_5 = currentUser1.IsInRole(adminGroup5); // false
WindowsPrincipal currentUser2 = new WindowsPrincipal(WindowsIdentity.GetCurrent());
bool IsAdmin2_1 = currentUser2.IsInRole(adminGroup1); // false
bool IsAdmin2_2 = currentUser2.IsInRole(adminGroup2); …Run Code Online (Sandbox Code Playgroud) 我有以下方法可用于将对象转换为给定类型:
public static TTarget Convert<TTarget>(object source) where TTarget : new()
{
var target = new TTarget();
Type targetType = typeof (TTarget);
foreach (PropertyInfo sourceProperty in source.GetType().GetProperties())
{
if (!sourceProperty.CanRead || (sourceProperty.GetIndexParameters().Length > 0))
continue;
PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
if ((targetProperty != null) && (targetProperty.CanWrite))
targetProperty.SetValue(target, sourceProperty.GetValue(source, null), null);
}
return target;
}
Run Code Online (Sandbox Code Playgroud)
它适用于具有属性值类型等的简单类,但复杂属性需要映射到另一个类,它不是很清楚如何去做.如果我将映射存储到静态属性中:
private static Dictionary<Type, Type> Mappings;
static TypeConverter()
{
Mappings = new Dictionary<Type, Type>
{
{typeof (DbSpace), typeof (DmsSpace)},
{typeof (DbDirectory), typeof (DmsDirectory)},
{typeof (DbFile), typeof (DmsFile)}
}; …Run Code Online (Sandbox Code Playgroud) 我需要能够取消对我的webservice的异步调用.我的一个解决方案是使用管理我自己的线程,并使用SOAP客户端的同步方法.这很好,它需要一些更细粒度的线程管理.
如果我使用添加Web服务引用提供的这两种模式中的任何一种,请说:
var Client = new ASL_WS.SvcSoapClient()
IAsyncResult result = Client.BeginAuthenticateUser(Email, Password, new AsyncCallback(AuthCompleted));
Run Code Online (Sandbox Code Playgroud)
要么
var Client = new ASL_WS.SvcSoapClient()
Client.AuthenticateUserCompleted += AuthCompleted;
Client.AuthenticateUserAsync(Email, Passsword);
Run Code Online (Sandbox Code Playgroud)
这两种模式中的任何一种都能给我一种取消请求的方法吗?一个用例可能是:用户登录,但想要在身份验证调用完成之前取消.
当然,我可以通过修改传递给这些调用的asyncState并将其设置为禁用UI更新来实现这一点,但这不是我正在寻找的.
我可以取消所有未完成的操作吗?Client.Abort()是否取消此类操作.如果有很多异步请求会被取消怎么办?有没有其他API方法可以做到这一点?
我需要在应用程序进入后台后进行一些处理,所以我将此代码添加到我的应用程序中:
public override void DidEnterBackground (UIApplication application)
{
int taskid = 0;
taskid = application.BeginBackgroundTask(() => {
if(taskid != 0)
{
System.IO.File.WriteAllText(System.IO.Path.Combine(AppState.Current.User.Path, "blah"), "test");
application.EndBackgroundTask(taskid);
taskid = 0;
}
});
}
Run Code Online (Sandbox Code Playgroud)
然后我监视文件系统(模拟器应用程序),文件从未写入目标.有什么理由发生这种情况吗?我错过了什么吗?
c# ×5
.net ×1
asp.net ×1
ios5 ×1
nuget ×1
ruby ×1
sql-server ×1
web-services ×1
winforms ×1
xamarin.ios ×1