Exemple #1
0
        /// <summary>
        /// Finds an item from the remote repository by Id
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="id">The id.</param>
        /// <param name="contentType">The Content-Type to request</param>
        /// <returns></returns>
        public byte[] FindById <TModel>(string id, string contentType)
            where TModel : EndpointModelBase
        {
            Type collectionType = ModelTypeHelper.GetElementCollectionType(typeof(TModel));

            return(_proxy.FindOne(collectionType.Name, id, contentType));
        }
Exemple #2
0
        public string FindElements(IApiQueryDescription apiQueryDescription)
        {
            IConsumerResponse consumerResponse = CallApi(
                "GET",
                string.Empty,
                _oauthSession.ConsumerContext.BaseEndpointUri,
                ModelTypeHelper.Pluralize(apiQueryDescription.ElementName),
                apiQueryDescription.ElementId,
                apiQueryDescription.UpdatedSinceDate,
                apiQueryDescription.QueryStringParams,
                null);

            if (consumerResponse.ResponseCode == HttpStatusCode.NotFound)
            {
                return(string.Empty);
            }

            if (consumerResponse.IsGoodResponse || consumerResponse.IsClientError)
            {
                return(consumerResponse.Content);
            }

            // TODO: trap http 404 responses

            throw new ApiResponseException(consumerResponse);
        }
        // GET (one)

        public Attachment GetAttachmentFor <TModel>(TModel model)
            where TModel : ModelBase, IAttachmentParent
        {
            // List the attachments against this model.
            var modelItemId = ModelTypeHelper.GetModelItemId(model);

            var allAttachmentsXml = _integrationProxy.FindAttachments(typeof(TModel).Name, modelItemId);

            var allAttachments = ModelSerializer.DeserializeTo <Response>(allAttachmentsXml).Attachments;

            if (allAttachments == null || allAttachments.Count == 0)
            {
                return(null);
            }

            var theFirstAttachment = allAttachments.First();

            // Get the attachment content
            var content = _integrationProxy.FindOneAttachment(
                typeof(TModel).Name,
                modelItemId,
                theFirstAttachment.AttachmentID.ToString());

            return(theFirstAttachment.WithContent(content));
        }
        public Attachment Create <TModel>(TModel model, Attachment attachment)
            where TModel : ModelBase, IAttachmentParent
        {
            string xml = _integrationProxy.CreateAttachment(
                typeof(TModel).Name,
                ModelTypeHelper.GetModelItemId(model),
                attachment);

            return(ModelSerializer.DeserializeTo <Response>(xml).Attachments.First());
        }
Exemple #5
0
        public byte[] FindOne(string endpointName, string itemId, string acceptMimeType)
        {
            IConsumerResponse consumerResponse = CallApi(
                "GET",
                string.Empty,
                _oauthSession.ConsumerContext.BaseEndpointUri,
                ModelTypeHelper.Pluralize(endpointName),
                itemId,
                null,
                null,
                acceptMimeType);

            if (consumerResponse.IsGoodResponse || consumerResponse.IsClientError)
            {
                return(consumerResponse.ByteArray);
            }

            throw new ApiResponseException(consumerResponse);
        }
        public string CreateElements(string endpointName, string body)
        {
            IConsumerResponse consumerResponse = CallApi(
                "PUT",
                body,
                _oauthSession.ConsumerContext.BaseEndpointUri,
                ModelTypeHelper.Pluralize(endpointName),
                null,
                null,
                GetAdditionalQueryParams(),
                null);

            if (consumerResponse.IsGoodResponse || consumerResponse.IsClientError)
            {
                return(consumerResponse.Content);
            }

            throw new ApiResponseException(consumerResponse);
        }
Exemple #7
0
        public string CreateElements(string endpointName, string body)
        {
            IConsumerResponse consumerResponse = CallApi(
                "PUT",
                body,
                _oauthSession.ConsumerContext.BaseEndpointUri,
                ModelTypeHelper.Pluralize(endpointName),
                null,
                null,
                new NameValueCollection {
                { "summarizeErrors", "false" }
            },
                null);

            if (consumerResponse.IsGoodResponse || consumerResponse.IsClientError)
            {
                return(consumerResponse.Content);
            }

            throw new ApiResponseException(consumerResponse);
        }
        private void InitCommand()
        {
            PreferenceStockQueryCommand                   = new DelegateCommand((obj) => { });
            HugeAmountAutoSyncCommand                     = new DelegateCommand((obj) => { });
            PreferenceStockSelectionChangedCommand        = new DelegateCommand((obj) => { });
            HugeAmountFocusedStockSelectionChangedCommand = new DelegateCommand((obj) => { });
            RecommendedStockQueryCommmand                 = new DelegateCommand((obj) => { });

            CustomIndicatorMouseLeftClickCommand = new DelegateCommand((obj) =>
            {
                CustomIndicatorSelectedItem           = (obj as DataGridRow).Item as CustomIndicatorModel;
                CustomIndicatorSelectedItem.IsChecked = !CustomIndicatorSelectedItem.IsChecked;
            });


            CustomIndicatorAddCommand = new DelegateCommand((obj) =>
            {
                //MD5 md5 = MD5.Create(); var inputBytes = Encoding.Unicode.GetBytes("000001PAYH"); var hash = md5.ComputeHash(inputBytes);
                //StringBuilder sb = new StringBuilder();

                CustomIndicatorModel inputEntity = new CustomIndicatorModel();
                CustomIndicatorCreateView view   = new CustomIndicatorCreateView();

                (view.DataContext as CustomIndicatorCreateViewModel).WithParam(inputEntity, (type, outputEntity) =>
                {
                    view.Close();

                    if (type == 1)
                    {
                        outputEntity.Id = _customIndicatorService.GetContinuousId();
                        if (_customIndicatorService.Insert(outputEntity))
                        {
                            CustomIndicatorLists.Add(outputEntity);
                        }
                    }
                });
                view.ShowDialog();
            });

            CustomIndicatorModifyCommand = new DelegateCommand((obj) =>
            {
                CustomIndicatorCreateView view = new CustomIndicatorCreateView();
                var clone = ObjectDeepCopy <CustomIndicatorModel, CustomIndicatorModel> .Trans(CustomIndicatorSelectedItem);
                (view.DataContext as CustomIndicatorCreateViewModel).WithParam(clone, (type, outputEntity) =>
                {
                    view.Close();

                    if (type == 1)
                    {
                        if (_customIndicatorService.Update(outputEntity))
                        {
                            ModelTypeHelper.PropertyMapper(CustomIndicatorSelectedItem, outputEntity);
                        }
                    }
                });
                view.ShowDialog();
            });

            CustomIndicatorSelectedAllCommand            = new DelegateCommand((obj) => { });
            CustomIndicatorUnSelectedAllCommand          = new DelegateCommand((obj) => { });
            CustomIndicatorResultSelectionChangedCommand = new DelegateCommand((obj) => { });
        }