Пример #1
0
 /// <summary>
 /// If this is the last model of the chain, run the loop.
 /// Otherwise, delegate to the next model and wait for an exception.
 /// </summary>
 public void Run()
 {
     try
     {
         if (NextModel == null)
         {
             RunLoop();
         }
         else
         {
             IsWaiting = true;
             NextModel.Run();
         }
     }
     catch (Exception ex)
     {
         if (!CatchExceptions)
         {
             AppendOutput($"I see the exception, but can't handle it....");
             IsWaiting = false;
             IsRunning = false;
             throw;
         }
         AppendOutput($"Handler {Index} caught this:  {ex.Message}");
         if (LoopAfterCatch)
         {
             RunLoop(false);
         }
     }
     finally
     {
         IsWaiting = false;
     }
 }
Пример #2
0
        ///// <summary>
        ///// Draws the graph.
        ///// </summary>
        //public void DrawTheGraph()
        //{
        //    Canvas theGraph = new Canvas();

        // // Draw the edges for (int i = 0; i < Edges.Count; i++) {
        // theGraph.Children.Add(Edges[i].TheLine); }

        // // Draw the nodes for (int i = 0; i < TreeGraph.Count; i++) { PeopleGraphNode item = TreeGraph[i];

        // // Assume person PersonModel t = DV.PersonDV.GetModel(item.nodeHLink.HLinkKey);

        // if (t.HLink.Valid == true) { PersonCardSmall tt = new PersonCardSmall { DataContext = t,
        // Background = new SolidColorBrush(Colors.AliceBlue), }; theGraph.Children.Add(tt);

        // tt.SetValue(Canvas.LeftProperty, item.xStart); tt.SetValue(Canvas.TopProperty,
        // item.yStart); } else { // Assume Family FamilyModel tf =
        // DV.FamilyDV.GetModel(item.nodeHLink.HLinkKey); FamilyCardSmall tt = new FamilyCardSmall {
        // DataContext = tf, Background = new SolidColorBrush(Colors.AliceBlue), };

        // theGraph.Children.Add(tt);

        // tt.SetValue(Canvas.LeftProperty, item.xStart); tt.SetValue(Canvas.TopProperty,
        // item.yStart); } }

        //    // Display it
        //    GraphCanvas = theGraph;
        //}

        /// <summary>
        /// Gets the graph.
        /// </summary>
        /// <param name="argHLink">
        /// The argument h link.
        /// </param>
        public void GetGraph()
        {
            // Get people related to personObject person (within 3 jumps and starting at level zero
            // (the middlish point))
            nodeVisitQueue.Enqueue(new NextModel()
            {
                HLink = StartHLink, JumpsFromStartNode = 3, Level = 0
            });

            PeopleGraphNode theNode;

            do
            {
                NextModel t = nodeVisitQueue.Dequeue();

                // Handle people
                if (t.HLink.GetType() == typeof(HLinkPersonModel))
                {
                    // Add person to graph
                    theNode = new PeopleGraphNode
                    {
                        NodeHLink = (t.HLink as HLinkPersonModel).DeRef.HLink,
                        YStart    = t.Level,
                    };
                    TreeGraph.Add(theNode);

                    // Add one to the level
                    if (!maxXNodes.ContainsKey(t.Level))
                    {
                        maxXNodes.Add(t.Level, 0);
                    }

                    // Add one to the level
                    maxXNodes[t.Level] = maxXNodes[t.Level] + 1;

                    AddVisited((t.HLink as HLinkPersonModel).DeRef.HLinkKey, false);

                    if (t.JumpsFromStartNode > 0)
                    {
                        // get parents
                        AddHLink((t.HLink as HLinkPersonModel).DeRef.GChildOf, t.HLink, t.JumpsFromStartNode, t.Level - 1);

                        // get families
                        foreach (HLinkFamilyModel item in (t.HLink as HLinkPersonModel).DeRef.GParentInRefCollection)
                        {
                            AddHLink(t.HLink, item, t.JumpsFromStartNode, t.Level + 1);
                        }
                    }
                }

                // Handle families
                if (t.HLink.GetType() == typeof(HLinkFamilyModel))
                {
                    // Add Family
                    theNode = new PeopleGraphNode
                    {
                        NodeHLink = (t.HLink as HLinkFamilyModel).DeRef.HLink,
                        YStart    = t.Level,
                    };
                    TreeGraph.Add(theNode);

                    // Add one to the level
                    if (!maxXNodes.ContainsKey(t.Level))
                    {
                        maxXNodes.Add(t.Level, 0);
                    }

                    // Add one to the level
                    maxXNodes[t.Level] = maxXNodes[t.Level] + 1;

                    AddVisited((t.HLink as HLinkFamilyModel).DeRef.HLinkKey, false);

                    if (t.JumpsFromStartNode > 0)
                    {
                        // Add Mother and Father at previous level
                        AddHLink((t.HLink as HLinkFamilyModel).DeRef.GMother, t.HLink, t.JumpsFromStartNode, t.Level - 1);

                        AddHLink((t.HLink as HLinkFamilyModel).DeRef.GFather, t.HLink, t.JumpsFromStartNode, t.Level - 1);

                        // Add children at next level
                        foreach (HLinkPersonModel item in (t.HLink as HLinkFamilyModel).DeRef.GChildRefCollection)
                        {
                            AddHLink(t.HLink, item, t.JumpsFromStartNode, t.Level + 1);
                        }
                    }
                }
            }while (nodeVisitQueue.Count > 0);
        }