Пример #1
0
        public void CopyContentTo(Project project)
        {
            var sourcePath      = ContentDirectory.FullName;
            var destinationPath = project.ProjectDirectory.FullName;

            GetNewPathDelegate getNewPath = fsi => destinationPath + fsi.FullName.Substring(sourcePath.Length);

            // Now Create all of the directories
            foreach (var sourceDir in ContentDirectory.GetDirectories("*", SearchOption.AllDirectories))
            {
                Try(sourceDir, getNewPath, CreateDirectory);
            }

            // Copy all the files
            foreach (var sourceFile in ContentDirectory.GetFiles("*.*", SearchOption.AllDirectories))
            {
                Try(sourceFile, getNewPath, File.Copy);
            }
        }
Пример #2
0
        private static void Try(FileSystemInfo source, GetNewPathDelegate destPathGetter, FileSystemAction action)
        {
            var destPath = destPathGetter(source);

            if (File.Exists(destPath) || Directory.Exists(destPath))
            {
                Console.WriteLine("{0} already exists, skipping", destPath);
                return;
            }

            Console.WriteLine("{0} => {1}", source, destPath);

            try
            {
                action(source.FullName, destPath);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
        }
Пример #3
0
        private static void Try(FileSystemInfo source, GetNewPathDelegate destPathGetter, FileSystemAction action)
        {
            var destPath = destPathGetter(source);

            if (File.Exists(destPath) || Directory.Exists(destPath))
            {
                Console.WriteLine("{0} already exists, skipping", destPath);
                return;
            }

            Console.WriteLine("{0} => {1}", source, destPath);

            try
            {
                action(source.FullName, destPath);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
        }