Esempio n. 1
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Builds a list of product tree nodes that represents the full product tree for the
        /// host back-end item store.
        /// </summary>
        //------------------------------------------------------------------------------------
        private void BuildProductTree(ProductTree productTree, int startingTreeID)
        {
            Node rootPSNode   = HostItemStore.Instance.GetProductTreeRootNode();
            Node startingNode = rootPSNode.FindNodeInSubtree(startingTreeID);

            BuildProductTreeWorker(productTree.Nodes, startingNode);
        }
Esempio n. 2
0
 //------------------------------------------------------------------------------------
 /// <summary>
 /// Caches the given list of product tree nodes locally for quick access next time.
 /// </summary>
 //------------------------------------------------------------------------------------
 public static void CacheProductTree(ProductTree tree)
 {
     if (tree != null && tree.Count > 0)
     {
         IFormatter formatter = new BinaryFormatter();
         string     fullPath  = GetProductTreeCacheFullPath();
         Stream     stream    = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None);
         formatter.Serialize(stream, tree);
         stream.Close();
     }
 }
Esempio n. 3
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Kick-starts the process of building and caching the product task tree.
        /// </summary>
        //------------------------------------------------------------------------------------
        void BeginBuildTaskTree()
        {
            IsEnsureHostProductTreeInProgress = true;

            ProductTree = new ProductTree();
            Node           rootNode      = HostItemStore.Instance.GetProductTreeRootNode();
            BackgroundTask buildTreeTask = new BackgroundTask(false);

            buildTreeTask.DoWork        += buildTreeTask_DoWork;
            buildTreeTask.TaskCompleted += buildTreeTask_TaskCompleted;
            buildTreeTask.RunTaskAsync();
        }
Esempio n. 4
0
 //------------------------------------------------------------------------------------
 /// <summary>
 /// Checks to see if the product tree is loaded and ready, and if not, kicks off a
 /// background process to build it. Once the tree is ready, IsTreeItemCollectionAvailable
 /// will return true.
 /// </summary>
 //------------------------------------------------------------------------------------
 public void EnsureHostProductTree()
 {
     if (!IsEnsureHostProductTreeInProgress)
     {
         if (ProductTree == null)
         {
             ProductTree = UncacheProductTree();
             if (ProductTree == null)
             {
                 BeginBuildTaskTree();
             }
         }
     }
 }
Esempio n. 5
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Uncaches the last list of product tree nodes that was cached with CachProductTree.
        /// If there is no valid cache available, null will be returned.
        /// </summary>
        //------------------------------------------------------------------------------------
        public static ProductTree UncacheProductTree()
        {
            string fullPath = GetProductTreeCacheFullPath();

            if (System.IO.File.Exists(fullPath))
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                try
                {
                    ProductTree tree = (ProductTree)formatter.Deserialize(stream);
                    if (tree != null)
                    {
                        // If the help manager indicates that the host product tree has been updated in
                        // the back-end store since the last time the tree was cached, invalidate it so
                        // that it will be re-cached.
                        DateTime?lastProductTreeUpdate = HelpManager.Instance.HostProductTreeLastUpdate;
                        if (lastProductTreeUpdate != null)
                        {
                            DateTime lastCached = tree.CachedDateTime;
                            if (lastProductTreeUpdate.Value >= lastCached)
                            {
                                return(null);
                            }
                        }
                    }

                    return(tree);
                }

                // If the tree couldn't be uncached for any reason, return null to trigger a rebuild.
                catch (Exception e)
                {
                    Planner.Instance.HandleException(e);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
 public ProductTreeManager()
 {
     ProductTree = null;
     IsEnsureHostProductTreeInProgress = false;
     HasCacheBeenChecked = false;
 }