示例#1
0
        public void WriteCreatedEntity()
        {
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedEntityTestData();
            String xml = CyclicXmlHandler.Write(testData.obj);

            Assert.AssertEquals(testData.xml, xml);
        }
示例#2
0
        public void WriteServiceDescription()
        {
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getServiceDescriptionTestData();
            String xml = CyclicXmlHandler.Write(testData.obj);

            Assert.AssertEquals(testData.xml, xml);
        }
示例#3
0
        public void WriteMixedLinkedSet()
        {
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getMixedLinkedSetTestData();
            String xml = CyclicXmlHandler.Write(testData.obj);

            Assert.AssertEquals(testData.xml, xml);
        }
示例#4
0
        public void WriteEntityWithRelation()
        {
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getEntityWithRelationTestData();
            String xml = CyclicXmlHandler.Write(testData.obj);

            Assert.AssertEquals(testData.xml, xml);
        }
示例#5
0
        public void ReadMixedLinkedSet()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getMixedLinkedSetTestData();
            Object obj = CyclicXmlHandler.Read(testData.xml);

            AreSetsEqual((ISet <Object>)testData.obj, (ISet <Object>)obj);
        }
示例#6
0
        public void ReadMixedList()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getMixedListTestData();
            Object obj = CyclicXmlHandler.Read(testData.xml);

            AreCollectionsEqual((ICollection)testData.obj, (ICollection)obj);
        }
示例#7
0
        public void ReadMixedArray()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getMixedArrayTestData();
            object obj = CyclicXmlHandler.Read(testData.xml);

            AreArraysEqual((object[])testData.obj, (object[])obj);
        }
示例#8
0
        public void ReadEntityWithRelation()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getEntityWithRelationTestData();
            Object obj = CyclicXmlHandler.Read(testData.xml);

            Assert.AssertEquals(testData.obj, obj);
        }
示例#9
0
        public void ReadCreatedAndExistingChildrenJavaXML()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedAndExistingChildrenTestData();
            Object obj = CyclicXmlHandler.Read(testData.xmlJava);

            AssertEquals((EntityA)testData.obj, (EntityA)obj);
        }
示例#10
0
        public void ReadServiceDescription()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getServiceDescriptionTestData();
            Object obj = CyclicXmlHandler.Read(testData.xml);

            De.Osthus.Ambeth.Transfer.Assert.AssertEquals((ServiceDescription)testData.obj, (ServiceDescription)obj);
        }
示例#11
0
        public void ReadUpdatedEntityJavaXML()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getUpdatedEntityTestData();
            Object obj = CyclicXmlHandler.Read(testData.xmlJava);

            Assert.AssertEquals(testData.obj, obj);
            AssertEquals((Material)testData.obj, (Material)obj);
        }
示例#12
0
        public void ReadCreatedParentAndChildEntitiesJavaXML()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedParentAndChildEntitiesTestData();
            Object obj = CyclicXmlHandler.Read(testData.xmlJava);

            Assert.AssertTrue(obj is Material);
            AssertEquals((Material)testData.obj, (Material)obj);
        }
示例#13
0
        public void ReadCreatedParentAndChildEntitiesInListJavaXML()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedParentAndChildEntitiesInListTestData();
            Object obj = CyclicXmlHandler.Read(testData.xmlJava);

            Assert.AssertTrue(obj is IList);
            IList <Object> actuals = (IList <Object>)obj;

            AssertEquals((Material)((IList <Object>)testData.obj)[0], (Material)actuals[0]);
        }
示例#14
0
        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);
        }
示例#15
0
        public void ReadCreatedAndUpdatedEntitiesJavaXML()
        {
            InitManually(GetType());
            OriWrapperTestBed.TestData testData = OriWrapperTestBed.getCreatedAndUpdatedEntitiesTestData();
            Object        obj       = CyclicXmlHandler.Read(testData.xmlJava);
            List <Object> expecteds = (List <Object>)testData.obj;
            List <Object> actuals   = (List <Object>)obj;

            Assert.AssertEquals(expecteds.Count, actuals.Count);
            for (int i = 0; i < expecteds.Count; i++)
            {
                Material expected = expecteds[i] as Material;
                Material actual   = actuals[i] as Material;
                AssertEquals(expected, actual);
            }
        }
示例#16
0
        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);
        }