public override void Use(Player p, string message) { if (!p.group.CanExecute("write")) { Player.Message(p, "You must be able to use /write to use /writetext."); return; } if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(3); if (args.Length < 3) { Help(p); return; } byte scale = 1, spacing = 1; if (!byte.TryParse(args[0], out scale)) { scale = 1; } if (!byte.TryParse(args[1], out spacing)) { spacing = 1; } WriteArgs wArgs = new WriteArgs(); wArgs.scale = scale; wArgs.spacing = spacing; wArgs.message = args[2].ToUpper(); Player.Message(p, "Place or break two blocks to determine direction."); p.MakeSelection(2, "Selecting direction for %SWrite", wArgs, DoWrite); }
public void Dispose() { Socket?.Close(); Coder?.Dispose(); _autoResetEvent.Close(); ReadArgs?.Dispose(); WriteArgs?.Dispose(); }
protected void AsyncWriteInvoker(object state) { WriteArgs args = state as WriteArgs; if (args != null) { WriteObject(args.Object, args.Stream); //args.Stream.Close(); } }
public void Clear() { Socket?.Close(); Unpacker?.Clear(); _autoResetEvent?.Close(); ReadArgs?.Dispose(); WriteArgs?.Dispose(); Socket = null; ReadArgs = null; WriteArgs = null; }
private void DebugStateFinalStep(WriteArgs writeArgs) { if (writeArgs.debugState.IsFinalStep()) { IDebugWriter writer; if ((writer = Get(writeArgs.debugState.WorkspaceID)) != null) { var allDebugStates = DebugMessageRepo.Instance.FetchDebugItems(writeArgs.debugState.ClientID, writeArgs.debugState.SessionID); foreach (var state in allDebugStates) { var serializeObject = JsonConvert.SerializeObject(state, SerializerSettings); writer.Write(serializeObject); } } } }
bool DoWrite(Player p, Vec3S32[] marks, object state, byte type, byte extType) { WriteArgs wArgs = (WriteArgs)state; if (marks[0].X == marks[1].X && marks[0].Z == marks[1].Z) { Player.Message(p, "No direction was selected"); return(false); } WriteDrawOp op = new WriteDrawOp(); op.Text = wArgs.message; op.Scale = wArgs.scale; op.Spacing = wArgs.spacing; Brush brush = new SolidBrush(type, extType); return(DrawOp.DoDrawOp(op, brush, p, marks)); }
bool DoWrite(Player p, Vec3S32[] marks, object state, ExtBlock block) { WriteArgs wArgs = (WriteArgs)state; if (marks[0].X == marks[1].X && marks[0].Z == marks[1].Z) { Player.Message(p, "No direction was selected"); return(false); } WriteDrawOp op = new WriteDrawOp(); op.Text = wArgs.message; op.Scale = wArgs.scale; op.Spacing = wArgs.spacing; Brush brush = new SolidBrush(block); DrawOpPerformer.Do(op, brush, p, marks); return(true); }
public void TryWriteDebug(IDSFDataObject dataObject, DebugState debugState) { if (dataObject.IsDebugMode() || dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer) { var debugDispatcher = _getDebugDispatcher(); if (debugState.StateType == StateType.End) { var writeEndArgs = new WriteArgs { debugState = debugState, isTestExecution = dataObject.IsServiceTestExecution, isDebugFromWeb = dataObject.IsDebugFromWeb, testName = dataObject.TestName, isRemoteInvoke = dataObject.RemoteInvoke, remoteInvokerId = dataObject.RemoteInvokerID, parentInstanceId = dataObject.ParentInstanceID, remoteDebugItems = dataObject.RemoteDebugItems }; debugDispatcher.Write(writeEndArgs); var dataObjectExecutionId = dataObject.ExecutionID.ToString(); try { WriteDebug(dataObject, dataObjectExecutionId); } catch (Exception) { Dev2Logger.Debug("Error getting execution result for :" + dataObject.ResourceID, dataObjectExecutionId); } } else { var writeArgs = new WriteArgs { debugState = debugState, isTestExecution = dataObject.IsServiceTestExecution, isDebugFromWeb = dataObject.IsDebugFromWeb, testName = dataObject.TestName }; debugDispatcher.Write(writeArgs); } } }
public void Write(WriteArgs writeArgs) { if (writeArgs.debugState == null) { return; } if (writeArgs.isTestExecution) { TestDebugMessageRepo.Instance.AddDebugItem(writeArgs.debugState.SourceResourceID, writeArgs.testName, writeArgs.debugState); return; } if (writeArgs.isDebugFromWeb) { WebDebugMessageRepo.Instance.AddDebugItem(writeArgs.debugState.ClientID, writeArgs.debugState.SessionID, writeArgs.debugState); return; } if (writeArgs.isRemoteInvoke) { RemoteDebugMessageRepo.Instance.AddDebugItem(writeArgs.remoteInvokerId, writeArgs.debugState); return; } if (writeArgs.remoteDebugItems != null) { SetRemoteDebugItems(writeArgs); } _dev2Logger.Debug($"EnvironmentID: {writeArgs.debugState.EnvironmentID} Debug:{writeArgs.debugState.DisplayName}", GlobalConstants.WarewolfDebug); if (writeArgs.debugState != null) { DebugMessageRepo.Instance.AddDebugItem(writeArgs.debugState.ClientID, writeArgs.debugState.SessionID, writeArgs.debugState); } DebugStateFinalStep(writeArgs); }
public void DebugDispatcher_Write_WhenRemoteInvoke_ExpectRemoteItemsAddedToRepo() { var debugDispatcher = new DebugDispatcherImplementation(); //------------Setup for test-------------------------- var workspaceID = Guid.NewGuid(); var writer = new Mock <IDebugWriter>(); writer.Setup(s => s.Write(It.IsAny <IDebugState>())).Verifiable(); debugDispatcher.Add(workspaceID, writer.Object); var state = new Mock <IDebugState>(); state.Setup(s => s.WorkspaceID).Returns(workspaceID); var remoteID = Guid.NewGuid(); var writeArgs = new WriteArgs { debugState = state.Object, isRemoteInvoke = true, remoteInvokerId = remoteID.ToString() }; //------------Execute Test--------------------------- debugDispatcher.Write(writeArgs); //------------Assert Results------------------------- // Write happens asynchronously on a separate thread Thread.Sleep(50); writer.Verify(s => s.Write(It.IsAny <IDebugState>()), Times.Exactly(0)); var items = RemoteDebugMessageRepo.Instance.FetchDebugItems(remoteID); Assert.AreEqual(1, items.Count); Assert.IsNotNull(items[0]); }
public void DebugDispatcher_Write() { var debugDispatcher = new DebugDispatcherImplementation(); var workspaceID = Guid.NewGuid(); var writer = new Mock <IDebugWriter>(); writer.Setup(s => s.Write(It.IsAny <IDebugState>())).Verifiable(); debugDispatcher.Add(workspaceID, writer.Object); var mockState = new Mock <IDebugState>(); var clientId = Guid.NewGuid(); var sessionId = Guid.NewGuid(); mockState.Setup(o => o.WorkspaceID).Returns(workspaceID); mockState.Setup(o => o.ClientID).Returns(clientId); mockState.Setup(o => o.SessionID).Returns(sessionId); mockState.Setup(o => o.IsFinalStep()).Returns(true); var expectedJson = JsonConvert.SerializeObject(mockState.Object, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple }); var writeArgs = new WriteArgs { debugState = mockState.Object }; debugDispatcher.Write(writeArgs); debugDispatcher.Write(writeArgs); debugDispatcher.Write(writeArgs); Thread.Sleep(50); writer.Verify(s => s.Write(expectedJson), Times.Exactly(3)); }
private static void SetRemoteDebugItems(WriteArgs writeArgs) { Guid.TryParse(writeArgs.parentInstanceId, out var parentId); foreach (var item in writeArgs.remoteDebugItems) { item.WorkspaceID = writeArgs.debugState.WorkspaceID; item.OriginatingResourceID = writeArgs.debugState.OriginatingResourceID; item.ClientID = writeArgs.debugState.ClientID; if (Guid.TryParse(writeArgs.remoteInvokerId, out var remoteEnvironmentId)) { item.EnvironmentID = remoteEnvironmentId; } if (item.ParentID == Guid.Empty) { item.ParentID = parentId; } if (item != null) { DebugMessageRepo.Instance.AddDebugItem(item.ClientID, item.SessionID, item); } } writeArgs.remoteDebugItems.Clear(); }