/// <summary>
        /// Register input and output handlers that store the data in the mapper as GraphMLAttributes resp. can read them back.
        /// </summary>
        private void EnableDataPersistence()
        {
            // We get the IO handler that is used by the GraphControl for serialization and deserialization.
            var ioh = graphControl.GraphMLIOHandler;

            IMapperRegistry           registry   = manager.MasterGraph.MapperRegistry;
            IMapper <INode, DateTime> dateMapper = registry.GetMapper <INode, DateTime>(DateTimeMapperKey);

            if (dateMapper != null)
            {
                // The OutputHandler just stores the string value of the attribute
                // We need to provide the symbolic name of the attribute in the GraphML file, the data source as an IMapper and the
                // GraphML type of the attribute
                ioh.AddOutputMapper(DateTimeMapperKey, null, dateMapper, delegate(object args, HandleSerializationEventArgs e) {
                    if (e.Item is DateTime)
                    {
                        e.Writer.WriteString(((DateTime)e.Item).ToString(CultureInfo.InvariantCulture));
                    }
                    e.Handled = true;
                }, KeyType.String);

                // To read back a DateTime value from a string GraphML attribute, we have to provide an additional (very simple...) callback method.
                ioh.AddInputMapper((elem) => GraphMLIOHandler.MatchesName(elem, DateTimeMapperKey) && GraphMLIOHandler.MatchesType(elem, KeyType.String), dateMapper,
                                   delegate(object args, HandleDeserializationEventArgs e) {
                    //The actual value is a text node that can be retrieved from the event
                    try {
                        DateTime dateTime = DateTime.Parse(e.XmlNode.ToString(), CultureInfo.InvariantCulture);
                        e.Result          = dateTime;
                    } catch (Exception exception) {
                        Console.WriteLine(exception);
                        e.Result = DateTime.Now;
                    }
                });
            }
        }
Пример #2
0
 protected RestSharpRepository(ISearchResultsBuilder resultsBuilder,
                               IAbstractContextFactory contextFactory,
                               IMapperRegistry mapperRegistry,
                               IRestRequestBuilder <TTargetEntity, TTargetEntityId> restRequestBuilder)
     : base(resultsBuilder, contextFactory, mapperRegistry, restRequestBuilder)
 {
 }
Пример #3
0
 public TestDerivedManager(
     IMapperRegistry mapper,
     IProvider <int, TestEntity> provider,
     IValidationManager <TestEntity> validationManager,
     IWorkflowManager <TestEntity> workflowManager = null)
     : base(provider, validationManager, workflowManager)
 {
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RestRepositoryBase{TEntity, TTargetEntity, TEntityId, TTargetEntityId}"/> class.
 /// </summary>
 /// <param name="resultsBuilder">The results builder.</param>
 /// <param name="contextFactory">The context factory.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="restRequestBuilder">The rest request builder.</param>
 protected RestRepositoryBase(ISearchResultsBuilder resultsBuilder,
                              IAbstractContextFactory contextFactory,
                              IMapperRegistry mapperRegistry,
                              IRestRequestBuilder <TTargetEntity, TTargetEntityId> restRequestBuilder)
 {
     Context            = contextFactory.Create <IRestContext>(typeof(TTargetEntity));
     _resultsBuilder    = resultsBuilder;
     MapperRegistry     = mapperRegistry;
     RestRequestBuilder = restRequestBuilder;
 }
Пример #5
0
        private void ClearPreferredLabelPlacement(IGraph graph)
        {
            IMapperRegistry registry = graph.MapperRegistry;

            registry.RemoveMapper(LayoutGraphAdapter.EdgeLabelLayoutPreferredPlacementDescriptorDpKey);
            if (originalMapper != null)
            {
                registry.AddMapper(LayoutGraphAdapter.EdgeLabelLayoutPreferredPlacementDescriptorDpKey, originalMapper);
                originalMapper = null;
            }
        }
        /// <summary>
        /// Setup tooltips that return the value that is stored in the mapper.
        /// </summary>
        /// <remarks>
        /// Dynamic tooltips are implemented by adding a tooltip provider as an event handler for the
        /// <see cref="GraphEditorInputMode.QueryItemToolTip" /> event of the GraphEditorInputMode using the
        /// <see cref="QueryItemToolTipEventArgs{T}" /> parameter. This parameter provides three relevant
        /// properties:
        /// <list type="bullet">
        /// <item>
        /// <description>
        /// The <see cref="ToolTipQueryEventArgs.Handled" /> property is a flag which indicates
        /// whether the tooltip was already set by one of possibly several tooltip providers.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// The <see cref="QueryItemToolTipEventArgs{T}.Item" /> property contains the <see cref="IModelItem" />
        /// the mouse hovers over.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// The tooltip is set by setting the <see cref="ToolTipQueryEventArgs.ToolTip" />
        /// property.
        /// </description>
        /// </item>
        /// </list>
        /// </remarks>
        private void SetupTooltips()
        {
            GraphEditorInputMode geim = graphControl.InputMode as GraphEditorInputMode;

            if (geim != null)
            {
                geim.ToolTipItems      = GraphItemTypes.Node;
                geim.QueryItemToolTip +=
                    delegate(object src, QueryItemToolTipEventArgs <IModelItem> eventArgs) {
                    if (eventArgs.Handled)
                    {
                        // A tooltip has already been assigned -> nothing to do.
                        return;
                    }
                    INode hitNode = eventArgs.Item as INode;
                    if (hitNode == null)
                    {
                        return;
                    }
                    // Since the node the user interacts with is an instance on the managed view,
                    // rather than on the master graph to which we've bound our data,
                    // we retrieve the mapper indirectly through its symbolic name.
                    // The folding framework automagically returns an IMapper instance that translates
                    // to the original elements. If we were not using folding, this step would be unnecessary
                    // and we could use the mapper instance directly on the original nodes.
                    IMapperRegistry           registry   = Graph.MapperRegistry;
                    IMapper <INode, DateTime> dateMapper =
                        registry.GetMapper <INode, DateTime>(DateTimeMapperKey);
                    if (dateMapper != null)
                    {
                        // Found a suitable mapper.
                        // Finds out if a node is under the current location.
                        // Set the tooltip.
                        eventArgs.ToolTip = dateMapper[hitNode].ToString();

                        // Indicate that the tooltip has been set.
                        eventArgs.Handled = true;
                    }
                };

                // Add a little offset to the tooltip such that it is not obscured by the mouse pointer.
                geim.MouseHoverInputMode.ToolTipLocationOffset = new PointD(20, 20);
            }
        }
Пример #7
0
        private void SetupPreferredLabelPlacement(IGraph graph)
        {
            IMapperRegistry registry = graph.MapperRegistry;

            originalMapper = registry.GetMapper <ILabel, PreferredPlacementDescriptor>(
                LayoutGraphAdapter.EdgeLabelLayoutPreferredPlacementDescriptorDpKey);
            registry.CreateDelegateMapper(LayoutGraphAdapter.EdgeLabelLayoutPreferredPlacementDescriptorDpKey,
                                          delegate(ILabel label) {
                var oldDescriptor = originalMapper != null ? originalMapper[label] : null;
                var newDescriptor = oldDescriptor != null
                                                 ? new PreferredPlacementDescriptor(oldDescriptor)
                                                 : new PreferredPlacementDescriptor
                {
                    PlaceAlongEdge = LabelPlacements.Anywhere,
                    SideOfEdge     = LabelPlacements.Anywhere
                };
                SetPreferredSide(newDescriptor, oldDescriptor, label.LayoutParameter.Model);
                return(newDescriptor);
            });
        }
        public void OnLoaded(object source, EventArgs args)
        {
            EnableFolding();

            InitializeHighlightStyles();

            InitializeInputMode();

            IGraph graph = graphControl.Graph;

            graphControl.FileOperationsEnabled = true;

            IMapperRegistry masterRegistry = graph.GetFoldingView().Manager.MasterGraph.MapperRegistry;

            masterRegistry.CreateWeakMapper <INode, string>("ToolTip");
            masterRegistry.CreateWeakMapper <INode, string>("Description");
            masterRegistry.CreateWeakMapper <INode, string>("Url");
            masterRegistry.CreateWeakMapper <IGraph, string>("GraphDescription");

            graphControl.CurrentItemChanged += OnCurrentItemChanged;

            var ioHandler = graphControl.GraphMLIOHandler;

            ioHandler.AddGraphOutputData("GraphDescription", (g) => graphDescriptionTextBlock.Text);
            ioHandler.AddGraphInputData <string>("GraphDescription", (g, v) => graphDescriptionTextBlock.Text = v);

            ioHandler.AddRegistryInputMapper <INode, string>("Description");
            ioHandler.AddRegistryOutputMapper <INode, string>("Description", "Description");
            ioHandler.AddRegistryInputMapper <INode, string>("ToolTip");
            ioHandler.AddRegistryOutputMapper <INode, string>("ToolTip", "ToolTip");
            ioHandler.AddRegistryInputMapper <INode, string>("Url");
            ioHandler.AddRegistryOutputMapper <INode, string>("Url", "Url");

            graphChooserBox.ItemsSource = new[]
            {
                "computer-network", "movies", "family-tree", "hierarchy", "nesting",
                "social-network", "uml-diagram", "large-tree",
            };
            graphChooserBox.SelectedIndex = 0;
            graphControl.FitGraphBounds();
        }
Пример #9
0
        protected override void OnLoad(EventArgs e)
        {
            IGraph graph = graphControl.Graph;

            IMapperRegistry masterRegistry = graph.GetFoldingView().Manager.MasterGraph.MapperRegistry;

            masterRegistry.CreateWeakMapper <INode, string>("ToolTip");
            masterRegistry.CreateWeakMapper <INode, string>("Description");
            masterRegistry.CreateWeakMapper <INode, string>("Url");
            masterRegistry.CreateWeakMapper <IGraph, string>("GraphDescription");

            graphControl.CurrentItemChanged += OnCurrentItemChanged;

            InitializeHighlightStyles();

            InitializeInputMode();

            graphChooserBox.Items.AddRange(new[] { "computer-network", "movies", "family-tree", "hierarchy", "nesting", "social-network", "uml-diagram", "large-tree", });
            graphChooserBox.SelectedIndex = 0;

            graphControl.FitGraphBounds();
        }
Пример #10
0
        protected override Task RunModule()
        {
            IMapperRegistry registry      = CurrentIGraph.MapperRegistry;
            OptionGroup     toplevelGroup = Handler.GetGroupByName(TOP_LEVEL);

            if ((bool)toplevelGroup[ClearAllConstraints].Value)
            {
                //deregistriere den Mapper, d.h. port constraints werden nicht mehr vorgegeben.
                registry.RemoveMapper(PortConstraintKeys.SourceGroupIdDpKey);
                registry.RemoveMapper(PortConstraintKeys.TargetGroupIdDpKey);
                sourceIDMapper = null;
                targetIDMapper = null;
            }
            else
            {
                registry.RemoveMapper(PortConstraintKeys.SourceGroupIdDpKey);
                registry.RemoveMapper(PortConstraintKeys.TargetGroupIdDpKey);

                if (sourceIDMapper == null)
                {
                    sourceIDMapper = new DictionaryMapper <IEdge, object>();
                }
                if (targetIDMapper == null)
                {
                    targetIDMapper = new DictionaryMapper <IEdge, object>();
                }

                string scope = (string)toplevelGroup[Scope].Value;

                string sourceId = toplevelGroup[SourceID].Value.ToString();
                string targetId = toplevelGroup[TargetID].Value.ToString();

                foreach (IEdge edge in CurrentIGraph.Edges)
                {
                    bool isSelected = false;
                    switch (scope)
                    {
                    case ScopeAllEdges:
                        isSelected = true;
                        break;

                    case ScopeSelectedEdges:
                        isSelected = IsSelected(Context, edge);
                        break;

                    case ScopeEdgesAtSelectedNodes:
                        IPort sourcePort = edge.SourcePort;
                        IPort targetPort = edge.TargetPort;
                        isSelected = IsSelected(Context, sourcePort) ||
                                     IsSelected(Context, targetPort) ||
                                     IsSelected(Context, sourcePort.Owner) ||
                                     IsSelected(Context, targetPort.Owner);
                        break;
                    }
                    if (isSelected)
                    {
                        sourceIDMapper[edge] = sourceId.Length > 0 ? sourceId : null;
                        targetIDMapper[edge] = targetId.Length > 0 ? targetId : null;
                    }
                }

                registry.AddMapper(PortConstraintKeys.SourceGroupIdDpKey,
                                   sourceIDMapper);
                registry.AddMapper(PortConstraintKeys.TargetGroupIdDpKey,
                                   targetIDMapper);
            }
            return(Task.FromResult <object>(null));
        }
Пример #11
0
 public MappingEngine(IMapperFactoryRegistry factoryRegistry, IMapperRegistry mapperRegistry)
 {
     FactoryRegistry = factoryRegistry;
     MapperRegistry  = mapperRegistry;
 }
Пример #12
0
 public static IMapper <K, V> AddMapper <K, V>(this IMapperRegistry registry, object key, MapperDelegate <K, V> mapperDelegate)
 {
     return(registry.CreateDelegateMapper(key, mapperDelegate));
 }
Пример #13
0
 public static IMapper <K, V> AddDictionaryMapper <K, V>(this IMapperRegistry registry, object key)
 {
     return(registry.CreateMapper <K, V>(key));
 }
Пример #14
0
        protected override Task RunModule()
        {
            IMapperRegistry registry      = CurrentIGraph.MapperRegistry;
            OptionGroup     toplevelGroup = Handler.GetGroupByName(TOP_LEVEL);

            if ((bool)toplevelGroup[ClearAllConstraints].Value)
            {
                //deregistriere den Mapper, d.h. port constraints werden nicht mehr vorgegeben.
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);
                sourcePCMapper = null;
                targetPCMapper = null;
            }
            else
            {
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);

                if (sourcePCMapper == null)
                {
                    sourcePCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }
                if (targetPCMapper == null)
                {
                    targetPCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }

                string             scope      = (string)toplevelGroup[Scope].Value;
                OptionGroup        spcg       = (OptionGroup)toplevelGroup.GetGroupByName(SourcePortConstraints);
                OptionGroup        tpcg       = (OptionGroup)toplevelGroup.GetGroupByName(TargetPortConstraints);
                PortConstraintType sourceType = (PortConstraintType)spcg[PortConstraintStr].Value;
                bool strongSource             = (bool)spcg[StrongPortConstraint].Value;
                PortConstraintType targetType = (PortConstraintType)tpcg[PortConstraintStr].Value;
                bool strongTarget             = (bool)spcg[StrongPortConstraint].Value;

                foreach (IEdge edge in CurrentIGraph.Edges)
                {
                    bool isSelected = false;
                    switch (scope)
                    {
                    case ScopeAllEdges:
                        isSelected = true;
                        break;

                    case ScopeSelectedEdges:
                        isSelected = IsSelected(Context, edge);
                        break;

                    case ScopeEdgesAtSelectedNodes:
                        IPort sourcePort = edge.SourcePort;
                        IPort targetPort = edge.TargetPort;
                        isSelected = IsSelected(Context, sourcePort) ||
                                     IsSelected(Context, targetPort) ||
                                     IsSelected(Context, sourcePort.Owner) ||
                                     IsSelected(Context, targetPort.Owner);
                        break;
                    }
                    if (isSelected)
                    {
                        sourcePCMapper[edge] = CreatePortConstraint(edge, sourceType, true, strongSource);
                        targetPCMapper[edge] = CreatePortConstraint(edge, targetType, false, strongTarget);
                    }
                }

                registry.AddMapper(PortConstraintKeys.SourcePortConstraintDpKey,
                                   sourcePCMapper);
                registry.AddMapper(PortConstraintKeys.TargetPortConstraintDpKey,
                                   targetPCMapper);
            }
            return(Task.FromResult <object>(null));
        }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RestSharpClient"/> class.
 /// </summary>
 /// <param name="mapper">The mapper.</param>
 /// <summary>
 /// Initializes a new instance of the <see cref="RestSharpClient"/> class.
 /// </summary>
 /// <param name="mapper">The mapper.</param>
 public RestSharpClient(IMapperRegistry mapper)
 {
     _mapper = mapper;
 }
Пример #16
0
 protected TransactionScript(IRepositoryRegistry repositoryRegistry, IMapperRegistry mapperRegistry)
 {
     RepositoryRegistry = repositoryRegistry;
     MapperRegistry     = mapperRegistry;
 }