public IObservable<OsmEntity> ReadEntities(XmlReader reader,Stream underlyingStream,OperationCountDelegate progressDelegate) { var mapper = new OsmEntityMapper(); var streamLength = underlyingStream.Length; var operationCounter = new OperationCounter(progressDelegate, streamLength, 1000*1000*100); reader.MoveToContent(); return CreateElementSource(reader).Select<XElement, OsmEntity>(element => { var increment = underlyingStream.Position - operationCounter.Count; operationCounter.Increment(increment); if (element.Name == "node") { return mapper.ToNode(element); } if (element.Name == "way") { return mapper.ToWay(element); } if (element.Name == "relation") { return mapper.ToRelation(element); } return null; }).Where(e => e != null); }
public IObservable<OsmEntity> ReadEntities(string filename,OperationCountDelegate progressDelegate ) { var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true); var xmlReader = XmlReader.Create(fileStream, new XmlReaderSettings() {Async = true}); var observable = ReadEntities(xmlReader, fileStream, progressDelegate).Publish(); observable.Connect(); observable.Subscribe(entity => { }, ex => fileStream.Dispose(), fileStream.Dispose); return observable; }
public OperationCounter(OperationCountDelegate action,long totalOperationCount = -1,long callGranularity = 1000L) { this.action = action; this.totalOperationCount = totalOperationCount; this.callGranularity = callGranularity; this.lastTime = DateTime.UtcNow; }