public void WriteCreatedEntity() { OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedEntityTestData(); String xml = CyclicXmlHandler.Write(testData.obj); Assert.AssertEquals(testData.xml, xml); }
public void WriteServiceDescription() { OriWrapperTestBed.TestData testData = OriWrapperTestBed.getServiceDescriptionTestData(); String xml = CyclicXmlHandler.Write(testData.obj); Assert.AssertEquals(testData.xml, xml); }
public void WriteMixedLinkedSet() { OriWrapperTestBed.TestData testData = OriWrapperTestBed.getMixedLinkedSetTestData(); String xml = CyclicXmlHandler.Write(testData.obj); Assert.AssertEquals(testData.xml, xml); }
public void WriteEntityWithRelation() { OriWrapperTestBed.TestData testData = OriWrapperTestBed.getEntityWithRelationTestData(); String xml = CyclicXmlHandler.Write(testData.obj); Assert.AssertEquals(testData.xml, xml); }
public void WriteCreatedChildEntity() { OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedChildEntityTestData(); String xml = CyclicXmlHandler.Write(testData.obj); if (!testData.xml.Equals(xml)) { // Compensate for loss of order in set in CUDResut testData = OriWrapperTestBed.getCreatedChildEntityTestData2(); } Assert.AssertEquals(testData.xml, xml); }
protected override void InterceptIntern(IInvocation invocation) { if (GuiThreadHelper != null && GuiThreadHelper.IsInGuiThread()) { throw new Exception("It is not allowed to call this interceptor from GUI thread"); } lock (clientLock) { if (connectionChangePending) { // Wait till the connection change finished Monitor.Wait(clientLock); } } DateTime m1 = DateTime.Now; MethodInfo method = invocation.Method; String url = ServiceBaseUrl + "/" + ServiceName + "/" + method.Name; HttpWebRequest webRequest; #if SILVERLIGHT if (HttpUseClient) { webRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(url)); } else { webRequest = WebRequest.CreateHttp(url); } #else webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Proxy = null; webRequest.KeepAlive = true; #endif Object result = null; bool hasResult = false; Exception ex = null; lock (webRequest) { webRequest.Accept = "text/plain"; if (HttpAcceptEncodingZipped) { TryToSetHeader(HttpRequestHeader.AcceptEncoding, webRequest, "gzip"); webRequest.Headers["Accept-Encoding-Workaround"] = "gzip"; } SetAuthorization(webRequest); if (invocation.Arguments.Length == 0) { webRequest.Method = "GET"; webRequest.BeginGetResponse(delegate(IAsyncResult asyncResult2) { try { HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asyncResult2); using (Stream responseStream = response.GetResponseStream()) using (Stream memoryStream = new MemoryStream()) { int b; while ((b = responseStream.ReadByte()) != -1) { memoryStream.WriteByte((byte)b); } memoryStream.Position = 0; try { Stream deflateStream = GetResponseStream(response, memoryStream); result = CyclicXmlHandler.ReadFromStream(deflateStream); } catch (XmlTypeNotFoundException) { throw; } catch (Exception) { memoryStream.Position = 0; result = CyclicXmlHandler.ReadFromStream(memoryStream); } } hasResult = true; } catch (WebException e) { ex = ParseWebException(e); using (HttpWebResponse response = (HttpWebResponse)e.Response) { HandleException(e, response); } } catch (Exception e) { Log.Error(e); ex = e; } finally { lock (webRequest) { Monitor.PulseAll(webRequest); } } }, null); } else { webRequest.Method = "POST"; webRequest.ContentType = "text/plain"; if (HttpContentEncodingZipped) { TryToSetHeader(HttpRequestHeader.ContentEncoding, webRequest, "gzip"); webRequest.Headers["Content-Encoding-Workaround"] = "gzip"; } webRequest.BeginGetRequestStream(delegate(IAsyncResult asyncResult) { try { using (Stream stream = webRequest.EndGetRequestStream(asyncResult)) #if SILVERLIGHT using (Stream deflateStream = HttpContentEncodingZipped ? new GZipStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, false) : stream) #else using (Stream deflateStream = HttpContentEncodingZipped ? new GZipStream(stream, CompressionMode.Compress, false) : stream) #endif { CyclicXmlHandler.WriteToStream(deflateStream, invocation.Arguments); } webRequest.BeginGetResponse(delegate(IAsyncResult asyncResult2) { DateTime m4 = DateTime.Now; try { HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asyncResult2); DateTime m5 = DateTime.Now; using (Stream responseStream = response.GetResponseStream()) using (Stream memoryStream = new MemoryStream()) { int b; while ((b = responseStream.ReadByte()) != -1) { memoryStream.WriteByte((byte)b); } memoryStream.Position = 0; try { Stream deflateStream = GetResponseStream(response, memoryStream); result = CyclicXmlHandler.ReadFromStream(deflateStream); } catch (XmlTypeNotFoundException) { throw; } catch (Exception) { memoryStream.Position = 0; result = CyclicXmlHandler.ReadFromStream(memoryStream); } } hasResult = true; } catch (WebException e) { ex = ParseWebException(e); using (HttpWebResponse response = (HttpWebResponse)e.Response) { HandleException(e, response); } } catch (Exception e) { ex = e; } finally { lock (webRequest) { Monitor.PulseAll(webRequest); } } }, null); } catch (Exception e) { ex = e; lock (webRequest) { Monitor.PulseAll(webRequest); } } }, null); } while (!hasResult && ex == null) { Monitor.Wait(webRequest); } } if (result is AmbethServiceException) { ex = ParseServiceException((AmbethServiceException)result); throw new Exception("Error occured while calling " + webRequest.Method + " " + webRequest.RequestUri, ex); } if (ex != null) { if (ex is WebException) { throw new Exception(ex.Message + "\r\rError occured while calling " + webRequest.Method + " " + webRequest.RequestUri + ". " + CyclicXmlHandler.Write(invocation.Arguments), ex); } throw new Exception("Error occured while calling " + webRequest.Method + " " + webRequest.RequestUri + ". " + CyclicXmlHandler.Write(invocation.Arguments), ex); } if (!hasResult) { throw new Exception("This must never happen"); } invocation.ReturnValue = ConvertToExpectedType(method.ReturnType, result); }