コード例 #1
0
        /// <summary>
        /// Creates a new document in the project, and adds it to unoproj file.
        /// Also creates any missing directories in path.
        /// </summary>
        public async Task CreateDocument(RelativeFilePath relativePath, SourceFragment contents = null)
        {
            contents = contents ?? SourceFragment.Empty;

            var rootDir = await RootDirectory.FirstAsync();

            var newFilePath = rootDir.Combine(relativePath);

            var containingDir = newFilePath.ContainingDirectory;

            _shell.Create(containingDir);

            using (var stream = _shell.CreateNew(newFilePath))
            {
                var bytes = contents.ToBytes();
                stream.Write(bytes, 0, bytes.Length);
            }

            var projectFilePath = await FilePath.FirstAsync();

            var project = Uno.ProjectFormat.Project.Load(projectFilePath.NativePath);

            if (project.AllFiles.None(item => item.UnixPath == relativePath.NativeRelativePath))
            {
                project.MutableIncludeItems.Add(new Uno.ProjectFormat.IncludeItem(relativePath.NativeRelativePath));
                project.Save();
            }
        }