protected void InitalCustomDBProxyConfigManagement(GroupTypeEnum groupTypeEnum, string dbNodeName)
 {
     _currentDBGroup = GetCurrentDBGroup(groupTypeEnum);
     _listDBNode     = _currentDBGroup.DBNodes.Cast <DBNode>().ToList();
     _currentDBNode  = SetActionNodesCompositeWeight(_currentDBGroup, dbNodeName, out _dbNodeTotalCompositeWeight, out _currentReadWriteActionNodes, out _dbNodeReadWriteTotalCompositeWeight);
     _randomDBNodeTotalCompositeWeight          = new Random(1);
     _randomDBNodeReadWriteTotalCompositeWeight = new Random(1);
     _boolInital = true;
 }
        protected IList <DBNode> GetDBNodeList(CustomDBGroup customDBGroup)
        {
            IList <DBNode> listRtn = new List <DBNode>();

            var objList = from node in customDBGroup.DBNodes.Cast <DBNode>()
                          select node;

            return((IList <DBNode>)objList);
        }
        protected DBNode GetCurrentDBNode(GroupTypeEnum groupTypeEnum, string dbNodeName)
        {
            CustomDBGroup objGroup = GetCurrentDBGroup(groupTypeEnum);

            var objList = from dbNode in objGroup.DBNodes.Cast <DBNode>()
                          where dbNode.Name.Equals(dbNodeName, StringComparison.CurrentCultureIgnoreCase)
                          select dbNode;

            DBNode node = null;

            node = objList.FirstOrDefault <DBNode>();

            return(node);
        }
        protected CustomDBGroup GetCurrentDBGroup(GroupTypeEnum groupTypeEnum)
        {
            CustomDBGroup objGroup = null;

            CustomDBProxyConfigSection section = CustomDBProxyConfigSection.GetConfigSection();

            foreach (CustomDBGroup grp in CustomDBProxyConfigSection.GetConfigSection().CustomDBGroups)
            {
                if (grp.GroupTypeEnum == groupTypeEnum)
                {
                    objGroup = grp;
                    break;
                }
            }

            if (objGroup == null)
            {
                objGroup = CustomDBProxyConfigSection.GetConfigSection().CustomDBGroups.DefaultCustomDBGroup;
            }

            return(objGroup);
        }
        protected DBNode SetActionNodesCompositeWeight(CustomDBGroup customDBGroup, string dbNodeName, out int dbNodeTotalCompositeWeight, out IList <ActionNode> readWriteActionNodes, out int dbNodeReadWriteTotalCompositeWeight)
        {
            int intReadWriteImpactFactor = customDBGroup.DBNodes.ReadWriteImpactFactor;
            int intConstReadWrite        = customDBGroup.DBNodes.ConstReadWrite;
            int intConstRead             = customDBGroup.DBNodes.ConstRead;

            DBNode dbNode = GetCurrentDBNode(customDBGroup.GroupTypeEnum, dbNodeName);

            foreach (ActionNode aNode in dbNode)
            {
                switch (aNode.ActionEnum)
                {
                case ActionEnum.Read:
                    aNode.CompositeWeight = intReadWriteImpactFactor * intConstRead + aNode.Weight;
                    break;

                case ActionEnum.ReadWrite:
                    aNode.CompositeWeight = intReadWriteImpactFactor * intConstReadWrite + aNode.Weight;
                    break;
                }
            }

            var objActionList = from a in dbNode.Cast <ActionNode>()
                                orderby a.CompositeWeight ascending
                                select a;

            foreach (ActionNode aNode in objActionList)
            {
                var objListP = from n in objActionList
                               where n.CompositeWeight <= aNode.CompositeWeight
                               select n;

                int intTotalCompositeWeight = objListP.Sum <ActionNode>(actionNode => actionNode.CompositeWeight);

                aNode.CompositeWeightRangeEnd   = intTotalCompositeWeight;
                aNode.CompositeWeightRangeStart = intTotalCompositeWeight - aNode.CompositeWeight + 1;
            }

            dbNodeTotalCompositeWeight = objActionList.Sum <ActionNode>(actionNode => actionNode.CompositeWeight);


            var objReadWriteActionNodeList = from aNode in objActionList
                                             where aNode.ActionEnum == ActionEnum.ReadWrite
                                             select aNode;

            dbNodeReadWriteTotalCompositeWeight = objReadWriteActionNodeList.Sum <ActionNode>(aNode => aNode.CompositeWeight);

            List <ActionNode> listReadWriteActionNodes = new List <ActionNode>();

            foreach (ActionNode aNode in objReadWriteActionNodeList)
            {
                var objListP = from n in objReadWriteActionNodeList
                               where n.CompositeWeight <= aNode.CompositeWeight
                               select n;

                int intTotalReadWriteCompositeWeight = objListP.Sum <ActionNode>(actionNode => actionNode.CompositeWeight);

                ActionNode tempNode = new ActionNode(aNode.Name, aNode.ActionEnum, aNode.Weight, aNode.CompositeWeight, intTotalReadWriteCompositeWeight - aNode.CompositeWeight + 1, intTotalReadWriteCompositeWeight, aNode.ConnectionString);

                listReadWriteActionNodes.Add(tempNode);
            }

            readWriteActionNodes = listReadWriteActionNodes;

            return(dbNode);
        }
 protected void InitalCustomDBProxyConfigManagement(GroupTypeEnum groupTypeEnum, string dbNodeName)
 {
     _currentDBGroup = GetCurrentDBGroup(groupTypeEnum);
     _listDBNode = _currentDBGroup.DBNodes.Cast<DBNode>().ToList();
     _currentDBNode = SetActionNodesCompositeWeight(_currentDBGroup, dbNodeName, out _dbNodeTotalCompositeWeight, out _currentReadWriteActionNodes, out _dbNodeReadWriteTotalCompositeWeight);
     _randomDBNodeTotalCompositeWeight = new Random(1);
     _randomDBNodeReadWriteTotalCompositeWeight = new Random(1);
     _boolInital = true;
 }
        protected DBNode SetActionNodesCompositeWeight(CustomDBGroup customDBGroup, string dbNodeName, out int dbNodeTotalCompositeWeight, out IList<ActionNode> readWriteActionNodes, out int dbNodeReadWriteTotalCompositeWeight)
        {
            int intReadWriteImpactFactor = customDBGroup.DBNodes.ReadWriteImpactFactor;
            int intConstReadWrite = customDBGroup.DBNodes.ConstReadWrite;
            int intConstRead = customDBGroup.DBNodes.ConstRead;

            DBNode dbNode = GetCurrentDBNode(customDBGroup.GroupTypeEnum, dbNodeName);

            foreach (ActionNode aNode in dbNode)
            {
                switch (aNode.ActionEnum)
                {
                    case ActionEnum.Read:
                        aNode.CompositeWeight = intReadWriteImpactFactor * intConstRead + aNode.Weight;
                        break;
                    case ActionEnum.ReadWrite:
                        aNode.CompositeWeight = intReadWriteImpactFactor * intConstReadWrite + aNode.Weight;
                        break;
                }
            }

            var objActionList = from a in dbNode.Cast<ActionNode>()
                                orderby a.CompositeWeight ascending
                                select a;

            foreach (ActionNode aNode in objActionList)
            {
                var objListP = from n in objActionList
                               where n.CompositeWeight <= aNode.CompositeWeight
                               select n;

                int intTotalCompositeWeight = objListP.Sum<ActionNode>(actionNode => actionNode.CompositeWeight);

                aNode.CompositeWeightRangeEnd = intTotalCompositeWeight;
                aNode.CompositeWeightRangeStart = intTotalCompositeWeight - aNode.CompositeWeight + 1;
            }

            dbNodeTotalCompositeWeight = objActionList.Sum<ActionNode>(actionNode => actionNode.CompositeWeight);


            var objReadWriteActionNodeList = from aNode in objActionList
                                             where aNode.ActionEnum == ActionEnum.ReadWrite
                                             select aNode;

            dbNodeReadWriteTotalCompositeWeight = objReadWriteActionNodeList.Sum<ActionNode>(aNode => aNode.CompositeWeight);

            List<ActionNode> listReadWriteActionNodes = new List<ActionNode>();

            foreach (ActionNode aNode in objReadWriteActionNodeList)
            {
                var objListP = from n in objReadWriteActionNodeList
                               where n.CompositeWeight <= aNode.CompositeWeight
                               select n;

                int intTotalReadWriteCompositeWeight = objListP.Sum<ActionNode>(actionNode => actionNode.CompositeWeight);

                ActionNode tempNode = new ActionNode(aNode.Name, aNode.ActionEnum, aNode.Weight, aNode.CompositeWeight, intTotalReadWriteCompositeWeight - aNode.CompositeWeight + 1, intTotalReadWriteCompositeWeight, aNode.ConnectionString);

                listReadWriteActionNodes.Add(tempNode);
            }

            readWriteActionNodes = listReadWriteActionNodes;                       

            return dbNode;
        }
        protected IList<DBNode> GetDBNodeList(CustomDBGroup customDBGroup)
        {
            IList<DBNode> listRtn = new List<DBNode>();

            var objList = from node in customDBGroup.DBNodes.Cast<DBNode>()
                          select node;

            return (IList<DBNode>)objList;
        }