コード例 #1
0
 private static void ClearTransition(Transition transition)
 {
     transition.Source = null;
 }
コード例 #2
0
 static bool IsTransitionDestinationWithinStates(Transition transition, IEnumerable<State> states)
 {
     foreach (State state in states)
     {
         if (transition.To == state)
         {
             return true;
         }
     }
     return false;
 }
コード例 #3
0
 private ModelItem DoAutoConnect(UIElement sourceElement, ModelItem droppedModelItem, Transition transitionToCopy, int insertIndex = InvalidIndex)
 {
     ModelItem sourceModelItem = TryGetModelItemFromView(sourceElement);
     if (sourceModelItem != null && droppedModelItem.ItemType == typeof(State))
     {
         if (sourceModelItem.ItemType == typeof(State))
         {
             ModelItem stateMachineModelItem = GetStateMachineModelItem(sourceModelItem);
             Transition transition = new Transition
             {
                 DisplayName = StateContainerEditor.GenerateTransitionName(stateMachineModelItem),
                 To = droppedModelItem.GetCurrentValue() as State
             };
             if (transitionToCopy != null)
             {
                 transition.Action = transitionToCopy.Action;
                 transition.Condition = transitionToCopy.Condition;
                 transition.DisplayName = transitionToCopy.DisplayName;
                 transition.Trigger = transitionToCopy.Trigger;
             }
             ModelItem trasitionModelItem = null;
             if (insertIndex >= 0)
             {
                 trasitionModelItem = sourceModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Insert(insertIndex, transition);
             }
             else
             {
                 trasitionModelItem = sourceModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transition);
             }
             Fx.Assert(trasitionModelItem != null, "trasitionModelItem");
             return trasitionModelItem;
         }
         // auto-connect from the initial node
         else if (sourceModelItem.ItemType == typeof(StartNode))
         {
             this.ModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(droppedModelItem);
             return this.ModelItem;
         }
     }
     return null;
 }
        // referenceTransitionModelItem is used when a connector is re-linked.
        void CreateTransition(ConnectionPoint sourceConnPoint, ConnectionPoint destConnPoint, ModelItem referenceTransitionModelItem, bool isSourceMoved)
        {
            VirtualizedContainerService.VirtualizingContainer srcDesigner = sourceConnPoint.ParentDesigner as VirtualizedContainerService.VirtualizingContainer;
            Fx.Assert(srcDesigner != null, "srcDesigner should not be null.");
            VirtualizedContainerService.VirtualizingContainer destDesigner = destConnPoint.ParentDesigner as VirtualizedContainerService.VirtualizingContainer;
            Fx.Assert(destDesigner != null, "destDesigner should not be null.");

            ModelItem srcModelItem = srcDesigner.ModelItem;
            ModelItem destModelItem = destDesigner.ModelItem;
            ModelItem transitionModelItem = null;

            // We are moving the connector.
            if (referenceTransitionModelItem != null && referenceTransitionModelItem.ItemType == typeof(Transition))
            {
                transitionModelItem = referenceTransitionModelItem;
                // We are moving the start of the connector. We only preserve the trigger if it is not shared.
                if (isSourceMoved)
                {
                    Transition referenceTransition = referenceTransitionModelItem.GetCurrentValue() as Transition;
                    ModelItem stateModelItem = GetParentStateModelItemForTransition(referenceTransitionModelItem);
                    State state = stateModelItem.GetCurrentValue() as State;
                    bool isTriggerShared = false;
                    foreach (Transition transition in state.Transitions)
                    {
                        if (transition != referenceTransition && transition.Trigger == referenceTransition.Trigger)
                        {
                            isTriggerShared = true;
                            break;
                        }
                    }
                    if (isTriggerShared)
                    {
                        transitionModelItem.Properties[TransitionDesigner.TriggerPropertyName].SetValue(null);
                    }
                }
                transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destModelItem);
                srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem);
            }
            // We are creating a new connector. 
            else
            {
                ModelItem stateMachineModelItem = GetStateMachineModelItem(srcModelItem);
                Transition newTransition = new Transition() { DisplayName = StateContainerEditor.GenerateTransitionName(stateMachineModelItem) };
                newTransition.To = destModelItem.GetCurrentValue() as State;
                // Assign the shared trigger.
                if (sourceConnPoint.AttachedConnectors.Count > 0)
                {
                    Connector connector = sourceConnPoint.AttachedConnectors[0];
                    Transition existingTransition = StateContainerEditor.GetConnectorModelItem(connector).GetCurrentValue() as Transition;
                    newTransition.Trigger = existingTransition.Trigger;
                }
                transitionModelItem = srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(newTransition);
            }
            if (transitionModelItem != null)
            {
                // if the transition connection is re-routed, the SrcConnPointIndex needs to be updated.
                PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnPoint, destConnPoint));
                int srcConnectionPointIndex = StateContainerEditor.GetConnectionPoints(sourceConnPoint.ParentDesigner).IndexOf(sourceConnPoint);
                int destConnectionPointIndex = StateContainerEditor.GetConnectionPoints(destConnPoint.ParentDesigner).IndexOf(destConnPoint);
                this.StoreConnectorLocationViewState(transitionModelItem, connectorViewState, true);
                this.ViewStateService.StoreViewStateWithUndo(transitionModelItem, SrcConnectionPointIndexStateKey, srcConnectionPointIndex);
                this.ViewStateService.StoreViewStateWithUndo(transitionModelItem, DestConnectionPointIndexStateKey, destConnectionPointIndex);
            }
        }
コード例 #5
0
        static void AddTransitionData(NativeActivityMetadata metadata, InternalTransition internalTransition, Transition transition)
        {
            TransitionData  transitionData = new TransitionData();
            Activity <bool> condition      = transition.Condition;

            transitionData.Condition = condition;

            if (condition != null)
            {
                metadata.AddChild(condition);
            }

            Activity action = transition.Action;

            transitionData.Action = action;

            if (action != null)
            {
                metadata.AddChild(action);
            }

            if (transition.To != null)
            {
                transitionData.To = transition.To.InternalState;
            }

            internalTransition.TransitionDataList.Add(transitionData);
        }
コード例 #6
0
ファイル: BitsModuleConverter.cs プロジェクト: BrianGoff/BITS
        public static bool ConvertToFlowchart(ref StateMachine chart, XmlDocument jobSpec)
        {
            int cntr = 1;
            Dictionary<string, Object> enrichedSteps = new Dictionary<string, Object>();

            try
            {
                var modules = from m in XDocument.Parse(jobSpec.InnerXml).Descendants()
                              where m.Name.LocalName.Equals("Module")
                              select new MyState(new XElement(m));

                IEnumerable<MyState> myStates = modules as IList<MyState> ?? modules.ToList();
                foreach (MyState m in myStates)
                {
                    //for debugging
                    //if (cntr++ >= 5)
                    //    break;

                    IEnumerable<MyState> enumerable;
                    foreach (string input in m.Inputs)
                    {
                        var myInputState = myStates.Where(ip => input != null && input.Equals(ip.Name));

                        enumerable = myInputState as IList<MyState> ?? myInputState.ToList();
                        if (myInputState != null && enumerable.First<MyState>() != null && m.State != null)
                        {
                            MyState inputState;
                            inputState = enumerable.First<MyState>();
                            if (enrichedSteps.ContainsKey(inputState.Name))
                            {
                                string transitionKey = String.Format("{0}_{1}", input, m.Name);
                                if (!transitions.ContainsKey(transitionKey))
                                {
                                    Transition t = new Transition();
                                    //t.DisplayName = transitionKey;
                                    t.To = m.State;
                                    transitions.Add(transitionKey, t);
                                }
                                ((MyState)enrichedSteps[input]).State.Transitions.Add(transitions[transitionKey]);
                            }
                        }
                    }
                    if (!enrichedSteps.ContainsKey(m.Name))
                        enrichedSteps.Add(m.Name, m);
                    if (chart.InitialState == null)
                        chart.InitialState = m.State;
                }

                chart.DisplayName = ""; // jobSpec.SelectSingleNode("/Job").Attributes["name"].Value;
                foreach (KeyValuePair<string, Object> kvp in enrichedSteps)
                {
                    chart.States.Add(((MyState)kvp.Value).State);
                }
            }
            catch (Exception ex)
            {
                return false;
            }

            return true;
        }