Esempio n. 1
0
        internal async Task ProcessChildItemsAsync(string documentText, string filePath)
        {
            var physicalFile = await PhysicalFile.FromFileAsync(filePath);

            var spans = Scanner.GetSpans(documentText, true);

            var generator = SpansToContent.Convert(spans);

            await CreateSqlContentAsync(physicalFile, generator);

            await CreateEnumContentAsync(physicalFile, generator);
        }
Esempio n. 2
0
        internal async Task <PhysicalFile> WriteFileAsync(string content, string path, Project project)
        {
            using (var sw = new StreamWriter(path))
            {
                await sw.WriteAsync(content);
            }

            var file = await PhysicalFile.FromFileAsync(path);

            if (file == null)
            {
                file = (await project.AddExistingFilesAsync(path)).Single();
            }

            return(file);
        }
Esempio n. 3
0
        internal async Task CreateEnumContentAsync(PhysicalFile physicalFile, ContentGenerator generator)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var language = physicalFile.AsProjectItem().ContainingProject.CodeModel.Language;

            var codePath = Path.ChangeExtension(physicalFile.FullPath,
                                                CodeModelLanguageConstants.vsCMLanguageVB == language
                    ? ".dv.vb"
                    : ".dv.cs"
                                                );

            var codeProvider = CodeModelLanguageConstants.vsCMLanguageVB == language
                ? CodeDomProvider.CreateProvider("VisualBasic")
                : CodeDomProvider.CreateProvider("C#");

            var fileNamespace = GenerateNamespace(physicalFile);

            var enumContent = generator.GetEnumCode(codeProvider, fileNamespace);

            if (string.IsNullOrWhiteSpace(enumContent))
            {
                var vsFile = await PhysicalFile.FromFileAsync(codePath);

                if (vsFile != null)
                {
                    await vsFile.TryRemoveAsync();
                }

                return;
            }

            var file = await WriteFileAsync(enumContent, codePath, physicalFile.ContainingProject);

            if (file == null)
            {
                return;
            }

            await file.SetAsChildItemAsync(physicalFile);

            await physicalFile.ContainingProject.SaveAsync();
        }