Ejemplo n.º 1
0
        /// <summary>
        /// Threadsafe mechanism for loading folder information and guaranteeing
        /// the folder exists.
        /// </summary>
        /// <param name="folderPath">The desired folder path.</param>
        /// <param name="navonAction">Action to perform on the folder's Navon.</param>
        /// <returns>A PSFolder object containing details of the folder.</returns>
        /// <remarks>The folder path specified must be fully qualified with the //Sites/ folder
        /// and the base of the specific site. e.g. //Sites/CancerGov.</remarks>
        public PSFolder GuaranteeFolder(string folderPath, NavonAction navonAction)
        {
            if (folderPath == null)
            {
                throw new ArgumentNullException("folderPath");
            }

            if (folderPath.EndsWith("/") && folderPath != "/")
            {
                folderPath = folderPath.Substring(0, folderPath.Length - 1);
            }

            // Does the path already exist in the collection?
            if (!_folderCollection.ContainsKey(folderPath))
            {
                // Lock the container for possible updating.
                lock (_folderCollection)
                {
                    // Was the folder looked up while we were waiting for
                    // the lock?
                    if (!_folderCollection.ContainsKey(folderPath))
                    {
                        PSFolder folderInfo = ForceFolderToExist(folderPath, navonAction);
                        _folderCollection.Add(folderPath, folderInfo);
                    }
                }
            }

            return(_folderCollection[folderPath]);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to load a folder's information. If the folder doesn't
        /// exist, create it.
        /// </summary>
        /// <param name="folderPath">Folder which is to be created.</param>
        /// <param name="navonAction">Action to perform on the folder's Navon.</param>
        /// <returns></returns>
        private PSFolder ForceFolderToExist(string folderPath, NavonAction navonAction)
        {
            PSFolder returnItem;

            // TODO: Rewrite to use  PSWSUtils.LoadFolders()

            returnItem = GetExistingFolder(folderPath);

            if (returnItem == null)
            {
                returnItem = CreateNewFolder(folderPath, navonAction);
            }

            return(returnItem);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new folder in Percussion and obtains the detailed
        /// PSFolder object.
        /// </summary>
        /// <param name="folderPath">Path of the folder to be created.</param>
        /// <param name="navonAction">Action to perform on the folder's Navon.</param>
        /// <returns>PSFolder object detailing the new folder.</returns>
        private PSFolder CreateNewFolder(string folderPath, NavonAction navonAction)
        {
            int    splitPoint    = folderPath.LastIndexOfAny(new char[] { '/', '\\' });
            string parentFolder  = folderPath.Substring(0, splitPoint);
            string newFolderName = folderPath.Substring(splitPoint + 1);

            // Force the parent path to exist if it doesn't already.
            // This seems scary because GuaranteeFolder() establishes a lock which would need
            // to be released before execution could continue.  So what happens when another
            // thread has a lock inside GuaranteeFolder()? Doesn't that create a deadlock
            // since the other thread is waiting for us to finish and we're waiting for the
            // other thread?
            //
            // It turns out the lock is smart and only applies to *other* threads.
            // When the current execution encounters the lock, it's able to continue.
            // Ref: ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_csref/html/656da1a4-707e-4ef6-9c6e-6d13b646af42.htm
            GuaranteeFolder(parentFolder, navonAction);

            AddFolderRequest req = new AddFolderRequest();

            req.Path = parentFolder;
            req.Name = newFolderName;
            AddFolderResponse resp = _contentService.AddFolder(req);

            // Folder is newly created, update Navon
            switch (navonAction)
            {
            // FUTURE.
            //case NavonAction.Suppress:
            //    break;

            case NavonAction.MakePublic:
                MakeNavonPublic(folderPath);
                break;

            case NavonAction.None:
            default:
                break;
            }

            return(resp.PSFolder);
        }