/// <summary> /// Connects the server instance to COM server. /// </summary> /// <exception cref="System.InvalidOperationException">Already connected to the OPC DA server.</exception> public void Connect() { if (IsConnected) { throw new InvalidOperationException("Already connected to the OPC DA server."); } Log.TraceFormat("Connecting to '{0}' opc server", Uri); var enumerator = new OpcServerEnumeratorAuto(); Tuple <string, Guid> hostAndCLSID = UrlParser.Parse( Uri, (host, progId) => new Tuple <string, Guid>(host, enumerator.CLSIDFromProgId(progId, host)), (host, clsid) => new Tuple <string, Guid>(host, clsid)); ComObject = Com.CreateInstanceWithBlanket(hostAndCLSID.Item2, hostAndCLSID.Item1, null, ComProxyBlanket); _shutdownConnectionPoint.TryConnect(ComObject); Log.TraceFormat("Connected to '{0}' opc server.", Uri); try { ClientName = _clientName; } catch (Exception ex) { Log.Warn("Cannot setup name of client.", ex); } OnConnectionStateChanged(true); }
private void TryConnect(object comServer) { if (comServer == null) { return; } _connectionPoint.TryConnect(comServer); }
/// <summary> /// Connect the ParentNode's Port and ChildNode's Port /// </summary> /// <param name="parentNode">ParentNode's Port</param> /// <param name="childNode">ChildNode's Port</param> /// <param name="decoratorShape">DecoratorShape of the connector</param> /// <param name="labelText">Set the text to the label</param> /// <param name="OffsetX">Set the OffsetX to the label</param> /// <param name="OffsetY">Set the OffsetY to the label</param> /// <param name="DrawImage">Determines whether image should draw with label or not</param> /// <param name="classType">Classtype</param> private ConnectorBase ConnectNodes(ConnectionPoint parentNode, ConnectionPoint childNode, DecoratorShape decoratorShape, string labelText, float OffsetX, float OffsetY, bool DrawImage, int classType) { if (parentNode != null && childNode != null) { OrthogonalConnector lConnector = new OrthogonalConnector(System.Drawing.PointF.Empty, new System.Drawing.PointF(0, 1)); lConnector.LineRoutingEnabled = true; lConnector.LineRoutingEnabled = true; lConnector.HeadDecorator.DecoratorShape = decoratorShape; lConnector.LineStyle.LineColor = Color.Goldenrod; lConnector.LineStyle.LineWidth = 1; lConnector.CentralPort.ConnectionsLimit = 10000; ImageLabel imageLabel = new ImageLabel(lConnector, labelText); imageLabel.OffsetX = OffsetX; imageLabel.OffsetY = OffsetY; imageLabel.ImageOffsetX = OffsetX - 25; imageLabel.ImageOffsetY = OffsetY - 5; imageLabel.DrawImage = DrawImage; if (classType == 1) { imageLabel.TextImage = System.Drawing.Image.FromFile(@"..\..\..\..\..\..\..\Common\Images\Diagram\class diagram\6.png"); } else { imageLabel.TextImage = System.Drawing.Image.FromFile(@"..\..\..\..\..\..\..\Common\Images\Diagram\class diagram\7.png"); } lConnector.Labels.Add(imageLabel); lConnector.HeadDecorator.Size = new System.Drawing.SizeF(12, 12); if (decoratorShape == DecoratorShape.Filled45Arrow) { lConnector.HeadDecorator.FillStyle.Color = Color.White; } lConnector.HeadDecorator.LineStyle.LineColor = Color.Goldenrod; lConnector.LineRoutingEnabled = true; parentNode.TryConnect(lConnector.TailEndPoint); childNode.TryConnect(lConnector.HeadEndPoint); this.diagram1.Model.AppendChild(lConnector); this.diagram1.Model.SendToBack(lConnector); return(lConnector); } else { return(null); } }