public static bool delete(int id, KeyTarget target) { bool check = false; string cstr = ConfigurationManager.ConnectionStrings["Db"].ConnectionString; using (var connection = new SqlConnection(cstr)) using (var command = connection.CreateCommand()) { try { connection.Open(); if (target == KeyTarget.roomId) { command.CommandText = "DELETE FROM Section WHERE roomId = @id"; command.Parameters.Add(new SqlParameter("@id", id)); } else if (target == KeyTarget.studentId) { command.CommandText = "DELETE FROM Section WHERE studentId = @id"; command.Parameters.Add(new SqlParameter("@id", id)); } else { return(false); } check = command.ExecuteNonQuery() != 0; connection.Close(); } catch (SqlException) { } } return(check); }
public void SetKey(string uniqueKeyName, KeyCode keyCode, KeyTarget keyTarget = KeyTarget.PositivePrimary) { int i = GetUniqueIndex(uniqueKeyName); inputs[i].Type = KeyType.KeyPress; switch (keyTarget) { case KeyTarget.PositivePrimary: inputs[i].Positive.Primary = keyCode; break; case KeyTarget.PositiveSecondary: inputs[i].Positive.Secondary = keyCode; break; case KeyTarget.NegativePrimary: inputs[i].Negative.Primary = keyCode; break; case KeyTarget.NegativeSecondary: inputs[i].Negative.Secondary = keyCode; break; } hUtility.SaveBinings(inputs); }
internal void DeleteKey(Type addin, IEnumerable <object> addinAttributes, KeyTarget keyTarget) { Dictionary <object, Type> attributeTypes = GetAttributeTypes(addinAttributes); KeyValuePair <object, Type> progId = GetAttribute <ProgIdAttribute>(attributeTypes); KeyValuePair <object, Type> guid = GetAttribute <GuidAttribute>(attributeTypes); KeyValuePair <object, Type> comAddin = GetAttribute(attributeTypes, _attributeName); if (comAddin.Value == null) { return; } KeyValuePair <object, Type> reg = GetAttribute(attributeTypes, _regLocationAttributeName); KeyValuePair <object, Type> multi = GetAttribute(attributeTypes, _multiRegisterName); bool isMultiAddin = IsMultiAddin(addin); if (isMultiAddin && multi.Key == null) { return; } string progIdValue = (progId.Key as ProgIdAttribute).Value; int regLocation = 0; if (null != reg.Key) { regLocation = (int)reg.Value.InvokeMember("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField, null, reg.Key, new string[0]); } if (regLocation < 0 || regLocation > 2) { throw new ArgumentException("regLocation"); } if (1 == regLocation) { keyTarget = KeyTarget.User; } else if (2 == regLocation) { keyTarget = KeyTarget.System; } if (isMultiAddin) { IEnumerable products = multi.Value.InvokeMember("Products", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField, null, multi.Key, new string[0]) as IEnumerable; if (null != products) { foreach (object item in products) { int productIndex = Convert.ToInt32(item); DeleteOfficeRegistryKey(_multiRegisterIn[productIndex], progIdValue, keyTarget); } } } else { string key = GetKeyName(addin); DeleteOfficeRegistryKey(key, progIdValue, keyTarget); } }
public KeyCode DefailsFromKey(string uniqueKeyCode, KeyTarget keyTarget) { int i = GetUniqueIndex(uniqueKeyCode); switch (keyTarget) { default: return(inputs[i].Positive.Primary); case KeyTarget.PositiveSecondary: return(inputs[i].Positive.Secondary); case KeyTarget.NegativePrimary: return(inputs[i].Negative.Primary); case KeyTarget.NegativeSecondary: return(inputs[i].Negative.Secondary); } }
/// <summary> /// Lists the known keys. /// </summary> /// <param name="target">The target.</param> /// <returns></returns> public IEnumerable<KeyId> ListKeys(KeyTarget target) { var args = "--fixed-list-mode --with-colons --with-fingerprint --list-public-keys"; var keyHead = "pub"; if (target == KeyTarget.Secret) { args = "--fixed-list-mode --with-colons --with-fingerprint --list-secret-keys"; keyHead = "sec"; } if (!string.IsNullOrWhiteSpace(KeyringFolder)) { args += string.Format(" --homedir \"{0}\" ", KeyringFolder); } using (var proc = new RedirectedProcess(GnuPGConfig.GnuPGExePath, args)) { if (proc.Start()) { proc.WaitForExit(); string[] lines = proc.Output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { var fields = lines[i].Split(':'); if (fields[0] == keyHead) { var id = fields[4]; var allowCap = KeyCapabilities.None; var useCap = KeyCapabilities.None; ParseKeyCapField(fields[11], ref allowCap, ref useCap); i++; // read more lines as part of this key string finger = null; List<string> users = new List<string>(); for (; i < lines.Length; i++) { fields = lines[i].Split(':'); if (fields[0] == keyHead) { // another key, exit loop i--; break; } switch (fields[0]) { case "uid": users.Add(IOUtility.DecodeAsciiEscapes(fields[9])); break; case "fpr": finger = fields[9]; break; } } yield return new KeyId(id, finger, allowCap, useCap, users); } } } } }
public static KeyCode DetailsFromKey(string uniqueKeyName, KeyTarget keyTarget) { return(hManager.Active().DefailsFromKey(uniqueKeyName, keyTarget)); }
public static void SetKey(string uniqueKeyName, KeyCode keyCode, KeyTarget keyTarget = KeyTarget.PositivePrimary) { hManager.Active().SetKey(uniqueKeyName, keyCode, keyTarget); }
/// <summary> /// Lists the known keys. /// </summary> /// <param name="target">The target.</param> /// <returns></returns> public IEnumerable <KeyId> ListKeys(KeyTarget target) { var args = "--fixed-list-mode --with-colons --with-fingerprint --list-public-keys"; var keyHead = "pub"; if (target == KeyTarget.Secret) { args = "--fixed-list-mode --with-colons --with-fingerprint --list-secret-keys"; keyHead = "sec"; } if (!string.IsNullOrWhiteSpace(KeyringFolder)) { args += string.Format(" --homedir \"{0}\" ", KeyringFolder); } using (var proc = new RedirectedProcess(GnuPGConfig.GnuPGExePath, args)) { if (proc.Start()) { proc.WaitForExit(); string[] lines = proc.Output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { var fields = lines[i].Split(':'); if (fields[0] == keyHead) { var id = fields[4]; var allowCap = KeyCapabilities.None; var useCap = KeyCapabilities.None; ParseKeyCapField(fields[11], ref allowCap, ref useCap); i++; // read more lines as part of this key string finger = null; List <string> users = new List <string>(); for (; i < lines.Length; i++) { fields = lines[i].Split(':'); if (fields[0] == keyHead) { // another key, exit loop i--; break; } switch (fields[0]) { case "uid": users.Add(IOUtility.DecodeAsciiEscapes(fields[9])); break; case "fpr": finger = fields[9]; break; } } yield return(new KeyId(id, finger, allowCap, useCap, users)); } } } } }
private void DeleteOfficeRegistryKey(string officeKeyName, string addinProgId, KeyTarget target) { RegistryKey[] rootKey = null; switch (target) { case KeyTarget.System: rootKey = new RegistryKey[] { RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default) }; break; case KeyTarget.User: rootKey = new RegistryKey[] { RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default) }; break; case KeyTarget.Both: rootKey = new RegistryKey[] { RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default), RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default) }; break; default: throw new IndexOutOfRangeException("target"); } foreach (var item in rootKey) { string targetKey = String.Format(_officeRelatedKey + "\\{1}", officeKeyName, addinProgId); try { item.DeleteSubKeyTree(targetKey, false); item.Close(); } catch (System.Security.SecurityException) { ; } catch (System.UnauthorizedAccessException) { ; } catch (Exception) { throw; } } }