예제 #1
0
        public void Remove()
        {
            foreach (var connection in ConnectionsFrom)
            {
                // remove shapes
                connection.RemoveFromUICollection((Parent as Canvas).Children);
                // remove connection from connected element
                connection.Left.RemoveConnection(connection);
                // remove connection from global list
                Workspace.Connections.Remove(connection);
            }

            foreach (var connection in ConnectionsTo)
            {
                // remove shapes
                connection.RemoveFromUICollection((Parent as Canvas).Children);
                // remove connection from connected element
                connection.Right.RemoveConnection(connection);
                // remove connection from global list
                Workspace.Connections.Remove(connection);
            }

            // remove all connections
            ConnectionsFrom.Clear();
            ConnectionsTo.Clear();

            // remove user control
            (Parent as Canvas).Children.Remove(this);
        }
예제 #2
0
        private void HilightInputAnchorOffByName(string name)
        {
            var anchor = GetElementByName(name);

            if (anchor == null)
            {
                return;
            }

            var inputColor = ConnectionsFrom.SingleOrDefault(c => c.RightAnchorName == name)?.Left?.CustomColor ?? InputBackground;

            // set anchor color
            (anchor as Rectangle).Fill = new SolidColorBrush(inputColor);

            var label = GetElementByName((anchor as Rectangle).Name.Replace(InputAnchorPrefix, LabelPrefix)) as Label;

            if (label != null)
            {
                label.Foreground = new SolidColorBrush(TextForeground);
            }

            // set connection color
            var connection = ConnectionsFrom.SingleOrDefault(c => c.RightAnchorName == name);

            if (connection != null)
            {
                connection.Hilight(inputColor);
            }

            Cursor = Cursors.Arrow;
        }
예제 #3
0
        public virtual void AddConnectionFrom(Connection connection, bool execute = true)
        {
            ConnectionsFrom.Add(connection);
            EnableInputElement(connection.RightAnchorName, false);

            if (execute)
            {
                Execute(Guid.NewGuid());
            }
        }
예제 #4
0
        /// <summary>
        /// resets input anchor background color based on connection
        /// </summary>
        /// <param name="name"></param>
        public void ResetInputAnchorColor(string name)
        {
            var anchor = GetElementByName(name);

            if (anchor == null)
            {
                return;
            }

            var inputColor = ConnectionsFrom.SingleOrDefault(c => c.RightAnchorName == name)?.Left?.CustomColor ?? InputBackground;

            // set anchor color
            (anchor as Rectangle).Fill = new SolidColorBrush(inputColor);
        }
예제 #5
0
        public virtual void RemoveConnection(Connection connection)
        {
            if (ConnectionsTo.Remove(connection))
            {
                HilightOutputAnchorOffByName(connection.LeftAnchorName);
            }

            if (ConnectionsFrom.Remove(connection))
            {
                // set right input value to null
                var rightProperty = NodeInstance.GetType().GetProperty(connection.RightPropertyName);
                if (rightProperty != null)
                {
                    rightProperty.SetValue(NodeInstance, null);
                }

                EnableInputElement(connection.RightAnchorName);
                HilightInputAnchorOffByName(connection.RightAnchorName);
            }
        }
예제 #6
0
        protected void HilightInputAnchorOn(object sender, MouseEventArgs e)
        {
            var anchorName = (sender as FrameworkElement).Name;
            var connection = ConnectionsFrom.SingleOrDefault(c => c.RightAnchorName == anchorName);

            // allow hilight only if connection is in progress and rightAnchor is valid, or if no connection is in progress and right anchor is not empty
            if ((Workspace.NewConnection != null && Workspace.CheckConnectionInProgress(this, anchorName)) || Workspace.NewConnection == null && connection != null)
            {
                (sender as Rectangle).Fill = new SolidColorBrush(Colors.White);

                var label = GetElementByName((sender as Rectangle).Name.Replace(InputAnchorPrefix, LabelPrefix)) as Label;
                if (label != null)
                {
                    label.Foreground = new SolidColorBrush(Colors.White);
                }

                if (connection != null)
                {
                    connection.Hilight(Colors.White);
                }

                Cursor = Cursors.Hand;
            }
        }
예제 #7
0
        public virtual Guid Execute(Guid transactionId)
        {
            if (LastTransactionId == transactionId || (ConnectionsFrom.Count != 0 && ConnectionsFrom.All(c => c.TransactionId == transactionId)))
            {
                return(LastTransactionId);
            }

            try
            {
                var stopWatch = new Stopwatch();

                foreach (var connection in ConnectionsFrom)
                {
                    if (connection.TransactionId == transactionId)
                    {
                        continue;
                    }

                    // generate output from left node
                    (connection.Left as Node).Execute(transactionId);

                    // get left output value
                    var leftNode  = connection.Left.NodeInstance;
                    var leftValue = leftNode
                                    .GetType()
                                    .GetProperty(connection.LeftPropertyName)
                                    .GetValue(leftNode);

                    // set right input value
                    var rightProperty = NodeInstance?.GetType().GetProperty(connection.RightPropertyName);
                    if (rightProperty != null)
                    {
                        rightProperty.SetValue(NodeInstance, Common.Tools.Convert.ChangeType(leftValue, rightProperty.PropertyType));
                    }

                    connection.TransactionId = transactionId;
                }

                if (NodeInstance != null && LastTransactionId != transactionId)
                {
                    try
                    {
                        stopWatch.Reset();
                        stopWatch.Start();

                        NodeInstance.Execute();
                        RaiseImpulseEvent();

                        stopWatch.Stop();

                        // log node input & output
                        var nodeName   = AttributeHelper.GetValue <NodeInfoAttribute, string>(NodeInstance.GetType(), nameof(NodeInfoAttribute.DisplayName)) ?? NodeInstance.GetType().Name;
                        var nodeInputs = (NodeInstance as ILoggable)?.GetInputs()
                                         ?.Select(i => i == null ? null : (i.Length < LOG_MAX_INPUT_LENGTH ? i : (i.Substring(0, LOG_MAX_INPUT_LENGTH) + "...")).Replace(Environment.NewLine, "\\r\\n"));
                        var nodeOutputs = (NodeInstance as ILoggable)?.GetOutputs()
                                          ?.Select(i => i == null ? null : (i.Length < LOG_MAX_OUTPUT_LENGTH ? i : (i.Substring(0, LOG_MAX_OUTPUT_LENGTH) + "...")).Replace(Environment.NewLine, "\\r\\n"));
                        Log.WriteLine($"{ CustomNodeName.Text }:{ nodeName }('{ string.Join("', '", nodeInputs ?? new string[] { }) }')=['{ string.Join("', '", nodeOutputs ?? new string[] { }) }'] | { stopWatch.ElapsedMilliseconds }ms");

                        LastTransactionId = transactionId;
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(ex.ToString());
                    }
                }

                foreach (var outputConnection in ConnectionsTo)
                {
                    outputConnection.Right.Execute(transactionId);
                }
            }
            catch (FriendlyException ex)
            {
                Log.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString());
            }

            return(LastTransactionId);
        }