private void GenerateXamlFile(string xamlFile)
        {
            var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath);

            if (!Path.IsPathRooted(xamlFile))
            {
                xamlFile = Path.Combine(Path.GetDirectoryName(ProjectFilePath), xamlFile);
            }

            xamlFile = Path.GetFullPath(xamlFile);
            var sourceXmlFile = xamlFile;

            if (!File.Exists(sourceXmlFile))
            {
                return;
            }

            var relativePath = Paths.MakeRelativeToFolder(sourceXmlFile, projectSourceFolder);

            relativePath = relativePath.Replace("..", "parent");

            var destinationHtmlFile = Path.Combine(ProjectDestinationFolder, relativePath) + ".html";

            var xamlSupport = new XamlSupport(this);

            xamlSupport.GenerateXaml(sourceXmlFile, destinationHtmlFile, relativePath);

            OtherFiles.Add(relativePath);
            AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(relativePath), relativePath, 0);
        }
Пример #2
0
        public IFormFile CreateFile(IFormFile file)
        {
            var supportedTypes = new[] { "zip", "rar", "tgz" };

            var fileName = System.IO.Path.GetFileName(file.FileName);

            var fileExtension = System.IO.Path.GetExtension(file.FileName).Substring(1);

            using (var stream = new System.IO.MemoryStream())
            {
                file.CopyTo(stream);

                if (!supportedTypes.Contains(fileExtension))
                {
                    throw new NotSupportedException("Unsupported File Format");
                }

                var otherFile = new OtherFiles()
                {
                    FileId    = 0,
                    FileName  = fileName,
                    FileType  = file.ContentType,
                    OtherFile = stream.ToArray(),
                    CreatedOn = DateTime.Now
                };

                _context.OtherFiles.Add(otherFile);
                _context.SaveChanges();
            }

            return(file);
        }
Пример #3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="target">セマンティックモデル</param>
        /// <param name="container">イベントコンテナ</param>
        public FileRoot(SemanticModel target, EventContainer container)
        {
            // ファイルパス取得
            FilePath = target.SyntaxTree.FilePath;

            // 外部参照イベント登録
            container.Register <OtherFileReferenced>(this, (ev) =>
            {
                if (!OtherFiles.ContainsKey(ev.ClassName))
                {
                    OtherFiles.Add(ev.ClassName, ev.FilePath);
                }
            });

            // 解析処理
            var rootNode = target.SyntaxTree.GetRoot().ChildNodes().Where(syntax => syntax.IsKind(SyntaxKind.NamespaceDeclaration)).First();

            foreach (var item in (rootNode as NamespaceDeclarationSyntax).Members)
            {
                var memberResult = ItemFactory.Create(item, target, container);
                if (memberResult != null)
                {
                    Members.Add(memberResult);
                }
            }

            // 外部参照イベント登録解除
            container.Unregister <OtherFileReferenced>(this);
        }
        private void GenerateProjectFile()
        {
            var projectExtension = Path.GetExtension(ProjectFilePath);

            if (!File.Exists(ProjectFilePath) ||
                ".dll".Equals(projectExtension, StringComparison.OrdinalIgnoreCase) ||
                ".winmd".Equals(projectExtension, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            ProjectCollection projectCollection = null;

            try
            {
                var title = Path.GetFileName(ProjectFilePath);
                var destinationFileName = Path.Combine(ProjectDestinationFolder, title) + ".html";

                AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(title), title, 0);

                // ProjectCollection caches the environment variables it reads at startup
                // and doesn't re-get them later. We need a new project collection to read
                // the latest set of environment variables.
                projectCollection   = new ProjectCollection();
                this.msbuildProject = new Project(
                    ProjectFilePath,
                    null,
                    null,
                    projectCollection,
                    ProjectLoadSettings.IgnoreMissingImports);

                var msbuildSupport = new MSBuildSupport(this);
                msbuildSupport.Generate(ProjectFilePath, destinationFileName, msbuildProject, true);

                GenerateXmlFiles(msbuildProject);

                GenerateXamlFiles(msbuildProject);

                GenerateResxFiles(msbuildProject);

                GenerateTypeScriptFiles(msbuildProject);

                OtherFiles.Add(title);
            }
            catch (Exception ex)
            {
                Log.Exception("Exception during Project file generation: " + ProjectFilePath + "\r\n" + ex.ToString());
            }
            finally
            {
                if (projectCollection != null)
                {
                    projectCollection.UnloadAllProjects();
                    projectCollection.Dispose();
                }
            }
        }
        private string AddOtherFileRelativeToProject(string filePath)
        {
            var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath);

            relativePath = relativePath.Replace("..", "parent");

            OtherFiles.Add(relativePath);

            return(relativePath);
        }
Пример #6
0
        public byte[] GetHash(string fileName)
        {
            var hash = OtherFiles.Where(i => i.FileName != null).FirstOrDefault(i =>
                                                                                string.Equals(i.FileName, fileName, StringComparison.OrdinalIgnoreCase))?.Hash;

            if (Logger.IsEnabled(LogLevel.Trace))
            {
                Logger.LogTrace("LOOKUP: {fileName} ({status})", fileName, hash == null ? "NOT FOUND" : ToHexString(hash));
            }

            return(hash);
        }
Пример #7
0
        private void AddHtmlFilesToRedirectMap()
        {
            var files = Directory
                        .GetFiles(ProjectDestinationFolder, "*.html", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var relativePath = file.Substring(ProjectDestinationFolder.Length + 1).Replace('\\', '/');
                relativePath = relativePath.Substring(0, relativePath.Length - 5); // strip .html
                AddFileToRedirectMap(relativePath);
                OtherFiles.Add(relativePath);
            }
        }
        private void GenerateTypeScriptFile(string filePath)
        {
            var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath);

            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(Path.GetDirectoryName(ProjectFilePath), filePath);
            }

            SolutionGenerator.AddTypeScriptFile(filePath);

            var relativePath = Paths.MakeRelativeToFile(filePath, ProjectFilePath);

            relativePath = relativePath.Replace("..", "parent");
            OtherFiles.Add(relativePath);
        }
Пример #9
0
        private void GenerateDeclarations()
        {
            Log.Write("Declarations...");

            var lines = new List <string>();

            if (DeclaredSymbols != null)
            {
                foreach (var declaredSymbol in DeclaredSymbols
                         .OrderBy(s => SymbolIdService.GetName(s.Key))
                         .ThenBy(s => s.Value))
                {
                    lines.Add(string.Join(";",
                                          SymbolIdService.GetName(declaredSymbol.Key),                                   // symbol name
                                          declaredSymbol.Value,                                                          // 8-byte symbol ID
                                          SymbolKindText.GetSymbolKind(declaredSymbol.Key),                              // kind (e.g. "class")
                                          Markup.EscapeSemicolons(SymbolIdService.GetDisplayString(declaredSymbol.Key)), // symbol full name and signature
                                          SymbolIdService.GetGlyphNumber(declaredSymbol.Key)));                          // icon number
                }
            }

            if (OtherFiles != null)
            {
                foreach (var document in OtherFiles.OrderBy(d => d))
                {
                    lines.Add(string.Join(";",
                                          Path.GetFileName(document),
                                          SymbolIdService.GetId(document),
                                          "file",
                                          Markup.EscapeSemicolons(document),
                                          Serialization.GetIconForExtension(document)));
                }
            }

            Serialization.WriteDeclaredSymbols(ProjectDestinationFolder, lines);
        }
Пример #10
0
        public async Task Generate()
        {
            try
            {
                if (string.IsNullOrEmpty(ProjectFilePath))
                {
                    Log.Exception("ProjectFilePath is empty: " + Project.ToString());
                    return;
                }

                ProjectDestinationFolder = GetProjectDestinationPath(Project, SolutionGenerator.SolutionDestinationFolder);
                if (ProjectDestinationFolder == null)
                {
                    Log.Exception("Errors evaluating project: " + Project.Id);
                    return;
                }

                Log.Write(ProjectDestinationFolder, ConsoleColor.DarkCyan);

                if (SolutionGenerator.SolutionSourceFolder is string solutionFolder)
                {
                    ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, solutionFolder);
                }
                else
                {
                    ProjectSourcePath = ProjectFilePath;
                }

                if (File.Exists(Path.Combine(ProjectDestinationFolder, Constants.DeclaredSymbolsFileName + ".txt")))
                {
                    // apparently someone already generated a project with this assembly name - their assembly wins
                    Log.Exception(string.Format(
                                      "A project with assembly name {0} was already generated, skipping current project: {1}",
                                      this.AssemblyName,
                                      this.ProjectFilePath), isSevere: false);
                    return;
                }

                if (Configuration.CreateFoldersOnDisk)
                {
                    Directory.CreateDirectory(ProjectDestinationFolder);
                }

                var documents = Project.Documents.Where(IncludeDocument).ToList();

                var generationTasks = Partitioner.Create(documents)
                                      .GetPartitions(Environment.ProcessorCount)
                                      .Select(partition =>
                                              Task.Run(async() =>
                {
                    using (partition)
                    {
                        while (partition.MoveNext())
                        {
                            await GenerateDocument(partition.Current);
                        }
                    }
                }));

                await Task.WhenAll(generationTasks);

                foreach (var document in documents)
                {
                    OtherFiles.Add(Paths.GetRelativeFilePathInProject(document));
                }

                if (Configuration.WriteProjectAuxiliaryFilesToDisk)
                {
                    GenerateProjectFile();
                    GenerateDeclarations();
                    GenerateBaseMembers();
                    GenerateImplementedInterfaceMembers();
                    GenerateProjectInfo();
                    GenerateReferencesDataFiles(
                        this.SolutionGenerator.SolutionDestinationFolder,
                        ReferencesByTargetAssemblyAndSymbolId);
                    GenerateSymbolIDToListOfDeclarationLocationsMap(
                        ProjectDestinationFolder,
                        SymbolIDToListOfLocationsMap);
                    GenerateReferencedAssemblyList();
                    GenerateUsedReferencedAssemblyList();
                    GenerateProjectExplorer();
                    GenerateNamespaceExplorer();
                    GenerateIndex();
                }

                var compilation = Project.GetCompilationAsync().Result;
                var diagnostics = compilation.GetDiagnostics().Select(d => d.ToString()).ToArray();
                if (diagnostics.Length > 0)
                {
                    var diagnosticsTxt = Path.Combine(this.ProjectDestinationFolder, "diagnostics.txt");
                    File.WriteAllLines(diagnosticsTxt, diagnostics);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex, "Project generation failed for: " + ProjectSourcePath);
            }
        }