public void GetterIndexedProperty_not_included()
        {
            var sut = new IndexedProperty() { i = 1, j = 2 };
            var printer = CreatePrinter();

            Assert.AreEqual(@"new IndexedProperty()
            {
            i = 1
            j = 2
            }", printer.PrintObject(sut, ""));
        }
Example #2
0
        public EventPropertyGetterIndexedSPI GetGetterIndexedSPI(string indexedPropertyName)
        {
            var item = _propertyItems.Get(indexedPropertyName);
            if (item == null || !item.PropertyDescriptor.IsIndexed) {
                return null;
            }

            var indexedProperty = new IndexedProperty(indexedPropertyName);
            return _getterFactory.GetPropertyProvidedGetterIndexed(
                _nestableTypes,
                indexedPropertyName,
                indexedProperty,
                _beanEventTypeFactory.EventBeanTypedEventFactory,
                _beanEventTypeFactory);
        }
        public void GetterIndexedProperty_not_included()
        {
            var sut = new IndexedProperty()
            {
                i = 1, j = 2
            };
            var printer = CreatePrinter();

            Assert.AreEqual(@"new IndexedProperty()
{
    i = 1
    j = 2
}
", printer.PrintObject(sut, ""));
        }
        public EventPropertyGetterIndexedSPI GetPropertyProvidedGetterIndexed(
            IDictionary <string, object> nestableTypes,
            string indexedPropertyName,
            IndexedProperty indexedProperty,
            EventBeanTypedEventFactory eventBeanTypedEventFactory,
            BeanEventTypeFactory beanEventTypeFactory)
        {
            var field = FindField(indexedPropertyName);

            if (field == null)
            {
                return(null);
            }

            if (field.OptionalField != null)
            {
                return(new JsonGetterIndexedRuntimeIndexProvided(field.OptionalField));
            }

            return(new JsonGetterIndexedRuntimeIndexSchema(field));
        }
        public DependencyGraph2(BasicTransformContext context,
                                IEnumerable <IStatement> inputs,
                                BackEdgeHandling backEdgeHandling,
                                Action <IWhileStatement> beginWhile,
                                Action <IWhileStatement> endWhile,
                                Action <IConditionStatement> beginFirstIterPost,
                                Action <IConditionStatement> endFirstIterPost,
                                Action <IStatement, NodeIndex> action)
        {
            Set <NodeIndex> nodesInCurrentWhile = new Set <EdgeIndex>();
            int             whileDepth          = 0;

            // create a dependency graph where while loops are flattened (the while loops themselves are not nodes)
            // the graph will only contain read-after-write and write-after-alloc dependencies for now
            // add write-after-read dependencies
            isWriteAfterRead = dependencyGraph.CreateEdgeData(false);
            DeadCodeTransform.ForEachStatement(inputs,
                                               delegate(IWhileStatement iws)
            {
                beginWhile(iws);
                nodesInCurrentWhile.Clear();
                whileDepth++;
            },
                                               delegate(IWhileStatement iws)
            {
                // all duplicates in a while loop should share all targets
                foreach (KeyValuePair <IStatement, Set <NodeIndex> > entry in duplicates)
                {
                    IStatement ist          = entry.Key;
                    Set <NodeIndex> set     = entry.Value;
                    Set <NodeIndex> targets = new Set <EdgeIndex>();
                    // collect all targets in the while loop
                    foreach (NodeIndex node in set)
                    {
                        foreach (NodeIndex target in dependencyGraph.TargetsOf(node))
                        {
                            if (nodesInCurrentWhile.Contains(target))
                            {
                                targets.Add(target);
                            }
                        }
                    }
                    Set <NodeIndex> backEdgeTargets = null;
                    if (!backEdges.TryGetValue(ist, out backEdgeTargets))
                    {
                        backEdgeTargets = new Set <EdgeIndex>();
                        backEdges[ist]  = backEdgeTargets;
                    }
                    // add all targets to all duplicates in the loop
                    foreach (NodeIndex node in set)
                    {
                        if (!nodesInCurrentWhile.Contains(node))
                        {
                            continue;
                        }
                        foreach (NodeIndex target in targets)
                        {
                            if (!dependencyGraph.ContainsEdge(node, target))
                            {
                                if (backEdgeHandling == BackEdgeHandling.Include)
                                {
                                    dependencyGraph.AddEdge(node, target);
                                }
                                else if (backEdgeHandling == BackEdgeHandling.Reverse)
                                {
                                    if (!dependencyGraph.ContainsEdge(target, node))
                                    {
                                        dependencyGraph.AddEdge(target, node);
                                    }
                                }
                                if (target < node)
                                {
                                    if (backEdgeTargets == null && !backEdges.TryGetValue(ist, out backEdgeTargets))
                                    {
                                        backEdgeTargets = new Set <EdgeIndex>();
                                        backEdges[ist]  = backEdgeTargets;
                                    }
                                    backEdgeTargets.Add(target);
                                }
                            }
                        }
                    }
                }
                endWhile(iws);
                whileDepth--;
            },
                                               beginFirstIterPost,
                                               endFirstIterPost,
                                               delegate(IStatement ist)
            {
                DependencyInformation di = context.InputAttributes.Get <DependencyInformation>(ist);
                if (di == null)
                {
                    context.Error("Dependency information not found for statement: " + ist);
                    di = new DependencyInformation();
                }
                NodeIndex targetIndex = dependencyGraph.AddNode();
                Set <NodeIndex> backEdgeTargets;
                Set <NodeIndex> sources = new Set <NodeIndex>();                                  // for fast checking of duplicate sources
                foreach (IStatement source in
                         di.GetDependenciesOfType(DependencyType.Dependency | DependencyType.Declaration))
                {
                    int sourceIndex;
                    // we assume that the statements are already ordered properly to respect dependencies.
                    // if the source is not in indexOfNode, then it must be a cyclic dependency in this while loop.
                    if (indexOfNode.TryGetValue(source, out sourceIndex))
                    {
                        if (!sources.Contains(sourceIndex))
                        {
                            sources.Add(sourceIndex);
                            EdgeIndex edge = dependencyGraph.AddEdge(sourceIndex, targetIndex);
                        }
                    }
                    else
                    {
                        sourceIndex = -1;
                    }
                    if (sourceIndex == -1)
                    {
                        // add a back edge
                        if (!backEdges.TryGetValue(source, out backEdgeTargets))
                        {
                            backEdgeTargets   = new Set <EdgeIndex>();
                            backEdges[source] = backEdgeTargets;
                        }
                        backEdgeTargets.Add(targetIndex);
                        // add a dependency on the initializers of source
                        Stack <IStatement> todo = new Stack <IStatement>();
                        todo.Push(source);
                        while (todo.Count > 0)
                        {
                            IStatement source2        = todo.Pop();
                            DependencyInformation di2 = context.InputAttributes.Get <DependencyInformation>(source2);
                            if (di2 == null)
                            {
                                context.Error("Dependency information not found for statement: " + source2);
                                continue;
                            }
                            foreach (IStatement init in di2.Overwrites)
                            {
                                int initIndex;
                                if (indexOfNode.TryGetValue(init, out initIndex))
                                {
                                    if (!sources.Contains(initIndex))
                                    {
                                        sources.Add(initIndex);
                                        EdgeIndex edge = dependencyGraph.AddEdge(initIndex, targetIndex);
                                    }
                                }
                                else
                                {
                                    todo.Push(init);
                                }
                            }
                        }
                    }
                }
                if (indexOfNode.ContainsKey(ist))
                {
                    Set <int> set;
                    if (!duplicates.TryGetValue(ist, out set))
                    {
                        set             = new Set <int>();
                        duplicates[ist] = set;
                        set.Add(indexOfNode[ist]);
                    }
                    set.Add(targetIndex);
                }
                // the same statement may appear multiple times.  when looking up indexOfNode, we want to use the last occurrence of the statement.
                indexOfNode[ist] = targetIndex;                                    // must do this at the end, in case the stmt depends on a previous occurrence of itself
                nodesInCurrentWhile.Add(targetIndex);
                nodes.Add(ist);
                if (backEdgeHandling != BackEdgeHandling.Ignore && backEdges.TryGetValue(ist, out backEdgeTargets))
                {
                    // now that ist has an index, we can fill in the back edges
                    foreach (NodeIndex node in backEdgeTargets)
                    {
                        if (backEdgeHandling == BackEdgeHandling.Include)
                        {
                            if (dependencyGraph.ContainsEdge(targetIndex, node))
                            {
                                throw new Exception("Internal: back edge already present");
                            }
                            dependencyGraph.AddEdge(targetIndex, node);
                        }
                        else
                        {
                            // make a new edge, even if one exists.
                            EdgeIndex edge         = dependencyGraph.AddEdge(node, targetIndex);
                            isWriteAfterRead[edge] = true;
                        }
                    }
                }
                action(ist, targetIndex);
            });
            if (string.Empty.Length > 0)
            {
                // loop statements in their original order
                foreach (NodeIndex target in dependencyGraph.Nodes)
                {
                    IStatement ist = nodes[target];
                    if (ist is IWhileStatement)
                    {
                        continue;
                    }
                    foreach (NodeIndex source in GetPreviousReaders(context, dependencyGraph, target, nodes, indexOfNode).ToReadOnlyList())
                    {
                        if (source > target)
                        {
                            throw new Exception("Internal: source statement follows target");
                        }
                        // make a new edge, even if one exists.
                        EdgeIndex edge = dependencyGraph.AddEdge(source, target);
                        isWriteAfterRead[edge] = true;
                    }
                }
            }
            isWriteAfterWrite = dependencyGraph.CreateEdgeData(false);
            // loop statements in their original order
            foreach (NodeIndex target in dependencyGraph.Nodes)
            {
                IStatement ist = nodes[target];
                if (ist is IWhileStatement)
                {
                    continue;
                }

                foreach (NodeIndex source in GetOverwrites(context, dependencyGraph, target, nodes, indexOfNode).ToReadOnlyList())
                {
                    if (source > target)
                    {
                        throw new Exception("Internal: source statement follows target");
                    }
                    if (dependencyGraph.ContainsEdge(source, target))
                    {
                        foreach (EdgeIndex edge in dependencyGraph.EdgesLinking(source, target))
                        {
                            isWriteAfterWrite[edge] = true;
                        }
                    }
                    else
                    {
                        EdgeIndex edge = dependencyGraph.AddEdge(source, target);
                        isWriteAfterWrite[edge] = true;
                    }
                }
            }

            dependencyGraph.NodeCountIsConstant = true;
            dependencyGraph.IsReadOnly          = true;
            for (int targetIndex = 0; targetIndex < dependencyGraph.Nodes.Count; targetIndex++)
            {
                IStatement            ist = nodes[targetIndex];
                DependencyInformation di  = context.InputAttributes.Get <DependencyInformation>(ist);
                if (di == null)
                {
                    continue;
                }
                if (di.IsOutput)
                {
                    outputNodes.Add(targetIndex);
                }
            }
        }
Example #6
0
        public async Task InstallSchema(int tenantId)
        {
            var correlationId = String.Empty;
            var errorCode     = String.Empty;

            try
            {
                _apiContext = new ApiContext(tenantId);

                var eventQueueEntityList = new EntityList
                {
                    IsSandboxDataCloningSupported = false,
                    IsShopperSpecific             = false,
                    IsVisibleInStorefront         = false,
                    Name      = EntityListConstants.MozuEventQueueName,
                    NameSpace = _listNameSpace
                };

                var idProperty = new IndexedProperty {
                    DataType = "string", PropertyName = "Id"
                };

                var indexProperties = new List <IndexedProperty>
                {
                    new IndexedProperty {
                        DataType = "string", PropertyName = "EventId"
                    },
                    new IndexedProperty {
                        DataType = "string", PropertyName = "EntityId"
                    },
                    new IndexedProperty {
                        DataType = "string", PropertyName = "Status"
                    },
                    new IndexedProperty {
                        DataType = "date", PropertyName = "QueuedDateTime"
                    }
                };

                var entitySchemaHandler = new EntitySchemaHandler(_appSetting);

                await
                entitySchemaHandler.InstallSchemaAsync(_apiContext, eventQueueEntityList, EntityScope.Tenant,
                                                       idProperty, indexProperties);
            }
            catch (AggregateException ex)
            {
                ex.Flatten().Handle(e =>
                {
                    var apiEx = e as ApiException;
                    if (apiEx != null)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(apiEx);
                        correlationId      = apiEx.CorrelationId;
                        errorCode          = apiEx.ErrorCode;
                    }
                    else if (e is HttpRequestException || e is TaskCanceledException)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    else
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    return(true);
                });
            }
            catch (ApiException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
                correlationId      = ex.CorrelationId;
                errorCode          = ex.ErrorCode;
            }
            catch (HttpRequestException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            catch (TaskCanceledException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            catch (Exception ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            if (_capturedException != null)
            {
                var message = String.Format("{0}. CorrId: {1}, ErrorCode: {2}",
                                            _capturedException.SourceException.Message, correlationId,
                                            errorCode);
                if (_capturedException.SourceException.InnerException != null)
                {
                    //Log it
                    _logger.Error(message, _capturedException.SourceException);
                }
            }
        }
Example #7
0
 public SettingContainer()
 {
     SettingByName = new IndexedProperty<string, Setting>(GetSettingByName, SetSettingByName);
 }
Example #8
0
        private List <IStatement> Schedule(DependencyGraph g, IList <IStatement> stmts, bool createFirstIterPostBlocks)
        {
            List <IStatement>     output       = new List <IStatement>();
            List <StatementBlock> blocks       = new List <StatementBlock>();
            List <NodeIndex>      currentBlock = null;
            DirectedGraphFilter <NodeIndex, EdgeIndex> graph2 = new DirectedGraphFilter <NodeIndex, EdgeIndex>(g.dependencyGraph, edge => !g.isDeleted[edge]);
            StrongComponents2 <NodeIndex> scc = new StrongComponents2 <NodeIndex>(graph2.SourcesOf, graph2);

            scc.AddNode        += delegate(NodeIndex node) { currentBlock.Add(node); };
            scc.BeginComponent += delegate() { currentBlock = new List <int>(); };
            scc.EndComponent   += delegate() {
                bool isCyclic = false;
                if (currentBlock.Count == 1)
                {
                    NodeIndex node = currentBlock[0];
                    foreach (NodeIndex source in graph2.SourcesOf(node))
                    {
                        if (source == node)
                        {
                            isCyclic = true;
                            break;
                        }
                    }
                }
                else
                {
                    isCyclic = true;
                }
                if (isCyclic)
                {
                    blocks.Add(new Loop()
                    {
                        indices = currentBlock
                    });
                }
                else
                {
                    blocks.Add(new StraightLine()
                    {
                        indices = currentBlock
                    });
                }
            };
            scc.SearchFrom(graph2.Nodes);
            //scc.SearchFrom(g.outputNodes);

            bool check = false;

            if (check)
            {
                // check that there are no edges from a later component to an earlier component
                Set <NodeIndex> earlierNodes = new Set <int>();
                foreach (StatementBlock block in blocks)
                {
                    earlierNodes.AddRange(block.indices);
                    foreach (NodeIndex node in block.indices)
                    {
                        foreach (NodeIndex source in graph2.SourcesOf(node))
                        {
                            if (!earlierNodes.Contains(source))
                            {
                                Console.WriteLine(g.NodeToString(node) + Environment.NewLine + "   depends on later node " + g.NodeToString(source));
                                Error("Internal error: Strong components are not ordered properly");
                            }
                        }
                    }
                }
            }

            Set <NodeIndex> nodesToMove = new Set <NodeIndex>();
            Dictionary <Loop, IBlockStatement> firstIterPostprocessing = null;

            if (createFirstIterPostBlocks)
            {
                firstIterPostprocessing = GetFirstIterPostprocessing(blocks, graph2, stmts, nodesToMove);
            }
            IVariableDeclaration iteration = Builder.VarDecl("iteration", typeof(int));

            IndexedProperty <NodeIndex, bool> isUniform = graph2.CreateNodeData <bool>(true);

            foreach (StatementBlock block in blocks)
            {
                if (block is Loop)
                {
                    foreach (NodeIndex i in block.indices)
                    {
                        isUniform[i] = false;
                    }
                    IWhileStatement    ws        = Builder.WhileStmt(Builder.LiteralExpr(true));
                    IList <IStatement> whileBody = ws.Body.Statements;

                    if (ContainsIterationStatement(stmts, block.indices))
                    {
                        List <IStatement> nodes = new List <IStatement>();
                        foreach (NodeIndex i in block.indices)
                        {
                            IStatement ist = stmts[i];
                            if (!context.InputAttributes.Has <IterationStatement>(ist))
                            {
                                nodes.Add(ist);
                            }
                        }
                        // build a new dependency graph with the dummy iteration statement removed
                        DependencyGraph   g2  = new DependencyGraph(context, nodes, ignoreMissingNodes: true, ignoreRequirements: true);
                        List <IStatement> sc3 = Schedule(g2, nodes, false);
                        if (sc3.Count == 1 && sc3[0] is IWhileStatement)
                        {
                            ws = (IWhileStatement)sc3[0];
                        }
                        else
                        {
                            // The statements in the outer loop are not strongly connected.
                            // Since we want the next transform to only process strong components,
                            // we mark the outer while loop as DoNotSchedule, leaving only the
                            // inner while loops to be scheduled.
                            // add all statements in sc3 to whileBody, but remove while loops around a single statement.
                            foreach (IStatement ist in sc3)
                            {
                                if (ist is IWhileStatement)
                                {
                                    IWhileStatement iws2 = (IWhileStatement)ist;
                                    if (iws2.Body.Statements.Count == 1)
                                    {
                                        whileBody.AddRange(iws2.Body.Statements);
                                        continue;
                                    }
                                }
                                whileBody.Add(ist);
                            }
                            context.OutputAttributes.Set(ws, new DoNotSchedule());
                        }
                    }
                    else // !ContainsIterationStatement
                    {
                        foreach (NodeIndex i in block.indices)
                        {
                            IStatement st = stmts[i];
                            whileBody.Add(st);
                            DependencyInformation di = context.InputAttributes.Get <DependencyInformation>(st);
                            di.AddClones(clonesOfStatement);
                        }
                        RegisterUnchangedStatements(whileBody);
                    }
                    Loop loop = (Loop)block;
                    if (firstIterPostprocessing != null && firstIterPostprocessing.ContainsKey(loop))
                    {
                        var thenBlock         = firstIterPostprocessing[loop];
                        var iterIsZero        = Builder.BinaryExpr(BinaryOperator.ValueEquality, Builder.VarRefExpr(iteration), Builder.LiteralExpr(0));
                        var firstIterPostStmt = Builder.CondStmt(iterIsZero, thenBlock);
                        context.OutputAttributes.Set(firstIterPostStmt, new FirstIterationPostProcessingBlock());
                        whileBody.Add(firstIterPostStmt);
                    }
                    output.Add(ws);
                }
                else
                {
                    // not cyclic
                    foreach (NodeIndex i in block.indices)
                    {
                        IStatement st = stmts[i];
                        if (!nodesToMove.Contains(i))
                        {
                            output.Add(st);
                            DependencyInformation di = context.InputAttributes.Get <DependencyInformation>(st);
                            di.AddClones(clonesOfStatement);
                        }
                        isUniform[i] = g.IsUniform(i, source => !isUniform[source]);
                        if (isUniform[i] != g.isUniform[i])
                        {
                            Assert.IsTrue(isUniform[i]);
                            g.isUniform[i] = isUniform[i];
                            DependencyInformation di = context.InputAttributes.Get <DependencyInformation>(st);
                            di.IsUniform = isUniform[i];
                        }
                        // mark sources of output statements (for SchedulingTransform)
                        if (g.outputNodes.Contains(i))
                        {
                            foreach (NodeIndex source in graph2.SourcesOf(i))
                            {
                                IStatement sourceSt = stmts[source];
                                if (!context.InputAttributes.Has <OutputSource>(sourceSt))
                                {
                                    context.OutputAttributes.Set(sourceSt, new OutputSource());
                                }
                            }
                        }
                    }
                }
            }
            return(output);
        }
Example #9
0
        public void GraphSearchTest()
        {
            // this is the example graph at http://www.codeproject.com/cs/miscctrl/quickgraph.asp
            Graph <BasicNode> g = new Graph <BasicNode>();
            BasicNode         u = new BasicNode("u");
            BasicNode         v = new BasicNode("v");
            BasicNode         w = new BasicNode("w");
            BasicNode         x = new BasicNode("x");
            BasicNode         y = new BasicNode("y");
            BasicNode         z = new BasicNode("z");

            g.Nodes.Add(u);
            g.Nodes.Add(v);
            g.Nodes.Add(w);
            g.Nodes.Add(x);
            g.Nodes.Add(y);
            g.Nodes.Add(z);
            g.AddEdge(u, v);
            g.AddEdge(u, x);
            g.AddEdge(v, y);
            g.AddEdge(y, x);
            g.AddEdge(x, v);
            g.AddEdge(w, u);
            g.AddEdge(w, y);
            g.AddEdge(w, z);

            DepthFirstSearch <BasicNode> dfs = new DepthFirstSearch <BasicNode>(g);

            dfs.DiscoverNode   += delegate(BasicNode node) { Console.WriteLine("discover " + node); };
            dfs.FinishNode     += delegate(BasicNode node) { Console.WriteLine("finish " + node); };
            dfs.DiscoverEdge   += delegate(Edge <BasicNode> edge) { Console.WriteLine("discover " + edge); };
            dfs.TreeEdge       += delegate(Edge <BasicNode> edge) { Console.WriteLine("tree edge " + edge); };
            dfs.FinishTreeEdge += delegate(Edge <BasicNode> edge) { Console.WriteLine("finish tree edge " + edge); };
            dfs.CrossEdge      += delegate(Edge <BasicNode> edge) { Console.WriteLine("cross edge " + edge); };
            dfs.BackEdge       += delegate(Edge <BasicNode> edge) { Console.WriteLine("back edge " + edge); };
            Console.WriteLine("dfs from u:");
            dfs.SearchFrom(u);
            Console.WriteLine();
            Console.WriteLine("dfs from w:");
            dfs.SearchFrom(w);
            Console.WriteLine();
            dfs.Clear();
            Console.WriteLine("cleared dfs from w:");
            dfs.SearchFrom(w);
            Console.WriteLine();

            Console.WriteLine("bfs:");
            BreadthFirstSearch <BasicNode>      bfs      = new BreadthFirstSearch <BasicNode>(g);
            IndexedProperty <BasicNode, double> distance = g.CreateNodeData <double>(Double.PositiveInfinity);

            bfs.DiscoverNode += delegate(BasicNode node) { Console.WriteLine("discover " + node); };
            bfs.FinishNode   += delegate(BasicNode node) { Console.WriteLine("finish " + node); };
            bfs.TreeEdge     += delegate(Edge <BasicNode> edge)
            {
                Console.WriteLine("tree edge " + edge);
                distance[edge.Target] = distance[edge.Source] + 1;
            };
            // compute distances from w
            distance[w] = 0;
            bfs.SearchFrom(w);
            Console.WriteLine("distances from w:");
            foreach (BasicNode node in g.Nodes)
            {
                Console.WriteLine("[" + node + "] " + distance[node]);
            }
            Assert.Equal(2.0, distance[x]);
            Console.WriteLine();

            Console.WriteLine("distances from w:");
            DistanceSearch <BasicNode> dists = new DistanceSearch <BasicNode>(g);

            dists.SetDistance += delegate(BasicNode node, int dist) { Console.WriteLine("[" + node + "] " + dist); };
            dists.SearchFrom(w);
            Console.WriteLine();

            BasicNode start = z, end;

            (new PseudoPeripheralSearch <BasicNode>(g)).SearchFrom(ref start, out end);
            Console.WriteLine("pseudo-peripheral nodes: " + start + "," + end);

            StrongComponents <BasicNode> scc = new StrongComponents <BasicNode>(g);
            int count = 0;

            scc.AddNode        += delegate(BasicNode node) { Console.Write(" " + node); };
            scc.BeginComponent += delegate()
            {
                Console.Write("[");
                count++;
            };
            scc.EndComponent += delegate() { Console.Write("]"); };
            Console.Write("strong components reachable from w (topological order): ");
            scc.SearchFrom(w);
            Assert.Equal(4, count);
            Console.WriteLine();

            count = 0;
            StrongComponents2 <BasicNode> scc2 = new StrongComponents2 <BasicNode>(g);

            scc2.AddNode        += delegate(BasicNode node) { Console.Write(" " + node); };
            scc2.BeginComponent += delegate()
            {
                Console.Write("[");
                count++;
            };
            scc2.EndComponent += delegate() { Console.Write("]"); };
            Console.Write("strong components reachable from w (rev topological order): ");
            scc2.SearchFrom(w);
            Assert.Equal(4, count);
            Console.WriteLine();

#if false
            Console.WriteLine("CyclicDependencySort:");
            List <BasicNode> schedule = CyclicDependencySort <BasicNode> .Schedule(g,
                                                                                   delegate(BasicNode node, ICollection <BasicNode> available) {
                if (node == x)
                {
                    return(available.Contains(u));
                }
                else
                {
                    return(false);
                }
            },
                                                                                   g.Nodes);

            foreach (BasicNode node in schedule)
            {
                Console.Write(node + " ");
            }
            Console.WriteLine();
            Assert.Equal <int>(6, schedule.Count);
            // order should be: w u x v y z (z can be re-ordered)
            Assert.Equal <BasicNode>(w, schedule[0]);
            Assert.Equal <BasicNode>(u, schedule[1]);
            //Assert.Equal<BasicNode>(z,schedule[5]);
#endif
        }
Example #10
0
 internal DependencyGraphView(IndexedGraph dg, IEnumerable <EdgeStylePredicate> edgeStyles = null,
                              Func <NodeIndex, string> nodeName = null,
                              Func <EdgeIndex, string> edgeName = null)
 {
     this.dg         = dg;
     this.edgeStyles = edgeStyles;
     this.nodeName   = nodeName;
     this.edgeName   = edgeName;
     nodeOf          = dg.CreateNodeData <Node>(null);
     OnGraphChanged();
     panel.Dock   = DockStyle.Fill;
     gviewer.Dock = DockStyle.Fill;
     panel.Controls.Add(gviewer);
     if (edgeStyles != null)
     {
         // draw the legend
         TableLayoutPanel legend = new TableLayoutPanel();
         legend.AutoSize    = true;
         legend.ColumnCount = 2 * edgeStyles.Count();
         foreach (EdgeStylePredicate esp in edgeStyles)
         {
             PictureBox pic = new PictureBox();
             pic.SizeMode = PictureBoxSizeMode.AutoSize;
             legend.Controls.Add(pic);
             int size     = 8;
             var bitmap   = new System.Drawing.Bitmap(size, size);
             var graphics = System.Drawing.Graphics.FromImage(bitmap);
             var color    = System.Drawing.Color.Black;
             if ((esp.Style & EdgeStyle.Dimmed) > 0)
             {
                 color = System.Drawing.Color.LightGray;
             }
             else if ((esp.Style & EdgeStyle.Back) > 0)
             {
                 color = System.Drawing.Color.Red;
             }
             else if ((esp.Style & EdgeStyle.Blue) > 0)
             {
                 color = System.Drawing.Color.Blue;
             }
             int width = 1;
             if ((esp.Style & EdgeStyle.Bold) > 0)
             {
                 width = 2;
             }
             var pen = new System.Drawing.Pen(color, width);
             if ((esp.Style & EdgeStyle.Dashed) > 0)
             {
                 pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
             }
             int y = bitmap.Height / 2;
             graphics.DrawLine(pen, 0, y, bitmap.Width - 1, y);
             pic.Image = bitmap;
             ToolLabel label = new ToolLabel();
             label.Text     = esp.Name;
             label.AutoSize = true;
             legend.Controls.Add(label);
         }
         legend.Anchor = AnchorStyles.None; // centers the legend in its parent
         TableLayoutPanel legendPanel = new TableLayoutPanel();
         legendPanel.AutoSize  = true;
         legendPanel.BackColor = System.Drawing.Color.LightGray;
         legendPanel.Controls.Add(legend);
         legendPanel.Dock = DockStyle.Bottom;
         panel.Controls.Add(legendPanel);
     }
 }
Example #11
0
 public EventPropertyGetterIndexed GetPropertyProvidedGetterIndexed(IDictionary <String, Object> nestableTypes, String indexedPropertyName, IndexedProperty indexedProperty, EventAdapterService eventAdapterService)
 {
     return((EventPropertyGetterIndexed)indexedProperty.GetGetterObjectArray(PropertiesIndex, nestableTypes, eventAdapterService));
 }
Example #12
0
 public EventPropertyGetterIndexed GetPropertyProvidedGetterIndexed(IDictionary <String, Object> nestableTypes, String indexedPropertyName, IndexedProperty indexedProperty, EventAdapterService eventAdapterService)
 {
     return(indexedProperty.GetGetterMap(nestableTypes, eventAdapterService) as EventPropertyGetterIndexed);
 }
Example #13
0
 internal EqualityAnalysisTransform()
 {
     newExpression = graph.CreateNodeData <IExpression>();
 }