public void UpdateConnectionsClosedTime(CommandConnection item) { if (item.ClosedAt != null || item.Type == CommandConnectionType.Opened) { return; } item.ClosedAt = item.AtDateTime; var connection = PluginContext.ProfilerData.Connections.FirstOrDefault( x => x.ConnectionId == item.ConnectionId && x.ApplicationIdentity.Equals(item.ApplicationIdentity) && x.ClosedAt == null); if (connection == null) { return; } connection.ClosedAt = item.ClosedAt; UpdateTotalConnectionOpenTime(GetContext(item), connection); UpdateTotalConnectionOpenTime(GetStackTrace(item), connection); UpdateTotalConnectionOpenTime(GetTrafficUrl(item), connection); }
public async Task <IActionResult> DoCode() { string code; using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { code = await reader.ReadToEndAsync(); } try { using CommandConnection connection = await BuildConnection(); _logger.LogInformation($"[{nameof(DoCode)}] Executing code '{code}'"); string result = await connection.PerformSimpleCode(code, CodeChannel.HTTP); return(Content(result)); } catch (AggregateException ae) when(ae.InnerException is IncompatibleVersionException) { _logger.LogError($"[{nameof(DoCode)}] Incompatible DCS version"); return(StatusCode(502, ae.InnerException.Message)); } catch (AggregateException ae) when(ae.InnerException is SocketException) { _logger.LogError($"[{nameof(DoCode)}] DCS is unavailable"); return(StatusCode(503, ae.InnerException.Message)); } catch (Exception e) { _logger.LogWarning(e, $"[{nameof(DoCode)}] Failed to execute code {code}"); return(StatusCode(500, e.Message)); } }
public async Task <IActionResult> Status() { try { using CommandConnection connection = await BuildConnection(); MemoryStream json = await connection.GetSerializedMachineModel(); if (json != null) { return(new FileStreamResult(json, "application/json")); } return(new NoContentResult()); } catch (AggregateException ae) when(ae.InnerException is IncompatibleVersionException) { _logger.LogError($"[{nameof(Status)}] Incompatible DCS version"); return(StatusCode(502, ae.InnerException.Message)); } catch (AggregateException ae) when(ae.InnerException is SocketException) { _logger.LogError($"[{nameof(Status)}] DCS is unavailable"); return(StatusCode(503, ae.InnerException.Message)); } catch (Exception e) { _logger.LogWarning(e, $"[{nameof(Status)}] Failed to retrieve status"); return(StatusCode(500, e.Message)); } }
public void RemoveDisposedConnection(CommandConnection item) { if (item.Type != CommandConnectionType.Disposed) { return; } var connections = _localCommandConnection .Where(x => x.ConnectionId == item.ConnectionId && x.ApplicationIdentity.Equals(item.ApplicationIdentity)) .ToList(); foreach (var commandConnection in connections) { _localCommandConnection.Remove(commandConnection); PluginContext.NotifyPluginsHost(NotificationType.Update, -1); UpdateAppIdentityNotificationsCount(item, -1); } connections = GuiModelData.RelatedConnections .Where(x => x.ConnectionId == item.ConnectionId && x.ApplicationIdentity.Equals(item.ApplicationIdentity)) .ToList(); foreach (var commandConnection in connections) { GuiModelData.RelatedConnections.Remove(commandConnection); } }
private async Task <CommandConnection> BuildConnection() { CommandConnection connection = new CommandConnection(); await connection.Connect(_configuration.GetValue("SocketPath", DuetAPI.Connection.Defaults.FullSocketPath)); return(connection); }
public void LogConnection(DbConnection connection, DbConnectionContext interceptionConnectionContext, CommandConnectionType type) { var commandConnection = new CommandConnection { IsAsync = interceptionConnectionContext.IsAsync, Type = type, IsCanceled = interceptionConnectionContext.IsCanceled, ConnectionString = connection.ConnectionString, Exception = interceptionConnectionContext.Exception != null ? interceptionConnectionContext.Exception.Message : "", StackTrace = new CallingMethod { AssembliesToExclude = AssembliesToExclude }.GetCallingMethodInfo() }; setBaseInfo(interceptionConnectionContext, commandConnection); if (commandConnection.ConnectionId == null) { commandConnection.ConnectionId = UniqueIdExtensions <DbConnection> .GetUniqueId(connection).ToInt(); } _baseInfoQueue.Enqueue(commandConnection); }
public void SetConnectionAndContexAsDisposed(CommandConnection item) { if (item.Type != CommandConnectionType.Disposed) { return; } var connections = PluginContext.ProfilerData.Connections .Where(x => x.ConnectionId == item.ConnectionId && x.ApplicationIdentity.Equals(item.ApplicationIdentity)) .ToList(); foreach (var commandConnection in connections) { commandConnection.DisposedAt = item.AtDateTime; if (commandConnection.ClosedAt != null) { commandConnection.Duration = (int)Math.Round((commandConnection.ClosedAt.Value - commandConnection.AtDateTime).TotalMilliseconds); } } var contextIds = connections.Select(x => x.ObjectContextId).ToList(); var contexts = PluginContext.ProfilerData.Contexts.Where(x => contextIds.Contains(x.ObjectContextId)); foreach (var context in contexts.Where(x => x.DisposedAt == null)) { context.DisposedAt = item.AtDateTime; } }
public async Task <IActionResult> Status() { try { using CommandConnection connection = await BuildConnection(); string machineModel = await connection.GetSerializedObjectModel(); return(Content(machineModel, "application/json")); } catch (Exception e) { if (e is AggregateException ae) { e = ae.InnerException; } if (e is IncompatibleVersionException) { _logger.LogError($"[{nameof(Status)}] Incompatible DCS version"); return(StatusCode(502, "Incompatible DCS version")); } if (e is SocketException) { _logger.LogError($"[{nameof(Status)}] DCS is not started"); return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)")); } _logger.LogWarning(e, $"[{nameof(Status)}] Failed to retrieve status"); return(StatusCode(500, e.Message)); } }
public void ManageDisposedConnection(CommandConnection disposedItem) { if (disposedItem.Type != CommandConnectionType.Disposed) { return; } var opendConnection = PluginContext.ProfilerData.Connections .FirstOrDefault(x => x.ConnectionId == disposedItem.ConnectionId && x.Type == CommandConnectionType.Opened && x.ApplicationIdentity.Equals(disposedItem.ApplicationIdentity)); if (opendConnection == null) { return; } if (opendConnection.Duration >= OneSecond) { if (disposedItem.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity)) { GuiModelData.RelatedConnections.Add(opendConnection); } _localCommandConnection.Add(opendConnection); PluginContext.NotifyPluginsHost(NotificationType.Update, 1); UpdateAppIdentityNotificationsCount(disposedItem); } }
static void Main(string[] args) { // Connect to DCS CommandConnection connection = new CommandConnection(); if (args.Length == 0) { connection.Connect().Wait(); } else { connection.Connect(args[0]).Wait(); } Console.WriteLine("Connected!"); // Start reading lines from stdin and send them to DCS as simple codes. // When the code has finished, the result is printed to stdout string input = Console.ReadLine(); while (connection.IsConnected && input != null && input != "exit" && input != "quit") { try { string output = connection.PerformSimpleCode(input).Result; Console.Write(output); } catch (AggregateException ae) { Console.WriteLine(ae.InnerException.Message); } input = Console.ReadLine(); } }
protected void ShowSelectedConnectionRelatedCommands(CommandConnection connection) { if (connection == null || GuiModelData.SelectedApplicationIdentity == null) { return; } GuiModelData.RelatedCommands.Clear(); GuiModelData.RelatedStackTraces.Clear(); if (!connection.CommandsIds.Any()) { return; } var commands = PluginContext.ProfilerData.Commands .Where(command => command.ConnectionId == connection.ConnectionId && command.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity) && command.ObjectContextId == connection.ObjectContextId && command.TransactionId == connection.TransactionId && command.AtDateTime >= connection.AtDateTime && connection.CommandsIds.Contains(command.CommandId ?? 0)) .OrderBy(command => command.AtDateTime) .ToList(); foreach (var item in commands) { GuiModelData.RelatedCommands.Add(item); } ActivateRelatedStackTraces(); }
void HandleCLOSE(CommandConnection connection, TcpCommandParams parameters) { try { SendResponseAndClose(connection, parameters.Command, "100"); } catch (SocketError) { } }
private async Task <string> ResolvePath(string path) { using (CommandConnection connection = await BuildConnection()) { return(await connection.ResolvePath(path)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public SpooledFileInfo[] getSpooledFiles(final CommandConnection conn, String user) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual SpooledFileInfo[] getSpooledFiles(CommandConnection conn, string user) { spooledFiles_ = null; counter_ = -1; userName_ = user; handler_.process(conn, 1000); return spooledFiles_; }
public HttpResponseMessage Post([FromBody] CommandConnection commandConnection) { commandConnection.ReceivedId = IdGenerator.GetId(); commandConnection.JsonContent = this.Request.Content.ReadAsStringAsync().Result.ToFormattedJson(); DispatcherHelper.DispatchAction(() => AppMessenger.Messenger.NotifyColleagues("AddCommandConnection", commandConnection)); return(new HttpResponseMessage(HttpStatusCode.Created)); }
protected static void UpdateTotalConnectionOpenTime(StatisticsBase info, CommandConnection connection) { if (info == null || connection.ClosedAt == null) { return; } info.ContextStatistics.TotalConnectionOpenTime += (long)(connection.ClosedAt.Value - connection.AtDateTime).TotalMilliseconds; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public ObjectInfo[] getObjects(final CommandConnection conn, String name, String library, String type) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual ObjectInfo[] getObjects(CommandConnection conn, string name, string library, string type) { objectList_.ObjectName = name; objectList_.ObjectLibrary = library; objectList_.ObjectType = type; objects_ = null; counter_ = -1; handler_.process(conn, 2800); return(objects_); }
public void ManageCommandConnections(CommandConnection item) { if (item.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity)) { GuiModelData.RelatedConnections.Add(item); } PluginContext.NotifyPluginsHost(NotificationType.Update, 1); UpdateAppIdentityNotificationsCount(item); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public synchronized MessageInfo[] getMessages(final CommandConnection conn) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual MessageInfo[] getMessages(CommandConnection conn) { lock (this) { messages_ = null; counter_ = -1; handler_.process(conn, 1000); return(messages_); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public synchronized JobInfo[] getJobs(final CommandConnection conn, final boolean reset) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual JobInfo[] getJobs(CommandConnection conn, bool reset) { lock (this) { jobs_ = null; counter_ = -1; jobList_.ResetStatusStatistics = reset; handler_.process(conn, 600); return(jobs_); } }
void HandleGETLINES(CommandConnection connection, TcpCommandParams parameters) { SendResponse(connection, parameters.Command, "100"); StringCollectionEx lines = new StringCollectionEx(); lines.Add("This is a first line of data"); lines.Add("This is a second line of data"); lines.Add("This is a third line of data"); SendMultipleLines(connection, lines, "."); }
// ================ CONNECTIONS ========================== public CommandConnection GetOrCreateCommandConnection(GroupableNode sourceNode, GroupableNode targetNode) { var commandConnection = this.FindConnection(sourceNode, targetNode) as CommandConnection; if (commandConnection == null) { commandConnection = new CommandConnection(sourceNode, targetNode); this.Connections.Add(commandConnection); } return(commandConnection); }
void ISoftDebuggerConnectionProvider.EndConnect(IAsyncResult result, out VirtualMachine vm, out string appName) { appName = this.appName; Stream transport, output; CommandConnection.EndStartDebugger(result, out transport, out output); var transportConnection = new IPhoneTransportConnection( CommandConnection, transport); var outputReader = new StreamReader(output); vm = VirtualMachineManager.Connect(transportConnection, outputReader, null); }
private async Task ValidateProvider() { using (CommandConnection connection = new CommandConnection()) { await connection.Connect(_configuration.GetValue("SocketPath", DuetAPI.Connection.Defaults.SocketPath)); string wwwRoot = await connection.ResolvePath("0:/www"); if (wwwRoot != _wwwRoot) { _provider = new PhysicalFileProvider(wwwRoot); _wwwRoot = wwwRoot; } } }
public async Task <IActionResult> SetPluginData() { try { PluginPatchInstruction instruction = await JsonSerializer.DeserializeAsync <PluginPatchInstruction>(HttpContext.Request.Body); using CommandConnection connection = await BuildConnection(); ObjectModel model = await connection.GetObjectModel(); foreach (Plugin plugin in model.Plugins) { if (plugin.Name == instruction.plugin) { if (!string.IsNullOrEmpty(plugin.SbcExecutable)) { _logger.LogWarning("Tried to set plugin data for {0} but it has an SBC executable set"); return(Forbid()); } await connection.SetPluginData(instruction.key, instruction.value, instruction.plugin); return(NoContent()); } } return(NotFound()); } catch (Exception e) { if (e is AggregateException ae) { e = ae.InnerException; } if (e is IncompatibleVersionException) { _logger.LogError($"[{nameof(SetPluginData)}] Incompatible DCS version"); return(StatusCode(502, "Incompatible DCS version")); } if (e is SocketException) { _logger.LogError($"[{nameof(SetPluginData)}] DCS is not started"); return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)")); } _logger.LogWarning(e, $"[{nameof(SetPluginData)} Failed to set plugin data"); return(StatusCode(500, e.Message)); } }
public void CreateOrUpdateContext(CommandConnection item) { var isNewContext = false; var context = GetContext(item); if (context != null) { context.ContextStatistics.NumberOfConnections++; } else { isNewContext = true; context = new Context { ObjectContextId = item.ObjectContextId, Url = item.HttpInfo.Url, AtDateTime = item.AtDateTime, ObjectContextName = item.ObjectContextName, ContextStatistics = { NumberOfConnections = 1 }, ManagedThreadId = item.ManagedThreadId, HttpContextCurrentId = item.HttpInfo.HttpContextCurrentId, ApplicationIdentity = item.ApplicationIdentity }; PluginContext.ProfilerData.Contexts.Add(context); if (item.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity)) { GuiModelData.Contexts.Add(context); } PluginContext.NotifyPluginsHost(NotificationType.Update, 1); UpdateAppIdentityNotificationsCount(context.ApplicationIdentity); } UpdateMultipleContextPerRequestInfo(context); UpdateNumberOfConnections(GetStackTrace(item)); var trafficUrl = GetTrafficUrl(item); UpdateNumberOfConnections(trafficUrl); if (trafficUrl != null && isNewContext) { trafficUrl.NumberOfContexts++; } }
public async Task <IActionResult> InstallPlugin() { string zipFile = Path.GetTempFileName(); try { try { // Write ZIP file using (FileStream stream = new FileStream(zipFile, FileMode.Create, FileAccess.Write, FileShare.None)) { await Request.Body.CopyToAsync(stream); } // Install it using CommandConnection connection = await BuildConnection(); await connection.InstallPlugin(zipFile); return(NoContent()); } catch (Exception e) { if (e is AggregateException ae) { e = ae.InnerException; } if (e is IncompatibleVersionException) { _logger.LogError($"[{nameof(InstallPlugin)}] Incompatible DCS version"); return(StatusCode(502, "Incompatible DCS version")); } if (e is SocketException) { _logger.LogError($"[{nameof(InstallPlugin)}] DCS is not started"); return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)")); } _logger.LogWarning(e, $"[{nameof(InstallPlugin)} Failed to upload ZIP file to {zipFile}"); return(StatusCode(500, e.Message)); } } finally { System.IO.File.Delete(zipFile); } }
public async Task <IActionResult> GetFileInfo(string filename) { filename = HttpUtility.UrlDecode(filename); string resolvedPath = "n/a"; try { resolvedPath = await ResolvePath(filename); if (!System.IO.File.Exists(resolvedPath)) { _logger.LogWarning($"[{nameof(GetFileInfo)}] Could not find file {filename} (resolved to {resolvedPath})"); return(NotFound(HttpUtility.UrlPathEncode(filename))); } using CommandConnection connection = await BuildConnection(); var info = await connection.GetFileInfo(resolvedPath); string json = JsonSerializer.Serialize(info, JsonHelper.DefaultJsonOptions); return(Content(json, "application/json")); } catch (Exception e) { if (e is AggregateException ae) { e = ae.InnerException; } if (e is IncompatibleVersionException) { _logger.LogError($"[{nameof(GetFileInfo)}] Incompatible DCS version"); return(StatusCode(502, "Incompatible DCS version")); } if (e is SocketException) { _logger.LogError($"[{nameof(GetFileInfo)}] DCS is not started"); return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)")); } _logger.LogWarning(e, $"[{nameof(GetFileInfo)}] Failed to retrieve file info for {filename} (resolved to {resolvedPath})"); return(StatusCode(500, e.Message)); } }
public async Task <IActionResult> GetFileinfo(string filename) { filename = HttpUtility.UrlDecode(filename); string resolvedPath = "n/a"; try { resolvedPath = await ResolvePath(filename); if (!System.IO.File.Exists(resolvedPath)) { _logger.LogWarning($"[{nameof(GetFileinfo)}] Could not find file {filename} (resolved to {resolvedPath})"); return(NotFound(HttpUtility.UrlPathEncode(filename))); } using (CommandConnection connection = await BuildConnection()) { var info = await connection.GetFileInfo(resolvedPath); string json = JsonConvert.SerializeObject(info, JsonHelper.DefaultSettings); return(Content(json, "application/json")); } } catch (AggregateException ae) when(ae.InnerException is IncompatibleVersionException) { _logger.LogError($"[{nameof(GetFileinfo)}] Incompatible DCS version"); return(StatusCode(502, ae.InnerException.Message)); } catch (AggregateException ae) when(ae.InnerException is SocketException) { _logger.LogError($"[{nameof(GetFileinfo)}] DCS is unavailable"); return(StatusCode(503, ae.InnerException.Message)); } catch (Exception e) { _logger.LogWarning(e, $"[{nameof(GetFileinfo)}] Failed to retrieve file info for {filename} (resolved to {resolvedPath})"); return(StatusCode(500, e.Message)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public synchronized MessageInfo[] getMessages(final CommandConnection conn, JobInfo job) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual MessageInfo[] getMessages(CommandConnection conn, JobInfo job) { lock (this) { messages_ = null; counter_ = -1; jobName_ = job.JobName; while (jobName_.Length < 10) { jobName_ = jobName_ + " "; } jobName_ = jobName_ + job.UserName; while (jobName_.Length < 20) { jobName_ = jobName_ + " "; } jobName_ = jobName_ + job.JobNumber; handler_.process(conn, 1000); return(messages_); } }