示例#1
0
        /// <summary>
        /// Creates a node
        /// </summary>
        /// <param name="shape"></param>
        /// <returns></returns>
        object IObservableGraphSource.CreateNode(IShape shape)
        {
            IsDirty = true;
            if (shape is BaseNodeShape)
            {
                var baseNodeShape = shape as BaseNodeShape;

                var def = NodeDefinitions.FirstOrDefault(x => x.Name == baseNodeShape.Name);

                var nodeConfig = new Configuration.NodeConfiguration
                {
                    Id        = Guid.NewGuid(),
                    ClassName = def.Name,
                    NodeType  = def is ActionNodeDefinition ? "ActionNode" : "EventNode"
                };

                this.flowConfiguration.Nodes.Add(nodeConfig);

                NodeViewModel nodeViewModel = null;

                if (def is ActionNodeDefinition)
                {
                    nodeViewModel             = new ActionNodeViewModel(def, nodeConfig);
                    baseNodeShape.DataContext = nodeViewModel;
                }
                else if (def is EventNodeDefinition)
                {
                    nodeViewModel             = new EventNodeViewModel(def, nodeConfig);
                    baseNodeShape.DataContext = nodeViewModel;
                }

                baseNodeShape.CreateConnectors();
                baseNodeShape.Height = nodeViewModel.Height;
                baseNodeShape.Width  = nodeViewModel.Width;
                return(nodeViewModel);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Fills the configuration values
        /// </summary>
        private void FillConfiguration()
        {
            if (!flowConfiguration.Nodes.Any())
            {
                return;
            }

            // create node view models
            foreach (var node in flowConfiguration.Nodes)
            {
                NodeViewModel nodeViewModel  = null;
                var           nodeDefinition = NodeDefinitions.Where(x => x.Name == node.ClassName).FirstOrDefault();

                if (node.NodeType == "ActionNode")
                {
                    nodeViewModel = new ActionNodeViewModel(nodeDefinition, node);
                }
                else if (node.NodeType == "EventNode")
                {
                    nodeViewModel = new EventNodeViewModel(nodeDefinition, node);
                }

                Nodes.Add(nodeViewModel);
            }

            // create flow links
            foreach (var flow in flowConfiguration.Links)
            {
                var sourceNodeViewModel      = Nodes.Where(x => x.Id == flow.From.NodeId).FirstOrDefault();
                var sourceConnectorViewModel = sourceNodeViewModel.FlowPins.Where(x => x.Name == flow.From.PinName).FirstOrDefault();

                var targetNodeViewModel      = Nodes.Where(x => x.Id == flow.To.NodeId).FirstOrDefault();
                var targetConnectorViewModel = targetNodeViewModel.FlowPins.Where(x => x.Name == flow.To.PinName).FirstOrDefault();

                var connectionViewModel = new NodeConnectionViewModel(sourceNodeViewModel, targetNodeViewModel, sourceConnectorViewModel, targetConnectorViewModel);
                Connections.Add(connectionViewModel);
            }

            // create data pins
            foreach (var pin in flowConfiguration.Pins)
            {
                var sourceNodeViewModel      = Nodes.Where(x => x.Id == pin.From.NodeId).FirstOrDefault();
                var sourceConnectorViewModel = sourceNodeViewModel.DataPins.Where(x => x.Name == pin.From.PinName).FirstOrDefault();

                var targetNodeViewModel      = Nodes.Where(x => x.Id == pin.To.NodeId).FirstOrDefault();
                var targetConnectorViewModel = targetNodeViewModel.DataPins.Where(x => x.Name == pin.To.PinName).FirstOrDefault();

                var connectionViewModel = new NodeConnectionViewModel(sourceNodeViewModel, targetNodeViewModel, sourceConnectorViewModel, targetConnectorViewModel);
                Connections.Add(connectionViewModel);

                // if the target connector is a generic data type, update all other generic types to the source data type
                if (targetConnectorViewModel.IsGeneric)
                {
                    (targetNodeViewModel as ActionNodeViewModel).UpdateDataTypes(sourceConnectorViewModel.DataConnectorType);
                }
            }

            // create workflow variables
            foreach (var variable in flowConfiguration.Variables)
            {
                Variables.Add(new FlowVariable
                {
                    Name  = variable.Name,
                    Value = variable.Value,
                    Type  = variable.Type
                });
            }
        }