private void NotifyCommandShortcutsChanged(IGlobalCommand command) { if (!LoadingScope.IsInScope) { EventAggregator.GetEvent <ShortcutChangedEvent>().Publish(new GlobalCommandShortcutChangedArgs(command)); } }
private void ProcessGlobalCommandInvalidators(IGlobalCommand command) { foreach (var metadata in command.Metadata.OfType <IAutoInvalidateMetadata>()) { metadata.AttachMetadataDefinition(EventAggregator, () => command.RaiseCanExecuteChanged()); } }
public bool HasShortcut(IGlobalCommand command) { command.AssertParameterNotNull(nameof(command)); if (!CommandManager.IsRegistered(command)) { throw new Exception("Error : Requesting shortcut information of an unknown command : The command is not registered in the command manager."); } return(command.Metadata.OfType <KeyShortcut>().Any()); }
public void ClearShortcut(IGlobalCommand command) { command.AssertParameterNotNull(nameof(command)); if (!CommandManager.IsRegistered(command)) { throw new Exception($"Error : Requesting shortcut cleanup on an unknown command : The command is not registered in the CommandManager."); } if (HasShortcut(command)) { var shortcut = GetShortcut(command); command.Metadata.Remove(shortcut); NotifyCommandShortcutsChanged(command); } }
public static GlobalCommandShortcutInformation CreateFromGlobalCommand(IGlobalCommand command) { command.AssertParameterNotNull(nameof(command)); var guid = command.Metadata.OfType <CommandGuid>().Single().Guid; var hasShortcut = command.Metadata.OfType <KeyShortcut>().Any(); return(new GlobalCommandShortcutInformation() { CommandGuid = guid, HasShortcut = hasShortcut, IsDefault = true, ModifierKeys = hasShortcut ? command.Metadata.OfType <KeyShortcut>().Single().ModifierKeys : ModifierKeys.None, Key = hasShortcut ? command.Metadata.OfType <KeyShortcut>().Single().Key : Key.None }); }
public KeyShortcut GetShortcut(IGlobalCommand command) { command.AssertParameterNotNull(nameof(command)); if (!CommandManager.IsRegistered(command)) { throw new Exception("Error : Requesting shortcut information of an unknown command : The command is not registered in the command manager."); } try { return(command.Metadata.OfType <KeyShortcut>().Single()); } catch (InvalidOperationException) { throw new Exception("Error : The specified command doesn't have an associated shortcut."); } }
public static Tuple <IGlobalCommand, Commands.Attributes.Command> GetGlobalCommand(string commandName) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == module); if (assembly == null) { try { assembly = Assembly.Load(module); } catch { } } var exportedTypes = assembly.ExportedTypes .Where(t => t.IsClass && typeof(IGlobalCommand).IsAssignableFrom(t) && t.GetCustomAttributes(typeof(Commands.Attributes.Command)).Count() > 0).ToList(); IGlobalCommand command = null; Commands.Attributes.Command attribute = null; foreach (var type in exportedTypes) { var commandAttribute = type.GetCustomAttributes(typeof(Commands.Attributes.Command), true) .Cast <Commands.Attributes.Command>().FirstOrDefault(); if (commandAttribute.Name == commandName) { command = (IGlobalCommand)Activator.CreateInstance(type); attribute = commandAttribute; break; } } return(new Tuple <IGlobalCommand, Commands.Attributes.Command>(command, attribute)); }
public void MakeRequest(string commandName, string[] args, IGlobalCommand command, Commands.Attributes.Command attribute) { var template = attribute.Template; var body = command.Send(args); var targets = command.GetTargets(args); string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = Dns.GetHostByName(hostName).AddressList; string ip = ips[ips.Length - 1].ToString(); foreach (var target in targets) { var socket = client.StartSocket(target.Item1, target.Item2); if (!AsyncClient.CanConnect) { Console.WriteLine($"Cannot connect to {target.Item1}:{target.Item2}"); continue; } var data = new SocketDataBody() { CommandName = commandName, Body = body, Type = SocketDataType.Send, NodesPair = new Tuple <string, string>($"{ip}:{AsyncListener.Port}", $"{target.Item1.ToString()}:{target.Item2}") }; client.Send(socket, data); AsyncClient.sendDone.WaitOne(); client.Receive(socket); AsyncClient.receiveDone.WaitOne(); //client.StopSocket(socket); } }
public void SetShortcut(IGlobalCommand command, ModifierKeys modifierKeys, Key key) { command.AssertParameterNotNull(nameof(command)); if (!CommandManager.IsRegistered(command)) { throw new Exception("Error : Cannot set the shortcut for the specified command : The command is not registered in the command manager."); } if (!LoadingScope.IsInScope) { var matchingElements = GetElementsMatchingShortcut(modifierKeys, key).Where(o => !(o == command)); if (matchingElements.Any()) { throw new Exception($"Error setting the shortcut {modifierKeys.ToString()}+{key.ToString()} on command {GetElementName(command)} " + $"because element(s) {string.Join(",", matchingElements.Select(o => GetElementName(o)))} already have a shortcut with the same " + $"key combination."); } } if (HasShortcut(command)) { var shortcut = GetShortcut(command); if (shortcut.ModifierKeys == modifierKeys && shortcut.Key == key) { return; } shortcut.ModifierKeys = modifierKeys; shortcut.Key = key; } else { command.Metadata.Add(new KeyShortcut(modifierKeys, key)); } NotifyCommandShortcutsChanged(command); }
public GlobalCommandShortcutChangedArgs(IGlobalCommand command) { Command = command; }
public TMetadata GetMenuMetadata <TMetadata>(IGlobalCommand globalCommand) where TMetadata : IMainMenuMetadata { return(globalCommand.Metadata.OfType <MainMenuOption>().Single().OfType <TMetadata>().SingleOrDefault()); }
public bool Matches(IGlobalCommand command) { command.AssertParameterNotNull(nameof(command)); return(CommandGuid == command.Metadata.OfType <CommandGuid>().Single().Guid); }