Ejemplo n.º 1
0
        static ParsedDocument UpdateFile(Project[] projects, string fileName, Func <string> getContent)
        {
            try {
                if (GetParser(fileName) == null)
                {
                    return(null);
                }

                ParsedDocument parseInformation = null;
                string         fileContent;
                if (getContent == null)
                {
                    if (!System.IO.File.Exists(fileName))
                    {
                        fileContent = "";
                    }
                    else
                    {
                        try {
                            fileContent = System.IO.File.ReadAllText(fileName);
                        } catch (Exception e) {
                            LoggingService.LogError("Error reading file {0} for ProjectDomService: {1}", fileName, e);
                            fileContent = "";
                        }
                    }
                }
                else
                {
                    fileContent = getContent();
                }

                // Remove any pending jobs for this file
                RemoveParseJob(fileName);
                ProjectDom dom = projects != null && projects.Length > 0 ? GetProjectDom(projects [0]) : null;
                parseInformation = DoParseFile(dom, fileName, fileContent);
                if (parseInformation == null)
                {
                    return(null);
                }
                // don't update project dom with incorrect parse informations, they may not contain all
                // information.
                if (projects != null && projects.Length > 0 && parseInformation.CompilationUnit != null)
                {
                    SetSourceProject(parseInformation.CompilationUnit, dom);
                }

//				if (parseInformation.Errors.Any ()) {
//					Console.WriteLine (fileName + "-- Errors:");
//					foreach (var e in parseInformation.Errors) {
//						Console.WriteLine (e);
//					}
//				}

                if (parseInformation.CompilationUnit != null &&
                    (parseInformation.Flags & ParsedDocumentFlags.NonSerializable) == 0)
                {
                    if (projects != null && projects.Length > 0)
                    {
                        foreach (Project project in projects)
                        {
                            ProjectDom db = GetProjectDom(project);
                            if (db != null)
                            {
                                try {
                                    if (parseInformation.HasErrors)
                                    {
                                        db.UpdateTemporaryCompilationUnit(parseInformation.CompilationUnit);
                                    }
                                    else
                                    {
                                        db.UpdateTagComments(fileName, parseInformation.TagComments);
                                        db.RemoveTemporaryCompilationUnit(parseInformation.CompilationUnit);
                                        TypeUpdateInformation res = db.UpdateFromParseInfo(parseInformation.CompilationUnit, getContent == null);
                                        if (res != null)
                                        {
                                            NotifyTypeUpdate(project, fileName, res);
                                        }
                                        UpdatedCommentTasks(fileName, parseInformation.TagComments, project);
                                    }
                                } catch (Exception e) {
                                    LoggingService.LogError(e.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        ProjectDom db = GetFileDom(fileName);
                        db.UpdateFromParseInfo(parseInformation.CompilationUnit, getContent == null);
                    }
                }

                return(parseInformation);
            } catch (Exception e) {
                LoggingService.LogError(e.ToString());
                return(null);
            }
        }
        static ParsedDocument UpdateFile(Project[] projects, string fileName, string mimeType, ContentDelegate getContent)
        {
            try {
                if (GetParser(fileName, mimeType) == null)
                {
                    return(null);
                }

                ParsedDocument parseInformation = null;
                string         fileContent;
                if (getContent == null)
                {
                    StreamReader sr = new StreamReader(fileName);
                    fileContent = sr.ReadToEnd();
                    sr.Close();
                }
                else
                {
                    fileContent = getContent();
                }

                // Remove any pending jobs for this file
                RemoveParseJob(fileName);
                ProjectDom dom = projects != null && projects.Length > 0 ? GetProjectDom(projects [0]) : null;
                parseInformation = DoParseFile(dom, fileName, fileContent);
                if (parseInformation == null)
                {
                    return(null);
                }
                // don't update project dom with incorrect parse informations, they may not contain all
                // information.
                if (projects != null && projects.Length > 0 && parseInformation.CompilationUnit != null)
                {
                    SetSourceProject(parseInformation.CompilationUnit, dom);
                }
                if (parseInformation.CompilationUnit != null &&
                    (parseInformation.Flags & ParsedDocumentFlags.NonSerializable) == 0)
                {
                    if (projects != null && projects.Length > 0)
                    {
                        foreach (Project project in projects)
                        {
                            ProjectDom db = GetProjectDom(project);
                            if (db != null)
                            {
                                try {
                                    if (parseInformation.HasErrors)
                                    {
                                        db.UpdateTemporaryCompilationUnit(parseInformation.CompilationUnit);
                                    }
                                    else
                                    {
                                        db.UpdateTagComments(fileName, parseInformation.TagComments);
                                        db.RemoveTemporaryCompilationUnit(parseInformation.CompilationUnit);
                                        TypeUpdateInformation res = db.UpdateFromParseInfo(parseInformation.CompilationUnit);
                                        if (res != null)
                                        {
                                            NotifyTypeUpdate(project, fileName, res);
                                        }
                                        UpdatedCommentTasks(fileName, parseInformation.TagComments, project);
                                    }
                                } catch (Exception e) {
                                    LoggingService.LogError(e.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        ProjectDom db = GetFileDom(fileName);
                        db.UpdateFromParseInfo(parseInformation.CompilationUnit);
                    }
                }

                return(parseInformation);
            } catch (Exception e) {
                LoggingService.LogError(e.ToString());
                return(null);
            }
        }