示例#1
0
        /// <summary>
        /// Initializes the managed application and session state.
        /// </summary>
        private static void InitializeApplicationState()
        {
            try
            {
                //Get the feature's configuration info
                StateProviderConfiguration qc =
                    (StateProviderConfiguration)ConfigurationManager.GetSection("StateProvider");

                if (qc.DefaultProvider == null || qc.Providers == null || qc.Providers.Count < 1)
                {
                    throw new ProviderException("You must specify a valid default provider.");
                }

                //Instantiate the providers
                providerCollection = new StateProviderCollection();
                ProvidersHelper.InstantiateProviders(qc.Providers, providerCollection, typeof(BaseStateProvider));
                providerCollection.SetReadOnly();
                defaultProvider = providerCollection[qc.DefaultProvider];

                if (HttpContext.Current != null && HttpContext.Current.Request != null)
                {
                    defaultProvider.ApplicationPath         = HttpContext.Current.Request.ApplicationPath;
                    defaultProvider.PhysicalApplicationPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
                }

                if (defaultProvider == null)
                {
                    throw new ConfigurationErrorsException(
                              "You must specify a default provider for the feature.",
                              qc.ElementInformation.Properties["defaultProvider"].Source,
                              qc.ElementInformation.Properties["defaultProvider"].LineNumber);
                }

                StateAccess.State = defaultProvider;
            }
            catch (Exception ex)
            {
                initializationException = ex;
                isInitialized           = false;
                throw ex;
            }
        }
示例#2
0
 private void TraceOutsideFunctionBoundsRec(InstructionNode currentNode, Dictionary <InstructionNode, int> visitCount, Dictionary <InstructionNode, MergeNodeTraceData> mergingNodesData, InstructionNode lastNode = null, StateProviderCollection stateProviders = null)
 {
     if (lastNode == null)
     {
         lastNode       = currentNode;
         stateProviders = new StateProviderCollection();
         GlobalVisited.Clear();
     }
     while (true)
     {
         GlobalVisited.Add(currentNode);
         bool reachedMergeNodeNotLast;
         ActOnCurrentNode(currentNode, mergingNodesData, lastNode, ref stateProviders, out reachedMergeNodeNotLast);
         if (reachedMergeNodeNotLast)
         {
             return;
         }
         visitCount[currentNode]++;
         if (!(currentNode is ConditionalJumpNode) && visitCount[currentNode] > currentNode.BranchProperties.Branches.Count(x => x.BranchType == BranchType.Loop) * 2 + 1 && currentNode.ProgramFlowBackRoutes.Count == 1)
         {
             return;
         }
         lastNode = currentNode;
         if (currentNode.ProgramFlowForwardRoutes.Count == 1)
         {
             currentNode = currentNode.ProgramFlowForwardRoutes[0];
             continue;
         }
         else
         {
             var firstInLoopNodes = currentNode.ProgramFlowForwardRoutes.Where(x => x.BranchProperties.FirstInLoop).ToList();
             if (firstInLoopNodes.Count > 1)
             {
                 throw new Exception("Can't have 2 first loop nodes");
             }
             else if (firstInLoopNodes.Count == 1)
             {
                 var loopNode = firstInLoopNodes[0];
                 if (visitCount[loopNode] < 2)
                 {
                     //Console.WriteLine("looping at " + loopNode.InstructionIndex);
                     currentNode = loopNode;
                     continue;
                 }
                 else
                 {
                     //Console.WriteLine("looped more than twice at " + loopNode.InstructionIndex);
                     visitCount[loopNode] = 0;
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
     }
     if (currentNode.ProgramFlowForwardRoutes.Count == 0)
     {
         return;
     }
     if (!(currentNode is ConditionalJumpNode))
     {
         throw new Exception("split without a conditional");
     }
     foreach (var node in currentNode.ProgramFlowForwardRoutes.Where(x => !x.BranchProperties.FirstInLoop).ToList())
     {
         TraceOutsideFunctionBoundsRec(node, visitCount, mergingNodesData, currentNode, stateProviders.Clone());
     }
 }
示例#3
0
        private static void ActOnCurrentNode(InstructionNode currentNode, Dictionary <InstructionNode, MergeNodeTraceData> mergingNodesData, InstructionNode lastNode, ref StateProviderCollection stateProviders, out bool reachedMergeNodeNotLast)
        {
            if (currentNode.BranchProperties.MergingNodeProperties.IsMergingNode)
            {
                lock (mergingNodesData)
                {
                    mergingNodesData[currentNode].ReachedNodes.Add(lastNode);
                    BranchID emptyBranchToMe = null;
                    IEnumerable <BranchID> nonEmptyBranchesToMe = null;
                    if ((lastNode is ConditionalJumpNode))
                    {
                        emptyBranchToMe = ((ConditionalJumpNode)lastNode).CreatedBranches.FirstOrDefault(x => x.BranchNodes.SequenceEqual(new[] { currentNode }));
                    }
                    if (emptyBranchToMe == null)
                    {
                        nonEmptyBranchesToMe = lastNode.BranchProperties.Branches.Intersect(currentNode.BranchProperties.MergingNodeProperties.MergedBranches);
                    }
                    if (emptyBranchToMe != null || nonEmptyBranchesToMe.Any())
                    {
                        mergingNodesData[currentNode].AccumelatedStateProviders.AddRange(stateProviders.ToList());
                        var  mergedBrachesNonEmpty    = currentNode.ProgramFlowBackRoutes.Where(x => x.BranchProperties.Branches.Any(y => currentNode.BranchProperties.MergingNodeProperties.MergedBranches.Contains(y)));
                        var  mergedBrachesEmpty       = currentNode.ProgramFlowBackRoutes.Where(x => x is ConditionalJumpNode).Cast <ConditionalJumpNode>().Where(x => x.CreatedBranches.Intersect(currentNode.BranchProperties.MergingNodeProperties.MergedBranches).Any());
                        var  splitMergeMergedBranches = mergedBrachesEmpty.Concat(mergedBrachesNonEmpty).ToList();
                        bool allBranchesReached       = !splitMergeMergedBranches.Except(mergingNodesData[currentNode].ReachedNodes).Any();
                        if (allBranchesReached)
                        {
                            stateProviders = new StateProviderCollection(mergingNodesData[currentNode].AccumelatedStateProviders);
                            mergingNodesData[currentNode].AccumelatedStateProviders.Clear();
                            //prepare for next run (for loops)
                            mergingNodesData[currentNode].ReachedNodes.Clear();
                        }
                        else
                        {
                            reachedMergeNodeNotLast = true;
                            return;
                        }
                    }
                    else
                    {
                    }
                }
            }
            var newStoreStateProviders = StoreDynamicDataStateProvider.GetMatchingStateProvider(currentNode);

            if (newStoreStateProviders != null)
            {
                foreach (var newStateProvider in newStoreStateProviders)
                {
                    stateProviders.AddNewProvider(newStateProvider);
                }
            }
            IDynamicDataLoadNode loadNode = currentNode as IDynamicDataLoadNode;

            if (loadNode != null)
            {
                foreach (var stateProvider in stateProviders.MatchLoadToStore(currentNode))
                {
                    stateProvider.ConnectToLoadNode((InstructionNode)loadNode);
                    //have to change this to abstract
                }
            }
            reachedMergeNodeNotLast = false;
        }