public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor) { object readObject = null; ProjectExtensionUtil.BeginLoadOperation(); try { string ext = Path.GetExtension(fileName).ToLower(); if (ext == ".mdp") { object project = ReadProjectFile(fileName, monitor); if (project is DotNetProject) { ((DotNetProject)project).SetItemHandler(new MD1DotNetProjectHandler((DotNetProject)project)); } readObject = project; } else if (ext == ".mds") { readObject = ReadCombineFile(fileName, monitor); } else if (ext == ".mdw") { readObject = ReadWorkspaceItemFile(fileName, monitor); } else { XmlTextReader reader = new XmlTextReader(new StreamReader(fileName)); try { monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading solution item: {0}"), fileName), 1); reader.MoveToContent(); XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext); ser.SerializationContext.BaseFile = fileName; ser.SerializationContext.ProgressMonitor = monitor; SolutionEntityItem entry = (SolutionEntityItem)ser.Deserialize(reader, typeof(SolutionEntityItem)); entry.FileName = fileName; MD1ProjectService.InitializeHandler(entry); readObject = entry; } catch (Exception ex) { monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load solution item: {0}"), fileName), ex); throw; } finally { monitor.EndTask(); reader.Close(); } } } finally { ProjectExtensionUtil.EndLoadOperation(); } IWorkspaceFileObject fo = readObject as IWorkspaceFileObject; if (fo != null) { fo.ConvertToFormat(MD1ProjectService.FileFormat, false); } return(readObject); }
public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor) { string ext = Path.GetExtension(fileName).ToLower(); if (ext != ".mdw") { throw new ArgumentException(); } object readObject = null; ProjectExtensionUtil.BeginLoadOperation(); try { readObject = ReadWorkspaceItemFile(fileName, monitor); } finally { ProjectExtensionUtil.EndLoadOperation(); } IWorkspaceFileObject fo = readObject as IWorkspaceFileObject; if (fo != null) { fo.ConvertToFormat(MD1ProjectService.FileFormat, false); } return(readObject); }
public object ReadFile(FilePath fileName, bool hasParentSolution, IProgressMonitor monitor) { FilePath basePath = fileName.ParentDirectory; MonoMakefile mkfile = new MonoMakefile(fileName); string aname = mkfile.GetVariable("LIBRARY"); if (aname == null) { aname = mkfile.GetVariable("PROGRAM"); } try { ProjectExtensionUtil.BeginLoadOperation(); if (aname != null) { // It is a project monitor.BeginTask("Loading '" + fileName + "'", 0); DotNetAssemblyProject project = new DotNetAssemblyProject("C#"); MonoSolutionItemHandler handler = new MonoSolutionItemHandler(project); ProjectExtensionUtil.InstallHandler(handler, project); project.Name = Path.GetFileName(basePath); handler.Read(mkfile); monitor.EndTask(); return(project); } else { string subdirs; StringBuilder subdirsBuilder = new StringBuilder(); subdirsBuilder.Append(mkfile.GetVariable("common_dirs")); if (subdirsBuilder.Length != 0) { subdirsBuilder.Append("\t"); subdirsBuilder.Append(mkfile.GetVariable("net_2_0_dirs")); } if (subdirsBuilder.Length == 0) { subdirsBuilder.Append(mkfile.GetVariable("SUBDIRS")); } subdirs = subdirsBuilder.ToString(); if (subdirs != null && (subdirs = subdirs.Trim(' ', '\t')) != "") { object retObject; SolutionFolder folder; if (!hasParentSolution) { Solution sol = new Solution(); sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat("MonoMakefile"), false); sol.FileName = fileName; folder = sol.RootFolder; retObject = sol; foreach (string conf in MonoMakefileFormat.Configurations) { SolutionConfiguration sc = new SolutionConfiguration(conf); sol.Configurations.Add(sc); } } else { folder = new SolutionFolder(); folder.Name = Path.GetFileName(Path.GetDirectoryName(fileName)); retObject = folder; } subdirs = subdirs.Replace('\t', ' '); string[] dirs = subdirs.Split(' '); monitor.BeginTask("Loading '" + fileName + "'", dirs.Length); Hashtable added = new Hashtable(); foreach (string dir in dirs) { if (added.Contains(dir)) { continue; } added.Add(dir, dir); monitor.Step(1); if (dir == null) { continue; } string tdir = dir.Trim(); if (tdir == "") { continue; } string mfile = Path.Combine(Path.Combine(basePath, tdir), "Makefile"); if (File.Exists(mfile) && CanReadFile(mfile, typeof(SolutionItem))) { SolutionItem it = (SolutionItem)ReadFile(mfile, true, monitor); folder.Items.Add(it); } } monitor.EndTask(); return(retObject); } } } finally { ProjectExtensionUtil.EndLoadOperation(); } return(null); }