Ejemplo n.º 1
0
        private ServiceFolder EnsureServiceFolder(ServiceFolders serviceFolders, List <string> folderList)
        {
            string folderToEnsure = folderList[0];

            folderList.RemoveAt(0);

            foreach (ServiceFolder folder in serviceFolders)
            {
                if (string.Compare(folder.Name, folderToEnsure) == 0) // we found the folder
                {
                    if (folderList.Count == 0)                        // we're at the end of our path
                    {
                        return(folder);
                    }

                    // we're not at the end of our path, so go deeper.
                    return(EnsureServiceFolder(folder.ServiceFolders, folderList));
                }
            }

            // We didn't find the folder, so create it and go deeper.
            ServiceFolder newSf = new ServiceFolder(folderToEnsure, new MetaData(folderToEnsure, folderToEnsure));

            serviceFolders.Create(newSf);
            if (folderList.Count != 0)
            {
                return(EnsureServiceFolder(newSf.ServiceFolders, folderList));
            }
            return(newSf);
        }
Ejemplo n.º 2
0
        private List <string> ValidateFolders(ServiceFolders actual, string folderName, FullPath path)
        {
            var errors           = new List <string>();
            var actualDictionary = actual.ToDictionary();

            if (!Path.IsPathRooted((string)path))
            {
                var error = $"Path must be rooted, not relative, but was '{path}'.";
                errors.Add(error);
                return(errors);
            }

            if (!actualDictionary.TryGetValue(folderName, out string current))
            {
                //folder should be known to the service
                var error = $"Folder '{folderName}'('{path}') is unknown.";
                errors.Add(error);
                return(errors);
            }

            if (Folder.Exists((string)path))
            {
                //target folder should not exist
                var error =
                    $"Folder '{folderName}'('{path}') already exists. Remove it before starting the operation.";
                errors.Add(error);
                return(errors);
            }

            // folder path should be valid
            var result = Folder.EnsureExists((string)path);

            if (!result.Exists)
            {
                var error = $"Cannot create folder '{folderName}'('{path}'). Possibly invalid path.";
                errors.Add(error);
                return(errors);
            }

            Folder.EnsureDeleted((string)path);
            return(errors);
        }
Ejemplo n.º 3
0
        private void MoveFolders(ServiceFolders actual, string folderName, FullPath path, DeploymentTaskContext context)
        {
            var cloned = actual.Clone();

            var source      = (string)actual[folderName];
            var destination = path;

            var haveSameRoot = Path.GetPathRoot(source) == Path.GetPathRoot((string)destination);

            if (haveSameRoot)
            {
                MoveSimple(context.BuildLog, source, destination);
            }
            else
            {
                CopyAndDelete(context.BuildLog, source, destination);
            }

            cloned[folderName] = destination;
            context.NewFolders = cloned;
        }