Ejemplo n.º 1
0
        private static List <TreeLayerViewModel> InitTree(TreeMember currentElement, List <TreeLayerViewModel> treeLayers, int currentLevel)
        {
            if (treeLayers == null)
            {
                treeLayers = new List <TreeLayerViewModel>();
            }

            if (!treeLayers.Any(tl => tl.Level == currentLevel))
            {
                treeLayers.Add(new TreeLayerViewModel()
                {
                    Level         = currentLevel,
                    IsInitialized = false,
                    Members       = new List <TreeMemberViewModel>()
                });
            }

            treeLayers[currentLevel].Members.Add(new TreeMemberViewModel(currentElement));
            if (currentElement.Children.Any(c => c.IsDocumentType(TreeMember.ModelTypeAlias)))
            {
                foreach (var child in currentElement.Children.Where(c => c.IsDocumentType(TreeMember.ModelTypeAlias)).Select(c => (TreeMember)c))
                {
                    InitTree(child, treeLayers, currentLevel + 1);
                }
            }

            return(treeLayers);
        }
 protected void ASPxTreeList1_VirtualModeCreateChildren(object sender, DevExpress.Web.ASPxTreeList.TreeListVirtualModeCreateChildrenEventArgs e)
 {
     if (e.NodeObject == null)
     {
         using (IDocumentSession session = Global.Store.OpenSession())
         {
             //TODO: Query the list of treelist members to get unique results based on appIds
             if (session.Query <TreeMember>().Any())
             {
                 var allData       = session.Query <TreeMember>().ToList();
                 var processedData = session.Query <TreeMember>().ToList();
                 foreach (var data in allData)
                 {
                     if (processedData.Where(x => x.AppID == data.AppID).Count() > 1)
                     {
                         TreeMember uniqueMember = data;
                         processedData.RemoveAll(x => x.AppID == data.AppID);
                         processedData.Add(data);
                     }
                 }
                 e.Children = processedData;
             }
         }
     }
     else
     {
         TreeMember theMember = e.NodeObject as TreeMember;
         using (IDocumentSession session = Global.Store.OpenSession())
         {
             var theChildren = session.Query <TreeMember>().Where(x => x.ParentComponentId == theMember.AppID).ToList();
             e.Children = theChildren;
         }
     }
 }
Ejemplo n.º 3
0
        void AssertPaternity()
        // For each branch out from the given root which is not a parent branch, assign that branch
        // as the child's parent branch.
        // As this could be deeply recursive and could result in a stack overflow, this must be coded as a loop.
        {
            Stack <Tuple <TreeMember, TreeBranch> > arguments = new Stack <Tuple <TreeMember, TreeBranch> >();
            TreeBranch prevBranch = new TreeBranch();
            bool       stepBack   = false;

            foreach (TreeBranch rootBranch in root.Branches)
            {
                arguments.Push(Tuple.Create(rootBranch.Follow(root), rootBranch));

                while (arguments.Count > 0)
                {
                    Tuple <TreeMember, TreeBranch> nextArgument = arguments.Peek();
                    TreeMember member       = nextArgument.Item1;
                    TreeBranch parentBranch = nextArgument.Item2;
                    stepBack = false;

                    member.parentBranch = parentBranch;
                    ((TreeNode)parentBranch.Follow(member)).SetChild(parentBranch);

                    if (member.GetType() == typeof(TreeNode))
                    {
                        TreeNode node = (TreeNode)member;
                        if (node.Branches.Contains(prevBranch))
                        // If the previously-used branch is a member of this node's branches, that means we've already used the
                        // branches of this node, and can discard it.
                        {
                            stepBack = true;
                        }
                        else
                        {
                            foreach (TreeBranch branch in node.Branches)
                            {
                                if (branch != parentBranch)
                                {
                                    arguments.Push(Tuple.Create(branch.Follow(node), branch));
                                }
                            }
                        }
                    }
                    else
                    {
                        stepBack = true;
                    }

                    if (stepBack)
                    {
                        prevBranch = parentBranch;
                        arguments.Pop();
                    }
                }
            }
        }
        protected void ASPxTreeList1_VirtualModeNodeCreating(object sender, DevExpress.Web.ASPxTreeList.TreeListVirtualModeNodeCreatingEventArgs e)
        {
            TreeMember theMember = e.NodeObject as TreeMember;

            e.IsLeaf = theMember.HasSubComponents;
            e.SetNodeValue("Name", theMember.AppName);
            e.SetNodeValue("AppID", theMember.AppID);
            e.SetNodeValue("Status", theMember.Status);
            e.SetNodeValue("DateChecked", theMember.DateChecked);
            e.NodeKeyValue = theMember.AppID;
        }
Ejemplo n.º 5
0
 public TreeBranch GetBranch(TreeMember member)
 {
     foreach (TreeBranch branch in branches)
     {
         if (branch.Follow(this) == member)
         {
             return(branch);
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
        static double GetAverageBranchLength(TreeMember member, TreeBranch baseBranch, bool includeBranch, out int numLeaves)
        // From the given tree member, this will calculate the average branch length of the branches extending
        // from it. The switch "includeBranch" indicates whether the branch should be included in the numbers
        // (used for distance to the other end of the branch). If the TreeMember is a leaf, this function returns 0.
        {
            double averageBranchLength = 0;
            double sumBranchLength     = GetSumBranchLength(member, baseBranch, includeBranch, out numLeaves);

            averageBranchLength = sumBranchLength / numLeaves;

            return(averageBranchLength);
        }
Ejemplo n.º 7
0
            public TreeMember Follow(TreeMember origin)
            // Returns the connection that the branch leads to, given the starting node
            {
                if (origin == connection1)
                {
                    return(connection2);
                }
                if (origin == connection2)
                {
                    return(connection1);
                }

                throw new ArgumentException("This branch does not connect to the member provided.");
            }
Ejemplo n.º 8
0
        private TreeMember GetSelectedMember(RoutedEventArgs args)
        {
            TreeMember member = null;

            if (args.Source is TreeViewItem)
            {
                var selectedItem = args.Source as TreeViewItem;
                member = selectedItem.DataContext as TreeMember;
            }
            else if (args.Source is ContentPresenter)
            {
                var selectedItem = args.Source as ContentPresenter;
                member = selectedItem.DataContext as TreeMember;
            }
            return(member);
        }
Ejemplo n.º 9
0
 protected void ASPxTreeList1_HtmlRowPrepared(object sender, DevExpress.Web.ASPxTreeList.TreeListHtmlRowEventArgs e)
 {
     using (IDocumentSession session = Global.Store.OpenSession())
     {
         using (var transaction = new TransactionScope())
         {
             if (e.RowKind != TreeListRowKind.Preview && session.Query <TreeListMember>().Where(x => x.AppID == e.NodeKey).Any())
             {
                 TreeMember member = session.Load <TreeMember>(session.Query <TreeMember>().Where(x => x.AppID == e.NodeKey).First().Id);
                 member.RowClientId = e.Row.ClientID;
                 session.SaveChanges();
             }
             transaction.Complete();
         }
     }
 }
 public TreeMemberViewModel(TreeMember treeMember)
 {
     if (treeMember != null)
     {
         this.ID                 = treeMember.Id;
         this.Name               = treeMember.Name;
         this.Spouse             = treeMember.Spouse.FormatSpouseName();
         this.SpouseSecond       = treeMember.SpouseSecond.FormatSpouseName();
         this.BirthDate          = treeMember.BirthDate != DateTime.MinValue ? treeMember.BirthDate.ToShortDateString() : String.Empty;
         this.DeathDate          = treeMember.DateOfDeath != DateTime.MinValue ? treeMember.DateOfDeath.ToShortDateString() : String.Empty;
         this.Children           = treeMember.Children.Where(c => c.IsDocumentType(TreeMember.ModelTypeAlias)).Select(c => c.Id).ToList();
         this.ParentID           = treeMember.Parent.Id;
         this.Length             = this.Name.Length;
         this.SpouseLength       = this.Spouse.Length;
         this.SpouseSecondLength = this.SpouseSecond.Length;
     }
 }
Ejemplo n.º 11
0
 protected void ASPxTreeList1_CustomDataCallback(object sender, DevExpress.Web.ASPxTreeList.TreeListCustomDataCallbackEventArgs e)
 {
     using (IDocumentSession session = Global.Store.OpenSession())
     {
         string processedId = e.Argument;
         if (e.Argument.StartsWith("!-!"))
         {
             processedId = "{" + e.Argument.Substring(3, e.Argument.Length - 3);
         }
         if (e.Argument.EndsWith("!-!"))
         {
             processedId = processedId.Substring(0, processedId.Length - 3) + "}";
         }
         using (var transaction = new TransactionScope())
         {
             if (session.Query <TreeCheckResult>().Where(x => x.AppID == processedId).Any())
             {
                 TreeMember             member           = session.Load <TreeMember>(session.Query <TreeMember>().Where(x => x.AppID == processedId).First().Id);
                 List <TreeCheckResult> allResults       = session.Query <TreeCheckResult>().Where(r => r.AppID == processedId).ToList();
                 List <TreeCheckResult> processedResults = session.Query <TreeCheckResult>().Where(r => r.AppID == processedId).ToList();
                 foreach (var result in allResults)
                 {
                     if (processedResults.Where(x => x.Title == result.Title).Count() > 1)
                     {
                         TreeCheckResult uniqueResult = result;
                         processedResults.RemoveAll(x => x.Title == result.Title);
                         processedResults.Add(result);
                     }
                 }
                 e.Result = TreeListMemberLogic.HtmlizeResults(processedResults);
             }
             else
             {
                 e.Result = "Results not found";
             }
             transaction.Complete();
         }
     }
 }
Ejemplo n.º 12
0
            public static void Build(TreeMember member1, TreeMember member2, double length)
            {
                TreeBranch newBranch = new TreeBranch(member1, member2, length);

                if (member1.GetType() == typeof(TreeNode))
                {
                    ((TreeNode)member1).AddBranch(newBranch);
                }
                else
                {
                    member1.parentBranch = newBranch;
                }

                if (member2.GetType() == typeof(TreeNode))
                {
                    ((TreeNode)member2).AddBranch(newBranch);
                }
                else
                {
                    member2.parentBranch = newBranch;
                }
            }
Ejemplo n.º 13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //RAVEN Db
     using (IDocumentSession session = Global.Store.OpenSession())
     {
         if (session.Query <TreeMember>().Any())
         {
             var allData       = session.Query <TreeMember>().ToList();
             var processedData = session.Query <TreeMember>().ToList();
             foreach (var data in allData)
             {
                 if (processedData.Where(x => x.AppID == data.AppID).Count() > 1)
                 {
                     TreeMember uniqueMember = data;
                     processedData.RemoveAll(x => x.AppID == data.AppID);
                     processedData.Add(data);
                 }
             }
             myTree.DataSource = processedData;
             myTree.DataBind();
         }
     }
 }
Ejemplo n.º 14
0
        private Point DrowWithoutBorders(Graphics g, TreeMember knot, Rectangle rect)
        {
            var center = new Point(rect.Left + rect.Width / 2, rect.Top);;

            if (knot == null)
            {
                DrawKnot(g, null, center.X, center.Y);
                return(center);
            }
            DrawKnot(g, knot.Value, center.X, center.Y);

            var subSize   = new Size((rect.Width - HorizontalMarging) / 2, rect.Height - VerticalMarging);
            var leftRect  = new Rectangle(new Point(rect.Left, rect.Top + VerticalMarging), subSize);
            var rightRect = new Rectangle(new Point(rect.Left + (rect.Width + HorizontalMarging) / 2, rect.Top + VerticalMarging), subSize);

            var leftPoint  = DrowWithoutBorders(g, knot.Left, leftRect);
            var rightPoint = DrowWithoutBorders(g, knot.Right, rightRect);

            DrawLine(g, center, leftPoint);
            DrawLine(g, center, rightPoint);

            return(center);
        }
Ejemplo n.º 15
0
        static double GetSumBranchLength(TreeMember member, TreeBranch baseBranch, bool includeBranch, out int numLeaves)
        // This is a recursive function
        //
        {
            // Algorithm:
            //   1. Store the branch length to the current member in "distance" (except the first if includeBranch is true).
            //   2. If the current member is a node, add the other branches to the stack and continue the loop.
            //      If the current member is a leaf, add 1 to the number of leaves, add the stemLength to the sumBranchLength, and subtract the length to this branch from the distance.
            //   3.

            double sumBranchLength = 0;

            numLeaves = 0;
            Stack <Tuple <TreeMember, TreeBranch> > arguments = new Stack <Tuple <TreeMember, TreeBranch> >();
            double distance = 0;

            arguments.Push(Tuple.Create(baseBranch.Follow(member), baseBranch));
            TreeBranch prevBranch = new TreeBranch();
            bool       stepBack   = false;

            while (arguments.Count > 0)
            {
                Tuple <TreeMember, TreeBranch> nextArgument = arguments.Peek();
                TreeMember nextMember     = nextArgument.Item1;
                TreeBranch nextBaseBranch = nextArgument.Item2;

                if (nextMember.GetType() == typeof(TreeNode))
                {
                    TreeNode node = (TreeNode)nextMember;
                    if (node.Branches.Contains(prevBranch))
                    // If the previously-used branch is a member of this node's branches, that means we've already used the
                    // branches of this node, and can discard it.
                    {
                        stepBack = true;
                    }
                    else
                    {
                        distance += nextBaseBranch.BranchLength;
                        foreach (TreeBranch branch in node.Branches)
                        {
                            if (branch != nextBaseBranch)
                            {
                                arguments.Push(Tuple.Create(branch.Follow(node), branch));
                            }
                        }
                    }
                }
                else
                // This is a leaf, so add the distance to the sum, increment the leaf count, and step backward
                {
                    distance        += nextBaseBranch.BranchLength;
                    sumBranchLength += distance;
                    numLeaves++;
                    stepBack = true;
                }

                if (stepBack)
                {
                    prevBranch = nextBaseBranch;
                    distance  -= nextBaseBranch.BranchLength;
                    arguments.Pop();
                    stepBack = false;
                }
            }

            if (!includeBranch)
            {   // If we didn't want to include the base branch length, correct for that here.
                sumBranchLength -= numLeaves * baseBranch.BranchLength;
            }

            return(sumBranchLength);
        }
Ejemplo n.º 16
0
        public void Draw(Graphics g, TreeMember knot, Rectangle rect)
        {
            var newRect = new Rectangle(rect.Left + Radius, rect.Top + Radius, rect.Width - 2 * Radius, rect.Height - 2 * Radius);

            DrowWithoutBorders(g, knot, newRect);
        }
Ejemplo n.º 17
0
 TreeBranch(TreeMember member1, TreeMember member2, double length)
 {
     connection1  = member1;
     connection2  = member2;
     branchLength = length;
 }
Ejemplo n.º 18
0
 private void ItemExpandedEventAction(TreeMember member)
 {
     var test = "this is a test";
 }
        public void Handle(SelfHealthMessage message)
        {
            GlobalHost.ConnectionManager.GetConnectionContext <MonitorHub>().Connection.Broadcast("messageReceived");
            using (IDocumentSession session = Global.Store.OpenSession())
            {
                try
                {
                    if (session.Query <TreeMember>().Where(x => x.AppID == message.AppID).Any())
                    {
                        TreeMember theMember = session.Load <TreeMember>(session.Query <TreeMember>().Where(x => x.AppID == message.AppID).First().Id);
                        using (var transaction = new TransactionScope())
                        {
                            theMember.DateChecked = message.DateChecked;
                            List <TreeCheckResult> memberResults = session.Query <TreeCheckResult>().Where(x => x.AppID == message.AppID).ToList();
                            foreach (var result in message.Results)
                            {
                                if (memberResults.Any(x => x.Title == result.Title))
                                {
                                    TreeCheckResult formerResult = session.Load <TreeCheckResult>(session.Query <TreeCheckResult>().Where(x => x.AppID == message.AppID && x.Title == result.Title).First().Id);
                                    formerResult.Status = result.Status;
                                    formerResult.AdditionalInformation = result.AdditionalInformation;
                                    formerResult.TimeElasped           = result.TimeElasped;
                                    session.SaveChanges();
                                }
                                else
                                {
                                    TreeCheckResult newResult = new TreeCheckResult();
                                    newResult.AppID  = message.AppID;
                                    newResult.Title  = result.Title;
                                    newResult.Status = result.Status;
                                    newResult.AdditionalInformation = result.AdditionalInformation;
                                    newResult.TimeElasped           = result.TimeElasped;
                                    session.Store(newResult);
                                    session.SaveChanges();
                                }
                                //session.SaveChanges();
                            }
                            List <TreeCheckResult> newMemberResults = session.Query <TreeCheckResult>().Where(x => x.AppID == message.AppID).ToList();
                            theMember.Status = GetOverallStatus(newMemberResults);
                            session.SaveChanges();
                            transaction.Complete();
                        }

                        //:: SignalR CLIENT ::
                        GlobalHost.ConnectionManager.GetConnectionContext <MonitorHub>().Connection.Broadcast("afterProcessing");
                        var hubContext = GlobalHost.ConnectionManager.GetConnectionContext <MonitorHub>();
                        hubContext.Connection.Broadcast(JsonConvert.SerializeObject(theMember));
                        //}
                    }


                    else
                    {
                        Component c = new Component();
                        using (var datacontext = new ServiceMonitorDataContext())
                        {
                            var comp = datacontext.Components.Where(x => x.AppID == message.AppID);
                            if (comp.Any())
                            {
                                c.AppID             = comp.First().AppID;
                                c.AppName           = comp.First().AppName;
                                c.HasSubComponents  = comp.First().HasSubComponents == true ? true : false;
                                c.ParentComponentId = comp.First().ParentComponentId;
                            }
                        }
                        using (var transaction = new TransactionScope())
                        {
                            TreeMember m = new TreeMember()
                            {
                                AppID             = message.AppID,
                                AppName           = c.AppName,
                                DateChecked       = message.DateChecked,
                                HasSubComponents  = c.HasSubComponents,
                                ParentComponentId = c.ParentComponentId,
                                Status            = message.OverallStatus
                            };
                            session.Store(m);

                            foreach (var result in message.Results)
                            {
                                TreeCheckResult r = new TreeCheckResult()
                                {
                                    AppID  = message.AppID,
                                    Title  = result.Title,
                                    Status = result.Status,
                                    AdditionalInformation = result.AdditionalInformation,
                                    TimeElasped           = result.TimeElasped
                                };
                                session.Store(r);
                            }
                            ;
                            session.SaveChanges();
                            transaction.Complete();
                        }

                        //:: SignalR CLIENT ::
                        var hubContext = GlobalHost.ConnectionManager.GetConnectionContext <MonitorHub>();
                        hubContext.Connection.Broadcast("reloadPage");
                    }
                }
                catch (Exception exp)
                {
                    GlobalHost.ConnectionManager.GetConnectionContext <MonitorHub>().Connection.Broadcast("error:" + exp.Message);
                }
            }
        }
Ejemplo n.º 20
0
 public void InvokeExpandedEvent(MedKitTreeViewItem item)
 {
     this.ExpandingMember = item.DataContext as TreeMember;
     this.ItemExpandedEvent?.Invoke(item, EventArgs.Empty);
 }