// Main parser internal SdlParser(TextReader input, String outputDir, ArrayList outCodeStreamList, String locationURL, bool bWrappedProxy) { Util.Log("SdlParser.SdlParser outputDir "+outputDir+" locationURL "+locationURL+" bWrappedProxy "+bWrappedProxy); // Initialize member variables _XMLReader = null; _readerStreams = new ReaderStream(locationURL); _readerStreams.InputStream = input; _writerStreams = null; _outputDir = outputDir; _outCodeStreamList = outCodeStreamList; _bWrappedProxy = bWrappedProxy; if (outputDir == null) outputDir = "."; int length = outputDir.Length; if(length > 0) { char endChar = outputDir[length-1]; if(endChar != '\\' && endChar != '/') _outputDir = _outputDir + '\\'; } //_namespaceStack = null; _URTNamespaces = new ArrayList(); _blockDefault = SchemaBlockType.ALL; }
public async Task ListServersRequestHandlerReturnsValueIfKnownHostsIsNotEmpty() { var serverList = this.server.ServerList; const string hostname = "host"; const ushort port = 1; serverList.InsertOrUpdate(new ServerRegistration { Hostname = hostname, Port = port }); var response = await this.httpClient.GetAsync(TestUtils.GetUri(this.server, ListServersRequestHandler.CommandPrefix, string.Empty)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader <ListServerResponse>(); var res = reader.Deserialize(); Assert.AreEqual(1, res.Servers.Count); var server = res.Servers[0]; Assert.AreEqual(hostname, server.Hostname); Assert.AreEqual(port, server.Port); } }
public override int ReadContent(Reader reader, Frame f) { CheckPreconditions(f); if (SizeContent > 0) { using (ReaderStream tmpStream = new ReaderStream(reader, SizeContent, Reader.UnsyncMode.CountExcludesUnsyncBytes)) { try { f.Content.Codec.Read(tmpStream, SizeContent, f.Content); } catch (CorruptFrameContentException e) { throw e; } finally { tmpStream.SeekToStreamEnd(); } } } return(SizeContent); }
// Main parser internal WsdlParser(TextReader input, String outputDir, ArrayList outCodeStreamList, String locationURL, bool bWrappedProxy, String proxyNamespace) { Util.Log("WsdlParser.WsdlParser outputDir "+outputDir+" locationURL "+locationURL+" bWrappedProxy "+bWrappedProxy+" proxyNamespace "+proxyNamespace); // Initialize member variables _XMLReader = null; _readerStreamsWsdl = new ReaderStream(locationURL); _readerStreamsWsdl.InputStream = input; _writerStreams = null; _outputDir = outputDir; _outCodeStreamList = outCodeStreamList; _bWrappedProxy = bWrappedProxy; if (proxyNamespace == null || proxyNamespace.Length == 0) _proxyNamespace = "InteropNS"; else _proxyNamespace = proxyNamespace; if (outputDir == null) outputDir = "."; int length = outputDir.Length; if (length > 0) { char endChar = outputDir[length-1]; if (endChar != '\\' && endChar != '/') _outputDir = _outputDir + '\\'; } //_namespaceStack = null; _URTNamespaces = new ArrayList(); _blockDefault = SchemaBlockType.ALL; _primedNametable = CreatePrimedNametable(); }
public void CanReadAndWritePrimitives() { const string test = "tacos"; const float a = float.MinValue; const int b = int.MaxValue; const ulong c = ulong.MaxValue; const double d = double.NegativeInfinity; using (var str = new MemoryStream()) using (var writer = new WriterStream(str)) { writer.WriteString(Encoding.UTF8, test, test.Length); writer.WriteFloat(a); writer.WriteUInt32(b); writer.WriteUInt64(c); writer.WriteDouble(d); writer.WriteVarUInt32(b); writer.WriteVarUInt64(c); str.Position = 0; using (var reader = new ReaderStream(str)) { Assert.AreEqual(reader.ReadString(Encoding.UTF8, test.Length), test); Assert.AreEqual(reader.ReadFloat(), a); Assert.AreEqual(reader.ReadUInt32(), b); Assert.AreEqual(reader.ReadUInt64(), c); Assert.AreEqual(reader.ReadDouble(), d); Assert.AreEqual(reader.ReadVarUInt32(), b); Assert.AreEqual(reader.ReadVarUInt64(), c); } } }
public void CanTranscode() { using (var stream1 = new MemoryStream()) using (var stream2 = new MemoryStream()) using (var writerStream1 = new WriterStream(stream1)) using (var writerStream2 = new WriterStream(stream2)) { // write into compact binary protocol first var writer = writerStream1.CreateCompactBinaryWriter(); writer.Write(this.testObject); stream1.Position = 0; using (var readerStream1 = ReaderStream.FromMemoryStreamBuffer(stream1, null)) { var reader = readerStream1.CreateCompactBinaryReader(); // re-write as simple protocol var writer2 = writerStream2.CreateSimpleBinaryWriter(); Transcode.FromTo(reader, writer2); stream2.Position = 0; using (var readerStream2 = new ReaderStream(stream2)) { var reader2 = readerStream2.CreateSimpleBinaryReader(); var anotherObject = reader2.Read <AnotherDerivedThing>(); Assert.IsTrue(Comparer.Equal(anotherObject, this.testObject)); } } } }
public async Task BatchQueryMissingCounterStillProducesGoodResponse() { var data = new BatchQueryRequest(); data.Queries.Add(new BatchCounterQuery { CounterName = "Tacos", UserContext = "Tacos" }); var response = await this.httpClient.PostAsync(TestUtils.GetUri(this.server, RestCommands.BatchQueryCommand, string.Empty), GetRequestPayload(data)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader <BatchQueryResponse>(); var responseData = reader.Deserialize(); Assert.AreEqual(1, responseData.Responses.Count); var singleResponse = (responseData.Responses as List <CounterQueryResponse>).Find(item => item.UserContext.Equals("Tacos")); Assert.IsNotNull(singleResponse); Assert.AreEqual((int)HttpStatusCode.NotFound, singleResponse.HttpResponseCode); } }
internal static async Task <TData> ReadResponseData <TData>(HttpResponseMessage response) where TData : class { using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { return(readerStream.CreateCompactBinaryReader().Read <TData>()); } }
public void VerifyEmbeddedPolymorphicTypes <TStream>(Func <TStream> createWriter, Func <TStream, TStream> createReaderFromWriter) where TStream : Stream { const int secretValToUse = 0x12345; var listOfThings = new ListOfThings(); this.testObject.secretVal = secretValToUse; listOfThings.list.Add(new Bonded <AnotherDerivedThing>(this.testObject)); listOfThings.list.Add(new Bonded <DerivedThing>(new DerivedThing { anotherVal = 100, secretVal = secretValToUse })); using (var writeStream = createWriter()) using (var writerStream = new WriterStream(writeStream)) { var writer = writerStream.CreateCompactBinaryWriter(); writer.Write(listOfThings); using (var readStream = createReaderFromWriter(writeStream)) using (var reader = new ReaderStream(readStream, null, false)) { var cbReader = reader.CreateBondedCompactBinaryReader <ListOfThings>(); var newThing = cbReader.Deserialize <ListOfThings>(); Assert.IsNotNull(newThing); var matchesFound = 0; foreach (var thing in newThing.list) { var baseThing = thing.Deserialize(); var another = thing.TryDeserialize <Base, AnotherDerivedThing>(); var derived = thing.TryDeserialize <Base, DerivedThing>(); Assert.IsNotNull(baseThing); if (another != null) { Assert.IsNull(derived); Assert.IsTrue(Comparer.Equal <AnotherDerivedThing>(another, this.testObject)); matchesFound++; } if (derived != null) { Assert.IsNull(another); Assert.AreEqual(100, derived.anotherVal); matchesFound++; } } Assert.AreEqual(2, matchesFound); } } }
public override int Read(byte[] buffer, int offset, int count) { long left = MaxBytes - Position; if (left < count) { count = (int)left; } return(ReaderStream.Read(buffer, offset, count)); }
/// <summary> /// Constructs a new in-memory stream. /// </summary> /// <param name="maxBytes">The maximum number of bytes to hold available for reading. Note that due to buffers, the memory usage of this type may be higher than this parameter.</param> public ProducerConsumerStream(int maxBytes = int.MaxValue) { _maxBytes = maxBytes; _data = new LinkedList <byte[]>(); _mutex = new AsyncLock(); _notFullOrCompleted = new AsyncConditionVariable(_mutex); _notEmptyOrCompleted = new AsyncConditionVariable(_mutex); Reader = new ReaderStream(this); Writer = new WriterStream(this); }
private void InnerCreateTest(ReaderStream stream, MemoryStream readedStream) { Assert.NotNull(stream); Assert.True(stream.CanRead); Assert.True(stream.CanSeek); Assert.False(stream.CanWrite); Assert.True(stream.CanTimeout); Assert.Equal(0, stream.Position); Assert.False(stream.IsUseFileCache); Assert.Equal(readedStream.Length, stream.Length); }
internal ReadWriteStreamManager() #endif { ReaderFirstBufferPosition = 0; WriterFirstBufferPosition = 0; ReaderBufferArrayList = new ArrayList(); WriterBufferArrayList = new ArrayList(); _writerStream = new WriterStream(this); _readerStream = new ReaderStream(this); _bufferLock = new ReaderWriterLock(); }
internal static async Task <TRequest> UnpackRequest <TRequest>(HttpRequestMessage request) { using (var requestData = new MemoryStream()) { await request.Content.CopyToAsync(requestData); requestData.Position = 0; using (var reader = ReaderStream.FromMemoryStreamBuffer(requestData, null)) { var cbReader = reader.CreateCompactBinaryReader(); return(cbReader.Read <TRequest>()); } } }
public override int ReadContent(Reader reader, Frame f) { CheckPreconditions(f); FrameDescription.FrameType type = DescriptionMap[f.FrameId].Type; using (ReaderStream stream = new ReaderStream(reader, SizeContent, Reader.UnsyncMode.CountExcludesUnsyncBytes)) { (f.Content.Codec as FrameContentCodec1_0).FrameId = f.FrameId; f.Content.Codec.Read(stream, SizeContent, f.Content); stream.SeekToStreamEnd(); } return(SizeContent); }
/// <summary> /// Reads a Bond object from the input data sent with the request. /// </summary> /// <typeparam name="TValue">The type to use for deserialization.</typeparam> /// <returns>The object deserialized, or a default value if nothing can be read.</returns> public async Task <TValue> ReadInputBody <TValue>() where TValue : class, new() { if (!this.HasInputBody) { return(default(TValue)); } using (var ms = this.GetStream(this.Context.Request.ContentLength64)) { await this.Context.Request.InputStream.CopyToAsync(ms); ms.Position = 0; using (var reader = ReaderStream.FromMemoryStreamBuffer(ms, this.memoryStreamManager)) { try { string contentType; if (!this.Headers.TryGetValue("Content-Type", out contentType)) { contentType = Protocol.BondCompactBinaryMimeType; } switch (contentType) { case Protocol.ApplicationJsonMimeType: return(Deserialize <TValue> .From(reader.CreateSimpleJsonReader())); case Protocol.BondCompactBinaryMimeType: return(reader.CreateCompactBinaryReader().Read <TValue>()); default: Events.Write.InvalidContentTypeProvided(this, contentType); return(default(TValue)); } } catch (Exception ex) { if (ex is InvalidDataException || ex is EndOfStreamException || ex is IOException) { return(default(TValue)); } throw; } } } }
public void CanReadAndWriteSimpleProtocol() { using (var stream = new MemoryStream()) using (var writerStream = new WriterStream(stream, this.mgr)) { var writer = writerStream.CreateSimpleBinaryWriter(); writer.Write(this.testObject); stream.Position = 0; using (var reader = ReaderStream.FromMemoryStreamBuffer(stream, this.mgr)) { var sbReader = new SimpleBinaryReader <ReaderStream>(reader); var anotherObject = sbReader.Read <AnotherDerivedThing>(); Assert.IsTrue(Comparer.Equal(anotherObject, this.testObject)); } } }
public void CanReadWritePolymorphicTypes() { using (var stream = new MemoryStream()) using (var writerStream = new WriterStream(stream)) { var writer = writerStream.CreateCompactBinaryWriter(); writer.Write(this.testObject); stream.Position = 0; using (var readerStream = new ReaderStream(stream.GetBuffer(), 0, stream.Length)) { var reader = readerStream.CreateBondedCompactBinaryReader <Base>(); var baseThing = reader.Deserialize <Base>(); var derivedThing = reader.Deserialize <AnotherDerivedThing>(); Assert.AreEqual(baseThing.secretVal, derivedThing.secretVal); Assert.IsTrue(Comparer.Equal <AnotherDerivedThing>(derivedThing, this.testObject)); } } }
public void CanMixAndMatchStreamReaders() { using (var stream = new MemoryStream()) { // use the 'stock' output stream var outputStream = new OutputStream(stream); var writer = new CompactBinaryWriter <OutputStream>(outputStream); writer.Write(this.testObject); outputStream.Flush(); // read with the custom stream stream.Position = 0; using (var reader = new ReaderStream(stream.GetBuffer(), 0, stream.Length, this.mgr)) { var cbReader = reader.CreateCompactBinaryReader(); var anotherObject = cbReader.Read <AnotherDerivedThing>(); Assert.IsTrue(Comparer.Equal(anotherObject, this.testObject)); } } }
public void TestRegistration() { const string sourceHostname = "chazwazer"; // see http://simpsons.wikia.com/wiki/Made-up_words#C const string sourceMachineFunction = "cromulent"; const string sourceDatacenter = "unpossible"; const ushort sourcePort = 867; using ( var client = new RegistrationClient("localhost", (ushort)this.server.Port, sourceHostname, sourcePort, sourceMachineFunction, sourceDatacenter, TimeSpan.FromSeconds(60), this.dataManager)) { client.Start(); this.server.GotRequest += request => { var uri = request.Request.Url; Assert.AreEqual(RegistrationClient.RegistrationEndpoint, uri.AbsolutePath); using (var readStream = new ReaderStream(request.Request.InputStream)) { var reader = readStream.CreateCompactBinaryReader(); var serverRegistration = reader.Read<ServerRegistration>(); Assert.AreEqual(sourceHostname, serverRegistration.Hostname); Assert.AreEqual(sourcePort, serverRegistration.Port); Assert.AreEqual(1, serverRegistration.Counters.Count); Assert.IsTrue( serverRegistration.Counters.Any( c => c.Name.Equals( RandomCounterName))); return HttpStatusCode.OK; } }; } }
public void TestRegistration() { const string sourceHostname = "chazwazer"; // see http://simpsons.wikia.com/wiki/Made-up_words#C const string sourceMachineFunction = "cromulent"; const string sourceDatacenter = "unpossible"; const ushort sourcePort = 867; using ( var client = new RegistrationClient("localhost", (ushort)this.server.Port, sourceHostname, sourcePort, sourceMachineFunction, sourceDatacenter, TimeSpan.FromSeconds(60), this.dataManager)) { client.Start(); this.server.GotRequest += request => { var uri = request.Request.Url; Assert.AreEqual(RegistrationClient.RegistrationEndpoint, uri.AbsolutePath); using (var readStream = new ReaderStream(request.Request.InputStream)) { var reader = readStream.CreateCompactBinaryReader(); var serverRegistration = reader.Read <ServerRegistration>(); Assert.AreEqual(sourceHostname, serverRegistration.Hostname); Assert.AreEqual(sourcePort, serverRegistration.Port); Assert.AreEqual(1, serverRegistration.Counters.Count); Assert.IsTrue( serverRegistration.Counters.Any( c => c.Name.Equals( RandomCounterName))); return(HttpStatusCode.OK); } }; } }
public async Task ListServersRequestHandlerReturnsValueIfKnownHostsIsNotEmpty() { var serverList = this.server.ServerList; const string hostname = "host"; const ushort port = 1; serverList.InsertOrUpdate(new ServerRegistration {Hostname = hostname, Port = port}); var response = await this.httpClient.GetAsync(TestUtils.GetUri(this.server, ListServersRequestHandler.CommandPrefix, string.Empty)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader<ListServerResponse>(); var res = reader.Deserialize(); Assert.AreEqual(1, res.Servers.Count); var server = res.Servers[0]; Assert.AreEqual(hostname, server.Hostname); Assert.AreEqual(port, server.Port); } }
public void CanReadAndWriteToFile() { var tempFile = Path.GetTempFileName(); using (var createFileStream = File.Create(tempFile)) using (var writerStream = new WriterStream(createFileStream)) { var writer = writerStream.CreateCompactBinaryWriter(); writer.Write(this.testObject); createFileStream.Close(); } using (var openFileStream = File.OpenRead(tempFile)) using (var readerStream = new ReaderStream(openFileStream)) { var reader = readerStream.CreateCompactBinaryReader(); var anotherObject = reader.Read <AnotherDerivedThing>(); Assert.IsTrue(Comparer.Equal(anotherObject, this.testObject)); } File.Delete(tempFile); }
public bool ScraptDataFromWebKBBI(string kata) { try { string url = "http://kbbi.web.id/" + kata; // string cachePath = ImportantLocation.getWordScrapedCacheLocation(); string cachePath = Lingkungan.getDataCacheKata(); string Data = ""; HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); if (Request != null && Response != null) { Stream receiveStream = Response.GetResponseStream(); StreamReader ReaderStream = null; if (Response.CharacterSet == null) { ReaderStream = new StreamReader(receiveStream); } else { ReaderStream = new StreamReader(receiveStream, Encoding.GetEncoding(Response.CharacterSet)); } Data = ReaderStream.ReadToEnd(); ReaderStream.Close(); System.IO.FileInfo file = new System.IO.FileInfo(cachePath + kata.ToLower() + ".html"); file.Directory.Create(); // If the directory already exists, this method does nothing. System.IO.File.WriteAllText(file.FullName, Data); } return(true); } catch (Exception e) { // System.Windows.Forms.MessageBox.Show(e.Message); return(false); } }
public async Task BatchQueryMultipleQueriesForSameCounterWithDifferentParametersWorksFine() { // Fill up the taco truck var dimensionSet = new DimensionSet(new HashSet<Dimension> {new Dimension("Filling")}); var counter = await this.dataManager.CreateHitCounter("/Tacos", dimensionSet); var chickenTacos = new DimensionSpecification {{"Filling", "Chicken"}}; var beefTacos = new DimensionSpecification {{"Filling", "Beef"}}; var veggieTacos = new DimensionSpecification {{"Filling", "TOFU"}}; var baconTacos = new DimensionSpecification {{"Filling", "bacon"}}; counter.Increment(100, chickenTacos); counter.Increment(200, beefTacos); counter.Increment(300, veggieTacos); this.dataManager.Flush(); var data = new BatchQueryRequest(); data.Queries.Add(new BatchCounterQuery {CounterName = "/Tacos", UserContext = "TotalTacos"}); data.Queries.Add(new BatchCounterQuery { CounterName = "/Tacos", UserContext = "CluckCluck", QueryParameters = chickenTacos.Data }); data.Queries.Add(new BatchCounterQuery { CounterName = "/Tacos", UserContext = "BACON!", QueryParameters = baconTacos.Data }); var response = await this.httpClient.PostAsync( TestUtils.GetUri(this.server, RestCommands.BatchQueryCommand, string.Empty), GetRequestPayload(data)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader<BatchQueryResponse>(); var responseData = reader.Deserialize(); Assert.AreEqual(3, responseData.Responses.Count); // unfiltered should have 100+200+300 hitcount VerifyHitCounter(responseData, "TotalTacos", 600); //only 100 chicken tacos VerifyHitCounter(responseData, "CluckCluck", 100); //sadly, there is no bacon... VerifyHitCounter(responseData, "BACON!", -1); } }
public async Task BatchQueryMissingCounterStillProducesGoodResponse() { var data = new BatchQueryRequest(); data.Queries.Add(new BatchCounterQuery {CounterName = "Tacos", UserContext = "Tacos"}); var response = await this.httpClient.PostAsync(TestUtils.GetUri(this.server, RestCommands.BatchQueryCommand, string.Empty), GetRequestPayload(data)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader<BatchQueryResponse>(); var responseData = reader.Deserialize(); Assert.AreEqual(1, responseData.Responses.Count); var singleResponse = (responseData.Responses as List<CounterQueryResponse>).Find(item => item.UserContext.Equals("Tacos")); Assert.IsNotNull(singleResponse); Assert.AreEqual((int)HttpStatusCode.NotFound, singleResponse.HttpResponseCode); } }
/// <summary> /// Send a single query for a block of sources (select a random leader) and record responses /// </summary> /// <param name="httpClient">Client to use for this request</param> /// <param name="blockSources">List of all sources in this block</param> /// <param name="originalRequest">The original request body. This will be cloned and modified for this specific block</param> /// <param name="command">command to send the http POST request to</param> private async Task <TResponseType> SendQuery <TRequestType, TResponseType>(IHttpRequester httpClient, List <ServerInfo> blockSources, TRequestType originalRequest, string command) where TRequestType : TieredRequest, new() where TResponseType : TieredResponse, new() { // select a random leader to process this block and remove it from the block var leaderIndex = this.random.Value.Next(blockSources.Count); var leader = blockSources[leaderIndex]; blockSources.RemoveAt(leaderIndex); HttpResponseMessage responseMessage = null; try { var uri = string.Format("http://{0}:{1}{2}", leader.Hostname, leader.Port, command); var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri); requestMessage.Headers.Add(HttpRequestHeader.Accept.ToString(), Protocol.BondCompactBinaryMimeType); // RequestMessage is disposed in the finalize statement below. That disposes its .Content which disposes the stream it is given requestMessage.Content = new StreamContent(this.CreatePostBody(originalRequest, blockSources)); Events.Write.SendingBlockQuery(leader, uri, blockSources, this.Timeout.TotalMilliseconds); responseMessage = await httpClient.StartRequest(requestMessage).ConfigureAwait(false); Events.Write.ReceivedResponseHeaders(leader); // regardless of getting back a 200 or failure response (e.g. 4xx, 5xx), we still // **expect** diagnostic information in the payload. Try to read it. If parsing the response // fails, we will look at the response code later. // read the response body into a stream var length = responseMessage.Content.Headers.ContentLength ?? 0; using (var dataStream = this.MemoryStreamManager.GetStream("QueryClient/Http/Read", (int)length, true)) { using (var responseStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false)) { // WARNING: Do NOT use await CopyToAsync. There is a BCL bug where certain exceptions // are not marshaled back to the correct task and the await is never finished. This // shows up as a deadlock. To work around this, we use the synchronous API and are sad about it. responseStream.CopyTo(dataStream); dataStream.Position = 0; } Events.Write.ReceivedResponseBody(leader, dataStream.Length); using (var readerStream = ReaderStream.FromMemoryStreamBuffer(dataStream, this.MemoryStreamManager)) { var reader = readerStream.CreateCompactBinaryReader(); var result = reader.Read <TResponseType>(); Events.Write.QueryFinished(leader, responseMessage.StatusCode == HttpStatusCode.OK ? RequestStatus.Success.ToString() : RequestStatus.ServerFailureResponse.ToString(), (int)responseMessage.StatusCode, responseMessage.ReasonPhrase ); return(result); } } } catch (Exception ex) { if (IsTimedOutException(ex)) { Events.Write.QueryTimedOut(leader); return(TimedOutResponse <TResponseType>(originalRequest.IncludeRequestDiagnostics, leader, blockSources)); } if (responseMessage != null && !responseMessage.IsSuccessStatusCode) { Events.Write.ServerFailureResponse(leader, responseMessage); return(ServerFailureResponse <TResponseType>(originalRequest.IncludeRequestDiagnostics, leader, responseMessage, blockSources)); } if (ex is WebException || ex is IOException || ex is SocketException || ex is ObjectDisposedException || ex is InvalidDataException || ex is HttpRequestException || ex is UriFormatException) { Events.Write.RequestException(leader, ex); return(ExceptionResponse <TResponseType>(originalRequest.IncludeRequestDiagnostics, leader, ex, blockSources)); } // rethrow unknown exceptions Events.Write.FatalExceptionWhenGatheringData(ex.Message, ex.StackTrace); throw; } finally { if (responseMessage != null) { responseMessage.Dispose(); } } }
private void ParseReaderStreamLocation(ReaderStream reader, ReaderStream currentReaderStream) { string location = reader.Location; int index = location.IndexOf(':'); if (index == -1) { if ((currentReaderStream == null) || (currentReaderStream.Location == null)) { throw new SUDSParserException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Suds_Import"), new object[] { reader.Location })); } if (currentReaderStream.Uri == null) { currentReaderStream.Uri = new Uri(currentReaderStream.Location); } Uri uri = new Uri(currentReaderStream.Uri, location); reader.Uri = uri; location = uri.ToString(); index = location.IndexOf(':'); if (index == -1) { return; } reader.Location = location; } string str2 = location.Substring(0, index).ToLower(CultureInfo.InvariantCulture); string path = location.Substring(index + 1); if (str2 == "file") { reader.InputStream = new StreamReader(path); } else if (str2.StartsWith("http", StringComparison.Ordinal)) { Stream responseStream = WebRequest.Create(location).GetResponse().GetResponseStream(); reader.InputStream = new StreamReader(responseStream); } }
private void ParseSchemaImportElement(bool bImport) { if (bImport) { this.LookupAttribute(s_namespaceString, null, true); } string location = null; location = this.LookupAttribute(s_schemaLocationString, null, false); if ((location != null) && (location.Length > 0)) { if (this._readerStreamsXsd == null) { this._readerStreamsXsd = new ReaderStream(location); this.ParseReaderStreamLocation(this._readerStreamsXsd, (ReaderStream) this._currentSchemaReaderStack.Peek()); } else { ReaderStream reader = new ReaderStream(location); this.ParseReaderStreamLocation(reader, (ReaderStream) this._currentSchemaReaderStack.Peek()); ReaderStream.GetReaderStream(this._readerStreamsWsdl, reader); } } this.ReadNextXmlElement(); }
public bool ReadDataHeader() { Events.Write.BeginReadPersistedDataHeader(); if (this.pendingObjects != 0) { throw new PersistedDataException("Attempted to read data header without reading pending data objects"); } this.usePreviousProtocol = false; if (this.nextHeaderOffset > 0) { if (this.nextHeaderOffset >= this.sourceStream.Length) { return(false); } this.sourceStream.Position = this.nextHeaderOffset; } using (var readerStream = new ReaderStream(this.sourceStream, this.memoryStreamManager, false)) { try { var version = readerStream.ReadUInt16(); if (version != PersistedDataProtocol.ProtocolVersion) { if (version == PersistedDataProtocol.PreviousProtocolVersion) { this.usePreviousProtocol = true; } else { throw new PersistedDataException("Attempted to read protocol data of unsupported version."); } } this.Version = version; } catch (EndOfStreamException) { // This is dumb but we don't have a better way to handle this condition. It's okay if we're at the end // of the stream when reading the version header, it just means we don't have more data in the payload. return(false); } try { var blockLength = readerStream.ReadUInt64(); this.nextHeaderOffset = this.sourceStream.Position + (long)blockLength; if (this.usePreviousProtocol) { this.Header = this.LoadLegacyHeader(); } else { this.Header = this.LoadHeader(); } if (this.TargetDimensionSet == null) { this.TargetDimensionSet = this.DimensionSet; } this.pendingObjects = this.Header.DataCount; Events.Write.EndReadPersistedDataHeader(); return(true); } catch (Exception ex) { if (ex is EndOfStreamException || ex is InvalidDataException) { throw new PersistedDataException("Stream data may be truncated", ex); } throw; } } }
internal static ReaderStream GetNextReaderStream(ReaderStream input) { Util.Log("ReaderStream.GetNextReaderStream "+input._next); return input._next; }
// Starts the parser private void ParseInput(ReaderStream input) { Util.Log("WsdlParser.ParseInput" + input.Location); _parsingInput = input; try { ReadNextXmlElement(); String elementName = _XMLReader.LocalName; if (MatchingNamespace(s_wsdlNamespaceString) && MatchingStrings(elementName, s_definitionsString)) { Util.Log("WsdlParser.ParseInput before ParseWsdl "+input.Location); _currentReaderStack.Push(input); // need this to get the base url for relative import elements. ParseWsdl(); _currentReaderStack.Pop(); // need this to get the base url for relative import elements. } else if (MatchingNamespace(s_wsdlNamespaceString) && MatchingStrings(elementName, s_typesString)) { Util.Log("WsdlParser.ParseInput before ParseWsdlTypes "+input.Location); _currentReaderStack.Push(input); // need this to get the base url for relative import elements. ParseWsdlTypes(); _currentReaderStack.Pop(); // need this to get the base url for relative import elements. } else if (MatchingSchemaNamespace() && MatchingStrings(elementName, s_schemaString)) { Util.Log("WsdlParser.ParseInput before ParseWsdl "+input.Location); _currentReaderStack.Push(input); // need this to get the base url for relative import elements. ParseSchema(); _currentReaderStack.Pop(); // need this to get the base url for relative import elements. } else throw new SUDSParserException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Suds_UnknownElementAtRootLevel"), elementName)); } finally { WriterStream.Flush(_writerStreams); } }
private void ParseReaderStreamLocation(ReaderStream reader, ReaderStream currentReaderStream) { Util.Log("WsdlParser.ParseReaderStreamLocation location "+reader.Location+" current location "+currentReaderStream.Location); String location = reader.Location; int index = location.IndexOf(':'); if (index == -1) { // relative path if (currentReaderStream == null || currentReaderStream.Location == null) throw new SUDSParserException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Suds_Import"), reader.Location)); if (currentReaderStream.Uri == null) currentReaderStream.Uri= new Uri(currentReaderStream.Location); // If relative path, will already be changed to absolute path by next statement in previous invocation. Uri uri = new Uri(currentReaderStream.Uri, location); reader.Uri= uri; location = uri.ToString(); index = location.IndexOf(':'); if (index == -1) return; reader.Location= location; } String protocol = location.Substring(0, index).ToLower(CultureInfo.InvariantCulture); String value = location.Substring(index+1); if (protocol == "file") { //Console.WriteLine("Loading file:" + value); reader.InputStream = new StreamReader(value); } else if (protocol.StartsWith("http", StringComparison.Ordinal)) { Util.Log("WsdlParser.ParseReaderStreamLocation http "+location); WebRequest request = WebRequest.Create(location); WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); reader.InputStream = new StreamReader(responseStream); } }
private void ParseReaderStreamLocation(ReaderStream reader) { Util.Log("SdlParser.ParseReaderStreamLocation"); String location = reader.Location; int index = location.IndexOf(':'); if(index != -1) { String protocol = location.Substring(0, index).ToLower(CultureInfo.InvariantCulture); String value = location.Substring(index+1); if(protocol == "file") { //Console.WriteLine("Loading file:" + value); reader.InputStream = new StreamReader(value); } else if(protocol.StartsWith("http")) { //Console.WriteLine("Loading " + protocol + ':' + value); /* // Setup proxy settings DefaultControlObject proxyObject = new DefaultControlObject(); proxyObject.ProxyNoLocal = true; GlobalProxySelection.Select = proxyObject; */ WebRequest request = WebRequest.Create(location); WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); reader.InputStream = new StreamReader(responseStream); } } return; }
private void ParseImport() { this.LookupAttribute(s_namespaceString, null, true); string location = null; location = this.LookupAttribute(s_locationString, null, false); if ((location != null) && (location.Length > 0)) { ReaderStream reader = new ReaderStream(location); this.ParseReaderStreamLocation(reader, (ReaderStream) this._currentReaderStack.Peek()); ReaderStream.GetReaderStream(this._readerStreamsWsdl, reader); } this.ReadNextXmlElement(); }
private void ParseImportedSchema(ReaderStream input) { try { string localName = this._XMLReader.LocalName; this._currentSchemaReaderStack.Push(input); this.ReadNextXmlElement(); this.ParseSchema(); this._currentSchemaReaderStack.Pop(); } finally { WriterStream.Flush(this._writerStreams); } }
// Process the xsd schema imported from an xsd import statement private void ParseImportedSchema(ReaderStream input) { Util.Log("WsdlParser.ParseImportedSchema "+input.Location); try { String elementName = _XMLReader.LocalName; _currentSchemaReaderStack.Push(input); // need this to get the base url for relative import elements. ReadNextXmlElement(); ParseSchema(); _currentSchemaReaderStack.Pop(); // need this to get the base url for relative import elements. } finally { WriterStream.Flush(_writerStreams); } }
private void ParseInput(ReaderStream input) { this._parsingInput = input; try { this.ReadNextXmlElement(); string localName = this._XMLReader.LocalName; if (!this.MatchingNamespace(s_wsdlNamespaceString) || !MatchingStrings(localName, s_definitionsString)) { if (!this.MatchingNamespace(s_wsdlNamespaceString) || !MatchingStrings(localName, s_typesString)) { if (!this.MatchingSchemaNamespace() || !MatchingStrings(localName, s_schemaString)) { throw new SUDSParserException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Suds_UnknownElementAtRootLevel"), new object[] { localName })); } this._currentReaderStack.Push(input); this.ParseSchema(); this._currentReaderStack.Pop(); } else { this._currentReaderStack.Push(input); this.ParseWsdlTypes(); this._currentReaderStack.Pop(); } } else { this._currentReaderStack.Push(input); this.ParseWsdl(); this._currentReaderStack.Pop(); } } finally { WriterStream.Flush(this._writerStreams); } }
internal static void GetReaderStream(ReaderStream inputStreams, ReaderStream newStream) { Util.Log("ReaderStream.GetReaderStream "+newStream.Location); ReaderStream input = inputStreams; ReaderStream last; do { Util.Log("ReaderStream.GetReaderStream location match input.location "+input._location+" location "+newStream.Location); if (input._location == newStream.Location) return; last = input; input = input._next; } while (input != null); input = newStream; last._next = input; return; }
internal WsdlParser(TextReader input, string outputDir, ArrayList outCodeStreamList, string locationURL, bool bWrappedProxy, string proxyNamespace) { this._readerStreamsWsdl = new ReaderStream(locationURL); this._readerStreamsWsdl.InputStream = input; this._writerStreams = null; this._outputDir = outputDir; this._outCodeStreamList = outCodeStreamList; this._bWrappedProxy = bWrappedProxy; if ((proxyNamespace == null) || (proxyNamespace.Length == 0)) { this._proxyNamespace = "InteropNS"; } else { this._proxyNamespace = proxyNamespace; } if (outputDir == null) { outputDir = "."; } int length = outputDir.Length; if (length > 0) { char ch = outputDir[length - 1]; if ((ch != '\\') && (ch != '/')) { this._outputDir = this._outputDir + '\\'; } } this._URTNamespaces = new ArrayList(); this._blockDefault = SchemaBlockType.ALL; this._primedNametable = CreatePrimedNametable(); }
internal static ReaderStream GetReaderStream(ReaderStream inputStreams, String location) { Util.Log("ReaderStream.GetReaderStream "+location); ReaderStream input = inputStreams; ReaderStream last; do { if(input._location == location) return(input); last = input; input = input._next; } while(input != null); input = new ReaderStream(location); last._next = input; return(input); }
public async Task BatchQueryMultipleQueriesForSameCounterWithDifferentParametersWorksFine() { // Fill up the taco truck var dimensionSet = new DimensionSet(new HashSet <Dimension> { new Dimension("Filling") }); var counter = await this.dataManager.CreateHitCounter("/Tacos", dimensionSet); var chickenTacos = new DimensionSpecification { { "Filling", "Chicken" } }; var beefTacos = new DimensionSpecification { { "Filling", "Beef" } }; var veggieTacos = new DimensionSpecification { { "Filling", "TOFU" } }; var baconTacos = new DimensionSpecification { { "Filling", "bacon" } }; counter.Increment(100, chickenTacos); counter.Increment(200, beefTacos); counter.Increment(300, veggieTacos); this.dataManager.Flush(); var data = new BatchQueryRequest(); data.Queries.Add(new BatchCounterQuery { CounterName = "/Tacos", UserContext = "TotalTacos" }); data.Queries.Add(new BatchCounterQuery { CounterName = "/Tacos", UserContext = "CluckCluck", QueryParameters = chickenTacos.Data }); data.Queries.Add(new BatchCounterQuery { CounterName = "/Tacos", UserContext = "BACON!", QueryParameters = baconTacos.Data }); var response = await this.httpClient.PostAsync( TestUtils.GetUri(this.server, RestCommands.BatchQueryCommand, string.Empty), GetRequestPayload(data)); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (var readerStream = new ReaderStream(await response.Content.ReadAsStreamAsync())) { var reader = readerStream.CreateBondedCompactBinaryReader <BatchQueryResponse>(); var responseData = reader.Deserialize(); Assert.AreEqual(3, responseData.Responses.Count); // unfiltered should have 100+200+300 hitcount VerifyHitCounter(responseData, "TotalTacos", 600); //only 100 chicken tacos VerifyHitCounter(responseData, "CluckCluck", 100); //sadly, there is no bacon... VerifyHitCounter(responseData, "BACON!", -1); } }
private void ParseImport() { Util.Log("WsdlParser.ParseImport"); String ns = LookupAttribute(s_namespaceString, null, true); String location = null; location = LookupAttribute(s_locationString, null, false); //wsdl Util.Log("WsdlParser.ParseImport "+ns+" location "+location); if (location != null && location.Length > 0) { ReaderStream reader = new ReaderStream(location); ParseReaderStreamLocation(reader, (ReaderStream)_currentReaderStack.Peek()); ReaderStream.GetReaderStream(_readerStreamsWsdl, reader); } ReadNextXmlElement(); return; }
// Starts the parser private void ParseInput(ReaderStream input) { Util.Log("SdlParser.ParseInput"); _parsingInput = input; try { ReadNextXmlElement(); String elementName = _XMLReader.LocalName; if(MatchingNamespace(s_serviceNamespaceString) && MatchingStrings(elementName, s_serviceDescString)) { ParseSdl(); } else throw new SUDSParserException(CoreChannel.GetResourceString("Remoting_Suds_UnknownElementAtRootLevel")); } finally { WriterStream.Flush(_writerStreams); } }
// Processes an import statement in an xsd schema. private void ParseSchemaImportElement(bool bImport) { Util.Log("WsdlParser.ParseSchemaImportElement IsImport "+bImport); String ns = null; if (bImport) ns = LookupAttribute(s_namespaceString, null, true); String location = null; location = LookupAttribute(s_schemaLocationString, null, false); Util.Log("WsdlParser.ParseSchemaImportElement "+ns+" location "+location); if (location != null && location.Length > 0) { if (_readerStreamsXsd == null) { _readerStreamsXsd = new ReaderStream(location); ParseReaderStreamLocation(_readerStreamsXsd, (ReaderStream)_currentSchemaReaderStack.Peek()); } else { ReaderStream reader = new ReaderStream(location); ParseReaderStreamLocation(reader, (ReaderStream)_currentSchemaReaderStack.Peek()); ReaderStream.GetReaderStream(_readerStreamsWsdl, reader); } } ReadNextXmlElement(); return; }
internal void ParseImportedSchemaController() { CreatePrimedNametable(); ReaderStream input = this._readerStreamsXsd; XmlTextReader reader = this._XMLReader; ReaderStream stream2 = this._parsingInput; do { this._XMLReader = new XmlTextReader(input.InputStream, this._primedNametable); this._XMLReader.WhitespaceHandling = WhitespaceHandling.None; this._XMLReader.XmlResolver = null; this._parsingInput = input; this.ParseImportedSchema(input); input = ReaderStream.GetNextReaderStream(input); } while (input != null); this._readerStreamsXsd = null; this._XMLReader = reader; this._parsingInput = stream2; }