internal static Rect GetRectWithMargin(ConnectorInfo connectorThumb, double margin) { Rect rect = new Rect(connectorThumb.DesignerItemLeft, connectorThumb.DesignerItemTop, connectorThumb.DesignerItemSize.Width, connectorThumb.DesignerItemSize.Height); rect.Inflate(margin, margin); return rect; }
public List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation) { List<Point> linePoints = new List<Point>(); //Rect rectSource = PathFinderHelper.GetRectWithMargin(source, 0); //Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource); //Point endPoint = sinkPoint; linePoints.Add(source.Position); linePoints.Add(sinkPoint); return linePoints; }
public List<Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine) { List<Point> linePoints = new List<Point>(); //Rect rectSource = PathFinderHelper.GetRectWithMargin(source, margin); //Rect rectSink = PathFinderHelper.GetRectWithMargin(sink, margin); //Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource); //Point endPoint = PathFinderHelper.GetOffsetPoint(sink, rectSink); linePoints.Add(source.Position); linePoints.Add(sink.Position); return linePoints; }
private static void AddOtherPoints(List <Point> linePoints, ConnectorInfo source, ConnectorInfo sink, Rect sourceRect, Rect sinkRect) { if (IsPointVisible(source, sink.ConnectorPoint, sourceRect)) { linePoints.Add(sink.ConnectorPoint); OptimizeLine(linePoints, sourceRect); return; } if (TargetIsNotVisible(sourceRect, sinkRect, sink)) // когда нужно огибать элементы { AddLineAround(linePoints, source, sink, sourceRect, sinkRect); } else // когда целевой элемент над или под источником, при этом есть место для линии между ними { OptimizeLine(linePoints, source, sink, sourceRect, sinkRect); } }
private static Point GetNearestNeighborSource(ConnectorInfo source, Point endPoint, Rect rectSource, out bool flag) { Point n1, n2; // neighbors GetNeighborCorners(source.Orientation, rectSource, out n1, out n2); if ((Distance(n1, endPoint) <= Distance(n2, endPoint))) { flag = true; return(n1); } else { flag = false; return(n2); } }
/// <summary> /// Получает прямоугольную область,которая охватывает элемент с его выводом связи /// </summary> /// <param name="connectorInfo">Информация по выводу</param> /// <returns>Охватываемая область</returns> private static Rect GetElementRect(ConnectorInfo connectorInfo) { //TODO Get real size of ContentPresenter Rect rect = new Rect(connectorInfo.ConnectorParentX, connectorInfo.ConnectorParentY, 30, 30);//source.ParentViewModel.Width, source.ParentViewModel.Height); if (rect.Contains(connectorInfo.ConnectorPoint)) { rect.Inflate(10, 10); } else { double margin = connectorInfo.Orientation == ConnectorOrientation.RIGHT ? connectorInfo.ConnectorPoint.X - rect.Right : rect.Left - connectorInfo.ConnectorPoint.X; rect.Inflate(margin, margin); } return(rect); }
/// <summary> /// The install. /// </summary> /// <exception cref="Exception">ex</exception> public void InstallConnector(ConnectorInfo connectorInfo, Guid connectorGuid) { try { var connector = this.GetConnector(connectorGuid); if (connector == null) { HWLogger.Install.Info($"Start install {connectorInfo.Name}"); var cfMgmt = MGroup.Instance.GetConnectorFramework(); cfMgmt.Setup(connectorInfo, connectorGuid); HWLogger.Install.Info($"{connectorInfo.Name} install finish."); } } catch (Exception ex) { HWLogger.Install.Error(ex, "Install connector error:"); throw; } }
private APIOperation GetAPIOperation(OperationRequest request) { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = manager.FindConnectorInfo( request.ConnectorKey); if (info == null) { throw new Exception("No such connector: " + request.ConnectorKey); } String connectorFacadeKey = request.ConnectorFacadeKey; ConnectorFacade facade = ConnectorFacadeFactory.GetManagedInstance().NewInstance(info, connectorFacadeKey); return(facade.GetOperation(request.Operation)); }
public void TestValidate() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("failValidation"); property.Value = false; ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); facade.Validate(); property.Value = true; facade = facf.NewInstance(api); try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); facade.Validate(); Assert.Fail("exception expected"); } catch (ConnectorException e) { Assert.AreEqual("validation failed en", e.Message); } try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); facade.Validate(); Assert.Fail("exception expected"); } catch (ConnectorException e) { Assert.AreEqual("validation failed es", e.Message); } }
private static void CheckPathEnd(ConnectorInfo source, ConnectorInfo sink, bool showLastLine, List <Point> linePoints) { if (showLastLine) { Point startPoint = new Point(0, 0); Point endPoint = new Point(0, 0); double marginPath = 15; switch (source.Type) { case Direction.IN: startPoint = new Point(source.Position.X - marginPath, source.Position.Y); break; case Direction.OUT: startPoint = new Point(source.Position.X + marginPath, source.Position.Y); break; default: break; } switch (sink.Type) { case Direction.IN: endPoint = new Point(sink.Position.X - marginPath, sink.Position.Y); break; case Direction.OUT: endPoint = new Point(sink.Position.X + marginPath, sink.Position.Y); break; default: break; } linePoints.Insert(0, startPoint); linePoints.Add(endPoint); } else { linePoints.Insert(0, source.Position); linePoints.Add(sink.Position); } }
private async Task FollowUser(long userId, string userAlias, IMsgPublisher userToFollow) { if (logger.IsVerbose) { logger.Verbose("{0} FollowUser({1}).", Me, userAlias); } await userToFollow.AddFollower(State.UserAlias, State.UserId, this); ConnectorInfo userInfo = ConnectorInfo.GetUserInfo(userId, userAlias); State.Subscriptions[userInfo] = userToFollow; await WriteStateAsync(); // Notify any viewers that a subscription has been added for this user viewers.Notify( v => v.SubscriptionAdded(userInfo) ); }
private static void OptimizeLine(List <Point> linePoints, ConnectorInfo source, ConnectorInfo sink, Rect sourceRect, Rect sinkRect) { if (source.ConnectorPoint.Y > sink.ConnectorPoint.Y) { double middleY = sink.ConnectorPoint.Y + (source.ConnectorPoint.Y - sink.ConnectorPoint.Y) / 2; Point rectAngle = source.Orientation == ConnectorOrientation.LEFT ? sourceRect.TopLeft : sourceRect.TopRight; linePoints.Add(new Point(rectAngle.X, source.ConnectorPoint.Y)); linePoints.Add(new Point(rectAngle.X, middleY)); linePoints.Add(new Point(sink.ConnectorPoint.X, middleY)); } else { Point rectAngle = sink.Orientation == ConnectorOrientation.LEFT ? sinkRect.TopLeft : sinkRect.TopRight; if (sink.Orientation == ConnectorOrientation.LEFT) { if (rectAngle.X < source.ConnectorPoint.X) { linePoints.Add(new Point(source.ConnectorPoint.X, rectAngle.Y)); linePoints.Add(rectAngle); linePoints.Add(new Point(rectAngle.X, sink.ConnectorPoint.Y)); } else { double middleX = source.ConnectorPoint.X + (rectAngle.X - source.ConnectorPoint.X) / 2; linePoints.Add(new Point(middleX, source.ConnectorPoint.Y)); linePoints.Add(new Point(middleX, sink.ConnectorPoint.Y)); } } else { double middleY = sourceRect.Bottom + (sinkRect.Top - sourceRect.Bottom) / 2; linePoints.Add(new Point(source.ConnectorPoint.X, middleY)); linePoints.Add(new Point(rectAngle.X, middleY)); linePoints.Add(new Point(rectAngle.X, sink.ConnectorPoint.Y)); } } linePoints.Add(sink.ConnectorPoint); }
private static Point GetOffsetPoint(ConnectorInfo connector, Rect rect) { Point offsetPoint = new Point(); switch (connector.Type) { case Direction.IN: offsetPoint = new Point(rect.Left, connector.Position.Y); break; case Direction.OUT: offsetPoint = new Point(rect.Right, connector.Position.Y); break; default: break; } return(offsetPoint); }
internal static List <Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation) { _linePoints.Clear(); Rect sourceRect = GetElementRect(source); Point startPoint = source.ConnectorPoint; _linePoints.Add(startPoint); if (!sourceRect.Contains(sinkPoint)) { AddOtherPoints(_linePoints, source, sinkPoint, sourceRect); } else { _linePoints.Add(sinkPoint); } // задание изломов линии на сегменты под 90 градусов OptimizeLine(_linePoints, sourceRect); return(_linePoints); }
private void Init() { using (DatabaseContext db = new DatabaseContext()) { if (db.Info.ToList().Count == 0) { VendorInfo tempVendor = new VendorInfo(); tempVendor.name = "FH-Salzburg"; ConnectorInfo newConnector = new ConnectorInfo(); newConnector.Vendor = tempVendor; newConnector.Version = "0.1.4"; newConnector.UpdateSeq = "relpace-with-latest-update-seq"; newConnector.PeerUUID = Guid.NewGuid().ToString(); db.Info.Add(newConnector); db.SaveChanges(); } } }
/// <summary> /// Получает путь соединяющий 2 вывода /// </summary> /// <param name="source">Вывод-источник</param> /// <param name="sink">Целевой вывод</param> internal static List <Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink) { _linePoints.Clear(); Rect sourceRect = GetElementRect(source); Rect sinkRect = GetElementRect(sink); _linePoints.Add(source.ConnectorPoint); if (!sinkRect.Contains(source.ConnectorPoint) && !sourceRect.Contains(sink.ConnectorPoint)) { AddOtherPoints(_linePoints, source, sink, sourceRect, sinkRect); } else { _linePoints.Add(sink.ConnectorPoint); OptimizeLine(_linePoints, sourceRect); } return(_linePoints); }
private Connection CreateConnection(ITransceiver transceiver, ConnectorInfo ci) { lock (this) { Debug.Assert(_pending.ContainsKey(ci.Connector) && transceiver != null); // // Create and add the connection to the connection map. Adding the connection to the map // is necessary to support the interruption of the connection initialization and validation // in case the communicator is destroyed. // Connection connection; try { if (_destroyed) { throw new CommunicatorDestroyedException(); } connection = new Connection(_communicator, _monitor, transceiver, ci.Connector, ci.Endpoint.NewCompressionFlag(false), null); } catch (System.Exception) { try { transceiver.Close(); } catch (System.Exception) { // Ignore } throw; } _connections.Add(ci.Connector, connection); _connectionsByEndpoint.Add(connection.Endpoint, connection); _connectionsByEndpoint.Add(connection.Endpoint.NewCompressionFlag(true), connection); return(connection); } }
public HttpResponseMessage GetPeersInformation() { try { using (MessageControllerHelper helper = new MessageControllerHelper()) { ConnectorInfo TempConnI = new ConnectorInfo(); try { // TODO: Secure this, what if db info gets deleted while programm is running using (DatabaseContext db = new DatabaseContext()) TempConnI = db.Info.First(); } catch (Exception e) { Console.WriteLine("Error when getting data from Info, e: " + e.Message); throw new Exception(e.Message); } object tempRetObject = new { instance_start_time = TempConnI.InstanceStartTime, update_seq = TempConnI.UpdateSeq, version = TempConnI.Version, vendor = TempConnI.Vendor }; return(helper.GetJsonResponse(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(tempRetObject)))); } } catch (Exception e) { Console.WriteLine("Exception in Init Db, e: " + e.Message); object tempRetObject = new { exception = e.Message }; using (MessageControllerHelper helper = new MessageControllerHelper()) return(helper.GetJsonResponse(HttpStatusCode.InternalServerError, new StringContent(JsonConvert.SerializeObject(tempRetObject)))); } }
/// <summary> /// Creates a new diagram connection for provided pointer id /// </summary> /// <param name="hitTestInfo">The hit test result.</param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException">anchorInfo - null</exception> internal ConnectorInfo CreateDiagramConnection(HitTestInfo hitTestInfo) { ConnectorInfo connectionInfo = new ConnectorInfo() { HostLeft = this.Tranform.TranslateX, HostTop = this.Tranform.TranslateY, HostSize = this.GetSize(), HitTestInfo = hitTestInfo }; switch (hitTestInfo) { case HitTestInfo.AnchorLeft: connectionInfo.Position = new Point(this.Tranform.TranslateX, this.Tranform.TranslateY + connectionInfo.HostSize.Height / 2); connectionInfo.Orientation = ConnectorOrientation.Left; break; case HitTestInfo.AnchorTop: connectionInfo.Position = new Point(this.Tranform.TranslateX + connectionInfo.HostSize.Width / 2, this.Tranform.TranslateY); connectionInfo.Orientation = ConnectorOrientation.Top; break; case HitTestInfo.AnchorRight: connectionInfo.Position = new Point(this.Tranform.TranslateX + connectionInfo.HostSize.Width, this.Tranform.TranslateY + connectionInfo.HostSize.Height / 2); connectionInfo.Orientation = ConnectorOrientation.Right; break; case HitTestInfo.AnchorBottom: connectionInfo.Position = new Point(this.Tranform.TranslateX + connectionInfo.HostSize.Width / 2, this.Tranform.TranslateY + connectionInfo.HostSize.Height); connectionInfo.Orientation = ConnectorOrientation.Bottom; break; default: throw new ArgumentOutOfRangeException(nameof(hitTestInfo), hitTestInfo, null); } return(connectionInfo); }
private APIOperation GetAPIOperation(OperationRequest request) { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = manager.FindConnectorInfo( request.ConnectorKey); if (info == null) { throw new Exception("No such connector: " + request.ConnectorKey); } APIConfigurationImpl config = request.Configuration; //re-wire the configuration with its connector info config.ConnectorInfo = (AbstractConnectorInfo)info; ConnectorFacade facade = ConnectorFacadeFactory.GetInstance().NewInstance(config); return(facade.GetOperation(request.Operation)); }
public void TestConnectorContext() { ConnectorPoolManager.Dispose(); ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.ConnectorPoolConfiguration.MinIdle = 0; config.ConnectorPoolConfiguration.MaxIdle = 0; ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>(); string uid = facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); config = info1.CreateDefaultAPIConfiguration(); config.ConnectorPoolConfiguration.MinIdle = 1; config.ConnectorPoolConfiguration.MaxIdle = 2; facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); uid = facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid); }
internal static Point GetOffsetPoint(ConnectorInfo connector, Rect rect) { Point offsetPoint = new Point(); switch (connector.Orientation) { case ConnectorOrientation.Left: offsetPoint = new Point(rect.Left, connector.Position.Y); break; case ConnectorOrientation.Top: offsetPoint = new Point(connector.Position.X, rect.Top); break; case ConnectorOrientation.Right: offsetPoint = new Point(rect.Right, connector.Position.Y); break; case ConnectorOrientation.Bottom: offsetPoint = new Point(connector.Position.X, rect.Bottom); break; default: break; } return offsetPoint; }
public void TestAttributeTypeMap() { ConnectorPoolManager.Dispose(); ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.ConnectorPoolConfiguration.MinIdle = 0; config.ConnectorPoolConfiguration.MaxIdle = 0; ConnectorFacade facade = ConnectorFacadeFactory.GetInstance().NewInstance(config); HashSet <ConnectorAttribute> createAttributes = new HashSet <ConnectorAttribute>(); IDictionary <string, object> mapAttribute = new Dictionary <string, object>(); mapAttribute["email"] = "*****@*****.**"; mapAttribute["primary"] = true; mapAttribute["usage"] = new List <String>() { "home", "work" }; createAttributes.Add(ConnectorAttributeBuilder.Build("emails", mapAttribute)); Uid uid = facade.Create(ObjectClass.ACCOUNT, createAttributes, null); Assert.AreEqual(uid.GetUidValue(), "*****@*****.**"); ConnectorObject co = facade.GetObject(ObjectClass.ACCOUNT, new Uid("0"), null); object value = ConnectorAttributeUtil.GetSingleValue(co.GetAttributeByName("emails")); Assert.IsTrue(value is IDictionary); Assert.IsTrue(((IDictionary)value)["usage"] is IList); }
/// <summary> /// Добавление точек вокруг элементов для исключения пересечения элементов линией связи /// </summary> private static void AddLineAround(List <Point> linePoints, ConnectorInfo source, ConnectorInfo sink, Rect sourceRect, Rect sinkRect) { // ближайшая угловая точка рамки цели Point nearestSinkPoint = GetNearestNeighborSink(sink, sinkRect, source.ConnectorPoint); // ближе к верху if (Math.Abs(nearestSinkPoint.Y - sinkRect.Top) < 0.0001) { // верхние точки рамки источника Point sourceNeigbor = source.Orientation == ConnectorOrientation.LEFT ? sourceRect.TopLeft : sourceRect.TopRight; Point sourceOpposite = source.Orientation == ConnectorOrientation.LEFT ? sourceRect.TopRight : sourceRect.TopLeft; linePoints.Add(new Point(sourceNeigbor.X, source.ConnectorPoint.Y)); if (nearestSinkPoint.Y <= sourceRect.Top) { linePoints.Add(new Point(sourceNeigbor.X, nearestSinkPoint.Y)); linePoints.Add(nearestSinkPoint); linePoints.Add(new Point(nearestSinkPoint.X, sink.ConnectorPoint.Y)); } else { linePoints.Add(sourceNeigbor); if (sourceOpposite.X <= nearestSinkPoint.X) { linePoints.Add(sourceOpposite); linePoints.Add(new Point(sourceOpposite.X, sink.ConnectorPoint.Y)); } else { linePoints.Add(new Point(nearestSinkPoint.X, sourceOpposite.Y)); linePoints.Add(new Point(nearestSinkPoint.X, sink.ConnectorPoint.Y)); } } } else // ближе к низу { // Нижние точки рамки источника Point sourceNeigbor = source.Orientation == ConnectorOrientation.LEFT ? sourceRect.BottomLeft : sourceRect.BottomRight; Point sourceOpposite = source.Orientation == ConnectorOrientation.LEFT ? sourceRect.BottomRight : sourceRect.BottomLeft; linePoints.Add(new Point(sourceNeigbor.X, source.ConnectorPoint.Y)); if (sourceNeigbor.Y >= nearestSinkPoint.Y) { linePoints.Add(sourceNeigbor); // RIGHT INPUT if (nearestSinkPoint.X >= sourceOpposite.X) { linePoints.Add(sourceOpposite); linePoints.Add(new Point(sourceOpposite.X, sink.ConnectorPoint.Y)); } else { linePoints.Add(new Point(nearestSinkPoint.X, sourceOpposite.Y)); linePoints.Add(new Point(nearestSinkPoint.X, sink.ConnectorPoint.Y)); } } else { linePoints.Add(new Point(sourceNeigbor.X, nearestSinkPoint.Y)); linePoints.Add(nearestSinkPoint); linePoints.Add(new Point(nearestSinkPoint.X, sink.ConnectorPoint.Y)); } } linePoints.Add(sink.ConnectorPoint); }
protected static Point GetNearestNeighborSource(ConnectorInfo source, Point endPoint, Rect rectSource, Rect rectSink, out bool flag) { Point n1, n2; // neighbors GetNeighborCorners(source.Orientation, rectSource, out n1, out n2); if (rectSink.Contains(n1)) { flag = false; return n2; } if (rectSink.Contains(n2)) { flag = true; return n1; } if ((PathFinderHelper.Distance(n1, endPoint) <= PathFinderHelper.Distance(n2, endPoint))) { flag = true; return n1; } else { flag = false; return n2; } }
internal static List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation) { List<Point> linePoints = new List<Point>(); Rect rectSource = GetRectWithMargin(source, 10); Point startPoint = GetOffsetPoint(source, rectSource); Point endPoint = sinkPoint; linePoints.Add(startPoint); Point currentPoint = startPoint; if (!rectSource.Contains(endPoint)) { while (true) { if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource })) { linePoints.Add(endPoint); break; } bool sideFlag; Point n = GetNearestNeighborSource(source, endPoint, rectSource, out sideFlag); linePoints.Add(n); currentPoint = n; if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource })) { linePoints.Add(endPoint); break; } else { Point n1, n2; GetOppositeCorners(source.Orientation, rectSource, out n1, out n2); if (sideFlag) linePoints.Add(n1); else linePoints.Add(n2); linePoints.Add(endPoint); break; } } } else { linePoints.Add(endPoint); } if (preferredOrientation != ConnectorOrientation.None) linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, preferredOrientation); else linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Orientation, GetOpositeOrientation(source.Orientation)); return linePoints; }
/// <summary> /// Проверка на то, видна ли точка цели "напрямую" /// </summary> /// <param name="source">Источник с точкой</param> /// <param name="sinkPoint">Конечная точка</param> /// <param name="sourceRect">Рамка источника</param> private static bool IsPointVisible(ConnectorInfo source, Point sinkPoint, Rect sourceRect) { return(source.Orientation == ConnectorOrientation.LEFT ? sourceRect.Left > sinkPoint.X : sourceRect.Right < sinkPoint.X); }
/// <summary> /// Get a new instance of <see cref="ConnectorFacade" />. /// </summary> /// <param name="connectorInfo">TODO add doc later</param> /// <param name="config">all the configuration that the framework, connector, and pooling needs. It's a Base64 serialised APIConfiguration instance.</param> /// <returns> /// <see cref="ConnectorFacade" /> to call API operations against.</returns> /// <exception cref="ClassNotFoundException"></exception> /// since 1.4 public abstract ConnectorFacade NewInstance(ConnectorInfo connectorInfo, String config);
private static Point GetNearestVisibleNeighborTarget(Point currentPoint, Point endPoint, ConnectorInfo target, Rect rectSource, Rect rectTarget) { GetNeighborCorners(target.Orientation, rectTarget, out var s1, out var s2); var flag1 = IsPointVisible(currentPoint, s1, new[] { rectSource, rectTarget }); var flag2 = IsPointVisible(currentPoint, s2, new[] { rectSource, rectTarget }); if (flag1) // s1 visible { if (flag2) // s1 and s2 visible { if (rectTarget.Contains(s1)) { return(s2); } if (rectTarget.Contains(s2)) { return(s1); } if (Distance(s1, endPoint) <= Distance(s2, endPoint)) { return(s1); } return(s2); } return(s1); } if (flag2) // only s2 visible { return(s2); } return(new Point(double.NaN, double.NaN)); }
public static List <Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo target, bool showLastLine) { var linePoints = new List <Point>(); var rectSource = GetRectWithMargin(source, Margin); var rectTarget = GetRectWithMargin(target, Margin); var startPoint = GetOffsetPoint(source, rectSource); var endPoint = GetOffsetPoint(target, rectTarget); linePoints.Add(startPoint); var currentPoint = startPoint; if (!rectTarget.Contains(currentPoint) && !rectSource.Contains(endPoint)) { while (true) { #region source node if (IsPointVisible(currentPoint, endPoint, new[] { rectSource, rectTarget })) { linePoints.Add(endPoint); break; } var neighbour = GetNearestVisibleNeighborTarget(currentPoint, endPoint, target, rectSource, rectTarget); if (!double.IsNaN(neighbour.X)) { linePoints.Add(neighbour); linePoints.Add(endPoint); break; } if (currentPoint == startPoint) { var n = GetNearestNeighborSource(source, endPoint, rectSource, rectTarget, out var flag); linePoints.Add(n); currentPoint = n; if (!IsRectVisible(currentPoint, rectTarget, new[] { rectSource })) { GetOppositeCorners(source.Orientation, rectSource, out var n1, out var n2); if (flag) { linePoints.Add(n1); currentPoint = n1; } else { linePoints.Add(n2); currentPoint = n2; } if (!IsRectVisible(currentPoint, rectTarget, new[] { rectSource })) { if (flag) { linePoints.Add(n2); currentPoint = n2; } else { linePoints.Add(n1); currentPoint = n1; } } } } #endregion source node #region target node else // from here on we jump to the target node { GetNeighborCorners(target.Orientation, rectTarget, out var s1, out var s2); GetOppositeCorners(target.Orientation, rectTarget, out var n1, out var n2); var n1Visible = IsPointVisible(currentPoint, n1, new[] { rectSource, rectTarget }); var n2Visible = IsPointVisible(currentPoint, n2, new[] { rectSource, rectTarget }); if (n1Visible && n2Visible) { if (rectSource.Contains(n1)) { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); break; } if (rectSource.Contains(n2)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); break; } if (Distance(n1, endPoint) <= Distance(n2, endPoint)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); break; } linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); break; } if (n1Visible) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); break; } linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); break; } #endregion target node } } else { linePoints.Add(endPoint); } linePoints = OptimizeLinePoints(linePoints, new[] { rectSource, rectTarget }, source.Orientation, target.Orientation); CheckPathEnd(source, target, showLastLine, linePoints); return(linePoints); }
public override List <Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine) { List <Point> linePoints = new List <Point>(); Rect rectSource = PathFinderHelper.GetRectWithMargin(source, margin); Rect rectSink = PathFinderHelper.GetRectWithMargin(sink, margin); Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource); Point endPoint = PathFinderHelper.GetOffsetPoint(sink, rectSink); linePoints.Add(startPoint); Point currentPoint = startPoint; if (!rectSink.Contains(currentPoint) && !rectSource.Contains(endPoint)) { while (true) { #region source node if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource, rectSink })) { linePoints.Add(endPoint); currentPoint = endPoint; break; } Point neighbour = GetNearestVisibleNeighborSink(currentPoint, endPoint, sink, rectSource, rectSink); if (!double.IsNaN(neighbour.X)) { linePoints.Add(neighbour); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (currentPoint == startPoint) { bool flag; Point n = GetNearestNeighborSource(source, endPoint, rectSource, rectSink, out flag); linePoints.Add(n); currentPoint = n; if (!IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource })) { Point n1, n2; GetOppositeCorners(source.Orientation, rectSource, out n1, out n2); if (flag) { linePoints.Add(n1); currentPoint = n1; } else { linePoints.Add(n2); currentPoint = n2; } if (!IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource })) { if (flag) { linePoints.Add(n2); currentPoint = n2; } else { linePoints.Add(n1); currentPoint = n1; } } } } #endregion #region sink node else // from here on we jump to the sink node { Point n1, n2; // neighbour corner Point s1, s2; // opposite corner GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2); GetOppositeCorners(sink.Orientation, rectSink, out n1, out n2); bool n1Visible = IsPointVisible(currentPoint, n1, new Rect[] { rectSource, rectSink }); bool n2Visible = IsPointVisible(currentPoint, n2, new Rect[] { rectSource, rectSink }); if (n1Visible && n2Visible) { if (rectSource.Contains(n1)) { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); currentPoint = endPoint; break; } if (rectSource.Contains(n2)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); currentPoint = endPoint; break; } if ((PathFinderHelper.Distance(n1, endPoint) <= PathFinderHelper.Distance(n2, endPoint))) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); currentPoint = endPoint; break; } else { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); currentPoint = endPoint; break; } } else if (n1Visible) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else { linePoints.Add(s1); } linePoints.Add(endPoint); currentPoint = endPoint; break; } else { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else { linePoints.Add(s2); } linePoints.Add(endPoint); currentPoint = endPoint; break; } } #endregion } } else { linePoints.Add(endPoint); } linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource, rectSink }, source.Orientation, sink.Orientation); linePoints.Insert(0, new Point(source.Position.X, source.Position.Y)); linePoints.Add(new Point(sink.Position.X, sink.Position.Y)); return(linePoints); }
public void TestPagedSearch() { ConnectorPoolManager.Dispose(); ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulPoolableConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.ProducerBufferSize = 0; config.ConnectorPoolConfiguration.MinIdle = 1; config.ConnectorPoolConfiguration.MaxIdle = 2; config.ResultsHandlerConfiguration.FilteredResultsHandlerInValidationMode = true; // for paged searches, the filtered results handler should be either disabled or put into validation mode ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); OperationOptionsBuilder builder = new OperationOptionsBuilder(); builder.PageSize = 10; builder.SetSortKeys(new ICF.SortKey(Name.NAME, true)); SearchResult searchResult = null; ISet <Uid> UIDs = new HashSet <Uid>(); int iteration = 0; do { if (null != searchResult) { builder.PagedResultsCookie = searchResult.PagedResultsCookie; } int size = 0; searchResult = facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { if (size >= 10) { Assert.Fail("More then 10 objects was handled!"); } size++; if (UIDs.Contains(obj.Uid)) { Assert.Fail("Duplicate Entry in results"); } return(UIDs.Add(obj.Uid)); } }, builder.Build()); iteration++; Assert.IsNotNull(searchResult); Assert.AreEqual(searchResult.RemainingPagedResults, 100 - (iteration * 10)); } while (searchResult.PagedResultsCookie != null); // Search with paged results offset builder = new OperationOptionsBuilder(); builder.PageSize = 10; builder.PagedResultsOffset = 5; builder.SetSortKeys(new ICF.SortKey(Name.NAME, true)); searchResult = null; UIDs.Clear(); Filter filter = FilterBuilder.EqualTo(ConnectorAttributeBuilder.BuildEnabled(true)); iteration = 0; do { if (null != searchResult) { builder.PagedResultsCookie = searchResult.PagedResultsCookie; } int size = 0; searchResult = facade1.Search(ObjectClass.ACCOUNT, filter, new ResultsHandler() { Handle = obj => { if (size >= 10) { Assert.Fail("More then 10 objects was handled!"); } size++; if (UIDs.Contains(obj.Uid)) { Assert.Fail("Duplicate Entry in results"); } return(UIDs.Add(obj.Uid)); } }, builder.Build()); iteration++; Assert.IsNotNull(searchResult); Assert.AreEqual(searchResult.RemainingPagedResults, Math.Max(50 - (iteration * 15), 0)); } while (searchResult.PagedResultsCookie != null); }
public override ConnectorFacade NewInstance(ConnectorInfo connectorInfo, string config) { Pair<DateTime, ConnectorFacade> facade = CollectionUtil.GetValue(CACHE, config, null); if (null == facade) { lock (CACHE) { facade = CollectionUtil.GetValue(CACHE, config, null); if (null == facade) { facade = Pair<DateTime, ConnectorFacade>.Of(DateTime.Now, base.NewInstance(connectorInfo, config)); CACHE[facade.Second.ConnectorFacadeKey] = facade; } else { facade.First = DateTime.Now; Trace.TraceInformation("ConnectorFacade found in cache"); } } } else { facade.First = DateTime.Now; } return facade.Second; }
public override ConnectorFacade NewInstance(ConnectorInfo connectorInfo, string config) { ConnectorFacade facade = CollectionUtil.GetValue(CACHE, config, null); if (null == facade) { lock (CACHE) { facade = CollectionUtil.GetValue(CACHE, config, null); if (null == facade) { facade = base.NewInstance(connectorInfo, config); CACHE[facade.ConnectorFacadeKey] = facade; } else { Trace.TraceInformation("ConnectorFacade found in cache"); } } } return facade; }
private static Point GetNearestVisibleNeighborSink(Point currentPoint, Point endPoint, ConnectorInfo sink, Rect rectSource, Rect rectSink) { Point s1, s2; // neighbors on sink side GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2); bool flag1 = IsPointVisible(currentPoint, s1, new Rect[] { rectSource, rectSink }); bool flag2 = IsPointVisible(currentPoint, s2, new Rect[] { rectSource, rectSink }); if (flag1) // s1 visible { if (flag2) // s1 and s2 visible { if (rectSink.Contains(s1)) return s2; if (rectSink.Contains(s2)) return s1; if ((Distance(s1, endPoint) <= Distance(s2, endPoint))) return s1; else return s2; } else { return s1; } } else // s1 not visible { if (flag2) // only s2 visible { return s2; } else // s1 and s2 not visible { return new Point(double.NaN, double.NaN); } } }
public override List<Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine) { List<Point> linePoints = new List<Point>(); Rect rectSource = PathFinderHelper.GetRectWithMargin(source, margin); Rect rectSink = PathFinderHelper.GetRectWithMargin(sink, margin); Point startPoint = PathFinderHelper.GetOffsetPoint(source, rectSource); Point endPoint = PathFinderHelper.GetOffsetPoint(sink, rectSink); linePoints.Add(startPoint); Point currentPoint = startPoint; if (!rectSink.Contains(currentPoint) && !rectSource.Contains(endPoint)) { while (true) { #region source node if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource, rectSink })) { linePoints.Add(endPoint); currentPoint = endPoint; break; } Point neighbour = GetNearestVisibleNeighborSink(currentPoint, endPoint, sink, rectSource, rectSink); if (!double.IsNaN(neighbour.X)) { linePoints.Add(neighbour); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (currentPoint == startPoint) { bool flag; Point n = GetNearestNeighborSource(source, endPoint, rectSource, rectSink, out flag); linePoints.Add(n); currentPoint = n; if (!IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource })) { Point n1, n2; GetOppositeCorners(source.Orientation, rectSource, out n1, out n2); if (flag) { linePoints.Add(n1); currentPoint = n1; } else { linePoints.Add(n2); currentPoint = n2; } if (!IsRectVisible(currentPoint, rectSink, new Rect[] { rectSource })) { if (flag) { linePoints.Add(n2); currentPoint = n2; } else { linePoints.Add(n1); currentPoint = n1; } } } } #endregion #region sink node else // from here on we jump to the sink node { Point n1, n2; // neighbour corner Point s1, s2; // opposite corner GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2); GetOppositeCorners(sink.Orientation, rectSink, out n1, out n2); bool n1Visible = IsPointVisible(currentPoint, n1, new Rect[] { rectSource, rectSink }); bool n2Visible = IsPointVisible(currentPoint, n2, new Rect[] { rectSource, rectSink }); if (n1Visible && n2Visible) { if (rectSource.Contains(n1)) { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (rectSource.Contains(n2)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } if ((PathFinderHelper.Distance(n1, endPoint) <= PathFinderHelper.Distance(n2, endPoint))) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } else { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } } else if (n1Visible) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } else { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } } #endregion } } else { linePoints.Add(endPoint); } linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource, rectSink }, source.Orientation, sink.Orientation); linePoints.Insert(0, new Point(source.Position.X, source.Position.Y)); linePoints.Add(new Point(sink.Position.X, sink.Position.Y)); return linePoints; }
private static Point GetNearestNeighborSource(ConnectorInfo source, Point endPoint, Rect rectSource, out bool flag) { Point n1, n2; // neighbors GetNeighborCorners(source.Orientation, rectSource, out n1, out n2); if ((Distance(n1, endPoint) <= Distance(n2, endPoint))) { flag = true; return n1; } else { flag = false; return n2; } }
internal static List<Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine) { var linePoints = new List<Point>(); var rectSource = GetRectWithMargin(source, margin); var rectSink = GetRectWithMargin(sink, margin); var startPoint = GetOffsetPoint(source, rectSource); var endPoint = GetOffsetPoint(sink, rectSink); linePoints.Add(startPoint); var currentPoint = startPoint; if (!rectSink.Contains(currentPoint) && !rectSource.Contains(endPoint)) { while (true) { #region source node if (IsPointVisible(currentPoint, endPoint, new[] {rectSource, rectSink})) { linePoints.Add(endPoint); currentPoint = endPoint; break; } var neighbour = GetNearestVisibleNeighborSink(currentPoint, endPoint, sink, rectSource, rectSink); if (!double.IsNaN(neighbour.X)) { linePoints.Add(neighbour); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (currentPoint == startPoint) { bool flag; var n = GetNearestNeighborSource(source, endPoint, rectSource, rectSink, out flag); linePoints.Add(n); currentPoint = n; if (!IsRectVisible(currentPoint, rectSink, new[] {rectSource})) { Point n1, n2; GetOppositeCorners(source.Orientation, rectSource, out n1, out n2); if (flag) { linePoints.Add(n1); currentPoint = n1; } else { linePoints.Add(n2); currentPoint = n2; } if (!IsRectVisible(currentPoint, rectSink, new[] {rectSource})) { if (flag) { linePoints.Add(n2); currentPoint = n2; } else { linePoints.Add(n1); currentPoint = n1; } } } } #endregion #region sink node else // from here on we jump to the sink node { Point n1, n2; // neighbour corner Point s1, s2; // opposite corner GetNeighborCorners(sink.Orientation, rectSink, out s1, out s2); GetOppositeCorners(sink.Orientation, rectSink, out n1, out n2); var n1Visible = IsPointVisible(currentPoint, n1, new[] {rectSource, rectSink}); var n2Visible = IsPointVisible(currentPoint, n2, new[] {rectSource, rectSink}); if (n1Visible && n2Visible) { if (rectSource.Contains(n1)) { linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (rectSource.Contains(n2)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (Distance(n1, endPoint) <= Distance(n2, endPoint)) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } if (n1Visible) { linePoints.Add(n1); if (rectSource.Contains(s1)) { linePoints.Add(n2); linePoints.Add(s2); } else linePoints.Add(s1); linePoints.Add(endPoint); currentPoint = endPoint; break; } linePoints.Add(n2); if (rectSource.Contains(s2)) { linePoints.Add(n1); linePoints.Add(s1); } else linePoints.Add(s2); linePoints.Add(endPoint); currentPoint = endPoint; break; } #endregion } } else { linePoints.Add(endPoint); } linePoints = OptimizeLinePoints(linePoints, new[] {rectSource, rectSink}, source.Orientation, sink.Orientation); CheckPathEnd(source, sink, showLastLine, linePoints); return linePoints; }
private static void CheckPathEnd(ConnectorInfo source, ConnectorInfo sink, bool showLastLine, List<Point> linePoints) { if (showLastLine) { Point startPoint = new Point(0, 0); Point endPoint = new Point(0, 0); double marginPath = 15; switch (source.Orientation) { case ConnectorOrientation.Left: startPoint = new Point(source.Position.X - marginPath, source.Position.Y); break; case ConnectorOrientation.Top: startPoint = new Point(source.Position.X, source.Position.Y - marginPath); break; case ConnectorOrientation.Right: startPoint = new Point(source.Position.X + marginPath, source.Position.Y); break; case ConnectorOrientation.Bottom: startPoint = new Point(source.Position.X, source.Position.Y + marginPath); break; default: break; } switch (sink.Orientation) { case ConnectorOrientation.Left: endPoint = new Point(sink.Position.X - marginPath, sink.Position.Y); break; case ConnectorOrientation.Top: endPoint = new Point(sink.Position.X, sink.Position.Y - marginPath); break; case ConnectorOrientation.Right: endPoint = new Point(sink.Position.X + marginPath, sink.Position.Y); break; case ConnectorOrientation.Bottom: endPoint = new Point(sink.Position.X, sink.Position.Y + marginPath); break; default: break; } linePoints.Insert(0, startPoint); linePoints.Add(endPoint); } else { linePoints.Insert(0, source.Position); linePoints.Add(sink.Position); } }
public bool HasConnector(ConnectorInfo ci) => _connectors.Contains(ci);
public void Totalize(ConnectorInfo info) { base.Totalize(info); Connected = Connected && info.Connected; Unconnected = Unconnected && info.Unconnected; }
internal async ValueTask NextConnectorAsync() { System.Exception?lastException = null; for (int i = 0; i < _connectors.Count; ++i) { ConnectorInfo connector = _connectors[i]; try { ICommunicatorObserver?obsv = _factory._communicator.Observer; if (obsv != null) { _observer = obsv.GetConnectionEstablishmentObserver(connector.Endpoint, connector.Connector.ToString() !); if (_observer != null) { _observer.Attach(); } } if (_factory._communicator.TraceLevels.Network >= 2) { _factory._communicator.Logger.Trace(_factory._communicator.TraceLevels.NetworkCat, $"trying to establish {connector.Endpoint.Name} connection to " + $"{connector.Connector}"); } // TODO: Connection establishement code needs to be re-factored to use async/await Connection connection = _factory.CreateConnection(connector.Connector.Connect(), connector); await connection.StartAsync().ConfigureAwait(false); if (_observer != null) { _observer.Detach(); } _factory.FinishGetConnection(_connectors, connector, connection, this); return; } catch (CommunicatorDestroyedException ex) { lastException = ex; break; // No need to continue } catch (System.Exception ex) { if (_factory._communicator.TraceLevels.Network >= 2) { Debug.Assert(connector != null); _factory._communicator.Logger.Trace(_factory._communicator.TraceLevels.NetworkCat, $"failed to establish {connector.Endpoint.Name} connection to " + $"{connector.Connector}\n{ex}"); } if (_observer != null) { _observer.Failed(ex.GetType().FullName ?? "System.Exception"); _observer.Detach(); } _factory.HandleConnectionException(ex, _hasMore || (i + 1) < _connectors.Count); lastException = ex; } } _factory.FinishGetConnection(_connectors, lastException !, this); }
public void OnShortConnectorIdNotificationEvent(ConnectorInfo connectorInfo) => _logger.LogDebug("Method invoked '{0}'", nameof(ITouchPortalEventHandler.OnShortConnectorIdNotificationEvent));
public override ConnectorFacade NewInstance(ConnectorInfo connectorInfo, String config) { ConnectorFacade ret = null; if (connectorInfo is LocalConnectorInfoImpl) { try { // create a new Provisioner. ret = new LocalConnectorFacadeImpl((LocalConnectorInfoImpl)connectorInfo, config); } catch (Exception ex) { String connector = connectorInfo.ConnectorKey.ToString(); Trace.TraceError("Failed to create new connector facade: {1}, {2}: {0}", connector, config, ex); throw new ConnectorException(ex); } } else if (connectorInfo is RemoteConnectorInfoImpl) { ret = new RemoteConnectorFacadeImpl((RemoteConnectorInfoImpl)connectorInfo, config); } return ret; }
//----------------------------------------------------------------------------------- public static void Start(string[] args) { ManagementGroup mg = new ManagementGroup("localhost"); IConnectorFrameworkManagement icfm = mg.ConnectorFramework; Guid connectorGuid = new Guid("{6A1F8C0E-B8F1-4147-8C9B-5A2F98F10003}"); MonitoringConnector connector; System.Timers.Timer FeedBackTimer = new System.Timers.Timer(); FeedBackTimer.Elapsed += new ElapsedEventHandler(GetAlertForClosing); FeedBackTimer.Interval = 1000 * 60; FeedBackTimer.Start(); try { if (args.Length == 1) { if (args[0] == "InstallConnector") { ConnectorInfo info = new ConnectorInfo(); info.Description = "Sample connector"; info.DisplayName = "Sample connector"; info.Name = "Sample connector"; connector = icfm.Setup(info, connectorGuid); connector.Initialize(); Console.WriteLine("Connector {0} has been succefuly installed", info.DisplayName); } else if (args[0] == "UninstallConnector") { connector = icfm.GetConnector(connectorGuid); IList<MonitoringConnectorSubscription> subscriptions; subscriptions = icfm.GetConnectorSubscriptions(); foreach (MonitoringConnectorSubscription subscription in subscriptions) { if (subscription.MonitoringConnectorId == connectorGuid) { icfm.DeleteConnectorSubscription(subscription); } } connector.Uninitialize(); icfm.Cleanup(connector); } return; } connector = icfm.GetConnector(connectorGuid); //Обрабатываем предупреждения в бесконечном цикле так как наше приложение является службой Windows while (true) { //Обьявляем перменную типа коллекция для хранения предупреждений ReadOnlyCollection<ConnectorMonitoringAlert> alerts; alerts = connector.GetMonitoringAlerts(); //Запускаем цикл для обработки каждого предупреждения foreach (ConnectorMonitoringAlert alert in alerts) { //Делаем проверку должно ли предупреждение создавать инцидент, если да то переменной flag присваиваем значение Yes. if (alert.ResolutionState == 0) { string flag = "No"; if ((alert.Priority == ManagementPackWorkflowPriority.High) && (alert.Severity == ManagementPackAlertSeverity.Warning)) { flag = "Yes"; } if ((alert.Priority == ManagementPackWorkflowPriority.Normal) && (alert.Severity == ManagementPackAlertSeverity.Error)) { flag = "Yes"; } if ((alert.Priority == ManagementPackWorkflowPriority.High) && (alert.Severity == ManagementPackAlertSeverity.Error)) { flag = "Yes"; } Console.WriteLine("Begin Processing Alert!"); // The criteria specifies that you want to collect // computers running Windows Server 2003. String criteria = "Id = " + "'" +alert.ClassId + "'"; Console.WriteLine(criteria); ManagementPackClassCriteria classCriteria = new ManagementPackClassCriteria(criteria); Console.WriteLine("Querying for data..."); // There should only be one item in the monitoringClasses collection. IList<ManagementPackClass> monitoringClasses = mg.EntityTypes.GetClasses(classCriteria); // Get all instances of computers running Windows Server 2003 in the management group. List<MonitoringObject> targets = new List<MonitoringObject>(); IObjectReader<MonitoringObject> reader = mg.EntityObjects.GetObjectReader<MonitoringObject>(monitoringClasses[0], ObjectQueryOptions.Default); targets.AddRange(reader); string logicalgroup = ""; foreach (MonitoringObject target in targets) { logicalgroup = DisplayRelationshipInformation(target, mg, alert.MonitoringObjectId); Console.WriteLine("SCOM Group: {0}", logicalgroup); if (logicalgroup.Contains("PS.")) { break; } } Log operLog = new Log("log.txt", "C:\\SCOM_OT\\Log"); operLog.Write("Begin Processing Alert: " + alert.Name.ToString() + " with serial number " + i.ToString() + " and ID " + alert.Id.ToString()); Console.WriteLine("SCOM Group Substring: {0}", logicalgroup.Substring(3)); //Send the alert to the other management system with the appropriate API //from the other management system. //Add a comment to the alert. string AlertFilePath; AlertFilePath = "C:\\SCOM_OT\\Alerts\\" + alert.Id.ToString() + ".txt"; System.IO.StreamWriter file = new System.IO.StreamWriter(AlertFilePath, true); file.WriteLine("#{0} Alert received on {1}", i.ToString(), DateTime.Now); file.WriteLine(">> Name: {0}", alert.Name.ToString()); file.WriteLine(">> Id: {0}", alert.Id.ToString()); file.WriteLine(">> SCOM Group: {0}", logicalgroup.Substring(3)); file.WriteLine(">> Category: {0}", alert.Category.ToString()); file.WriteLine(">> ConnectorId: {0}", alert.ConnectorId.ToString()); file.WriteLine(">> ConnectorStatus: {0}", alert.ConnectorStatus.ToString()); file.WriteLine(">> RepeatCount: {0}", alert.RepeatCount.ToString()); file.WriteLine(">> ResolutionState: {0}", alert.ResolutionState.ToString()); file.WriteLine(">> LastModified: {0}", alert.LastModified.ToString()); file.WriteLine(">> LastModifiedByNonConnector: {0}", alert.LastModifiedByNonConnector.ToString()); file.WriteLine(">> Priority: {0}", alert.Priority.ToString()); file.WriteLine(">> Severity: {0}", alert.Severity.ToString()); file.WriteLine(">> Description: {0}", alert.Description); file.WriteLine(">> Monitoring Object ID: {0}", alert.MonitoringObjectId); file.WriteLine(">> Must Generate Incident: {0}", flag); file.WriteLine(">> Processed in OT: No"); file.WriteLine(""); file.Close(); Console.WriteLine("#{0} Alert received on {1}", i.ToString(), DateTime.Now); Console.WriteLine(">> Id: {0}", alert.Id.ToString()); Console.WriteLine(">> Category: {0}", alert.Category.ToString()); Console.WriteLine(">> ConnectorId: {0}", alert.ConnectorId.ToString()); Console.WriteLine(">> ConnectorStatus: {0}", alert.ConnectorStatus.ToString()); Console.WriteLine(">> RepeatCount: {0}", alert.RepeatCount.ToString()); Console.WriteLine(">> ResolutionState: {0}", alert.ResolutionState.ToString()); Console.WriteLine(">> LastModified: {0}", alert.LastModified.ToString()); Console.WriteLine(">> LastModifiedByNonConnector: {0}", alert.LastModifiedByNonConnector.ToString()); Console.WriteLine(">> Priority: {0}", alert.Priority.ToString()); Console.WriteLine(">> Severity: {0}", alert.Severity.ToString()); Console.WriteLine(">> Description: {0}", alert.Description); Console.WriteLine(""); i = i + 1; //Console.WriteLine("\nAlert Resolution State Before: " + alert.ResolutionState.ToString()); alert.ResolutionState = 11; //Console.WriteLine("\nAlert Resolution State After: " + alert.ResolutionState.ToString()); alert.Update("Alert has been forwarded to OT"); operLog.Write("End Processing Alert: " + alert.Name.ToString() + " with serial number " + i.ToString() + " and ID " + alert.Id.ToString()); } } //Wait for a minute before checking for new alerts again. Thread.Sleep(5 * 1000); } } catch (EnterpriseManagementException error) { Console.WriteLine(error.Message); } }