// this is a meta tast of the large stream mock-up public void LargeStreamTest() { using (var stream = File.OpenRead("TestFiles\\ifc2x3_final_wall.ifc")) using (var data = new LargeStream(stream)) { data.Position = LargeStream.offset; var buffer = new byte[stream.Length + 100]; var read = data.Read(buffer, 0, buffer.Length); Assert.AreEqual(stream.Length, read); Assert.AreEqual((byte)'I', buffer[0]); data.Position = LargeStream.offset - 100; buffer = new byte[stream.Length + 100]; read = data.Read(buffer, 0, buffer.Length); Assert.AreEqual(stream.Length + 100, read); Assert.AreEqual((byte)' ', buffer[99]); Assert.AreEqual((byte)'I', buffer[100]); data.Position = data.Length - 1; buffer = new byte[1000000]; read = data.Read(buffer, 0, buffer.Length); Assert.AreEqual(1, read); read = data.Read(buffer, 0, buffer.Length); Assert.AreEqual(0, read); } }
public void ParsingLargeFile() { using (var model = new Xbim.IO.Memory.MemoryModel(ef2x3)) { using (var stream = File.OpenRead("TestFiles\\ifc2x3_final_wall.ifc")) using (var data = new LargeStream(stream)) { var errCount = model.LoadStep21(data, data.Length); Assert.AreEqual(0, errCount); Assert.AreEqual(1, model.Instances.OfType <Ifc2x3.SharedBldgElements.IfcWallStandardCase>().Count()); } } }
public Stream GetWriteStream(object entity, string etag, bool?checkETagForEquality, DataServiceOperationContext operationContext) { this.ThrowIfDisposed(); CallOrderLog += "-GetWriteStream"; bool returnEmptyStream; if (!operationContext.IsBatchRequest || !operationContext.AbsoluteServiceUri.MakeRelativeUri(operationContext.AbsoluteRequestUri).OriginalString.StartsWith("$")) { CheckETag(entity, etag, checkETagForEquality, operationContext, out returnEmptyStream); } string slug = operationContext.RequestHeaders["Slug"]; if (entity.GetType() == typeof(Photo)) { Photo p = (Photo)entity; if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(slug)) { int id; if (int.TryParse(slug, out id)) { p.ID = id; } else { p.Description = slug; } } } else if (entity.GetType() == typeof(NorthwindModel.Customers)) { NorthwindModel.Customers c = (NorthwindModel.Customers)entity; if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) { Random rand = TestUtil.Random; c.CustomerID = "C" + rand.Next(1000, 9999).ToString(); c.CompanyName = "Microsoft"; if (!string.IsNullOrEmpty(slug)) { c.CustomerID = slug; } } } else if (entity.GetType() == typeof(NorthwindModel.Orders)) { NorthwindModel.Orders o = (NorthwindModel.Orders)entity; if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) { Random rand = TestUtil.Random; o.OrderID = rand.Next(1000, 9999); } } else if (entity.GetType() == typeof(RowEntityTypeWithIDAsKey) && (((RowEntityTypeWithIDAsKey)entity).TypeName == CustomRowBasedContext.CustomerFullName || ((RowEntityTypeWithIDAsKey)entity).TypeName == CustomRowBasedContext.CustomerWithBirthdayFullName)) { int id; if (int.TryParse(slug, out id)) { ((RowEntityTypeWithIDAsKey)entity).ID = id; } else { ((RowEntityTypeWithIDAsKey)entity).ID = TestUtil.Random.Next(1000, 9999); } } else if (entity.GetType() == typeof(RowComplexType) && (((RowComplexType)entity).TypeName == "AstoriaUnitTests.Stubs.Customer" || ((RowComplexType)entity).TypeName == "AstoriaUnitTests.Stubs.CustomerWithBirthday")) { int id; if (int.TryParse(slug, out id)) { ((RowComplexType)entity).Properties["ID"] = id; } else { ((RowComplexType)entity).Properties["ID"] = TestUtil.Random.Next(1000, 9999); } } ValidateArguments(entity, operationContext); SetCustomResponseHeaders(operationContext); Stream s; switch (DataServiceStreamProvider.ProviderStorageMode) { case StorageMode.Disk: s = File.Open(GetStoragePath(entity), FileMode.Create, FileAccess.Write); break; case StorageMode.LargeStream: s = new LargeStream(); LargeStreamStorage[GetStoragePath(entity)] = (LargeStream)s; break; default: throw new InvalidOperationException("Unknown StorageMode!"); } GetWriteStreamCalled = true; return(s); }