public static AnnotationRepository FromFile(string primaryRefParameter, string path, IProgress progress) { try { if (!File.Exists(path)) { RequireThat.Directory(Path.GetDirectoryName(path)).Exists(); File.WriteAllText(path, string.Format("<notes version='{0}'/>", kCurrentVersion.ToString())); } var doc = XDocument.Load(path); ThrowIfVersionTooHigh(doc, path); var result = new AnnotationRepository(primaryRefParameter, doc, path, progress); // Set up a watcher so that if something else...typically FLEx...modifies our file, we update our display. // This is useful in its own right for keeping things consistent, but more importantly, if we don't do // this and then the user does something in FlexBridge that changes the file, we could overwrite the // changes made elsewhere (LT-20074). result.UpateAnnotationFileWriteTime(); result._watcher = new FileSystemWatcher(Path.GetDirectoryName(path), Path.GetFileName(path)); result._watcher.NotifyFilter = NotifyFilters.LastWrite; result._watcher.Changed += result.UnderlyingFileChanged; result._watcher.EnableRaisingEvents = true; return(result); } catch (XmlException error) { throw new AnnotationFormatException(string.Empty, error); } }