/// <summary> /// Ends dragging of an object by attaching it to the given connector. /// </summary> /// <param name="target">The connector for attaching of a dragging object.</param> public void Drop(IUriPlacementConnector target) { var dragged = this._connected; target.Connect(dragged); this._uriDisconnectTable[dragged] = target; this._connected = null; this._data.Clear(); }
public void ThrowsExceptionWhenGettingPlacementConnectorForUnknownResolved() { var table = new UriDisconnectTable(); IUriPlacementConnector connector = null; var resolved = "unknown123"; ExceptionAssert.Throws <KeyNotFoundException>( ex => ex.Message.Equals(string.Format(Properties.Resources.UriResolvedNotRegisteredForDisconnect, resolved)), () => connector = table[resolved]); }
public void IsDraggingReturnsFalseAfterDisconnect() { var connected = new object(); var connector = Substitute.For <IUriPlacementConnector>(); var dragDrop = new ConnectedDragDrop(this._uriDisconnectTable); dragDrop.Drag(connected); IUriPlacementConnector dragDropConnector = dragDrop; dragDropConnector.Disconnect(connected); Assert.IsFalse(dragDrop.IsDragging(connected)); Assert.IsFalse(dragDrop.IsActive); }
/// <summary> /// Ensures that a given resolved object is refreshed if needed. /// </summary> /// <param name="resolved">The object resolved by URI.</param> /// <param name="placementConnector">The <see cref="IUriPlacementConnector"/>, /// used to connect the resolved to user interface.</param> private void SendRefresh(object resolved, IUriPlacementConnector placementConnector) { if (placementConnector.IsResponsibleForRefresh) { return; } var refreshable = resolved as IRefreshable; if (refreshable == null) { return; } refreshable.Refresh(); }
public void RaisesDraggedClosedOnDisconnect() { var connected = new object(); var connector = Substitute.For <IUriPlacementConnector>(); var dragDrop = new ConnectedDragDrop(this._uriDisconnectTable); dragDrop.Drag(connected); var wasRaised = false; dragDrop.DraggedClosed += (sender, e) => wasRaised = true; IUriPlacementConnector dragDropConnector = dragDrop; dragDropConnector.Disconnect(connected); Assert.IsTrue(wasRaised); }
public void DisposesDataOnDisconnect() { var connected = new object(); var dragDrop = new ConnectedDragDrop(this._uriDisconnectTable); dragDrop.Drag(connected); var key1 = new ConnectedDragDropKey <IDisposable>(); var key2 = new ConnectedDragDropKey <IContainer>(); var disposable1 = Substitute.For <IDisposable>(); var disposable2 = Substitute.For <IContainer>(); dragDrop.SetData(key1, disposable1); dragDrop.SetData(key2, disposable2); IUriPlacementConnector dragDropConnector = dragDrop; dragDropConnector.Disconnect(connected); disposable1.Received(1).Dispose(); disposable2.Received(1).Dispose(); }
/// <summary> /// Tries to make the object resolved via the URI available in the shell. /// </summary> /// <param name="uri">The URI of the resolved object.</param> /// <param name="resolved">The object resolved via the URI.</param> /// <param name="placementConnector"><see cref="IUriPlacementConnector"/> /// for connecting the object to the user interface.</param> /// <param name="appendToDisposable">When this method returns, contains the action that allows to add a <see cref="IDisposable"/> /// to the group of <see cref="IDisposable"/> in the metadata.</param> /// <returns><see cref="IDisposable"/> registered in the metadata.</returns> private IDisposable Connect(Uri uri, object resolved, IUriPlacementConnector placementConnector, out Action <IDisposable> appendToDisposable) { placementConnector.Connect(resolved); try { var composite = new CompositeDisposable(); appendToDisposable = composite.Add; this._uriResolvedObjectHolder.Add(resolved, new UriResolvedMetadata(uri, composite)); this._uriDisconnectTable[resolved] = placementConnector; return(composite); } catch (Exception ex) { if (!ex.IsCritical()) { // When failed to add the object in the holder - disconnect it from the UI. placementConnector.Disconnect(resolved); } throw; } }
public void Drop(IUriPlacementConnector target) { Contract.Requires <ArgumentNullException>(target != null); Contract.Requires <InvalidOperationException>(this.IsActive); }