我的功能几乎是一个标准的搜索功能...我已将它包含在下面.
在函数中,我有一行代码负责清除重新分配NTFS点.
if (attributes.ToString().IndexOf("ReparsePoint") == -1)
Run Code Online (Sandbox Code Playgroud)
问题是现在我收到了一个错误
Access to the path 'c:\System Volume Information' is denied.
我调试了代码,运行时该目录的唯一属性是:
System.IO.FileAttributes.Hidden
| System.IO.FileAttributes.System
| System.IO.FileAttributes.Directory
Run Code Online (Sandbox Code Playgroud)
我正在Windows 2008服务器上执行此代码,任何想法我能做些什么来治愈这个失败?
public void DirSearch(string sDir)
{
foreach (string d in Directory.GetDirectories(sDir))
{
DirectoryInfo dInfo = new DirectoryInfo(d);
FileAttributes attributes = dInfo.Attributes;
if (attributes.ToString().IndexOf("ReparsePoint") == -1)
{
foreach (string f in Directory.GetFiles(d, searchString))
{
//lstFilesFound.Items.Add(f);
ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
lvi = new ListViewItem();
lvi.Text = f;
lvi.ImageIndex = 1;
lvi.Tag = "tag";
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = …Run Code Online (Sandbox Code Playgroud) 我有一个Web应用程序,可以控制哪些Web应用程序从我们的负载均衡器获得流量.Web应用程序在每个服务器上运行.
它跟踪ASP.NET应用程序状态中对象中每个应用程序的"进入或退出"状态,并且只要状态发生更改,就将对象序列化为磁盘上的文件.Web应用程序启动时,将从文件反序列化状态.
虽然网站本身只获得了几个请求,并且它很少访问该文件,但我发现由于某种原因,在尝试读取或写入文件时发生冲突非常容易.这种机制需要非常可靠,因为我们有一个自动化系统,可以定期对服务器进行滚动部署.
在任何人发表任何有关上述任何一个问题的评论之前,请允许我简单地说,解释它背后的推理会使这个帖子比现在更长,所以我想避免移山.
也就是说,我用来控制文件访问的代码如下所示:
internal static Mutex _lock = null;
/// <summary>Executes the specified <see cref="Func{FileStream, Object}" /> delegate on
/// the filesystem copy of the <see cref="ServerState" />.
/// The work done on the file is wrapped in a lock statement to ensure there are no
/// locking collisions caused by attempting to save and load the file simultaneously
/// from separate requests.
/// </summary>
/// <param name="action">The logic to be executed on the
/// <see cref="ServerState" /> …Run Code Online (Sandbox Code Playgroud) 我正在创建一个方法,通过传递搜索字段从任何表中选择id.
private int SelectId(string tabela, string campo, string valor)
{
int id = 0;
using (command = new MySqlCommand())
{
command.Connection = conn;
command.Parameters.Add("@tabela", MySqlDbType.).Value = tabela;
command.Parameters.Add("@campo", MySqlDbType.Text).Value = campo;
command.Parameters.Add("@valor", MySqlDbType.VarChar).Value = valor;
command.CommandText = "SELECT `id` FROM @tabela WHERE @campo=@valor;";
try
{
id = (int)command.ExecuteScalar();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Number + " : " + ex.Message + command.CommandText);
}
catch (Exception)
{
throw;
}
}
return id;
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个关于语法错误的MySqlException.当我查看Exception消息时,它会显示带引号表的查询!如何在没有引号的情况下将表作为参数传递?
我正在尝试做这样的事情:
int x_1 = 1;
int x_2 = 2;
String s1 = "x";
String s2 = "_1";
Run Code Online (Sandbox Code Playgroud)
s1&s2将是来自用户或循环的变量,我希望能够int通过执行类似的操作来调用正确的变量(s1+s2).
可能吗?
我在为 XAML 窗口指定图标时发现了 WPF XAML 中的一个错误,尝试运行该程序会在行上生成一条错误消息:
System.Windows.Application.LoadComponent(Me, resourceLocater)
Run Code Online (Sandbox Code Playgroud)
发生 XamlParseException
在“System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值引发异常。行号“5”和行位置“100”。
我已经将图标设置为Always Createon Copy To Output Directory,但没有运气。
我将图标从 更改Resource为EmbeddedResource - 那里也没有运气。
我将它添加到Resources项目中 - 仍然没有运气。
我已经验证了文件,它的位置 100%。
窗口的XAML正确,名称正确,路径正确。
Icon="Resources/VisualizerIcon.ico"
Run Code Online (Sandbox Code Playgroud)
难倒 - 在线论坛说复制到输出目录是解决方案,但是,在构建解决方案后,仅复制文件夹(即使我明确设置了要复制的 ICO 文件)。
任何人?
假设一个 json 字符串如下所示:
string json = '{"string_property":"foo_bar", ... other objects here ...}';
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以对解析的对象运行转换,以便在运行以下方法后foo_bar我不会得到 ,而是得到(实际上可以是任何东西)foo bar
public string Transform(string s) {
return s.Replace("_"," ");
}
Run Code Online (Sandbox Code Playgroud)
我可以在反序列化后手动更改我的poco,但想知道什么是“更干净”的方法?
当我ViewModel在Mvvm Light中使用多个构造函数时,我遇到了这个问题:
我有一个具有空ctor的视图模型,然后我创建了第二个接收参数的模型(在某些情况下想要做其他事情......).如果我尝试运行应用程序,我会得到:
无法注册:在Inner_VM中找到多个构造函数,但没有使用PreferredConstructor标记.
这只是如果我注册碰巧ViewModel在Locator:
SimpleIoc.Default.Register<Inner_VM>();
Run Code Online (Sandbox Code Playgroud)
然后在属性中使用它:
public Inner_VM Inner
{
get { return ServiceLocator.Current.GetInstance<Inner_VM>(); }
}
Run Code Online (Sandbox Code Playgroud)
如果我省略了注册ViewModel,然后在属性中使用它:
public Inner_VM Inner
{
get { return new Inner_VM(); }
}
Run Code Online (Sandbox Code Playgroud)
一切似乎都有效......
我认为第一个选项使用正在重用的静态实例,第二个选项只是在我每次使用它时创建一个新实例.(这在我的应用程序中并不重要,但我试图了解原因,并且找不到任何解释它,即使在搜索SO和谷歌这个问题之后).
任何帮助都会受到欢迎.
我需要检查记录是否保存到数据库中。如果它保存在数据库中打开另一个表单,否则显示一条消息,它不在数据库中。
如果记录不在数据库中,我会收到此错误Object reference not set to an instance of an object.
这是我的代码,请帮助我在此处找到错误:
string cmdStr = "Select NO from COM_LIST_EXPORT where NO = '" + txtNO.Text + "'";
SqlCommand cmd = new SqlCommand(cmdStr, CN);
int count = (int)cmd.ExecuteScalar();
if (count == Convert.ToInt32(txtNO.Text))
{
Archive_Sader dd = new Archive_Sader();
dd.Show();
}
else
{
MessageBox.Show("please save first");
}
Run Code Online (Sandbox Code Playgroud) 我在使用Entity Framework 6和MySQL时遇到了问题,并且在ASP.NET C#MVC 3中使用模型/数据库优先技术.
目前的情况是我收到错误:
Keyword not supported.
Parameter name: metadata
Run Code Online (Sandbox Code Playgroud)
元数据在web.config -file的连接字符串中指定:
<add name="SiteNameContainer"
connectionString="metadata=res://*/Models. SiteName.csdl|
res://*/Models. SiteName.ssdl|
res://*/Models. SiteName.msl;
provider=MySql.Data.MySqlClient;
provider connection string='server=127.0.0.1;
user id=fire;password=fire_db;
database=fire_dotnet'"
providerName="MySql.Data.MySqlClient" />
Run Code Online (Sandbox Code Playgroud)
我试图删除connectionString中的元数据部分,但后来说它不支持关键字"provider",然后不支持"provider connection string".
我的web.config文件中也有这两个部分:
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices,
MySql.Data.Entity.EF6, Version=6.8.3.0,
Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<clear />
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySql.Data.MySqlClient"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory,
MySql.Data, Version=6.8.3.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Run Code Online (Sandbox Code Playgroud)
我引用了MySQL …
我有一个启动服务器的类:
public class SocketServer
{
private static IXSocketServerContainer server = null;
public SocketServer()
{
server = XSockets.Plugin.Framework.Composable
.GetExport<IXSocketServerContainer>();
}
public bool StartServers()
{
try
{
server.StartServers();
return true;
} catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这个类有一个方法:
public void SendEventMessageToAllClients(string message)
{
XSockets.Core.XSocket.Helpers.XSocketHelper
.SendToAll<MyController>(new MyController(), message, "events");
}
Run Code Online (Sandbox Code Playgroud)
MyController我自己的控制器在哪里,它被实现,服务器可以找到它,这个方法工作.
现在我想用一种新方法扩展功能,允许我将事件发送到特定客户端:
public void SendEventMessageToClient(string clientId, string message)
{
XSockets.Core.XSocket.Helpers.XSocketHelper
.SendTo<MyController>(new MyController(),
p => p.ClientId == clientId, message, "events");
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法还是我做错了什么?
谢谢!
c# ×8
.net ×2
asp.net ×2
mysql ×2
wpf ×2
java ×1
json.net ×1
locking ×1
mutex ×1
mvvm-light ×1
ntfs ×1
reflection ×1
reparsepoint ×1
sql ×1
variables ×1
xaml ×1
xsockets.net ×1