public static bool execute(KevoreeCoreBean originCore, IContainerNodeMarshalled rootNode, AdaptationModel adaptionModel, NodeType nodeInstance, Func<bool> afterUpdateFunc, Func<bool> preRollBack, Func<bool> postRollback)
        {
            var processedActions = new HashSet<AdaptationPrimitive>();
            bool success = true;
            foreach (AdaptationPrimitive action in adaptionModel.ToArray())
            {
                processedActions.Add(action);
                var resultAction = processAction(action, nodeInstance);
                if (!resultAction)
                {
                    success = false;
                    break;
                }
            }

            if (!success)
            {
                originCore.getLogger().Error("Adaptation failed");
                foreach (var act in processedActions.Reverse())
                {
                    processUndoAction(act, nodeInstance);
                }
            }
            else
            {
                originCore.getLogger().Debug("Adaptation succeeded");
            }
            return success;
        }
Example #2
0
 static void Recurse(int n, int depth, HashSet<int> set)
 {
     if (depth == n)
     {
         Console.Write("{");
         Console.Write(string.Join(" ", set.Reverse()));
         Console.WriteLine("}");
     }
     else
     {
         for (int ii = 1; ii <= n; ++ii)
         {
             if (set.Contains(ii))
                 continue;
             set.Add(ii);
             Recurse(n, depth + 1, set);
             set.Remove(ii);
         }
     }
 }
        void OffsetConnectorViewState(UIElement view, Point oldLocation, Point newLocation, bool offsetNonContainedConnectors)
        {
            // There is no need to do anything for the StartSymbol
            if (view is VirtualizedContainerService.VirtualizingContainer)
            {
                Vector offset = new Vector(newLocation.X - oldLocation.X, newLocation.Y - oldLocation.Y);

                // connectors whose dest points are outside the state and the src points are inside/on the state
                HashSet<Connector> outgoingConnectors = new HashSet<Connector>();
                // connectors whose src points are outside the state and the dest points are inside/on the state
                HashSet<Connector> incomingConnectors = new HashSet<Connector>();
                // connectors whose src points and dest points are both inside/on the state
                HashSet<ModelItem> containedTransitions = new HashSet<ModelItem>();

                if (view != null)
                {
                    // Here the incomingConnectors and outgoingConnectors contains connectors whose src points and dest
                    // points are both inside/on the state; they will be removed later on
                    List<Connector> connectors = StateContainerEditor.GetIncomingConnectors(view);
                    foreach (Connector connector in connectors)
                    {
                        incomingConnectors.Add(connector);
                    }
                    connectors = StateContainerEditor.GetOutgoingConnectors(view);
                    foreach (Connector connector in connectors)
                    {
                        outgoingConnectors.Add(connector);
                    }
                }

                // Add common connectors to the containedConnectors set and remove them
                // from the outgoingConnectors and incomingConnectors sets
                foreach (Connector connector in outgoingConnectors.Reverse<Connector>())
                {
                    if (incomingConnectors.Contains(connector))
                    {
                        containedTransitions.Add(StateContainerEditor.GetConnectorModelItem(connector));
                        outgoingConnectors.Remove(connector);
                        incomingConnectors.Remove(connector);
                    }
                }

                // For contained connectors, we offset all the points.
                this.OffsetLocationViewStates(offset, null, containedTransitions, true);

                if (offsetNonContainedConnectors)
                {
                    // For incoming connectors, we offset the end point and invalidate the view state.
                    // This way the start and end point will still connect to the same connection points
                    // on the source and destination shapes and later on the connector will be rerouted using
                    // those two fixed points.
                    foreach (Connector connector in incomingConnectors)
                    {
                        this.SetEndPointsAndInvalidateViewState(connector, offset, false);
                    }

                    // for outgoing connectors, we offset the start point and invalidate the view state.
                    foreach (Connector connector in outgoingConnectors)
                    {
                        this.SetEndPointsAndInvalidateViewState(connector, offset, true);
                    }
                }
                else
                {                    
                    HashSet<ModelItem> nonSelfTransitions = new HashSet<ModelItem>();

                    foreach (Connector connector in incomingConnectors)
                    {
                        nonSelfTransitions.Add(StateContainerEditor.GetConnectorModelItem(connector));
                    }
                    
                    foreach (Connector connector in outgoingConnectors)
                    {
                        nonSelfTransitions.Add(StateContainerEditor.GetConnectorModelItem(connector));
                    }

                    // Store ViewState for all non-self transitions to support undo/redo.
                    this.OffsetLocationViewStates(offset, null, nonSelfTransitions, true);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Explain one query node.
        /// </summary>
        /// <param name="plan">Return plan here.</param>
        /// <param name="n">Node to explain.</param>
        internal static void ExplainNode(StringBuilder plan, DryadQueryNode n)
        {
            if (n is DryadTeeNode || n is DryadOutputNode)
            {
                return;
            }
            else if (n is DryadInputNode)
            {
                plan.AppendLine("Input:");
                plan.Append("\t");
                n.BuildString(plan);
                plan.AppendLine();
                return;
            }

            plan.Append(n.m_vertexEntryMethod);
            plan.AppendLine(":");

            HashSet<DryadQueryNode> allchildren = new HashSet<DryadQueryNode>();

            if (n is DryadSuperNode)
            {
                DryadSuperNode sn = n as DryadSuperNode;
                List<DryadQueryNode> tovisit = new List<DryadQueryNode>();

                tovisit.Add(sn.RootNode);

                while (tovisit.Count > 0)
                {
                    DryadQueryNode t = tovisit[0];
                    tovisit.RemoveAt(0);
                    if (!(t is DryadSuperNode))
                        allchildren.Add(t);
                    foreach (DryadQueryNode tc in t.Children)
                    {
                        if (!allchildren.Contains(tc) && sn.Contains(tc))
                            tovisit.Add(tc);
                    }
                }
            }
            else
                allchildren.Add(n);

            foreach (DryadQueryNode nc in allchildren.Reverse())
            {
                Expression expression = null; // expression to print
                List<string> additional = new List<string>(); // additional arguments to print
                int argsToSkip = 0;
                string methodname = nc.OpName;

                plan.Append("\t");

                if (nc is DryadMergeNode)
                {
                    expression = ((DryadMergeNode)nc).ComparerExpression;
                }
                else if (nc is DryadHashPartitionNode)
                {
                    DryadHashPartitionNode hp = (DryadHashPartitionNode)nc;
                    expression = hp.KeySelectExpression;
                    additional.Add(hp.NumberOfPartitions.ToString());
                }
                else if (nc is DryadGroupByNode)
                {
                    DryadGroupByNode gb = (DryadGroupByNode)nc;
                    expression = gb.KeySelectExpression;
                    if (gb.ElemSelectExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(gb.ElemSelectExpression));
                    if (gb.ResSelectExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(gb.ResSelectExpression));
                    if (gb.ComparerExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(gb.ComparerExpression));
                    if (gb.SeedExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(gb.SeedExpression));
                    if (gb.AccumulatorExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(gb.AccumulatorExpression));
                }
                else if (nc is DryadOrderByNode)
                {
                    DryadOrderByNode ob = (DryadOrderByNode)nc;
                    expression = ob.KeySelectExpression;
                    if (ob.ComparerExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(ob.ComparerExpression));
                }
                else if (nc is DryadWhereNode) {
                    expression = ((DryadWhereNode)nc).WhereExpression;
                }
                else if (nc is DryadSelectNode) {
                    DryadSelectNode s = (DryadSelectNode)nc;
                    expression = s.SelectExpression;
                    if (s.ResultSelectExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(s.ResultSelectExpression));
                }
                else if (nc is DryadAggregateNode)
                {
                    DryadAggregateNode a = (DryadAggregateNode)nc;
                    expression = a.FuncLambda;
                    if (a.SeedExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(a.SeedExpression));
                    if (a.ResultLambda != null)
                        additional.Add(HpcLinqExpression.Summarize(a.ResultLambda));
                }
                else if (nc is DryadPartitionOpNode) {
                    expression = ((DryadPartitionOpNode)nc).ControlExpression;
                }
                else if (nc is DryadJoinNode)
                {
                    DryadJoinNode j = (DryadJoinNode)nc;
                    expression = j.OuterKeySelectorExpression;
                    additional.Add(HpcLinqExpression.Summarize(j.InnerKeySelectorExpression));
                    additional.Add(HpcLinqExpression.Summarize(j.ResultSelectorExpression));
                    if (j.ComparerExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(j.ComparerExpression));
                }
                else if (nc is DryadDistinctNode)
                {
                    expression = ((DryadDistinctNode)nc).ComparerExpression;
                }
                else if (nc is DryadContainsNode)
                {
                    DryadContainsNode c = (DryadContainsNode)nc;
                    expression = c.ValueExpression;
                    if (c.ComparerExpression != null)
                        additional.Add(HpcLinqExpression.Summarize(c.ComparerExpression));
                }
                else if (nc is DryadBasicAggregateNode)
                {
                    expression = ((DryadBasicAggregateNode)nc).SelectExpression;
                }
                else if (nc is DryadConcatNode)
                    // nothing to do
                {
                }
                else if (nc is DryadSetOperationNode)
                {
                    expression = ((DryadSetOperationNode)nc).ComparerExpression;
                }
                else if (nc is DryadRangePartitionNode)
                {
                    DryadRangePartitionNode r = (DryadRangePartitionNode)nc;
                    expression = r.CountExpression;
                    // TODO: there's some other possible interesting info
                }
                else if (nc is DryadApplyNode)
                {
                    expression = ((DryadApplyNode)nc).LambdaExpression;
                }

                else if (nc is DryadForkNode)
                {
                    expression = ((DryadForkNode)nc).ForkLambda;
                }

                else if (nc is DryadTeeNode)
                {
                    // nothing
                }
                else if (nc is DryadDynamicNode)
                {
                    // nothing
                }
                else
                {
                    expression = nc.QueryExpression;
                }

                if (expression is MethodCallExpression)
                {
                    MethodCallExpression mc = (MethodCallExpression)expression;
                    methodname = mc.Method.Name;  // overwrite methodname

                    // determine which arguments to skip
                    #region LINQMETHODS
                    switch (mc.Method.Name)
                    {
                        case "Aggregate":
                        case "AggregateAsQuery":
                        case "Select":
                        case "LongSelect":
                        case "SelectMany":
                        case "LongSelectMany":
                        case "OfType":
                        case "Where":
                        case "LongWhere":
                        case "First":
                        case "FirstOrDefault":
                        case "FirstAsQuery":
                        case "Single":
                        case "SingleOrDefault":
                        case "SingleAsQuery":
                        case "Last":
                        case "LastOrDefault":
                        case "LastAsQuery":
                        case "Distinct":
                        case "Any":
                        case "AnyAsQuery":
                        case "All":
                        case "AllAsQuery":
                        case "Count":
                        case "CountAsQuery":
                        case "LongCount":
                        case "LongCountAsQuery":
                        case "Sum":
                        case "SumAsQuery":
                        case "Min":
                        case "MinAsQuery":
                        case "Max":
                        case "MaxAsQuery":
                        case "Average":
                        case "AverageAsQuery":
                        case "GroupBy":
                        case "OrderBy":
                        case "OrderByDescending":
                        case "ThenBy":
                        case "ThenByDescending":
                        case "Take":
                        case "TakeWhile":
                        case "LongTakeWhile":
                        case "Skip":
                        case "SkipWhile":
                        case "LongSkipWhile":
                        case "Contains":
                        case "ContainsAsQuery":
                        case "Reverse":
                        case "Merge":
                        case "HashPartition":
                        case "RangePartition":
                        case "Fork":
                        case "ForkChoose":
                        case "AssumeHashPartition":
                        case "AssumeRangePartition":
                        case "AssumeOrderBy":
                        case "ToPartitionedTableLazy":
                        case "AddCacheEntry":
                        case "SlidingWindow":
                        case "SelectWithPartitionIndex":
                        case "ApplyWithPartitionIndex":
                            argsToSkip = 1;
                            break;
                        case "Join":
                        case "GroupJoin":
                        case "Concat":
                        case "MultiConcat":
                        case "Union":
                        case "Intersect":
                        case "Except":
                        case "SequenceEqual":
                        case "SequenceEqualAsQuery":
                        case "Zip":
                            argsToSkip = 2;
                            break;
                        case "Apply":
                        case "ApplyPerPartition":
                            if (mc.Arguments.Count < 3)
                                argsToSkip = 1;
                            else
                                argsToSkip = 2;
                            break;
                        default:
                            throw DryadLinqException.Create(HpcLinqErrorCode.OperatorNotSupported,
                                                          String.Format(SR.OperatorNotSupported, mc.Method.Name),
                                                          expression);
                    }
                    #endregion

                    plan.Append(methodname);
                    plan.Append("(");

                    int argno = 0;
                    foreach (var arg in mc.Arguments)
                    {
                        argno++;
                        if (argno <= argsToSkip) continue;
                        if (argno > argsToSkip + 1)
                        {
                            plan.Append(",");
                        }
                        plan.Append(HpcLinqExpression.Summarize(arg));
                    }
                    plan.AppendLine(")");
                }
                else
                {
                    // expression is not methodcall
                    plan.Append(methodname);
                    plan.Append("(");
                    if (expression != null)
                    {
                        plan.Append(HpcLinqExpression.Summarize(expression));
                    }
                    foreach (string e in additional)
                    {
                        plan.Append(",");
                        plan.Append(e);
                    }
                    plan.AppendLine(")");
                }
            }
        }