private void OnDeleteGraphNode(GraphNode node) { // Delete the all edges connected to this node var edges = m_graphView.edges.ToList(); for (int i = 0; i < edges.Count; i++) { PortDescription input = null; PortDescription output = null; GetSlots(edges[i], out input, out output); bool removeEdge = false; if (input.Owner == node) { removeEdge = true; } if (output.Owner == node) { removeEdge = true; } if (removeEdge) { OnDeleteEdge(edges[i]); } } // Delete the node m_graphView.RemoveElement(node); m_graph.RemoveNode(node.SerializedNode); }
public GraphNode CreateNode(SerializedNode serializedNode) { Type runtimeNodeType = serializedNode.NodeRuntimeType; NodeTemplate nodeTemplate = m_nodeProvider.GetTemplateFromRuntimeType(runtimeNodeType); GraphNode node = new GraphNode(nodeTemplate.Title.Last(), nodeTemplate.UXMLPath, nodeTemplate.USSPath, runtimeNodeType, m_edgeConnectorListener, serializedNode); node.Position = serializedNode.EditorPosition; var fieldTemplate = m_fieldProvider.GetNodeFieldTemplateByType(runtimeNodeType); for (int j = 0; j < serializedNode.SerializedPorts.Count; j++) { var sPort = serializedNode.SerializedPorts[j]; var port = new PortDescription(sPort.Guid, sPort.DisplayName, sPort.PortType, sPort.Direction, sPort.AllowMultipleConnections, sPort.AddIdenticalPortOnConnect); node.AddSlot(port, false); } foreach (var property in fieldTemplate.Properties) { node.AddProperty(new VisualProperty(property.FieldType, node.RuntimeInstance)); } node.BindPortsAndProperties(); return(node); }
/// <summary> /// Gets an array of serial port names and descriptions for the current computer. /// </summary> /// <remarks> /// This method uses the Windows Management Interface to obtain its information. Therefore, /// the list may be different to the list obtained using the GetPortNames() method which /// uses other techniques. /// <para>On Windows 7, this method shows to return normal COM ports, but not those /// associated with a modem driver.</para> /// </remarks> /// <returns>An array of serial ports for the current computer.</returns> public PortDescription[] GetPortDescriptions() { Dictionary <string, PortDescription> list = new Dictionary <string, PortDescription>(); using (RegistryKey local = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM", false)) { if (local != null) { string[] k = local.GetValueNames(); foreach (string p in k) { string n = local.GetValue(p) as string; list.Add(n, new PortDescription(n, "")); } } } #if !NETSTANDARD15 ManagementObjectCollection objects; // Look for standard serial ports using (ManagementObjectSearcher q = new ManagementObjectSearcher("select * from Win32_SerialPort")) { objects = q.Get(); using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = objects.GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject current = (ManagementObject)enumerator.Current; string k = current["DeviceID"].ToString(); if (list.ContainsKey(k)) { list[k].Description = current["Name"].ToString(); } } } } // Look for any modems that are attached to COM ports that aren't listed above using (ManagementObjectSearcher q = new ManagementObjectSearcher("select * from Win32_POTSModem")) { objects = q.Get(); using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = objects.GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject current = (ManagementObject)enumerator.Current; string k = current["AttachedTo"].ToString(); if (list.ContainsKey(k)) { list[k].Description = current["Name"].ToString(); } } } } #endif // Get the array and return it int i = 0; PortDescription[] ports = new PortDescription[list.Count]; foreach (PortDescription p in list.Values) { ports[i++] = p; } return(ports); }
private void OnDeleteEdge(Edge edge) { // Remove input/output if they're marked as auto add identical on connect. // This also means that we need to auto remove on disconnect PortDescription leftPort = null; PortDescription rightPort = null; GetSlots(edge, out leftPort, out rightPort); // Remove the edge edge.input.Disconnect(edge); edge.output.Disconnect(edge); m_graphView.RemoveElement(edge); if (leftPort.AddIdenticalPortOnConnect) { leftPort.Owner.TrimInputs(); leftPort.Owner.TrimOutputs(); } if (rightPort.AddIdenticalPortOnConnect) { rightPort.Owner.TrimInputs(); rightPort.Owner.TrimOutputs(); } }
public PortDescriptionService() { var fileReader = new StreamReader(PortDescriptionFilePath); var internalPortDescriptions = CsvSerializer.DeserializeFromReader <List <InternalPortDescription> >(fileReader); foreach (var internalPortDescription in internalPortDescriptions) { var port = internalPortDescription.Port; var description = internalPortDescription.Description; if (port.Contains("-")) { var ports = port.Split('-'); var startPort = Convert.ToUInt16(ports[0]); var endPort = Convert.ToUInt16(ports[1]); for (var portNumber = startPort; portNumber < endPort; portNumber++) { var portDescription = new PortDescription(portNumber, description); this.AddPortDescription(portDescription); } } else { var portDescription = new PortDescription(Convert.ToUInt16(port), description); this.AddPortDescription(portDescription); } } }
private static string AssignIndexer(PortDescription desc, PortConfiguration config) { if (desc.IsList || desc.IsDictionary) { return(config is null || config.Indexer is null ? string.Empty : config.Indexer); } return(null); }
private void ButtonYes_Click(object sender, RoutedEventArgs e) { if (DataGridInputs.SelectedItem is PortDescription desc) { Result = desc; DialogResult = true; } }
public virtual void AddSlot(PortDescription description, bool addToSerializedNode = true) { m_portDescriptions.Add(description); if (addToSerializedNode) { m_serializedNode.SerializedPorts.Add(description.ToSerializedPort()); } description.Owner = this; }
private void GetSlots(Edge edge, out PortDescription leftPortDescription, out PortDescription rightPortDescription) { leftPortDescription = (edge.output as VisualPort).PortDescription; rightPortDescription = (edge.input as VisualPort).PortDescription; if (leftPortDescription == null || rightPortDescription == null) { Debug.Log("an edge is null"); } }
public PortDescription[] serial_getports(SafeSerialHandle handle) { // The portdesc is an array of two string pointers, where the last element is zero IntPtr portdesc; #if !NETSTANDARD2_0 portdesc = UnsafeNativeMethods.serial_getports(handle); #else try { portdesc = UnsafeNativeMethods.serial_getports(handle); } catch (Exception ex) { // Ugly hack as .NET Standard doesn't have EntryPointNotFoundException, so if we // get any exception, we raise this one instead. To remove if it ever becomes // available. throw new EntryPointNotFoundException(ex.Message, ex); } #endif errno = Marshal.GetLastWin32Error(); if (portdesc.Equals(IntPtr.Zero)) { return(null); } // Get the number of ports in the system. int portNum = 0; IntPtr portName; do { portName = Marshal.ReadIntPtr(portdesc, portNum * 2 * IntPtr.Size); if (portName != IntPtr.Zero) { portNum++; } } while (portName != IntPtr.Zero); // Copy them into our struct PortDescription[] ports = new PortDescription[portNum]; for (int i = 0; i < portNum; i++) { IntPtr portPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size); string port = Marshal.PtrToStringAnsi(portPtr); IntPtr descPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size + IntPtr.Size); string desc; if (descPtr.Equals(IntPtr.Zero)) { desc = string.Empty; } else { desc = Marshal.PtrToStringAnsi(descPtr); } ports[i] = new PortDescription(port, desc); } return(ports); }
private PortDescription[] GetRuntimePortDescriptions() { string[] ports = System.IO.Ports.SerialPort.GetPortNames(); PortDescription[] portdescs = new PortDescription[ports.Length]; for (int i = 0; i < ports.Length; i++) { portdescs[i] = new PortDescription(ports[i], ""); } return portdescs; }
/// <summary> /// Gets an array of serial port names and descriptions for the current computer. /// </summary> /// <remarks> /// This method uses the Windows Management Interface to obtain its information. Therefore, /// the list may be different to the list obtained using the GetPortNames() method which /// uses other techniques. /// <para>On Windows 7, this method shows to return normal COM ports, but not those /// associated with a modem driver.</para> /// </remarks> /// <returns>An array of serial ports for the current computer.</returns> public PortDescription[] GetPortDescriptions() { string[] ports = GetPortNames(); PortDescription[] portdescs = new PortDescription[ports.Length]; for (int i = 0; i < ports.Length; i++) { portdescs[i] = new PortDescription(ports[i], ""); } return(portdescs); }
internal void RegisterECSPorts(PortDescription desc) { if (HostSystem == null) { return; } foreach (var c in desc.ComponentTypes) { AddWriter(c); } }
private void AddPortDescription(PortDescription portDescription) { if (this.PortDescriptions.ContainsKey(portDescription.Port)) { var description = this.PortDescriptions[portDescription.Port].Description; var newDescription = $"{description} ¦ {portDescription.Description}"; this.PortDescriptions[portDescription.Port].Description = newDescription; } else { this.PortDescriptions.Add(portDescription.Port, portDescription); } }
public static VisualPort Create(PortDescription description, IEdgeConnectorListener connectorListener) { var port = new VisualPort(Orientation.Horizontal, description.IsInputSlot ? Direction.Input : Direction.Output, description.AllowMultipleConnections ? Capacity.Multi : Capacity.Single, null) { m_EdgeConnector = new EdgeConnector <Edge>(connectorListener) }; port.AddManipulator(port.m_EdgeConnector); port.PortDescription = description; port.visualClass = "type" + port.PortDescription.PortType.Name; port.m_portGraphics.AddToClassList("type" + port.PortDescription.PortType.Name); return(port); }
public PortDescription[] serial_getports(IntPtr handle) { // The portdesc is an array of two string pointers, where the last element is zero IntPtr portdesc = UnsafeNativeMethods.serial_getports(handle); errno = Marshal.GetLastWin32Error(); if (portdesc.Equals(IntPtr.Zero)) { return(null); } // Get the number of ports in the system. int portNum = 0; IntPtr portName; do { portName = Marshal.ReadIntPtr(portdesc, portNum * 2 * IntPtr.Size); if (portName != IntPtr.Zero) { portNum++; } } while (portName != IntPtr.Zero); // Copy them into our struct PortDescription[] ports = new PortDescription[portNum]; for (int i = 0; i < portNum; i++) { IntPtr portPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size); string port = Marshal.PtrToStringAnsi(portPtr); IntPtr descPtr = Marshal.ReadIntPtr(portdesc, i * 2 * IntPtr.Size + IntPtr.Size); string desc; if (descPtr.Equals(IntPtr.Zero)) { desc = string.Empty; } else { desc = Marshal.PtrToStringAnsi(descPtr); } ports[i] = new PortDescription(port, desc); } return(ports); }
public void BindPort(PortDescription port) { if (port.Owner != this) { return; } var portVisuals = VisualPort.Create(port, EdgeConnectorListener); port.SetVisualPort(portVisuals); switch (port.PortDirection) { case PortDirection.Input: inputContainer.Add(portVisuals); break; case PortDirection.Output: outputContainer.Add(portVisuals); break; } }
public virtual void RemoveSlot(PortDescription slot) { for (int i = 0; i < m_portDescriptions.Count; i++) { PortDescription port = m_portDescriptions[i]; if (slot == port) { if (slot.IsInputSlot) { inputContainer.Remove(slot.VisualPort); } if (slot.IsOutputSlot) { outputContainer.Remove(slot.VisualPort); } m_portDescriptions.Remove(port); break; } } RefreshPorts(); }
private void ScanPorts(BasicScanItemDisplay basicScanItemDisplay) { if (basicScanItemDisplay.IPAddress == "Unknown") { return; } if (basicScanItemDisplay.IsPortScanRunning) { return; } basicScanItemDisplay.IsPortScanRunning = true; this.RunTask(uiThread => { var tcpPorts = this.portScanner.SynScan(basicScanItemDisplay.IPAddress); var udpPorts = this.portScanner.UdpScan(basicScanItemDisplay.IPAddress); uiThread.Execute(() => { basicScanItemDisplay.PortDescriptions.Clear(); foreach (var port in tcpPorts) { if (this.portDescriptionService.PortDescriptions.ContainsKey(port)) { var portDescription = this.portDescriptionService.PortDescriptions[port].Clone(); portDescription.Protocol = Layer4ProtocolType.TCP; basicScanItemDisplay.PortDescriptions.Add(portDescription); } else { var portDescription = new PortDescription(port, "Unknown") { Protocol = Layer4ProtocolType.TCP }; basicScanItemDisplay.PortDescriptions.Add(portDescription); } } foreach (var port in udpPorts) { if (this.portDescriptionService.PortDescriptions.ContainsKey(port)) { var portDescription = this.portDescriptionService.PortDescriptions[port].Clone(); portDescription.Protocol = Layer4ProtocolType.UDP; basicScanItemDisplay.PortDescriptions.Add(portDescription); } else { var portDescription = new PortDescription(port, "Unknown") { Protocol = Layer4ProtocolType.UDP }; basicScanItemDisplay.PortDescriptions.Add(portDescription); } } CommandManager.InvalidateRequerySuggested(); basicScanItemDisplay.IsPortScanRunning = false; }); }); }
private void ProcessFields(FieldInfo[] fields, PropertyInfo[] properties) { foreach (var field in fields) { var fieldType = field.FieldType; // skip non-generic types if (!fieldType.IsGenericType) { continue; } PortDescription desc = default; if (fieldType.GetGenericTypeDefinition() == typeof(InputPort <>)) { desc.Type = fieldType.GetGenericArguments()[0]; desc.Direction = PortDirection.Input; } else if (fieldType.GetGenericTypeDefinition() == typeof(InputPortMulti <>)) { desc.Type = fieldType.GetGenericArguments()[0]; desc.Direction = PortDirection.Input; desc.Capacity = PortCapacity.Multiple; } else if (fieldType.GetGenericTypeDefinition() == typeof(OutputPort <>)) { desc.Type = fieldType.GetGenericArguments()[0]; desc.Direction = PortDirection.Output; } else if (fieldType.GetGenericTypeDefinition() == typeof(OutputPortSingle <>)) { desc.Type = fieldType.GetGenericArguments()[0]; desc.Direction = PortDirection.Output; desc.Capacity = PortCapacity.Single; } if (desc.Type != null) { var value = field.GetValue(this); var idField = fieldType.GetField("Id"); desc.Id = idField.GetValue(value) as string; // if struct does not have own Id set, retreive it from field.Name if (string.IsNullOrEmpty(desc.Id)) { // backing fields are named as <PropertyName>k_BackingField // we extract PropertyName from it and use as port name var fn = field.Name; var startIdx = fn.IndexOf('<') + 1; var endIdx = fn.IndexOf('>'); desc.Id = fn.Substring(startIdx, endIdx - startIdx); // store new Id to port definition struct fieldType.GetField("Id").SetValue(value, desc.Id); } // store updated struct into field field.SetValue(this, value); _collectedPorts.Add(desc); } } }
public void AddEdge(Edge edgeVisual) { PortDescription leftPortDescription; PortDescription rightPortDescription; GetSlots(edgeVisual, out leftPortDescription, out rightPortDescription); if (!leftPortDescription.AllowMultipleConnections) { var edges = m_graphView.edges.ToList(); foreach (var _edge in edges) { if (_edge.input == leftPortDescription.VisualPort || _edge.output == leftPortDescription.VisualPort) { _edge.input.Disconnect(_edge); _edge.output.Disconnect(_edge); m_graphView.RemoveElement(_edge); } } leftPortDescription.VisualPort.DisconnectAll(); } if (!rightPortDescription.AllowMultipleConnections) { var edges = m_graphView.edges.ToList(); foreach (var _edge in edges) { if (_edge.input == rightPortDescription.VisualPort || _edge.output == rightPortDescription.VisualPort) { _edge.input.Disconnect(_edge); _edge.output.Disconnect(_edge); m_graphView.RemoveElement(_edge); } } rightPortDescription.VisualPort.DisconnectAll(); } edgeVisual.output.Connect(edgeVisual); edgeVisual.input.Connect(edgeVisual); m_graphView.AddElement(edgeVisual); m_graph.AddEdge(new SerializedEdge() { SourceNodeGUID = leftPortDescription.Owner.NodeGuid, SourcePortMemberName = leftPortDescription.MemberName, TargetNodeGUID = rightPortDescription.Owner.NodeGuid, TargetPortMemberName = rightPortDescription.MemberName }); if (leftPortDescription.AddIdenticalPortOnConnect) { PortDescription newPort = leftPortDescription.CreateCopy(); if (leftPortDescription.Owner.GetNumUnconnectOutput() == 0) { leftPortDescription.Owner.AddSlot(newPort); leftPortDescription.Owner.BindPort(newPort); } } if (rightPortDescription.AddIdenticalPortOnConnect) { PortDescription newPort = rightPortDescription.CreateCopy(); if (rightPortDescription.Owner.GetNumUnconnectInput() == 0) { rightPortDescription.Owner.AddSlot(newPort); rightPortDescription.Owner.BindPort(newPort); } } }