private void CreateCommands() { if (!IsInDesignModeStatic) { CommandNames.Each(name => Set(new DelegateCommand <object>(x => ExecuteCommand(name, x), x => CanExecuteCommand(name, x)), name)); } }
/// <summary> /// Resolve <see cref="CommandNames" /> to their database-specific command text. /// </summary> /// <param name="commandName"> /// A <see cref="CommandNames" /> indicating which command needs to be resolved. /// </param> public string ResolveCommandName(CommandNames commandName) { switch (commandName) { case CommandNames.InsertCompletedScope: return("WORKFLOW_PKG.InsertCompletedScope"); case CommandNames.InsertInstanceState: return("WORKFLOW_PKG.InsertInstanceState"); case CommandNames.RetrieveCompletedScope: return("WORKFLOW_PKG.RetrieveCompletedScope"); case CommandNames.RetrieveInstanceState: return("WORKFLOW_PKG.RetrieveInstanceState"); case CommandNames.RetrieveExpiredTimerIds: return("WORKFLOW_PKG.RetrieveExpiredTimerIds"); case CommandNames.RetrieveNonBlockingInstanceIds: return("WORKFLOW_PKG.RetrieveNonBlockingInstanceIds"); case CommandNames.UnlockInstanceState: return("WORKFLOW_PKG.UnlockInstanceState"); } throw new NotSupportedException("Specified CommandNames is not currently supported."); }
public void Clear() { _headerPartFromPreviousChunk = new byte[0]; _currentCommand = null; _currentCommandExpectedLength = 0; _currentCommandName = CommandNames.Unknown; }
public CommandAttribute(string category, string description, string example, /*CommandPermissionLevel permissionLevel,*/ params string[] commands) : this() { Category = category; Description = description; Example = example; //PermissionLevel = permissionLevel; CommandNames.AddRange(commands); }
public byte[] ToBytes(CommandNames name, byte[] data) { var result = new List<byte>(data.Length + LengthBytesCount + NameBytesCount); //just an optimization result.AddRange(CommandNameToBytes(name)); result.AddRange(BitConverter.GetBytes(data.Length)); result.AddRange(data); return result.ToArray(); }
public string GetHeader() { // ReSharper disable once UseStringInterpolation return(string.Format("{0}: {1} (0x{2}) Channel: {3} Length: {4} Time: {5} Number: {6}", Stream.Direction, CommandNames.Get(Header.Opcode, Header.Channel, Stream.Direction), Header.Opcode.ToString("X2"), Header.Channel, Stream.Length, Stream.Time.ToString("MM/dd/yyyy HH:mm:ss.fff"), Stream.Number)); }
public byte[] ToBytes(CommandNames name, byte[] data) { var result = new List <byte>(data.Length + LengthBytesCount + NameBytesCount); //just an optimization result.AddRange(CommandNameToBytes(name)); result.AddRange(BitConverter.GetBytes(data.Length)); result.AddRange(data); return(result.ToArray()); }
/// <summary> /// Resolve <see cref="ParameterNames" /> to their database-specific parameter name. /// </summary> /// <param name="commandName"> /// A <see cref="CommandNames" /> indicating which command the parameter /// name needs to be resolved for. /// </param> /// <param name="parameterName"> /// A <see cref="ParameterNames" /> indicating which parameter needs to be resolved. /// </param> public string ResolveParameterName(CommandNames commandName, ParameterNames parameterName) { switch (parameterName) { case ParameterNames.InstanceId: if (commandName == CommandNames.InsertCompletedScope) { return("InstanceID"); } else { return("uidInstanceID"); } case ParameterNames.ScopeId: return("completedScopeID"); case ParameterNames.State: return("state"); case ParameterNames.Status: return("status"); case ParameterNames.Unlock: return("unlocked"); case ParameterNames.IsBlocked: return("blocked"); case ParameterNames.Info: return("info"); case ParameterNames.CurrentOwnerId: return("currentOwnerID"); case ParameterNames.OwnerId: return("ownerID"); case ParameterNames.OwnedUntil: return("ownedUntil"); case ParameterNames.NextTimer: return("nextTimer"); case ParameterNames.Result: return("result"); case ParameterNames.Now: return("now"); case ParameterNames.WorkflowIds: return("workflowIds"); } throw new NotSupportedException("Specified CommandNames / ParameterNames combination is not currently supported."); }
/// <summary> /// Отправить устройству запрос /// </summary> /// <param name="ip"></param> /// <param name="commandName"></param> /// <param name="content"></param> /// <returns></returns> internal async Task <OperationResult> SendToDevice(IPAddress ip, CommandNames commandName, IEnumerable <ICommandParameter> content = null) { return(await Task.Run(async() => { OperationResult resilt = new OperationResult(); string strContent = $"&{commandName}&"; if (content != null) { foreach (var param in content) { strContent += $"{param.Name}={param.Value}&"; } } Uri uri = new Uri($"http://{ip}/{strContent}"); while (true) { using (HttpClient httpClient = new HttpClient()) { try { using (HttpResponseMessage responseMessage = await httpClient.GetAsync(uri)) { if (responseMessage.ReasonPhrase == "OK") { string response = await responseMessage.Content.ReadAsStringAsync(); resilt.Success = true; resilt.ResponseMessage = response.Replace("\r\n", string.Empty); System.Diagnostics.Debug.WriteLine("Post success!"); break; } else { resilt.ErrorMessage = "Post failed!"; System.Diagnostics.Debug.WriteLine("Post failed!"); } } } catch (Exception ex) { resilt.ErrorMessage = ex.Message; resilt.Success = false; break; } //responseMessage.EnsureSuccessStatusCode(); }; } return resilt; })); }
public override Task <bool> HandlesAsync(CommandContext session, string input) { /*if (RequiresSession && session.Session == null) * return false;*/ ParseCommand(input, out string command, out string[] parameters); return(Task.FromResult(CommandNames.Any(i => string.Equals(command, i, StringComparison.OrdinalIgnoreCase)) && (parameters.Length != 0 && IsHelpRequest(parameters[0]) || RequiresSession && session.Session != null || !RequiresSession))); }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns> /// A hash code for the current <see cref="T:System.Object"/>. /// </returns> /// <filterpriority>2</filterpriority> public override Int32 GetHashCode() { unchecked { var hashCode = Name?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ (Arguments?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (CommandNames?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); return(hashCode); } }
/// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns> /// A 32-bit signed integer that is the hash code for this instance. /// </returns> public override Int32 GetHashCode() { unchecked { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (CommandNames != null ? CommandNames.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Arguments != null ? Arguments.GetHashCode() : 0); return(hashCode); } }
private IEnumerable<byte> CommandNameToBytes(CommandNames name) { var bytes = new List<byte>(BitConverter.GetBytes((int) name)); if (bytes.Count > NameBytesCount) throw new InvalidOperationException(); while (bytes.Count < NameBytesCount) { bytes.Insert(0, 0); } return bytes; }
private bool CommandNamesEqual(ToolCommandName[] otherCommandNames) { if (CommandNames == null) { return(otherCommandNames == null); } if (otherCommandNames == null) { return(false); } return(CommandNames.SequenceEqual(otherCommandNames)); }
/// <summary> /// Resolve <see cref="ParameterNames" /> to their database-specific parameter name. /// </summary> /// <param name="commandName"> /// A <see cref="CommandNames" /> indicating which command the parameter /// name needs to be resolved for. /// </param> /// <param name="parameterName"> /// A <see cref="ParameterNames" /> indicating which parameter needs to be resolved. /// </param> /// <returns> /// </returns> public string ResolveParameterName(CommandNames commandName, ParameterNames parameterName) { switch (parameterName) { case ParameterNames.InstanceId: return("p_INSTANCE_ID"); case ParameterNames.ScopeId: return("p_COMPLETED_SCOPE_ID"); case ParameterNames.State: return("p_STATE"); case ParameterNames.Status: return("p_STATUS"); case ParameterNames.Unlock: return("p_UNLOCKED"); case ParameterNames.IsBlocked: return("p_BLOCKED"); case ParameterNames.Info: return("p_INFO"); case ParameterNames.CurrentOwnerId: return("p_CURRENT_OWNER_ID"); case ParameterNames.OwnerId: return("p_OWNER_ID"); case ParameterNames.OwnedUntil: return("p_OWNED_UNTIL"); case ParameterNames.NextTimer: return("p_NEXT_TIMER"); case ParameterNames.Result: return("p_RESULT"); case ParameterNames.Now: return("p_NOW"); case ParameterNames.WorkflowIds: return("p_WORKFLOW_IDS"); } throw new NotSupportedException("Specified CommandNames / ParameterNames combination is not currently supported."); }
private bool CommandNamesEqual(ToolCommandName[] otherCommandNames) { if (CommandNames == null && otherCommandNames == null) { return(true); } else if (otherCommandNames == null || CommandNames == null) { return(false); } else { return(CommandNames.SequenceEqual(otherCommandNames)); } }
private IEnumerable <byte> CommandNameToBytes(CommandNames name) { var bytes = new List <byte>(BitConverter.GetBytes((int)name)); if (bytes.Count > NameBytesCount) { throw new InvalidOperationException(); } while (bytes.Count < NameBytesCount) { bytes.Insert(0, 0); } return(bytes); }
public static BaseBotCommand ParseCommand(Update update) { BaseBotCommand command; var args = string.Empty; var tokens = Regex.Split(update.Message.Text.Trim(), @"\s"); var minCommandLength = CommandNames.Select(commandName => commandName.Length).Min(); if (!tokens.Any() || tokens[0].Length < minCommandLength) { return(null); } var commandText = tokens[0].Substring(1); if (commandText.IndexOf('@') != -1) { commandText = commandText.Substring(0, commandText.IndexOf('@')); } if (tokens.Length > 1) { args = tokens.Skip(1).Aggregate((s1, s2) => $"{s1} {s2}"); } switch (commandText.ToLower()) { case "mybd": command = new MyBdCommand(update, args); break; case "bdz": command = new BdzCommand(update); break; default: command = null; break; } return(command); }
public StreamCommand(CommandNames commandName, int param1, string param2) { CommandName = commandName; Param1 = param1; Param2 = param2; }
private void CreateCommands() { CommandNames.Each(name => Set(name, new DelegateCommand <object>(x => ExecuteCommand(name, x), x => CanExecuteCommand(name, x)))); }
public bool ContaisCommandName(string commandName) { return(commandName != null && CommandNames.Contains(commandName.ToLower())); }
public StreamCommand(CommandNames commandName) : this(commandName, 0, "") { }
public StreamCommand(CommandNames commandName, string param) : this(commandName, 0, param) { }
public AllCommandProvider(WorldPersisterService persister, Internal.Model.World world, VoxelTypesFactory typesFactory, ItemTypesFactory itemTypesFactory, UserInputProcessingService userInputProcessingService, GenericDatastore genericDatastore) { this.typesFactory = typesFactory; this.itemTypesFactory = itemTypesFactory; this.genericDatastore = genericDatastore; addDummy(); addPersistence(persister, world); addCommand("clearinfestation", () => { world.ForEach((v, _) => { if (v.Type != typesFactory.Get <InfestationVoxelType>()) { return; } typesFactory.Get <InfestationVoxelType>().CureInfestation(v); }); return("Cleared all infestation!"); }); addCommand("helpall", () => { return("All Commands: " + string.Join(", ", CommandNames.ToArray())); }); addCommand("help", partialCommand => { return("Commands containing '" + partialCommand + "': " + string.Join(", ", CommandNames.Where(c => c.Contains(partialCommand)).ToArray())); }); addCommand("clearWorld", () => { genericDatastore.ClearAll(); world.ForEach((v, _) => { v.Data.Type = typesFactory.Get <LandType>(); }); return("World cleared!"); }); addCommand("listsaves", () => { var saves = TWDir.GameData.CreateChild("Saves\\GodGame").GetFiles().ToList(); var outputstring = String.Join(", ", saves.Select(e => e.Name.Substring(0, e.Name.Length - 4))); // Drop extension return("Saved games: \n" + outputstring); }); addCommand("addresource", (typeStr, amountStr) => { var itemType = itemTypesFactory.AllTypes.FirstOrDefault(t => t.Name.ToLower() == typeStr.ToLower()); if (itemType == null) { return("Item type not found: " + typeStr); } var amount = 0; if (!int.TryParse(amountStr, out amount)) { return("Invalid item amount: " + amountStr); } var target = userInputProcessingService.GetTargetedVoxel(); if (target == null || target.Type != typesFactory.Get <WarehouseType>()) { return("Not targeting a warehouse"); } target.Data.Inventory.AddNewItems(itemType, amount); return("Added items!"); }); }
public StreamCommand(CommandNames commandName, int param) : this(commandName, param, "") { }
public LocalizedStringsResource() { CommandNames = new CommandNames(); SubCommandNames = new SubCommandNames(); }
public StreamCommand(CommandNames commandName, object param1) { CommandName = commandName; ParamObject = param1; }
public void AppendBytes(byte[] bytes, int offset, int length) { lock (SyncObj) { byte[] bytesToCopy = (offset == 0 && bytes.Length == length) ? bytes : CutSubsequence(bytes, offset, length); if (_headerPartFromPreviousChunk.Length > 0) { bytesToCopy = ConcatSequences(_headerPartFromPreviousChunk, bytesToCopy); _headerPartFromPreviousChunk = new byte[0]; } if (_currentCommand == null) { if (bytesToCopy.Length < HeaderLength + 1) { _headerPartFromPreviousChunk = bytesToCopy; return; } var expLengthBytes = CutSubsequence(bytesToCopy, CommandParser.NameBytesCount, CommandParser.LengthBytesCount); var expLengthInt = BitConverter.ToInt32(CutSubsequence(expLengthBytes, 0, CommandParser.LengthBytesCount), 0); var commandName = _commandParser.ParseCommandName(CutSubsequence(bytesToCopy, 0, CommandParser.NameBytesCount)); if (commandName == CommandNames.Unknown) { Clear(); //INVALID HEADER return; } if (expLengthInt > 0) { _currentCommandName = commandName; _currentCommandExpectedLength = expLengthInt; if (bytesToCopy.Length - HeaderLength >= _currentCommandExpectedLength) { CommandAssembled(new Command(commandName, CutSubsequence(bytesToCopy, HeaderLength, expLengthInt))); if (bytesToCopy.Length - HeaderLength - _currentCommandExpectedLength > 0) { int newoffset = HeaderLength + _currentCommandExpectedLength; AppendBytes(bytesToCopy, newoffset, bytesToCopy.Length - newoffset); return; } } else { _currentCommand = CutSubsequence(bytesToCopy, HeaderLength, -1); } } else { Clear(); //INVALID HEADER return; } } else { _currentCommand = ConcatSequences(_currentCommand, bytesToCopy); if (_currentCommand.Length >= _currentCommandExpectedLength) { var restData = CutSubsequence(_currentCommand, _currentCommandExpectedLength, -1); CommandAssembled(new Command(_currentCommandName, CutSubsequence(_currentCommand, 0, _currentCommandExpectedLength))); _currentCommand = null; _currentCommandExpectedLength = 0; _currentCommandName = CommandNames.Unknown; if (restData.Length > 0) { AppendBytes(restData, 0, restData.Length); return; } } } } }
private void CreateCommands() { CommandNames.ForEach(name => Set(name, new RelayedCommand <object>(x => ExecuteCommand(name, x), x => CanExecuteCommand(name, x)))); }
public static void processDroneCommand(string command, Drone drone, out bool shutDownReceived) { shutDownReceived = false; CommandNames commandName = CommandNames.Unassigned; string firstLetter = command.Substring(0, 1); if (firstLetter == "S") { commandName = CommandNames.Start; } if (firstLetter == "B") { commandName = CommandNames.Boundary; } if (firstLetter == "P") { commandName = CommandNames.InitiaPosition; } if (firstLetter == "R") { commandName = CommandNames.Restart; } if (firstLetter == "D") { commandName = CommandNames.Shutdown; } if (firstLetter == "T") { commandName = CommandNames.ToggleLights; } if (firstLetter == "F") { commandName = CommandNames.FlashLights; } if (firstLetter == "A") { commandName = CommandNames.Alert; } if (firstLetter == "H") { commandName = CommandNames.Home; } if (firstLetter == "M") { commandName = CommandNames.Move; } if (commandName == CommandNames.Start) { drone.started = true; Console.WriteLine("Drone is started"); } else if (commandName == CommandNames.Boundary) { drone.xBoundary = Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[0]); drone.yBoundary = Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[1]); Console.WriteLine("Boundary set to X = " + drone.xBoundary + " and Y = " + drone.yBoundary); } else if (commandName == CommandNames.InitiaPosition) { drone.xInitialCoordinates = drone.xCoordinates = Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[0]); drone.yInitialCoordinates = drone.yCoordinates = Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[1]); Console.WriteLine("Initial Position set to X = " + drone.xInitialCoordinates + " and Y = " + drone.yInitialCoordinates); } else if (commandName == CommandNames.ToggleLights) { if (FlyingActions.checkStarted(drone)) { drone.toggleLights(); } } else if (commandName == CommandNames.FlashLights) { if (FlyingActions.checkStarted(drone)) { drone.flashLights(); } } else if (commandName == CommandNames.Alert) { if (FlyingActions.checkStarted(drone)) { drone.soundHorn(Convert.ToDouble(command.Substring(1, command.Length - 1))); } } else if (commandName == CommandNames.Home) { if (FlyingActions.checkStarted(drone)) { FlyingActions.flyHome(drone); } } else if (commandName == CommandNames.Move) { if (FlyingActions.checkStarted(drone)) { bool reachedBoundary; FlyingActions.fly(drone, Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[1]), Convert.ToDouble(command.Substring(1, command.Length - 1).Split(',')[0]), out reachedBoundary); if (reachedBoundary) { drone.soundHorn(0.5); drone.soundHorn(0.5); drone.soundHorn(0.5); } } } else if (commandName == CommandNames.Restart) { drone.restart(); } else if (commandName == CommandNames.Shutdown) { shutDownReceived = true; } }
public Command(CommandNames name, byte[] data) { Name = name; Data = data; }