我编写了一个编辑特定文件类型的程序,我想让用户选择在启动时将我的应用程序设置为此文件类型的默认编辑器(因为我不需要安装程序).
我已经尝试编写一个可重用的方法,通过向HKEY_CLASSES_ROOT添加密钥,并将其与我的应用程序一起使用,但是它不会为我关联文件(最好是在任何操作系统上,虽然我正在运行Vista)似乎工作.
public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
{
RegistryKey BaseKey;
RegistryKey OpenMethod;
RegistryKey Shell;
RegistryKey CurrentUser;
BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
BaseKey.SetValue("", KeyName);
OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
OpenMethod.SetValue("", FileDescription);
OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
Shell = OpenMethod.CreateSubKey("Shell");
Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
BaseKey.Close();
OpenMethod.Close();
Shell.Close();
CurrentUser = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + Extension);
CurrentUser = CurrentUser.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
CurrentUser.Close();
}
Run Code Online (Sandbox Code Playgroud)
知道为什么它不起作用吗?一个示例用途可能是
SetAssociation(".ucs", "UCS_Editor_File", …Run Code Online (Sandbox Code Playgroud) 我想复制一个文件夹,我想先删除目标文件夹.所以我删除目标文件夹然后重新创建它,然后复制文件.问题是我An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
在尝试复制文件时得到了.这是代码
static public void CopyFolder(string sourceFolder, string destFolder)
{
if (Directory.Exists(destFolder)) // check if folde exist
{
Directory.Delete(destFolder, true); // delete folder
}
Directory.CreateDirectory(destFolder); // create folder
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
File.Copy(file, dest, true);
FileInfo fileinfo = new FileInfo(dest); // get file attrib
if (fileinfo.Attributes != FileAttributes.ReadOnly) // check if read only
File.SetAttributes(dest, FileAttributes.Normal);
}....... …Run Code Online (Sandbox Code Playgroud) Javascript中是否有免费的开源轻量级SCORM 2004播放器?我正在寻找一些不受任何技术(PHP,.NET,Java)约束的东西,只是实现基本的SCORM 2004 LMS API函数,处理错误代码以及解析SCORM清单.谢谢.
更新:我已经制作了一个非常简单的JavaSript SCORM 2004 API(但仍在寻找更成熟的代码).
Update2:我找到了一个非常好的项目TinyLMS.它只是SCORM 1.2,但我已与我的客户协商SCORM 1.2就足够了.所以我将基于TinyLMS制定解决方案.
我有一个经典的Hibernate @Inheritance(strategy=InheritanceType.SINGLE_TABLE)用@DiscriminatorFormula.它工作正常.但是,数据库中有大约500个不同的值@DiscriminatorValue,我需要将其中大约30个映射到Java类(子级),其余的映射到父级Java类.
可以将该问题建模为Animal类的示例继承.
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula("...")
public class Animal implements Serializable {
...
@Column
public String getName() { ... }
}
Run Code Online (Sandbox Code Playgroud)
所以我在Java代码中定义了大约30个Animal的子类@DiscriminatorValue.当Hibernate为鉴别器找到未知值时,它会抛出WrongClassException.但是,我需要将这些未知的鉴别器值映射到一个实体,最好是Animal类.(在这种情况下,我只需要使用方法getName().)
我知道一个解决方案是将一个SQL CASE放入其中@DiscriminatorFormula但是我必须说明所有30个已知的鉴别器值(当我需要添加其他值时再加上更多).所以我正在寻找更灵活的解决方案.
PS这是遗留代码,因此我无法更改模型.
我正在使用 Google 身份服务,并面临一些问题。看一下下面的函数loginUser并得到access_token:
const client = (window as any).google.accounts.oauth2.initTokenClient({
client_id: process.env.GOOGLE_CLIENT_ID,
scope: `profile email`,
callback: '' // defined at request time
});
const loginUser = async () => {
const tokenResponse = await new Promise<TokenResponse>((resolve, reject) => {
try {
// Settle this promise in the response callback for requestAccessToken()
client.callback = (resp) => {
if (resp.error !== undefined) {
reject(resp);
}
resolve(resp);
};
// requesting access token
client.requestAccessToken({ prompt: 'consent' });
} catch (err) { …Run Code Online (Sandbox Code Playgroud) javascript google-oauth google-signin google-identity react-google-login
在xUnit和Visual Studio中,我想[Collection("DB")]在“ 测试资源管理器”中对标记有属性的测试进行分组。我只能按[Trait("Collection", "DB")]属性分组测试。有什么办法可以Trait为所有带有[Collection("DB")]属性的测试分配一个特定的?
更新:我添加了xUnit问题#799。
JSON.NET JsonObjectAttribute具有一个属性Id。它是从继承的JsonContainerAttribute。我找不到,因为使用了什么Id属性?
我们在Google Compute Engine的一台服务器上拥有自己的MariaDB服务器.一个DB表包含大约10kB - 1.5MB的blob,这些blob只有INSERT,SELECT,没有UPDATE,DELETE很少.该表大约需要100GB并且正在增长.我们希望将其移出数据库,因此我们只是尝试在Google存储中存储一些blob.
但是一个简单的基准测试表明,使用Python google-api-python-client(和httplib2shim)读取blob objects().get_media()比连接到我们的MariaDB服务器要慢得多:400ms而不是10ms.OAuth2需要额外的HTTP请求,因此我预计总时间约为20毫秒,而不是400毫秒.新的Python库google-cloud-storage blob.download_as_string并不快.
更新:当我将文件提供给公共下载(http://storage.googleapis.com/...)时,速度可与MariaDB相媲美甚至更快.
这些Google Storage API OAuth的延迟是正常还是我错过了其他内容?当然,如果可能的话,我们更喜欢安全访问我们的数据.
我正在开发一个使用蓝牙连接到不同设备的 UWP 应用程序。
我的问题是,一些已配对或先前发现的设备显示在我的设备列表中,即使它们已关闭或不在范围内。
据我了解,属性System.Devices.Aep.IsPresent可用于过滤掉当时不可用的缓存设备,但即使我知道该设备无法访问,我也始终为该属性获取“True”。
关于如何解决这个问题的任何想法?
string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.IsPresent", "System.Devices.Aep.ContainerId", "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.Manufacturer", "System.Devices.Aep.ModelId", "System.Devices.Aep.ProtocolId", "System.Devices.Aep.SignalStrength"};
_deviceWatcher = DeviceInformation.CreateWatcher("{REMOVED, NOT IMPORTANT}", requestedProperties, DeviceInformationKind.AssociationEndpoint);
_deviceWatcher.Added += DeviceAdded;
_deviceWatcher.Updated += DeviceUpdated;
_deviceWatcher.Removed += DeviceRemoved;
_deviceWatcher.EnumerationCompleted += DeviceEnumerationCompleted;
Run Code Online (Sandbox Code Playgroud)
这里 isPresent 永远是真的
private void DeviceAdded(DeviceWatcher sender, DeviceInformation deviceInfo)
{
Device device = new Device(deviceInfo);
bool isPresent = (bool)deviceInfo.Properties.Single(p => p.Key == "System.Devices.Aep.IsPresent").Value;
Debug.WriteLine("*** Found device " + deviceInfo.Id + " / " + device.Id + ", " …Run Code Online (Sandbox Code Playgroud) 电子标志process.defaultApp和之间有什么区别app.isPackaged?两者都用于区分开发环境和生产环境。我的观察总是如此Boolean(process.defaultApp) == !app.isPackaged。是否存在两者都是true或两者都是的情况false?
来自文档和代码:
一个布尔值。当应用程序通过作为参数传递给默认应用程序来启动时,此属性在主进程中为 true,否则未定义。
一个布尔属性,如果应用程序已打包,则返回 true,否则返回 false。对于许多应用程序来说,此属性可用于区分开发和生产环境。
从代码中-当 exec 文件不是或app.isPackaged时设置。electronelectron.exe
注意:我知道一个细微的区别是process.defaultApp只能在主进程中使用。