Exemplo n.º 1
0
        public void GetData(WCFInvocationMethod clientInvocationMethod, WCFInvocationMethod serviceInvocationMethod, int value)
        {
            if (_wcfClient == null)
            {
                throw new InvalidOperationException("WCF Client not instantiated");
            }

            if (_needToPauseForWarmup)
            {
                PauseForWarmup();
            }

            string result = null;

            switch (clientInvocationMethod)
            {
            case WCFInvocationMethod.Sync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                    result = _wcfClient.Sync_SyncGetData(value);
                    break;

                case WCFInvocationMethod.BeginEndAsync:
                    result = _wcfClient.Sync_AsyncGetData(value);
                    break;

                case WCFInvocationMethod.TAPAsync:
                    result = _wcfClient.Sync_TAPGetData(value);
                    break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.BeginEndAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    var asyncResult = _wcfClient.Begin_SyncGetData(value, null, null);
                    result = _wcfClient.End_SyncGetData(asyncResult);
                }
                break;

                case WCFInvocationMethod.BeginEndAsync:
                {
                    var asyncResult = _wcfClient.Begin_AsyncGetData(value, null, null);
                    result = _wcfClient.End_AsyncGetData(asyncResult);
                }
                break;

                case WCFInvocationMethod.TAPAsync:
                {
                    var asyncResult = _wcfClient.Begin_TAPGetData(value, null, null);
                    result = _wcfClient.End_TAPGetData(asyncResult);
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.TAPAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    result = _wcfClient.TAP_SyncGetData(value).Result;
                }
                break;

                case WCFInvocationMethod.BeginEndAsync:
                {
                    result = _wcfClient.TAP_AsyncGetData(value).Result;
                }
                break;

                case WCFInvocationMethod.TAPAsync:
                {
                    result = _wcfClient.TAP_TAPGetData(value).Result;
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.EventBasedAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    using (var wait = new ManualResetEvent(false))
                    {
                        _wcfClient.Event_SyncGetData_Completed += (e, a) =>
                        {
                            result = a.Result;
                            wait.Set();
                        };
                        _wcfClient.Event_SyncGetData(32);
                        wait.WaitOne(TimeSpan.FromSeconds(20));
                    }
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            default:
                throw new NotImplementedException($"Client Invocation Method {clientInvocationMethod} Not supported");
            }

            Logger.Info($"Result: {result ?? "<NULL>"}");
        }