Esempio n. 1
0
        private void CheckCircularTree(WebFactorTreeNode factorTree,
                                       List <Int32> factorIds)
        {
            List <Int32> childFactorIds;

            if (factorTree.IsNotNull())
            {
                if (factorIds.Contains(factorTree.Id))
                {
                    // Circular factor tree found.
                    throw new Exception("Circular factor tree found! Factor id = " + factorTree.Id);
                }
                else
                {
                    factorIds.Add(factorTree.Id);
                }

                if (factorTree.Children.IsNotEmpty())
                {
                    foreach (WebFactorTreeNode child in factorTree.Children)
                    {
                        childFactorIds = new List <Int32>();
                        childFactorIds.AddRange(factorIds);
                        CheckCircularTree(child, childFactorIds);
                    }
                }
            }
        }
 /// <summary>
 /// Merge data object with this list.
 /// Only objects that are not already in the list
 /// are added to the list.
 /// </summary>
 /// <param name='data'>The data to merge.</param>
 public void Merge(WebFactorTreeNode data)
 {
     if (data.IsNotNull() && _idHashtable[data.Id].IsNull())
     {
         Add(data);
     }
 }
 public WebFactorTreeNode GetFactorTreeNode(Boolean refresh)
 {
     if (_factorTreeNode.IsNull() || refresh)
     {
         _factorTreeNode = FactorManagerTest.GetForestFactorTreeNode(GetContext());
     }
     return(_factorTreeNode);
 }
Esempio n. 4
0
 /// <summary>
 /// Load data into the WebFactorTreeNode instance.
 /// </summary>
 /// <param name="factorTreeNode">The factor tree node instance.</param>
 /// <param name='dataReader'>An open data reader.</param>
 public static void LoadData(this WebFactorTreeNode factorTreeNode,
                             DataReader dataReader)
 {
     factorTreeNode.Id     = dataReader.GetInt32(FactorData.ID);
     factorTreeNode.Factor = new WebFactor();
     factorTreeNode.Factor.LoadData(dataReader);
     factorTreeNode.Children = new List <WebFactorTreeNode>();
     factorTreeNode.Parents  = new List <WebFactorTreeNode>();
 }
Esempio n. 5
0
            /// <summary>
            /// Create a FactorInformation instance.
            /// </summary>
            /// <param name="context">The web service context.</param>
            /// <param name='dataReader'>An open data reader.</param>
            public FactorInformation(WebServiceContext context, DataReader dataReader)
            {
                WebFactorTreeNode childTreeNode, factorTreeNode, parentTreeNode;

                // Get all factors and factor tree nodes.
                FactorTreeNodes = new WebFactorTreeNodeList();
                Factors         = new List <WebFactor>();
                while (dataReader.Read())
                {
                    factorTreeNode = new WebFactorTreeNode();
                    factorTreeNode.LoadData(dataReader);

                    FactorTreeNodes.Merge(factorTreeNode);
                    Factors.Add(factorTreeNode.Factor);
                }

                // Get next result set.
                if (!dataReader.NextResultSet())
                {
                    throw new ApplicationException("No information about factors relations when getting factor tree");
                }

                // Get factor relations and build factor trees.
                while (dataReader.Read())
                {
                    try
                    {
                        parentTreeNode = FactorTreeNodes.Get(dataReader.GetInt32(FactorTreeData.PARENT_FACTOR_ID));
                        if (parentTreeNode != null)
                        {
                            childTreeNode = FactorTreeNodes.Get(dataReader.GetInt32(FactorTreeData.CHILD_FACTOR_ID));
                            if (childTreeNode != null)
                            {
                                parentTreeNode.AddChild(childTreeNode);
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        // Suppress any errors of type ArgumentException
                    }
                }

                // Extract all factor tree nodes that
                // are not child tree nodes.
                FactorTrees = new List <WebFactorTreeNode>();
                foreach (WebFactorTreeNode factorTree in FactorTreeNodes)
                {
                    if (!factorTree.IsChild())
                    {
                        FactorTrees.Add(factorTree);
                    }
                }
            }
        /// <summary>
        /// Convert a WebFactor instance into
        /// an IFactor instance.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webFactorTree">A WebFactorTreeNode instance.</param>
        /// <param name="factorTreeNodes">
        /// All factor tree nodes that have been created so far.
        /// This parameter is used to avoid duplication of
        /// factor tree nodes (factor tree nodes with same factor attached to it)
        /// if the same factor appears more than once in the tree.
        /// </param>
        /// <param name="factorDataTypes">List of factor data types.</param>
        /// <param name="factorOrigins">List of factor origins.</param>
        /// <param name="factorUpdateModes">List of factor update modes.</param>
        /// <returns>An IFactorTreeNode instance.</returns>
        private IFactorTreeNode GetFactorTree(IUserContext userContext, WebFactorTreeNode webFactorTree, Hashtable factorTreeNodes, FactorDataTypeList factorDataTypes, FactorOriginList factorOrigins, FactorUpdateModeList factorUpdateModes)
        {
            IFactorTreeNode child, factorTree;

            if (factorTreeNodes.ContainsKey(webFactorTree.Factor.Id))
            {
                factorTree = (IFactorTreeNode)factorTreeNodes[webFactorTree.Factor.Id];
            }
            else
            {
                factorTree = new FactorTreeNode
                {
                    DataContext = GetDataContext(userContext),
                    Factor      = GetFactor(userContext, webFactorTree.Factor, factorDataTypes, factorOrigins, factorUpdateModes),
                    Id          = webFactorTree.Id
                };
                if (webFactorTree.Children.IsNotEmpty())
                {
                    factorTree.Children = new FactorTreeNodeList();
                    foreach (WebFactorTreeNode webChild in webFactorTree.Children)
                    {
                        child = GetFactorTree(userContext, webChild, factorTreeNodes, factorDataTypes, factorOrigins, factorUpdateModes);
                        if (child.Parents.IsNull())
                        {
                            child.Parents = new FactorTreeNodeList();
                        }

                        child.Parents.Add(factorTree);
                        factorTree.Children.Add(child);
                    }
                }

                factorTreeNodes.Add(webFactorTree.Factor.Id, factorTree);
            }

            return(factorTree);
        }
 public WebFactorTreeNodeTest()
 {
     _factorTree     = null;
     _factorTreeNode = null;
 }
Esempio n. 8
0
 /// <summary>
 /// Test if this factor tree node is child.
 /// </summary>
 /// <param name="parent">The factor tree node instance.</param>
 /// <returns>True, if this factor tree node has parents.</returns>
 public static Boolean IsChild(this WebFactorTreeNode parent)
 {
     return(parent.Parents.Count > 0);
 }
Esempio n. 9
0
 /// <summary>
 /// Add a factor tree node to the children
 /// of this factor tree node.
 /// </summary>
 /// <param name="parent">Parent factor tree node.</param>
 /// <param name='child'>Child factor tree node.</param>
 public static void AddChild(this WebFactorTreeNode parent,
                             WebFactorTreeNode child)
 {
     parent.Children.Add(child);
     child.Parents.Add(parent);
 }