Ejemplo n.º 1
0
        ProcessOperationRequest(OperationRequest request)
        {
            Object    result;
            Exception exception = null;

            try
            {
                MethodInfo     method    = GetOperationMethod(request);
                APIOperation   operation = GetAPIOperation(request);
                IList <Object> arguments = request.Arguments;
                IList <Object> argumentsAndStreamHandlers =
                    PopulateStreamHandlers(ReflectionUtil.GetParameterTypes(method),
                                           arguments);
                try
                {
                    Object[] args = argumentsAndStreamHandlers.ToArray();
                    FixupArguments(method, args);
                    result = method.Invoke(operation, args);
                }
                catch (TargetInvocationException e)
                {
                    Exception root = e.InnerException;
                    ExceptionUtil.PreserveStackTrace(root);
                    throw root;
                }
                bool anyStreams =
                    argumentsAndStreamHandlers.Count > arguments.Count;
                if (anyStreams)
                {
                    try
                    {
                        _connection.WriteObject(new OperationResponseEnd());
                    }
                    catch (IOException e)
                    {
                        throw new BrokenConnectionException(e);
                    }
                }
            }
            catch (BrokenConnectionException w)
            {
                //at this point the stream is broken - just give up
                throw w.GetIOException();
            }
            catch (Exception e)
            {
                TraceUtil.TraceException(null, e);
                exception = e;
                result    = null;
            }
            return(new OperationResponsePart(exception, result));
        }
Ejemplo n.º 2
0
        protected override APIOperation GetOperationImplementation(SafeType <APIOperation> api)
        {
            // add remote proxy
            InvocationHandler handler = new RemoteOperationInvocationHandler(
                (RemoteConnectorInfoImpl)GetAPIConfiguration().ConnectorInfo, remoteConnectorFacadeKey, api);
            APIOperation proxy = NewAPIOperationProxy(api, handler);

            // now wrap the proxy in the appropriate timeout proxy
            proxy = CreateTimeoutProxy(api, proxy);
            // add logging proxy
            proxy = CreateLoggingProxy(api, proxy);

            return(proxy);
        }
Ejemplo n.º 3
0
        public void TestDeleteOperation()
        {
            string       apiId_rev1  = _apiId1;
            string       operationId = _operationId1;
            APIOperation operation   = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;

            var listBefore = Client.GetOperationsByAPIAsync(apiId_rev1).Result;
            var task       = Client.DeleteOperationAsync(apiId_rev1, operationId);

            task.Wait();
            var listAfter = Client.GetOperationsByAPIAsync(apiId_rev1).Result;

            Assert.AreEqual(listBefore.Count - 1, listAfter.Count);
        }
Ejemplo n.º 4
0
        public void TestDeleteOperaion()
        {
            string       apiId_rev1  = "api_7d1d97fd4cce41c09b5d0c703be89d15;rev=1";
            string       apiId_rev3  = "api_7d1d97fd4cce41c09b5d0c703be89d15;rev=3";
            string       operationId = "operation_fbe4209ab5d2413da5feaea6447499fa";
            APIOperation operation   = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;
            var          task        = Client.DeleteOperationAsync(apiId_rev1, operationId);

            task.Wait();
            var list  = Client.GetOperationsByAPIAsync(apiId_rev1).Result;
            var list3 = Client.GetOperationsByAPIAsync(apiId_rev3).Result;


            Assert.AreEqual(list.Count + 1, list3.Count);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 用默认设置初始化 CharmMessageBox 类的新实例
        /// </summary>
        public CharmMessageBox()
        {
            InitializeComponent();
            // 设置窗体阴影特效
            APIOperation.FormBorderShadow(Handle);
            // * 设置双缓冲模式 *
            SetStyle(ControlStyles.AllPaintingInWmPaint |  //不擦除背景 ,减少闪烁
                     ControlStyles.OptimizedDoubleBuffer | //双缓冲
                     ControlStyles.UserPaint,              //使用自定义的重绘事件,减少闪烁
                     true);
            UpdateStyles();

            // * 初始化属性 *
            TopMost         = true;
            FormBorderStyle = FormBorderStyle.None;
            StartPosition   = FormStartPosition.CenterParent;
            Width           = 350;

            mTitleColor = Color.White;
            mTextColor  = Color.Black;

            // 创建控件集合
            CharmControls = new List <CharmControl>();

            // 创建用户按钮
            mButtons = new CharmButton[3];
            for (int i = 0; i < mButtons.Length; i++)
            {
                mButtons[i]             = new CharmButton();
                mButtons[i].ButtonType  = ButtonType.Classic_Size_06922;
                mButtons[i].Visible     = false;
                mButtons[i].MouseClick += new MouseEventHandler(ButtonMouseClick);
                CharmControls.Add(mButtons[i]);
            }

            // 创建检查框
            mCheckBox         = new CharmCheckBox();
            mCheckBox.Visible = false;
            CharmControls.Add(mCheckBox);

            // 创建关闭按钮
            CharmSysButton btnClose = new CharmSysButton();

            btnClose.SysButtonType = SysButtonType.Close;
            btnClose.Location      = new Point(Width - 46, 1);
            btnClose.MouseClick   += new MouseEventHandler(btnClose_MouseClick);
            CharmControls.Add(btnClose);
        }
Ejemplo n.º 6
0
        public void TestUpdateOperation()
        {
            string       apiId_rev1  = _apiId1;
            string       operationId = _operationId1;
            APIOperation operation   = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;

            operation.Name = "zzzz";
            var task = Client.UpdateAPIOperationAsync(apiId_rev1, operationId, operation);

            task.Wait();
            APIOperation o1 = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;

            Assert.AreEqual(o1.Name, operation.Name);

            string json = JsonConvert.SerializeObject(o1);
        }
Ejemplo n.º 7
0
        public void TestCreateAPIOperation()
        {
            long   c1, c2;
            string apiId = _apiId1;

            RequestMethod method      = RequestMethod.DELETE;
            string        name        = method.ToString() + " Calc operation";
            string        urlTemplate = "/calc/" + method.ToString();
            string        description = "";

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, null, null, null, description, _operationId1);

            c1 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            APIOperation entity = Client.CreateAPIOperationAsync(apiId, operation).Result;

            c2 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            Assert.AreEqual(c1 + 1, c2);
        }
Ejemplo n.º 8
0
        public void APIOperationBuilder()
        {
            string        name        = "Server API operation";
            RequestMethod method      = RequestMethod.POST;
            string        urlTemplate = "/Get/a/{a}/b/{b}";
            string        description = "an operation created in the operation";

            ParameterContract[] parameters = null;
            RequestContract     request    = null;

            ResponseContract[] responses = null;

            parameters = Parameters();

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, parameters, request, responses, description);

            APIOperationHelper helper = new APIOperationHelper(operation);
        }
Ejemplo n.º 9
0
        public void TestUpdateOperation()
        {
            string       apiId_rev1  = "api_7d1d97fd4cce41c09b5d0c703be89d15;rev=1";
            string       apiId_rev3  = "api_7d1d97fd4cce41c09b5d0c703be89d15;rev=3";
            string       operationId = "operation_fbe4209ab5d2413da5feaea6447499fa";
            APIOperation operation   = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;

            operation.Name = "zzzz";
            var task = Client.UpdateAPIOperationAsync(apiId_rev1, operationId, operation);

            task.Wait();
            APIOperation o1 = Client.GetAPIOperationAsync(apiId_rev1, operationId).Result;
            APIOperation o3 = Client.GetAPIOperationAsync(apiId_rev3, operationId).Result;

            Assert.AreEqual(o1.Name, o3.Name);

            string json = JsonConvert.SerializeObject(o1);
        }
Ejemplo n.º 10
0
        public void CreateAPIOperation()
        {
            long   c1, c2;
            string apiId = _apiId;

            string        name        = "Operation_3";
            RequestMethod method      = RequestMethod.DELETE;
            string        urlTemplate = "/pet/{petId}";
            string        description = "post it";

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, Parameters(), Request(), Responses(), description, _operationId);

            c1 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            APIOperation entity = Client.CreateAPIOperationAsync(apiId, operation).Result;

            c2 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            Assert.AreEqual(c1 + 1, c2);
        }
Ejemplo n.º 11
0
            /// <summary>
            /// Build an APIOperation from a swagger operation
            /// </summary>
            /// <param name="method"></param>
            /// <returns>An APIOperation</returns>
            public APIOperation BuildOperation(RequestMethod method = RequestMethod.GET)
            {
                if (_operation == null)
                {
                    return(null);
                }

                PrepareParameterLists();

                string name        = _operation.OperationId;
                string description = _operation.Description;
                string urlTemplate = _baseUrl + BuildQueryUrl();

                ParameterContract[] parameters = _pathParameters.Concat(_queryParameters).ToArray();
                ResponseContract[]  responses  = BuildResponses();
                RequestContract     request    = BuildRequest();

                return(APIOperation.Create(name, method, urlTemplate, parameters, request, responses, description));
            }
Ejemplo n.º 12
0
        public void UpdateAPIOperation()
        {
            string       apiId       = _apiId;
            string       operationId = _operationId;
            APIOperation entity_v1   = Client.GetAPIOperationAsync(apiId, operationId).Result;

            APIOperation operation = new APIOperation()
            {
                Name   = "New Operation Name",
                Method = "POST"
            };

            var task = Client.UpdateAPIOperationAsync(apiId, operationId, operation);

            task.Wait();
            APIOperation entity_v2 = Client.GetAPIOperationAsync(apiId, operationId).Result;

            Assert.AreNotEqual(entity_v1.Name, entity_v2.Name);
            Assert.AreNotEqual(entity_v1.Method, entity_v2.Method);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 用默认设置初始化 CharmMenu 类的新实例
        /// </summary>
        public CharmMenu()
        {
            InitializeComponent();
            // 设置窗体阴影特效
            APIOperation.FormBorderShadow(Handle);
            // * 设置双缓冲模式 *
            SetStyle(ControlStyles.AllPaintingInWmPaint |  //不擦除背景 ,减少闪烁
                     ControlStyles.OptimizedDoubleBuffer | //双缓冲
                     ControlStyles.UserPaint,              //使用自定义的重绘事件,减少闪烁
                     true);
            UpdateStyles();

            // * 初始化属性 *
            TopMost         = true;
            ShowInTaskbar   = false;
            FormBorderStyle = FormBorderStyle.None;

            mItems         = new List <MenuItem>();
            mSelectedIndex = -1;
        }
Ejemplo n.º 14
0
        public void UpdateOperationParameter()
        {
            string apiId       = "api_b8aad5c90425479c9e50c2513bfbc804";
            string operationId = "operation_be5ecb981a0d43678ae492502c925047";

            APIOperation       entity = Client.GetAPIOperationAsync(apiId, operationId).Result;
            APIOperationHelper helper = new APIOperationHelper(entity);


            List <ParameterContract> parameters = new List <ParameterContract>();

            parameters.Add(ParameterContract.Create("account", "uuid"));
            parameters.Add(ParameterContract.Create("subscription", "uuid"));

            entity.UrlTemplate        = APIOperationHelper.BuildURL("/get", parameters);
            entity.TemplateParameters = parameters.ToArray();

            var task = Client.UpdateAPIOperationAsync(apiId, operationId, entity);

            task.Wait();
        }
Ejemplo n.º 15
0
        public void UpdateOperationParameter()
        {
            string apiId       = _apiId;
            string operationId = _operationId;

            APIOperation       entity = Client.GetAPIOperationAsync(apiId, operationId).Result;
            APIOperationHelper helper = new APIOperationHelper(entity);


            List <ParameterContract> parameters = new List <ParameterContract>();

            parameters.Add(ParameterContract.Create("account", "uuid"));
            parameters.Add(ParameterContract.Create("subscription", "uuid"));

            entity.UrlTemplate        = APIOperationHelper.BuildURL("/get", parameters);
            entity.TemplateParameters = parameters.ToArray();

            var task = Client.UpdateAPIOperationAsync(apiId, operationId, entity);

            task.Wait();
        }
Ejemplo n.º 16
0
        public void TestAPIOperationLifeCycle()
        {
            long   c1, c2;
            string apiId = "api_1de6f9ae1521400594ee3e234ffd630c;rev=3";

            RequestMethod method      = RequestMethod.DELETE;
            string        name        = method.ToString() + " Calc operation";
            string        urlTemplate = "/calc/" + method.ToString();
            string        description = "";

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, null, null, null, description);


            #region CREATE

            c1 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            APIOperation entity = Client.CreateAPIOperationAsync(apiId, operation).Result;
            c2 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            Assert.AreEqual(c1 + 1, c2);

            #endregion
        }
Ejemplo n.º 17
0
        public void UpdateOperationResponse()
        {
            string       apiId       = "api_b8aad5c90425479c9e50c2513bfbc804";
            string       operationId = "operation_ab7e97314cb840eca6cead919d7c003b";
            APIOperation entity_v1   = Client.GetAPIOperationAsync(apiId, operationId).Result;

            ResponseContract        response  = ResponseContract.Create(400, "Ok", null);
            List <ResponseContract> responses = entity_v1.Responses.ToList();

            responses.Add(response);

            APIOperation operation = new APIOperation()
            {
                Responses = responses.ToArray()
            };

            var task = Client.UpdateAPIOperationAsync(apiId, operationId, operation);

            task.Wait();
            APIOperation entity_v2 = Client.GetAPIOperationAsync(apiId, operationId).Result;

            Assert.AreEqual(entity_v2.Responses.Count(), operation.Responses.Count());
        }
Ejemplo n.º 18
0
        public void UpdateOperationResponse()
        {
            string       apiId       = _apiId;
            string       operationId = _operationId;
            APIOperation entity_v1   = Client.GetAPIOperationAsync(apiId, operationId).Result;

            ResponseContract        response  = ResponseContract.Create(400, "Ok", null);
            List <ResponseContract> responses = entity_v1.Responses.ToList();

            responses.Add(response);

            APIOperation operation = new APIOperation()
            {
                Responses = responses.ToArray()
            };

            var task = Client.UpdateAPIOperationAsync(apiId, operationId, operation);

            task.Wait();
            APIOperation entity_v2 = Client.GetAPIOperationAsync(apiId, operationId).Result;

            Assert.AreEqual(entity_v2.Responses.Count(), operation.Responses.Count());
        }
Ejemplo n.º 19
0
        public void ReadLocalOperation()
        {
            string filePath = @"C:\Users\inter\Downloads\swaggerOperation.json";
            AbstractSwaggerReader swaggerReader = new SwaggerFileReader(filePath);
            APIBuilder            builder       = APIBuilder.GetBuilder(swaggerReader);

            ICollection <APIOperation> operations = builder.BuildAPIAndOperations().Operations;


            string apiId  = "api_577edd5ee62543d297bd5d568af78a82";
            API    entity = _Client.GetAPIAsync(apiId).Result;
            string json   = JsonConvert.SerializeObject(entity.Operations);

            foreach (APIOperation o in operations)
            {
                try
                {
                    APIOperation e = _Client.CreateAPIOperationAsync(entity, o).Result;
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 20
0
        public void ReadLocalSwaggerFile()
        {
            var setting = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };

            string filePath = @"C:\Users\inter\Downloads\swagger.json";
            AbstractSwaggerReader swaggerReader = new SwaggerFileReader(filePath);
            APIBuilder            builder       = APIBuilder.GetBuilder(swaggerReader);

            API api    = builder.BuildAPIAndOperations();
            API entity = _Client.CreateAPIAsync(api).Result;

            foreach (APIOperation o in api.Operations)
            {
                try
                {
                    APIOperation e = _Client.CreateAPIOperationAsync(entity, o).Result;
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates the timeout proxy for the given operation.
        /// </summary>
        /// <param name="api">
        ///            The operation </param>
        /// <param name="target">
        ///            The underlying object </param>
        /// <returns> The proxy </returns>
        protected internal APIOperation CreateTimeoutProxy(SafeType<APIOperation> api, APIOperation target)
        {
            int timeout = GetAPIConfiguration().GetTimeout(api);
            int bufferSize = GetAPIConfiguration().ProducerBufferSize;

            DelegatingTimeoutProxy handler = new DelegatingTimeoutProxy(target, timeout, bufferSize);

            return NewAPIOperationProxy(api, handler);
        }
Ejemplo n.º 22
0
 protected APIOperation CreateLoggingProxy(SafeType<APIOperation> api, APIOperation target)
 {
     APIOperation ret = target;
     if (LOGGINGPROXY_ENABLED)
     {
         LoggingProxy logging = new LoggingProxy(api, target);
         ret = NewAPIOperationProxy(api, logging);
     }
     return ret;
 }
Ejemplo n.º 23
0
        public void APIOperationLifeCycle()
        {
            long   c1, c2;
            string apiId = "api_96c8b0b79c9342f7a42f56795c92fd1d";

            string        name        = "Operation_3";
            RequestMethod method      = RequestMethod.DELETE;
            string        urlTemplate = "/pet/{petId}";
            string        description = "post it";

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, Parameters(), Request(), Responses(), description);


            #region CREATE

            c1 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            APIOperation entity = Client.CreateAPIOperationAsync(apiId, operation).Result;
            c2 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
            Assert.AreEqual(c1 + 1, c2);

            #endregion

            /*
             #region RETRIEVE
             *
             * APIOperation other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Name, other.Name);
             * Assert.AreEqual(entity.UrlTemplate, other.UrlTemplate);
             *
             #endregion
             *
             #region Update INFO
             * entity.Name = entity.Name + "-new";
             * var task = Client.UpdateAPIOperationAsync(apiId, entity.Id, entity);
             * task.Wait();
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Name, other.Name);
             #endregion
             *
             *
             #region UPDATE REPSPONSE
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Responses.Count(), other.Responses.Count());
             * List<ResponseContract> responses = entity.Responses.ToList();
             * responses.Add(ResponseContract.Create(400, "so bad", new RepresentationContract[] {
             *  RepresentationContract.Create("application/json", null, null, "sample code", null)
             * }));
             * entity.Responses = responses.ToArray();
             * Assert.AreEqual(entity.Responses.Count() - 1, other.Responses.Count());
             * task = Client.UpdateAPIOperationAsync(apiId, entity.Id, entity);
             * task.Wait();
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Responses.Count(), other.Responses.Count());
             #endregion
             *
             *
             *
             #region UPDATE REQUEST
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Request.Description, other.Request.Description);
             * RequestContract request = RequestContract.Create(entity.Description + " -----new description");
             * entity.Request = request;
             * Assert.AreNotEqual(entity.Request.Description, other.Request.Description);
             * task = Client.UpdateAPIOperationAsync(apiId, entity.Id, entity);
             * task.Wait();
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.Request.Description, other.Request.Description);
             #endregion
             *
             *
             #region UPATE PARAMETERS
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.UrlTemplate, other.UrlTemplate);
             * Assert.AreEqual(entity.TemplateParameters.Count(), other.TemplateParameters.Count());
             * APIOperationHelper helper = new APIOperationHelper(entity);
             *
             * List<ParameterContract> parameters = new List<ParameterContract>();
             * parameters.Add(ParameterContract.Create("account", "uuid"));
             * parameters.Add(ParameterContract.Create("other", "number"));
             * parameters.Add(ParameterContract.Create("start", "date-time"));
             * parameters.Add(ParameterContract.Create("end", "date-time"));
             * parameters.Add(ParameterContract.Create("description", "string"));
             *
             *
             * entity.UrlTemplate = APIOperationHelper.BuildURL(helper.GetOriginalURL(), parameters);
             * entity.TemplateParameters = parameters.ToArray();
             *
             * Assert.AreNotEqual(entity.TemplateParameters.Count(), other.TemplateParameters.Count());
             * Assert.AreNotEqual(entity.UrlTemplate, other.UrlTemplate);
             * task = Client.UpdateAPIOperationAsync(apiId, entity.Id, entity);
             * task.Wait();
             *
             * other = Client.GetAPIOperationAsync(apiId, entity.Id).Result;
             * Assert.AreEqual(entity.UrlTemplate, other.UrlTemplate);
             * Assert.AreEqual(entity.TemplateParameters.Count(), other.TemplateParameters.Count());
             *
             #endregion
             *
             *
             *
             #region DELETE Operation
             * c1 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
             * task = Client.DeleteOperationAsync(apiId, entity.Id);
             * task.Wait();
             * c2 = Client.GetOperationsByAPIAsync(apiId).Result.Count;
             * Assert.AreEqual(c1 - 1, c2);
             #endregion
             */
        }