Ejemplo n.º 1
0
        private AmmyProject GetAmmyProject(string filename, out string projectName)
        {
            AmmyProject cachedProject;

            var genericProject = DteHelpers.GetProjectByFilename(filename);

            if (genericProject == null || genericProject.Kind == EnvDTE.Constants.vsProjectKindMisc)
            {
                throw new CompilerServiceException("Project not found for file: " + filename);
            }

            projectName = genericProject.Name;

            if (_projectCaches.TryGetValue(projectName, out cachedProject))
            {
                var cachedReferences = cachedProject.References.Select(r => r.Path).ToList();
                var cachedFiles      = GetCachedFiles(cachedProject);

                var newProject = new AmmyProject(cachedReferences, cachedFiles, cachedProject.CSharpProject, cachedProject.FsProject.Data, cachedProject.FsProject.ProjectDir, cachedProject.OutputPath, cachedProject.RootNamespace, cachedProject.AssemblyName, cachedProject.TargetPath);
                return(newProject);
            }

            var projectItems    = DteHelpers.GetFileList(genericProject);
            var ammyFileMetas   = GetAmmyFileMetas(projectItems);
            var sourceFilenames = projectItems.Select(pi => DteHelpers.GetFilename(pi)).ToArray();
            var project         = (VSProject)genericProject.Object;
            var fullPath        = genericProject.Properties.Item("FullPath").Value.ToString();
            var objRelativePath = genericProject.ConfigurationManager.ActiveConfiguration.Properties.Item("IntermediatePath").Value.ToString();
            var outputPath      = genericProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
            var outputFileName  = genericProject.Properties.Item("OutputFileName").Value.ToString();
            var targetPath      = Path.Combine(fullPath, outputPath, outputFileName);
            var rootNamespace   = genericProject.Properties.Item("RootNamespace").Value.ToString();
            var assemblyName    = genericProject.Properties.Item("AssemblyName").Value.ToString();
            //var hostAssemblyPath = Path.Combine(outputDir, outputFileName);
            var references      = GetReferences(project);
            var compilationData = NeedReferenceRefresh(references) ? null : LatestResult?.CompilationData;
            var csharpProject   = new CSharpProject(fullPath, sourceFilenames);
            var ammyProject     = new AmmyProject(references, ammyFileMetas, csharpProject, compilationData, fullPath, objRelativePath, rootNamespace, assemblyName, targetPath);

            _projectCaches[projectName] = ammyProject;
            SubscribeToReferenceChanges(project, projectName);

            return(ammyProject);
        }
Ejemplo n.º 2
0
        private List <AmmyFileMeta> GetCachedFiles(AmmyProject cachedProject)
        {
            var result = new List <AmmyFileMeta>();

            foreach (var file in cachedProject.Files)
            {
                var fileInfo = new FileInfo(file.FilePath);

                if (!fileInfo.Exists)
                {
                    continue;
                }

                var cachedVersion     = ((ITextSnapshot)file.Meta.Snapshot)?.Version.VersionNumber;
                var currentDoc        = _openDocuments.FirstOrDefault(d => d.FilePath == file.FilePath);
                var currentVersion    = currentDoc?.TextBuffer?.CurrentSnapshot?.Version?.VersionNumber;
                var isSnapshotUpdated = cachedVersion < currentVersion;

                if (fileInfo.LastWriteTime > file.LastWriteTime || isSnapshotUpdated)
                {
                    result.Add(ToAmmyFileMeta(file.FilePath, file.Meta.ProjectItem));
                    this.LogDebugInfo("Using new " + file.OutputFilename);
                }
                else
                {
                    file.DeepResetProperties();
                    file.BamlCompilerMessages.Clear();
                    result.Add(file.Meta);
                    //if (file.Meta.Snapshot == null)
                    TryAssignSnapshot(file);
                    this.LogDebugInfo("Using cached " + file.OutputFilename);
                }
            }

            return(result);
        }