public ParameterList GetParameters(string CommandName) { ParameterList pList = new ParameterList(); CommandInteraction ci = new CommandInteraction(); try { List <string> requierdInputs = ci.getRequiredInputs(CommandName); foreach (string i in requierdInputs) { Parameter p = new Parameter(); p.Name = i; pList.Add(p); } TeamInfo teamInfo = TeamInfoAccess.getTeam(0); using (PSDataAccess psDataAccess = new PSDataAccess(teamInfo.domain, teamInfo.product)) { string psFieldNames = string.Empty; foreach (Parameter p in pList) { p.Name = p.Name.Replace("__", " "); if (psFieldNames == string.Empty) { psFieldNames = p.Name;//"__" is for the white space issue } else { psFieldNames = string.Format("{0};{1}", psFieldNames, p.Name); } } List <PSFieldDefinition> fieldDefinitions = psDataAccess.LoadingPSFields(psFieldNames); foreach (Parameter p in pList) { if (p.Name.Equals("AssignedTo")) { p.Values.AddRange(new string[] { "t-limliu", "yuanzhua", "zachary", "zichsun" }); } foreach (PSFieldDefinition definition in fieldDefinitions) { if (p.Name.Equals(definition.Name)) { List <object> values = definition.GetAllowedValues(); foreach (object v in values) { p.Values.Add(v.ToString()); } break; } } } } } catch (Exception e) { throw new WebFaultException <string>(e.ToString(), HttpStatusCode.InternalServerError); } return(pList); }
public CommandInfo doCommand(CommandInfo CommandInfo) { CommandInteraction cmdInteraction = new CommandInteraction(); Dictionary <string, string> paras = new Dictionary <string, string>(); foreach (Parameter p in CommandInfo.ParameterList) { paras.Add(p.Name, p.Value); } cmdInteraction.executeCommand(CommandInfo.CommandName, paras); TrackingWorkFlowInteraction twfi = new TrackingWorkFlowInteraction(); twfi.doCommand(CommandInfo); return(CommandInfo); }
public CommandInfo doCommand(CommandInfo CommandInfo) { CommandInfo.CommandName = CommandInfo.CommandName.Trim(); try { CommandInteraction cmdInteraction = new CommandInteraction(); Dictionary <string, string> paras = new Dictionary <string, string>(); paras.Add("InstanceId", CommandInfo.InstanceId); paras.Add("WFName", CommandInfo.WFName); if (CommandInfo.ParameterList != null) { foreach (Parameter p in CommandInfo.ParameterList) { paras.Add(p.Name, p.Value); } } TrackingDataContext tdc = new TrackingDataContext(); Guid guid = new Guid(CommandInfo.InstanceId); IQueryable <CommonResource.Tracking> trackingQuery = from tracking in tdc.Trackings where ((tracking.wfinstanceid == guid)) select tracking; foreach (CommonResource.Tracking t in trackingQuery) { t.lastmodifiedby = AuthenticationHelper.GetCurrentUser(); } //CommonResource.Tracking t = new CommonResource.Tracking(); //t.wfname = this.WFName; //t.bugid = bugId; //t.wfinstanceid = new Guid(this.InstanceId); //tdc.Trackings.InsertOnSubmit(t); tdc.SubmitChanges(); cmdInteraction.executeCommand(CommandInfo.CommandName, paras); //this is do the real action in extension TrackingWorkFlowInteraction twfi = new TrackingWorkFlowInteraction(); twfi.doCommand(CommandInfo); // this is just trigger the state machine(WF) to do one step } catch (Exception e) { throw new WebFaultException <string>(e.ToString(), HttpStatusCode.InternalServerError); } return(CommandInfo); }
public ParameterList GetParameters(string CommandName) { ParameterList pList = new ParameterList(); CommandInteraction ci = new CommandInteraction(); try { List <string> requierdInputs = ci.getRequiredInputs(CommandName); foreach (string i in requierdInputs) { Parameter p = new Parameter(); p.Name = i; pList.Add(p); } } catch (Exception e) { throw new HttpException((int)HttpStatusCode.InternalServerError, e.Message); } return(pList); }
public WorkFlowInstance startWorkFlow(CommandInfo CommandInfo) { WorkFlowInstance wfi = new WorkFlowInstance(); try { string WFName = CommandInfo.WFName.Trim(); TrackingWorkFlowInteraction twfi = new TrackingWorkFlowInteraction(); string id = twfi.startProcess(WFName); CommandInteraction cmdInteraction = new CommandInteraction(); Dictionary <string, string> paras = new Dictionary <string, string>(); paras.Add("InstanceId", id); paras.Add("WFName", CommandInfo.WFName); if (CommandInfo.ParameterList != null) { foreach (Parameter p in CommandInfo.ParameterList) { paras.Add(p.Name, p.Value); } } TrackingWorkFlowInteraction II = new TrackingWorkFlowInteraction(); StateMachineDefinition statemachineDefinition = II.getStateMachineDefinition(CommandInfo.WFName); paras.Add("QFEStatus", statemachineDefinition.InitialState); cmdInteraction.executeCommand(CommandInfo.CommandName, paras); wfi.Id = id; List <string> candCmds = twfi.getCandidateCommands(WFName, id); CandidateCommandList ccl = new CandidateCommandList(); ccl.AddRange(candCmds); wfi.CandidateCommandList = ccl; } catch (Exception e) { throw new WebFaultException <string>(e.ToString(), HttpStatusCode.InternalServerError); // TrackingLog.Log(e.Message + "!!" + e.ToString()); } return(wfi); }
private bool TryExecuteSubCommand(string commandNameLC, CommandArgs args) { switch (commandNameLC) { case "commands": case "cmds": args.Player.SendMessage("Available Sub-Commands:", Color.White); args.Player.SendMessage("/ac blocks", Color.Yellow); args.Player.SendMessage("/ac toggle|switch", Color.Yellow); if (args.Player.Group.HasPermission(AdvancedCircuitsPlugin.ReloadCfg_Permission)) { args.Player.SendMessage("/ac reloadcfg", Color.Yellow); } return(true); case "reloadcfg": if (args.Player.Group.HasPermission(AdvancedCircuitsPlugin.ReloadCfg_Permission)) { this.PluginTrace.WriteLineInfo("Reloading configuration file."); try { this.ReloadConfigurationCallback(); this.PluginTrace.WriteLineInfo("Configuration file successfully reloaded."); if (args.Player != TSPlayer.Server) { args.Player.SendMessage("Configuration file successfully reloaded.", Color.Yellow); } } catch (Exception ex) { this.PluginTrace.WriteLineError( "Reloading the configuration file failed. Keeping old configuration. Exception details:\n{0}", ex ); } } else { args.Player.SendErrorMessage("You do not have the necessary permission to do that."); } return(true); case "blocks": case "ores": case "tiles": int pageNumber; if (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out pageNumber)) { return(true); } PaginationTools.SendPage( args.Player, pageNumber, new List <string>() { "Copper Ore - OR-Gate", "Silver Ore - AND-Gate", "Gold Ore - XOR-Gate / XOR-Port", "Obsidian - NOT-Gate / NOT-Port", "Iron Ore - Swapper", "Spike - Crossover Bridge", "Glass - Input Port", "Active Stone - Active Stone and Block Activator", "Adamantite Ore - Wireless Transmitter" }, new PaginationTools.Settings { HeaderFormat = "Advanced Circuits Special Blocks (Page {0} of {1})", HeaderTextColor = Color.Lime, LineTextColor = Color.LightGray, MaxLinesPerPage = 4, } ); return(true); case "toggle": case "switch": args.Player.SendInfoMessage("Place or destroy a wire on the component you want to toggle."); if (args.Parameters.Count > 3) { args.Player.SendErrorMessage("Proper syntax: /ac switch [state] [+p]"); args.Player.SendInfoMessage("Type /ac switch help to get more help to this command."); return(true); } bool persistentMode = false; bool?newState = null; if (args.Parameters.Count > 1) { int newStateRaw; if (int.TryParse(args.Parameters[1], out newStateRaw)) { newState = (newStateRaw == 1); } persistentMode = args.ContainsParameter("+p", StringComparison.InvariantCultureIgnoreCase); } CommandInteraction interaction = this.StartOrResetCommandInteraction(args.Player); interaction.DoesNeverComplete = persistentMode; interaction.TileEditCallback = (player, editType, blockType, location, blockStyle) => { if ( editType != TileEditType.PlaceTile || editType != TileEditType.PlaceWall || editType != TileEditType.DestroyWall || editType != TileEditType.PlaceActuator ) { CommandInteractionResult result = new CommandInteractionResult { IsHandled = true, IsInteractionCompleted = true }; ITile tile = TerrariaUtils.Tiles[location]; if ( !args.Player.HasBuildPermission(location.X, location.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, location, false) )) { player.SendErrorMessage("This object is protected."); player.SendTileSquare(location, 1); return(result); } int hitBlockType = tile.type; if (tile.active() && hitBlockType == TileID.ActiveStoneBlock) { if (newState == null || newState == false) { TerrariaUtils.Tiles.SetBlock(location, TileID.InactiveStoneBlock); } else { args.Player.SendTileSquare(location); } } else if (hitBlockType == TileID.InactiveStoneBlock) { if (tile.active() && newState == null || newState == true) { TerrariaUtils.Tiles.SetBlock(location, TileID.ActiveStoneBlock); } else { args.Player.SendTileSquare(location); } } else if (tile.active() && TerrariaUtils.Tiles.IsMultistateObject(hitBlockType)) { ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location); bool currentState = TerrariaUtils.Tiles.ObjectHasActiveState(measureData); if (newState == null) { newState = !TerrariaUtils.Tiles.ObjectHasActiveState(measureData); } if (currentState != newState.Value) { TerrariaUtils.Tiles.SetObjectState(measureData, newState.Value); } else { args.Player.SendTileSquare(location); } } else if ( hitBlockType == AdvancedCircuits.BlockType_ORGate || hitBlockType == AdvancedCircuits.BlockType_ANDGate || hitBlockType == AdvancedCircuits.BlockType_XORGate ) { if ( !args.Player.HasBuildPermission(location.X, location.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, location, false) )) { player.SendErrorMessage("This gate is protected."); player.SendTileSquare(location); return(result); } PaintColor paint = (PaintColor)TerrariaUtils.Tiles[location].color(); if (paint == AdvancedCircuits.Paint_Gate_TemporaryState) { player.SendErrorMessage("The gate is painted {0}, there's no point in initializing it.", AdvancedCircuits.Paint_Gate_TemporaryState); args.Player.SendTileSquare(location); return(result); } GateStateMetadata gateState; if (!this.WorldMetadata.GateStates.TryGetValue(location, out gateState)) { gateState = new GateStateMetadata(); this.WorldMetadata.GateStates.Add(location, gateState); } List <DPoint> gatePortLocations = new List <DPoint>(AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1))); for (int i = 0; i < 4; i++) { ITile gatePort = TerrariaUtils.Tiles[gatePortLocations[i]]; if (!gatePort.active() || gatePort.type != (int)AdvancedCircuits.BlockType_InputPort) { continue; } if (newState == null) { if (gateState.PortStates[i] == null) { gateState.PortStates[i] = true; } else { gateState.PortStates[i] = !gateState.PortStates[i]; } } else { gateState.PortStates[i] = newState.Value; } } player.SendSuccessMessage("The states of this gate's ports are now:"); this.SendGatePortStatesInfo(args.Player, gateState); args.Player.SendTileSquare(location); } else if (tile.active() && tile.type == (int)AdvancedCircuits.BlockType_InputPort) { foreach (DPoint adjacentTileLocation in AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1))) { ITile adjacentTile = TerrariaUtils.Tiles[adjacentTileLocation]; if (!adjacentTile.active() || !AdvancedCircuits.IsLogicalGate(adjacentTile.type)) { continue; } if ( !args.Player.HasBuildPermission(adjacentTileLocation.X, adjacentTileLocation.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, adjacentTileLocation, false) )) { player.SendErrorMessage("This gate is protected."); player.SendTileSquare(location); return(result); } PaintColor paint = (PaintColor)TerrariaUtils.Tiles[location].color(); if (paint == AdvancedCircuits.Paint_Gate_TemporaryState) { player.SendErrorMessage("The gate is painted {0}, there's no point in initializing it.", AdvancedCircuits.Paint_Gate_TemporaryState); args.Player.SendTileSquare(location); return(result); } GateStateMetadata gateState; if (!this.WorldMetadata.GateStates.TryGetValue(adjacentTileLocation, out gateState)) { gateState = new GateStateMetadata(); this.WorldMetadata.GateStates.Add(adjacentTileLocation, gateState); } int portIndex; switch (AdvancedCircuits.DirectionFromTileLocations(adjacentTileLocation, location)) { case Direction.Up: portIndex = 0; break; case Direction.Down: portIndex = 1; break; case Direction.Left: portIndex = 2; break; case Direction.Right: portIndex = 3; break; default: return(result); } if (newState == null) { if (gateState.PortStates[portIndex] == null) { gateState.PortStates[portIndex] = true; } else { gateState.PortStates[portIndex] = !gateState.PortStates[portIndex]; } } else { gateState.PortStates[portIndex] = newState.Value; } player.SendSuccessMessage("The states of this gate's ports are now:"); this.SendGatePortStatesInfo(args.Player, gateState); args.Player.SendTileSquare(location); return(result); } player.SendErrorMessage($"The state of \"{TerrariaUtils.Tiles.GetBlockTypeName(hitBlockType, 0)}\" can not be changed."); player.SendTileSquare(location); } return(result); } return(new CommandInteractionResult { IsHandled = false, IsInteractionCompleted = false }); }; interaction.TimeExpiredCallback = (player) => { player.SendErrorMessage("Waited too long, no component will be toggled."); }; args.Player.SendSuccessMessage("Hit an object to change its state."); return(true); } return(false); }