Exemplo n.º 1
0
        public static IProject LoadProject(IMSBuildEngineProvider provider, string location, string title, string projectTypeGuid, IProgressMonitor progressMonitor)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            if (projectTypeGuid == null)
            {
                throw new ArgumentNullException("projectTypeGuid");
            }

            if (progressMonitor != null)
            {
                progressMonitor.BeginTask("Loading " + title, 0, false);
            }

            IProject newProject;

            if (!File.Exists(location))
            {
                newProject          = new MissingProject(location, title);
                newProject.TypeGuid = projectTypeGuid;
            }
            else
            {
                ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location);
                if (binding != null)
                {
                    location = FileUtility.NormalizePath(location);
                    try {
                        newProject = binding.LoadProject(provider, location, title);
                    } catch (ProjectLoadException ex) {
                        LoggingService.Warn("Project load error", ex);
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = true;
                        }
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = false;
                        }
                    } catch (UnauthorizedAccessException ex) {
                        LoggingService.Warn("Project load error", ex);
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = true;
                        }
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = false;
                        }
                    }
                }
                else
                {
                    string ext = Path.GetExtension(location);
                    if (".proj".Equals(ext, StringComparison.OrdinalIgnoreCase) ||
                        ".build".Equals(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        newProject          = new MSBuildFileProject(location, title);
                        newProject.TypeGuid = projectTypeGuid;
                    }
                    else
                    {
                        newProject          = new UnknownProject(location, title);
                        newProject.TypeGuid = projectTypeGuid;
                    }
                }
            }
            return(newProject);
        }