Ejemplo n.º 1
0
        /// <summary>
        /// 生成if action
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private Core.Action.Models.ActionModel GenerateIFAction(ActionItem action)
        {
            //action input
            var inputdata = action.Builder.GetInputModelData() as IFActionInputModel;

            //else item
            var elseActionItem = ActionItems.Where(m => m.Action.ParentID == action.Action.ID && m.Action.ActionType == UI.Types.ActionType.IFElse).FirstOrDefault();
            //end item
            var endActionItem = ActionItems.Where(m => m.Action.ParentID == action.Action.ID && m.Action.ActionType == UI.Types.ActionType.IFEnd).FirstOrDefault();
            //pass actions
            var passActionItems = ActionItems.Where(m => m.Action.ParentID == action.Action.ID && m.Y > action.Y && m.Y < elseActionItem.Y).ToList();
            var passActions     = GenerateActions(passActionItems);

            //unpass actions
            var unpassActionItems = ActionItems.Where(m => m.Action.ParentID == action.Action.ID && m.Y > elseActionItem.Y && m.Y < endActionItem.Y).ToList();
            var unpassActions     = GenerateActions(unpassActionItems);

            var result = new Core.Action.Models.ActionModel()
            {
                ID        = action.Action.ID,
                Action    = Core.Action.Types.ActionType.IF,
                Parameter = new Core.Action.Models.IFActionParameterModel()
                {
                    LeftInput     = inputdata.Left,
                    RightInput    = inputdata.Right,
                    Condition     = inputdata.Condition == null ? Core.Action.Types.IFActionConditionType.Equal : (Core.Action.Types.IFActionConditionType)inputdata.Condition.ID,
                    PassActions   = passActions,
                    NoPassActions = unpassActions
                },
                Num = 1
            };

            GeneratedItems.AddRange(passActionItems);
            GeneratedItems.AddRange(unpassActionItems);

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 调整group类型action的间距
        /// </summary>
        /// <param name="action"></param>
        private void ResetGroupActionMargin(ActionItem action)
        {
            var actionPoint = action.RenderTransform as TranslateTransform;
            //查找当前控件的上一个控件
            var topActionItems = ActionItems.
                                 Where(
                m => m.Visibility != Visibility.Hidden &&
                m.Y < actionPoint.Y
                ).
                                 OrderBy(m => m.Y);
            ActionItem topActionItem = null;
            double     addMargin     = 0;

            if (topActionItems.Count() > 0)
            {
                //存在上一个时
                topActionItem = topActionItems.Last();
                if (marginActionTypes.Contains(topActionItem.Action.ActionType))
                {
                    addMargin = topActionItem.Margin.Left + 10;
                }
                else if (topActionItem.Margin.Left > 0)
                {
                    //上一个间距大于0时跟随
                    addMargin = topActionItem.Margin.Left;
                }
            }


            //调整所有子级的间距
            var groupActions = ActionItems.Where(m => m.Action.ID == action.Action.ID || m.Action.ParentID == action.Action.ID).OrderBy(m => m.Y).ToList();

            //foreach (var groupAction in groupActions)
            for (int i = 0; i < groupActions.Count; i++)
            {
                var groupAction = groupActions[i];
                var newmarigin  = addMargin;
                if (!marginActionTypes.Contains(groupAction.Action.ActionType) && !groupEndActionTypes.Contains(groupAction.Action.ActionType))
                {
                    newmarigin = addMargin + 10;
                }

                //if (
                //    i != 0 &&
                //    !groupActionTypes.Contains(groupAction.Action.ActionType) &&
                //    !noMoveActionTypes.Contains(groupAction.Action.ActionType)
                //    )
                //{
                //    newmarigin = groupActions[i - 1].Margin.Left;
                //}
                //if (i != 0)
                //{
                //    //获取当前控件的上一个控件
                //    var topAction = groupActions[i - 1];
                //    if (marginActionTypes.Contains(topAction.Action.ActionType) && !noMoveActionTypes.Contains(groupAction.Action.ActionType))
                //    {
                //        //需要调整间距的类型
                //        newmarigin = topAction.Margin.Left + 10;
                //    }
                //}


                groupAction.Margin = new Thickness(newmarigin, 0, newmarigin, 0);

                if (groupActionTypes.Contains(groupAction.Action.ActionType) && groupAction != action)
                {
                    ResetGroupActionMargin(groupAction);
                }
            }
        }
Ejemplo n.º 3
0
        private void HandleMoveEnd(ActionItem action)
        {
            AddActionBtn.Visibility = Visibility.Visible;

            var actionPoint = action.RenderTransform as TranslateTransform;
            //调整控件自身的位置对齐

            //查找当前控件的上一个控件
            var topActionItems = ActionItems.
                                 Where(
                m => m.Visibility != Visibility.Hidden &&
                m.Y < actionPoint.Y
                ).
                                 OrderBy(m => m.Y);
            ActionItem topActionItem = null;

            //新的父级id
            int newParentID = 0;
            //新的间距
            double newMargin = 0;
            //新的位置
            double newActionY = 0;

            if (topActionItems.Count() > 0)
            {
                //存在上一个时需要判断是否需要调整父子级关系

                //上一个action
                topActionItem = topActionItems.Last();
                //调整自身对齐上一个
                newActionY = topActionItem.Y + topActionItem.ActualHeight;

                //判断是否需要调整间距
                if (marginActionTypes.Contains(topActionItem.Action.ActionType))
                {
                    //上一个是组类型的顶级action

                    //自身设置为下级
                    newParentID = groupActionTypes.Contains(topActionItem.Action.ActionType) ? topActionItem.Action.ID : topActionItem.Action.ParentID;
                    //设置间距
                    newMargin = topActionItem.Margin.Left + 10;
                }
                else if (topActionItem.Action.ParentID > 0 && topActionItem.Margin.Left > 0)
                {
                    //上一个是某个action的子级

                    if (noMoveActionTypes.Contains(topActionItem.Action.ActionType))
                    {
                        //上一个是不可移动的类型,说明是特殊action的子级
                        //找到它的父级
                        var topActionParent = ActionItems.Where(m => m.Action.ID == topActionItem.Action.ParentID).FirstOrDefault();
                        //跟随父级关系
                        newParentID = topActionParent.Action.ParentID;
                        //跟随父级间距
                        newMargin = topActionParent.Margin.Left;
                    }
                    else
                    {
                        //自身设置为同等子级
                        newParentID = topActionItem.Action.ParentID;
                        //设置同等间距
                        newMargin = topActionItem.Margin.Left;
                    }
                }
            }

            //更新数据
            actionPoint.Y          = newActionY;
            action.Action.ParentID = newParentID;
            action.Margin          = new Thickness(newMargin, 0, newMargin, 0);



            //如果移动的是组类型的还需要将它们的子级展开
            if (groupActionTypes.Contains(action.Action.ActionType))
            {
                //查找 action下方的action
                var bottomActions = ActionItems.Where(m => m.Y > actionPoint.Y && m.Visibility != Visibility.Hidden).OrderBy(m => m.Y).ToList();

                //调整子级的位置
                for (int i = 0; i < groupActionItems.Count; i++)
                {
                    var actionItem      = groupActionItems[i];
                    var actionItemPoint = actionItem.RenderTransform as TranslateTransform;

                    double newY = 0;
                    if (i == 0)
                    {
                        //第一个跟随移动的action
                        newY = actionPoint.Y + action.ActualHeight;
                    }
                    else
                    {
                        //跟随前一个action
                        var lastItem      = groupActionItems[i - 1];
                        var lastItemPoint = lastItem.RenderTransform as TranslateTransform;
                        newY = lastItemPoint.Y + lastItem.ActualHeight;
                    }

                    actionItemPoint.Y = newY;
                    //恢复显示
                    actionItem.Visibility = Visibility.Visible;
                }
                if (bottomActions.Count > 0)
                {
                    for (int i = 0; i < bottomActions.Count; i++)
                    {
                        var actionTTF = bottomActions[i].RenderTransform as TranslateTransform;
                        if (i == 0)
                        {
                            actionTTF.Y = groupActionItems[groupActionItems.Count - 1].Y + groupActionItems[groupActionItems.Count - 1].ActualHeight;
                        }
                        else
                        {
                            var lastactionTTF = bottomActions[i - 1].RenderTransform as TranslateTransform;
                            actionTTF.Y = lastactionTTF.Y + bottomActions[i - 1].ActualHeight;
                        }
                        bottomActions[i].Y = actionTTF.Y;
                    }
                }
                groupActionItems.Clear();
            }


            //排序
            SortAction();
            //调整间距
            ResetAllActionsMarigin();
        }
Ejemplo n.º 4
0
        private void HandleActionMove(ActionItem action, double moveY)
        {
            bool moveUp = false;

            //更新自身Y
            action.Y = moveY;

            //查找相邻的action
            var items = ActionItems.Where(m => m.Y > moveY).OrderBy(m => m.Y);
            //相邻的action
            ActionItem item = null;
            //移动的距离
            double moveLength = action.ActualHeight;

            //if (action.Action.ActionType == UI.Types.ActionType.IF)
            //{
            //    moveLength += ifActionItems.Sum(m => m.ActualHeight);
            //}
            if (oldMoveItemY > moveY)
            {
                //向上拖动
                moveUp = true;
                //向上拖动,查找小于移动位置的action
                items = ActionItems.Where(m => m.Y < moveY).OrderBy(m => m.Y);
            }
            if (items.Count() > 0)
            {
                item = moveUp ? items.Last() : items.First();
            }


            if (moveUp)
            {
                //向上拖动,查找小于移动位置的action
                if (item != null)
                {
                    //存在时判断位置是否需要调换
                    if (moveY < item.Y + item.ActualHeight / 2)
                    {
                        //需要
                        (item.RenderTransform as TranslateTransform).Y += moveLength;
                        //更新Y
                        item.Y = (item.RenderTransform as TranslateTransform).Y;
                    }
                }
            }
            else
            {
                //向下拖动
                if (item != null)
                {
                    //存在时判断位置是否需要调换
                    if (moveY + action.ActualHeight > item.Y + item.ActualHeight / 2)
                    {
                        //需要
                        (item.RenderTransform as TranslateTransform).Y -= moveLength;

                        //更新Y
                        item.Y = (item.RenderTransform as TranslateTransform).Y;
                        if (ActionItems.Where(m => m.Y < item.Y && m.Visibility != Visibility.Hidden && m != item).ToList().Count() == 0)
                        {
                            (item.RenderTransform as TranslateTransform).Y = 0;
                            item.Y = 0;
                        }
                    }
                }
            }


            //更新
            oldMoveItemY = moveY;
        }
Ejemplo n.º 5
0
        private void AddItemControl(ActionItemModel action, IActionBuilder builder = null)
        {
            isRendering = true;
            double Y = 0;

            if (ActionItems.Count > 0)
            {
                var lastItem    = ActionItems.Last();
                var lastItemTTF = lastItem.RenderTransform as TranslateTransform;
                Y = lastItemTTF.Y + lastItem.ActualHeight;
            }

            var item = new ActionItem();

            item.ActionContainer = this;
            item.DataContext     = this;
            item.VMDataContext   = this.DataContext;
            BindingOperations.SetBinding(item, ActionItem.ContainerStateProperty, new Binding()
            {
                Source = this,
                Path   = new PropertyPath(nameof(State)),
                Mode   = BindingMode.Default,
            });
            BindingOperations.SetBinding(item, ActionItem.RuningIDProperty, new Binding()
            {
                Source = DataContext,
                Path   = new PropertyPath("RuningActionID"),
                Mode   = BindingMode.Default,
            });
            BindingOperations.SetBinding(item, ActionItem.RuningStateProperty, new Binding()
            {
                Source = DataContext,
                Path   = new PropertyPath("RuningActionState"),
                Mode   = BindingMode.Default,
            });
            item.ID = action.ID;
            //item.InputDataModel = inputdata == null ? ActionData.GetCreateDefaultInputData(action.ActionType) : inputdata;
            item.Builder = builder == null?ActionBuilder.BuilderByActionItem(action) : builder;

            item.Action            = action;
            item.VerticalAlignment = VerticalAlignment.Top;
            var ttf = item.RenderTransform as TranslateTransform;

            ttf.Y  = Y;
            item.Y = Y;
            item.MouseLeftButtonDown += Item_MouseLeftButtonDown;
            item.MouseLeftButtonUp   += Item_MouseLeftButtonUp;
            item.MouseMove           += Item_MouseMove;
            ttf.Changed += (e, c) =>
            {
                item.Y = ttf.Y;
            };

            item.OnRenderDone += (e, c) =>
            {
                if (item.Tag != null)
                {
                    //如果tag不为null表示已加载完成了
                    return;
                }
                item.Tag = string.Empty;
                if (ActionItems.Count == 1)
                {
                    //仅存在一个时使用auto height
                    ActionPanel.Height = Double.NaN;
                }
                else
                {
                    ActionPanel.Height = ActionPanel.ActualHeight + item.ActualHeight;
                }
                //ActionPanel.Height += item.ActualHeight;
                //if (double.IsNaN(ActionPanel.Height))
                //{
                //    ActionPanel.Height = item.ActualHeight;
                //}
                UpdateActionHeight(item);
                ActionTempPanel.Children.Remove(item);
                ActionPanel.Children.Add(item);
                //继续队列
                appendActionItemTempList.RemoveAt(0);
                appendBuilderTempList.RemoveAt(0);

                isRendering = false;
                if (appendActionItemTempList.Count > 0)
                {
                    AddItem(appendActionItemTempList[0], appendBuilderTempList[0]);
                }
                else
                {
                    ResetAllActionsMarigin();
                }
                //继续监控item高度变化
                item.LayoutUpdated += (e, v) =>
                {
                    UpdateActionHeight(item);
                };
            };
            //ActionPanel.Children.Add(item);
            //添加到临时容器中
            ActionTempPanel.Children.Add(item);
            ActionItems.Add(item);
            SortAction();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 生成普通action
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private Core.Action.Models.ActionModel GenerateAction(ActionItem action)
        {
            Core.Action.Models.ActionModel result = null;
            if (action.Action.ActionType == UI.Types.ActionType.IF)
            {
                result = GenerateIFAction(action);
            }
            else
            {
                //switch ActionType是UI中使用的Type,与Core使用的ActionType并不一致,这里需要转换

                result = action.Builder?.GetCoreActionModel();
                //switch (action.Action.ActionType)
                //{
                //    case UI.Types.ActionType.WriteFile:
                //        result = new Core.Action.Models.ActionModel();
                //        var inputdata = action.GetInputData() as WriteFileActionInputModel;
                //        result.Action = Core.Action.Types.ActionType.WriteFile;
                //        result.ID = action.Action.ID;
                //        result.Parameter = new WriteFileActionParameterModel()
                //        {
                //            FilePath = inputdata.FilePath,
                //            Content = inputdata.Content
                //        };
                //        result.Num = 1;
                //        break;
                //    case UI.Types.ActionType.HttpRequest:
                //        result = new Core.Action.Models.ActionModel();
                //        var httprequestInputdata = action.GetInputData() as HttpRequestActionInputModel;
                //        result.Action = Core.Action.Types.ActionType.HttpRequest;
                //        result.ID = action.Action.ID;
                //        result.Parameter = new HttpRequestActionParameterModel()
                //        {
                //            Url = httprequestInputdata.Url,
                //            QueryParams = httprequestInputdata.QueryParams,
                //            Method = httprequestInputdata.Method == null ? Core.Net.Types.MethodType.GET : (MethodType)httprequestInputdata.Method.ID,

                //            ParamsType = httprequestInputdata.PamramsType == null ? Core.Net.Types.ParamsType.Json : (ParamsType)httprequestInputdata.PamramsType.ID,
                //            Files = httprequestInputdata.Files,
                //            Headers = httprequestInputdata.Headers
                //        };
                //        result.Num = 1;
                //        break;
                //    case UI.Types.ActionType.Shutdown:
                //        result = new Core.Action.Models.ActionModel();
                //        result.Action = Core.Action.Types.ActionType.Shutdown;
                //        result.ID = action.Action.ID;
                //        result.Num = 1;
                //        break;
                //    case UI.Types.ActionType.StartProcess:
                //        result = new Core.Action.Models.ActionModel();
                //        result.Action = Core.Action.Types.ActionType.StartProcess;
                //        result.ID = action.Action.ID;
                //        var spinputdata = action.GetInputData() as StartProcessActionInputModel;
                //        result.Num = 1;
                //        result.Parameter = new StartProcessActionParamsModel()
                //        {
                //            Path = spinputdata.Path,
                //            Args = spinputdata.Args
                //        };
                //        break;
                //}
            }
            return(result);
        }
Ejemplo n.º 7
0
        private void HandleMoveEnd(ActionItem action)
        {
            AddActionBtn.Visibility = Visibility.Visible;

            var actionPoint = action.RenderTransform as TranslateTransform;
            //调整控件自身的位置对齐

            //查找当前控件的上一个控件
            var topActionItems = ActionItems.
                                 Where(
                m => m.Visibility != Visibility.Hidden &&
                m.Y < actionPoint.Y
                ).
                                 OrderBy(m => m.Y);
            ActionItem topActionItem = null;

            if (topActionItems.Count() > 0)
            {
                //存在上一个时
                topActionItem = topActionItems.Last();
                //调整自身对齐上一个
                actionPoint.Y = topActionItem.Y + topActionItem.ActualHeight;



                //判断上一个是否是判断action
                if (topActionItem.Action.ActionType == UI.Types.ActionType.IF ||
                    topActionItem.Action.ActionType == UI.Types.ActionType.IFElse ||
                    topActionItem.Action.ParentID > 0 &&
                    topActionItem.Action.ActionType != UI.Types.ActionType.IFEnd)
                {
                    //是的话需要将自身设置为if的下级
                    action.Action.ParentID = topActionItem.Action.ActionType == UI.Types.ActionType.IF ? topActionItem.Action.ID : topActionItem.Action.ParentID;

                    //设置间距
                    double margin = topActionItem.Action.ActionType == UI.Types.ActionType.IF || topActionItem.Action.ActionType == UI.Types.ActionType.IFElse ? topActionItem.Margin.Left + 10 : topActionItem.Margin.Left;
                    action.Margin = new Thickness(margin, 0, margin, 0);
                }
                else
                {
                    //重置父级id
                    action.Action.ParentID = 0;
                    action.Margin          = new Thickness(0);
                }
            }
            else
            {
                //不存在说明已经是第一个了
                actionPoint.Y = 0;
                //重置父级id
                action.Action.ParentID = 0;
                action.Margin          = new Thickness(0);
            }

            if (action.Action.ActionType == UI.Types.ActionType.IF)
            {
                //查找if action下方的action
                var bottomActions = ActionItems.Where(m => m.Y > actionPoint.Y && m.Visibility != Visibility.Hidden).OrderBy(m => m.Y).ToList();

                //调整子级的位置
                for (int i = 0; i < ifActionItems.Count; i++)
                {
                    var actionItem      = ifActionItems[i];
                    var actionItemPoint = actionItem.RenderTransform as TranslateTransform;

                    double newY = 0;
                    if (i == 0)
                    {
                        //第一个跟随移动的action
                        newY = actionPoint.Y + action.ActualHeight;
                    }
                    else
                    {
                        //跟随前一个action
                        var lastItem      = ifActionItems[i - 1];
                        var lastItemPoint = lastItem.RenderTransform as TranslateTransform;
                        newY = lastItemPoint.Y + lastItem.ActualHeight;
                    }

                    actionItemPoint.Y = newY;
                    //恢复显示
                    actionItem.Visibility = Visibility.Visible;
                }
                if (bottomActions.Count > 0)
                {
                    for (int i = 0; i < bottomActions.Count; i++)
                    {
                        var actionTTF = bottomActions[i].RenderTransform as TranslateTransform;
                        if (i == 0)
                        {
                            actionTTF.Y = ifActionItems[ifActionItems.Count - 1].Y + ifActionItems[ifActionItems.Count - 1].ActualHeight;
                        }
                        else
                        {
                            var lastactionTTF = bottomActions[i - 1].RenderTransform as TranslateTransform;
                            actionTTF.Y = lastactionTTF.Y + bottomActions[i - 1].ActualHeight;
                        }
                        bottomActions[i].Y = actionTTF.Y;
                    }
                }
                ifActionItems.Clear();

                //调整间距
                ResetIfActionMargin(action);
            }

            //排序
            SortAction();
        }