Exemple #1
0
        public override XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
        {
            using (var xdsService = new XmlDataService()) {
                var adapter = XmlDataTool.ResolveXmlDataManagerAdapter(ProductName);

                var tcs = new TaskCompletionSource <byte[]>(null);

                ExecuteCompletedEventHandler handler = null;
                handler =
                    (s, e) => EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteCompleted -= handler);
                xdsService.ExecuteCompleted += handler;

                try {
                    var requestBytes = adapter.RequestSerializer.Serialize(requestDocument);
                    xdsService.ExecuteAsync(requestBytes, ProductName, false, tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteCompleted -= handler;
                    tcs.TrySetException(ex);
                }


                tcs.Task.Wait();
                Assert.IsTrue(tcs.Task.IsCompleted);

                return(adapter.ResponseSerializer.Deserialize(tcs.Task.Result));
            }
        }
        /// <summary>
        /// 요청 문서를 <see cref="XmlSerializer"/>를 이용해 직렬화를 수행하여 <see cref="XmlDocument"/>로 반환합니다.
        /// </summary>
        /// <param name="requestDocument">요청 문서</param>
        /// <param name="enc">Encoding 방식</param>
        /// <returns>요청문서의 Xml 직렬화된 정보를 가진 <see cref="XmlDocument"/> 인스턴스</returns>
        public static XmlDocument ToXmlDocument(this XdsRequestDocument requestDocument, Encoding enc)
        {
            XmlDocument document;

            XmlTool.Serialize(requestDocument, out document);

            return(document);
        }
        /// <summary>
        /// 요청 정보중에 응답정보로 다시 보내기 위해서 헤더 정보를 복사한다.
        /// </summary>
        /// <param name="requestDocument">요청문서</param>
        /// <param name="responseDocument">응답문서</param>
        public static void CopyRequestHeader(this XdsRequestDocument requestDocument, XdsResponseDocument responseDocument)
        {
            requestDocument.ShouldNotBeNull("requestDocument");
            responseDocument.ShouldNotBeNull("responseDocument");

            responseDocument.ConnectionString = requestDocument.ConnectionString;
            responseDocument.Transaction      = requestDocument.Transaction;
            responseDocument.IsolationLevel   = requestDocument.IsolationLevel;
        }
Exemple #4
0
        public override XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
        {
            using (var xmlDataService = new XmlDataService()) {
                var adapter       = XmlDataTool.ResolveXmlDataManagerAdapter(ProductName);
                var requestBytes  = adapter.RequestSerializer.Serialize(requestDocument);
                var responseBytes = xmlDataService.Execute(requestBytes, ProductName, false);

                return(adapter.ResponseSerializer.Deserialize(responseBytes));
            }
        }
        /// <summary>
        /// 요청정보를 받은 해당 Database에서 작업하고, 결과를 반환한다.
        /// </summary>
        /// <param name="requestDocument">요청문서</param>
        /// <param name="dbName">요청을 실행할 Database connectionString name</param>
        /// <returns>응답문서</returns>
        public static XdsResponseDocument Execute(this XdsRequestDocument requestDocument, string dbName)
        {
            requestDocument.ShouldNotBeNull("requestDocument");

            if (IsDebugEnabled)
            {
                log.Debug("요청문서에 대한 실행을 수행합니다... dbName=[{0}]", dbName);
            }

            return(ResolveXmlDataManager(dbName).Execute(requestDocument));
        }
Exemple #6
0
        public override XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
        {
            var adapter      = XmlDataTool.ResolveXmlDataManagerAdapter(ProductName);
            var requestBytes = adapter.RequestSerializer.Serialize(requestDocument);

            using (var xdsProxy = new XmlDataServiceClient()) {
                var ar = xdsProxy.BeginExecute(requestBytes, ProductName, false, null, null);
                Thread.Sleep(1);
                var responseBytes = xdsProxy.EndExecute(ar);
                return(adapter.ResponseSerializer.Deserialize(responseBytes));
            }
        }
        /// <summary>
        /// 해당 제품 DB에 대해 요청정보를 처리한 후 결과를 반환합니다.
        /// </summary>
        /// <param name="xdsRequest"></param>
        /// <param name="productName"></param>
        /// <returns></returns>
        public static XdsResponseDocument Execute(XdsRequestDocument xdsRequest, string productName)
        {
            xdsRequest.ShouldNotBeNull("xdsRequest");

            if (productName.IsWhiteSpace())
            {
                productName = AdoTool.DefaultDatabaseName;
            }

            CheckProductExists(productName);
            return(XmlDataTool.Execute(xdsRequest, productName));
        }
        /// <summary>
        /// 요청문서를 XmlSerializer를 통해 스트림으로 빌드합니다.
        /// </summary>
        /// <param name="requestDocument">요청문서</param>
        /// <param name="enc">Encoding 방식</param>
        /// <returns>요청문서의 Xml 직렬화된 정보를 가진 Stream</returns>
        public static Stream ToStream(this XdsRequestDocument requestDocument, Encoding enc)
        {
            var stream = new MemoryStream();

            XmlTool.Serialize(requestDocument, stream);

            if (stream.CanSeek && stream.Position != 0)
            {
                stream.Position = 0;
            }

            return(stream);
        }
Exemple #9
0
        /// <summary>
        /// 비동기적으로 Web Service를 호출합니다. 비동기 호출을 동시다발적으로 호출 시 UserState로 각각의 호출을 구분할 수 있어야 한다.
        /// </summary>
        /// <param name="xdsRequest"></param>
        /// <param name="productName"></param>
        /// <param name="compress"></param>
        /// <param name="security"></param>
        private static void VerifyXmlDataServiceAsync(XdsRequestDocument xdsRequest, string productName, bool?compress, bool?security)
        {
            var serializer   = GetSerializer(compress, security);
            var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes());
            var xdsService   = new XmlDataService();

            var tcs = new TaskCompletionSource <byte[]>(null);

            if (security.GetValueOrDefault(false))
            {
                ExecuteSecurityCompletedEventHandler handler = null;
                handler =
                    (s, e) =>
                    EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteSecurityCompleted -= handler);
                xdsService.ExecuteSecurityCompleted += handler;

                try {
                    xdsService.ExecuteSecurityAsync(requestBytes, productName, compress.GetValueOrDefault(false), tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteSecurityCompleted -= handler;
                    tcs.TrySetException(ex);
                }
            }
            else
            {
                ExecuteCompletedEventHandler handler = null;
                handler =
                    (s, e) => EventAsyncPattern.HandleCompletion(tcs, e, () => e.Result, () => xdsService.ExecuteCompleted -= handler);
                xdsService.ExecuteCompleted += handler;

                try {
                    xdsService.ExecuteAsync(requestBytes, productName, compress.GetValueOrDefault(false), tcs);
                }
                catch (Exception ex) {
                    xdsService.ExecuteCompleted -= handler;
                    tcs.TrySetException(ex);
                }
            }

            tcs.Task.Wait();
            Assert.IsTrue(tcs.Task.IsCompleted);
            var xdsResponse = ((byte[])serializer.Deserialize(tcs.Task.Result)).ConvertToXdsResponseDocument();

            Assert.IsNotNull(xdsResponse);
            Assert.IsFalse(xdsResponse.HasError);
            Assert.IsTrue(xdsResponse.Responses.Count > 0);

            xdsService.Dispose();
        }
Exemple #10
0
        public void VerifyXmlDataService(string scriptPath, XdsRequestDocument requestDocument, bool?compress, bool?security)
        {
            var serializer = GetSerializer(compress, security);

            var requestBytes = serializer.Serialize(requestDocument.ConvertToBytes());

            // NOTE : SILVERLIGHT에서는 UploadDataAsync 메소드를 지원하지 않는다. Silverlight에서는 WebService나 WCF를 사용해야 한다.
            var webClient     = new WebClient();
            var responseBytes = webClient.UploadData(scriptPath, requestBytes);

            var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument();

            Assert.IsNotNull(xdsResponse);
            Assert.IsFalse(xdsResponse.HasError);
        }
Exemple #11
0
        public void VerifyXmlDataServiceAsync(string scriptPath, XdsRequestDocument requestDocument, bool?compress, bool?security)
        {
            var serializer = GetSerializer(compress, security);

            var requestBytes = serializer.Serialize(requestDocument.ConvertToBytes());

            var webClient = new WebClient();

            var uploadTask = webClient.UploadDataTask(new Uri(scriptPath), "POST", requestBytes);

            uploadTask.Wait();

            var responseBytes = uploadTask.Result;
            var xdsResponse   = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument();

            Assert.IsNotNull(xdsResponse);
            Assert.IsFalse(xdsResponse.HasError);
        }
Exemple #12
0
        private static void VerifyXmlDataServiceAsync(XdsRequestDocument xdsRequest, string productName, bool?compress,
                                                      bool?security)
        {
            var waitHandle   = new AutoResetEvent(false);
            var serializer   = GetSerializer(compress, security);
            var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes());

            var proxy = new XmlDataServiceClient();

            if (security.GetValueOrDefault(false))
            {
                // IAsyncResult를 반환받아서 필요할 때 기다리게 할 수도 있지만, 테스트를 위해 Synchronous하게 동작하게 한다.
                proxy.BeginExecuteSecurity(requestBytes, productName, compress.GetValueOrDefault(false),
                                           (ar) => {
                    var proxy2        = (XmlDataServiceClient)ar.AsyncState;
                    var responseBytes = proxy2.EndExecuteSecurity(ar);
                    var xdsResponse   =
                        ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument();

                    Assert.IsNotNull(xdsResponse);
                    Assert.IsFalse(xdsResponse.HasError);
                    Assert.IsTrue(xdsResponse.Responses.Count > 0);
                    proxy2.Close();
                },
                                           proxy);
            }
            else
            {
                // IAsyncResult를 반환받아서 필요할 때 기다리게 할 수도 있지만, 테스트를 위해 Synchronous하게 동작하게 한다.
                proxy.BeginExecute(requestBytes, productName, compress.GetValueOrDefault(false),
                                   (ar) => {
                    var proxy2        = (XmlDataServiceClient)ar.AsyncState;
                    var responseBytes = proxy2.EndExecute(ar);
                    var xdsResponse   =
                        ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument();

                    Assert.IsNotNull(xdsResponse);
                    Assert.IsFalse(xdsResponse.HasError);
                    Assert.IsTrue(xdsResponse.Responses.Count > 0);
                    proxy2.Close();
                },
                                   proxy);
            }
        }
Exemple #13
0
        /// <summary>
        /// 요청에 대한 실제 작업을 수행합니다.
        /// </summary>
        protected virtual void ExecuteRequestCore(XdsRequestDocument requestDocument, XdsResponseDocument responseDocument)
        {
            if (IsDebugEnabled)
            {
                log.Debug("요청 정보를 옵션에 따라 동기적으로 실행합니다...");
            }

            foreach (var request in requestDocument.Requests)
            {
                // 메소드인 경우는 QueryProvider를 이용하여, 실제 Query 문장으로 변경한다.
                //
                XmlDataTool.ConvertToQuery(Ado, request);

                ExecuteSimpleQuery(Ado, request.PreQueries);

                //! 실제 수행
                DoProcessRequestItem(request, responseDocument);

                ExecuteSimpleQuery(Ado, request.PostQueries);
            }
        }
Exemple #14
0
        private static void VerifyXmlDataService(XdsRequestDocument xdsRequest, string productName, bool?compress,
                                                 bool?security)
        {
            using (var xdsProxy = new XmlDataServiceClient()) {
                var serializer   = GetSerializer(compress, security);
                var requestBytes = serializer.Serialize(xdsRequest.ConvertToBytes());

                var responseBytes = security.GetValueOrDefault(false)
                                        ? xdsProxy.ExecuteSecurity(requestBytes, productName, compress.GetValueOrDefault(false))
                                        : xdsProxy.Execute(requestBytes, productName, compress.GetValueOrDefault(false));

                Assert.IsNotNull(responseBytes);

                var xdsResponse = ((byte[])serializer.Deserialize(responseBytes)).ConvertToXdsResponseDocument();

                Assert.IsNotNull(xdsResponse);
                Assert.IsFalse(xdsResponse.HasError);

                Assert.IsTrue(xdsResponse.Responses.Count > 0);
            }
        }
Exemple #15
0
        /// <summary>
        /// 요청 정보를 병렬로 모두 수행합니다.
        /// </summary>
        protected override void ExecuteRequestCore(XdsRequestDocument requestDocument, XdsResponseDocument responseDocument)
        {
            if (requestDocument.IsParallelToolecute == false)
            {
                base.ExecuteRequestCore(requestDocument, responseDocument);
                return;
            }

            if (IsDebugEnabled)
            {
                log.Debug(@"요청을 병렬방식으로 수행합니다...");
            }

            // 요청을 병렬로 처리합니다.
            requestDocument.Requests
            .AsParallel()
            .AsOrdered()
            .ForAll(request => DoProcessRequestItem(request, responseDocument));

            if (IsDebugEnabled)
            {
                log.Info(@"모든 요청을 병렬 수행으로 처리했습니다.");
            }
        }
Exemple #16
0
 public virtual XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
 {
     return(XmlDataTool.ResolveXmlDataManager().Execute(requestDocument));
 }
Exemple #17
0
        /// <summary>
        /// 요청정보를 실행하여 응답정보를 반환합니다.
        /// </summary>
        /// <param name="requestDocument">요청정보</param>
        /// <param name="commandTimeout">요청 처리 제한 시간 (단위 : seconds, 기본값 : 90)</param>
        /// <returns>요청 처리 응답정보</returns>
        public virtual XdsResponseDocument Execute(XdsRequestDocument requestDocument, int?commandTimeout)
        {
            if (IsDebugEnabled)
            {
                log.Debug("요청정보에 따른 Database 작업을 시작합니다...");
            }

            requestDocument.ShouldNotBeNull("requestDocument");

            if (requestDocument == null)
            {
                return(XmlDataTool.CreateResponseWithError(new InvalidOperationException(MsgConsts.NoRequestProvided)));
            }

            var responseDocument     = new XdsResponseDocument();
            TransactionScope txScope = null;

            try {
                if (IsDebugEnabled)
                {
                    log.Debug("요청문서 분석 및 응답문서를 초기화 합니다.");
                }

                requestDocument.CopyRequestHeader(responseDocument);

                if (requestDocument.CommandTimeout > commandTimeout.GetValueOrDefault(90))
                {
                    commandTimeout = requestDocument.CommandTimeout;
                }

                if (requestDocument.Transaction)
                {
                    if (IsDebugEnabled)
                    {
                        log.Debug("요청문서에 Transaction 적용 옵션이 설정되어 있습니다. TransactionScope를 이용하여, 전체 요청을 Transaction 하에서 실행합니다.");
                    }

                    txScope = AdoTool.CreateTransactionScope(TransactionScopeOption.Required, IsolationLevel.ReadCommitted);
                }

                //! 실제 요청 처리
                ExecuteRequestCore(requestDocument, responseDocument);


                // Transaction을 Commit 한다
                //
                if (txScope != null)
                {
                    if (IsDebugEnabled)
                    {
                        log.Debug("Transaction Commit을 시작합니다...");
                    }

                    txScope.Complete();

                    if (IsDebugEnabled)
                    {
                        log.Debug("Transaction Commit에 성공했습니다.!!!");
                    }
                }
            }
            catch (Exception ex) {
                responseDocument.ReportError(ex);
            }
            finally {
                if (txScope != null)
                {
                    txScope.Dispose();
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("모든 요청을 처리하고, ResponseDocument를 반환합니다.");
            }

            return(responseDocument);
        }
Exemple #18
0
 /// <summary>
 /// 요청정보를 실행하여 응답정보를 반환합니다.
 /// </summary>
 /// <param name="requestDocument">요청정보</param>
 /// <returns>요청 처리 응답정보</returns>
 public virtual XdsResponseDocument Execute(XdsRequestDocument requestDocument)
 {
     return(Execute(requestDocument, 90));
 }
Exemple #19
0
        public override XdsResponseDocument ExecuteXmlDataManager(XdsRequestDocument requestDocument)
        {
            var responseXml = XmlHttpTool.PostXml(ScriptPath, requestDocument.ToXmlDocument(XmlTool.XmlEncoding));

            return(XmlTool.Deserialize <XdsResponseDocument>(responseXml));
        }