Пример #1
0
            public async Task GetAll_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
            {
                var args = new GetAllArgs();
                await args.ReadAsync(iprot, cancellationToken);

                await iprot.ReadMessageEndAsync(cancellationToken);

                var result = new GetAllResult();

                try
                {
                    result.Success = await _iAsync.GetAllAsync(cancellationToken);

                    await oprot.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Reply, seqid), cancellationToken);

                    await result.WriteAsync(oprot, cancellationToken);
                }
                catch (TTransportException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error occurred in processor:");
                    Console.Error.WriteLine(ex.ToString());
                    var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error.");
                    await oprot.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Exception, seqid), cancellationToken);

                    await x.WriteAsync(oprot, cancellationToken);
                }
                await oprot.WriteMessageEndAsync(cancellationToken);

                await oprot.Transport.FlushAsync(cancellationToken);
            }
Пример #2
0
            public async Task <List <User> > GetAllAsync(CancellationToken cancellationToken)
            {
                await OutputProtocol.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Call, SeqId), cancellationToken);

                var args = new GetAllArgs();

                await args.WriteAsync(OutputProtocol, cancellationToken);

                await OutputProtocol.WriteMessageEndAsync(cancellationToken);

                await OutputProtocol.Transport.FlushAsync(cancellationToken);

                var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);

                if (msg.Type == TMessageType.Exception)
                {
                    var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);

                    await InputProtocol.ReadMessageEndAsync(cancellationToken);

                    throw x;
                }

                var result = new GetAllResult();
                await result.ReadAsync(InputProtocol, cancellationToken);

                await InputProtocol.ReadMessageEndAsync(cancellationToken);

                if (result.__isset.success)
                {
                    return(result.Success);
                }
                throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "GetAll failed: unknown result");
            }
        /// <summary>
        /// Gets the view models.
        /// </summary>
        /// <param name="entity">The entity object.</param>
        /// <returns>The generated view models.</returns>
        public async Task <IList <ItemViewModel> > GetViewModels(SitefinityDataEntity entity)
        {
            // get the tags first
            var tagsResponse = await this.service.GetItems <TaxonDto>(entity.Tags).ConfigureAwait(true);

            // get all the news items and filter them by items containing one of the specified tag ids
            var getAllArgs = new GetAllArgs
            {
                Type   = KnownContentTypes.News,
                Filter = new FilterClause()
                {
                    FieldName = "Tags",
                    // Operator = FilterClause.Operators.ContainsAnd - get all the news items and filter them by all the items containing the specified tag ids
                    // Operator = FilterClause.Operators.DoesNotContain - get all the news items and filter them by all the items not containing the specified tag ids
                    Operator   = FilterClause.Operators.ContainsOr,
                    FieldValue = tagsResponse.Items.Select(x => x.Id),
                },
            };

            var response = await this.service.GetItems <Item>(getAllArgs);

            var viewModels = response.Items.Select(x => this.GetItemViewModel(x)).ToList();

            return(viewModels);
        }
        /// <summary>
        /// Gets the view models.
        /// </summary>
        /// <param name="entity">The entity object.</param>
        /// <returns>The generated view models.</returns>
        public async Task <IList <ItemViewModel> > GetViewModels(SitefinityDataEntity entity)
        {
            // when using the OData client, the url is automatically prefixed with the value of web the service and the sitefinity instance url
            // we use an expand the get the related image

            var getAllArgs = new GetAllArgs
            {
                // required parameter, specifies the items to work with
                Type = KnownContentTypes.News
            };

            // optional parameter, specifies the fields to be returned, if not specified
            // the default service response fields will be returned
            getAllArgs.Fields.Add(nameof(Item.Title));

            // specifies the related fields to be included in the response (like related data or parent relationships)
            if (!entity.HideImage)
            {
                getAllArgs.Fields.Add(nameof(Item.Thumbnail));
            }

            var response = await this.service.GetItems <Item>(getAllArgs);

            var viewModels = response.Items.Select(x => this.GetItemViewModel(x)).ToList();

            return(viewModels);
        }
                public GetAllArgs DeepCopy()
                {
                    var tmp10 = new GetAllArgs();

                    return(tmp10);
                }
        /// <summary>
        /// Gets the view models.
        /// </summary>
        /// <param name="entity">The entity object.</param>
        /// <returns>The generated view models.</returns>
        public async Task <IList <ItemGroup> > GetViewModels(SitefinityDataEntity entity)
        {
            var viewModels = new List <ItemGroup>();
            var itemType   = "pressreleases";
            var provider   = "OpenAccessProvider";

            // when using the OData client, the url is automatically prefixed with the value of web the service and the sitefinity instance url
            // we use an expand the get the related image

            var getAllArgs = new GetAllArgs
            {
                // required parameter, specifies the items to work with
                Type = itemType
            };

            // optional parameter, specifies the fields to be returned, if not specified
            // the default service response fields will be returned
            getAllArgs.Fields.Add("Title");

            // "*" returns all the fields, even those that are available when requesting a single item only
            // getAllArgs.Fields.Add("*");

            // specifies the related fields to be included in the response (like related data or parent relationships)
            if (!entity.HideImage)
            {
                getAllArgs.Fields.Add("RelatedMediaSingle");
            }

            // optional parameter, specifies the maximum items to be returned
            getAllArgs.Take = 20;

            // optional parameter, specifies the items to be skipped
            getAllArgs.Skip = 0;

            // optional paramteter, specifies an ordering clause
            getAllArgs.OrderBy.Add(new OrderBy()
            {
                Name = "Title",
                Type = OrderType.Ascending
            });

            // optional parameter, specifies if the total count of the items should be returned
            getAllArgs.Count = true;

            // optional parameter, if nothing is specified, the default for the site will be used
            getAllArgs.Provider = provider;

            // The generic parameter here is a plain DTO for a one to one relationship with the model on the server
            // It contains a representation for every kind of field that is currently supported by the system
            getAllArgs.Filter = null;
            var responseWithoutFilter = await this.service.GetItems <Item>(getAllArgs).ConfigureAwait(true);

            viewModels.Add(new ItemGroup()
            {
                Name  = "Items without filter",
                Items = responseWithoutFilter.Items.Select(x => this.GetItemViewModel(x)).ToArray(),
            });

            getAllArgs.Filter = new FilterClause()
            {
                FieldName  = "Title",
                FieldValue = "test",
                Operator   = FilterClause.Operators.Equal
            };

            var responseWithBasicFilter = await this.service.GetItems <Item>(getAllArgs).ConfigureAwait(true);

            viewModels.Add(new ItemGroup()
            {
                Name  = "Items with simple filter",
                Items = responseWithBasicFilter.Items.Select(x => this.GetItemViewModel(x)).ToArray(),
            });

            var filterTitle = new FilterClause()
            {
                FieldName  = "Title",
                FieldValue = "test",
                Operator   = FilterClause.Operators.Equal,
            };

            var filterTitle2 = new FilterClause()
            {
                FieldName  = "Title",
                FieldValue = "test",
                Operator   = FilterClause.Operators.NotEqual,
            };

            var filterTitle3 = new FilterClause()
            {
                FieldName  = "Title",
                FieldValue = "test",
                Operator   = FilterClause.StringOperators.StartsWith,
            };

            var filterTitle4 = new FilterClause()
            {
                FieldName  = "Title",
                FieldValue = "test",
                Operator   = FilterClause.StringOperators.EndsWith,
            };

            var filtersByTitle = new CombinedFilter()
            {
                Operator     = CombinedFilter.LogicalOperators.Or,
                ChildFilters = new FilterClause[] { filterTitle, filterTitle2 },
            };

            var filtersByTitleWithStringOperators = new CombinedFilter()
            {
                Operator     = CombinedFilter.LogicalOperators.Or,
                ChildFilters = new FilterClause[] { filterTitle3, filterTitle4 },
            };

            var multipleFiltersCombined = new CombinedFilter
            {
                Operator     = CombinedFilter.LogicalOperators.And,
                ChildFilters = new CombinedFilter[] { filtersByTitle, filtersByTitleWithStringOperators },
            };

            getAllArgs.Filter = multipleFiltersCombined;
            var responseWithComplexFilter = await this.service.GetItems <Item>(getAllArgs).ConfigureAwait(true);

            viewModels.Add(new ItemGroup()
            {
                Name  = "Items with complex filter",
                Items = responseWithComplexFilter.Items.Select(x => this.GetItemViewModel(x)).ToArray(),
            });

            // in order to execute /create/read/update operations a token must be acquired from the web server
            var createItemArgs = new CreateArgs()
            {
                // required parameter, specifies the items to work with
                Type = itemType,

                // required parameter, specifies the data to be passed to the server
                Data = new Item()
                {
                    Title                = "Test",
                    DateAndTime          = DateTime.UtcNow,
                    Number               = 123456,
                    ChoicesSingle        = SingleChoice.FirstChoice,
                    ChociesMultiple      = MultipleChoice.FirstChoice | MultipleChoice.SecondChoice,
                    LongText             = "LongText",
                    ShortText            = "ShortText",
                    ArrayOfGuids         = new [] { Guid.NewGuid() },
                    GUIDField            = Guid.NewGuid(),
                    MetaTitle            = "Test",
                    MetaDescription      = "Test",
                    OpenGraphDescription = "Test",
                    OpenGraphTitle       = "Test",
                    Tags    = new [] { Guid.NewGuid() },
                    UrlName = "test" + Guid.NewGuid().ToString(),
                    YesNo   = true,

                    // related, properties are added through relation request
                    // RelatedMediaSingle
                },

                // optional parameter, if nothing is specified, the default for the site will be used
                Provider = provider
            };

            try
            {
                // reference to documentation on how to retrieve bearer tokens
                // https://www.progress.com/documentation/sitefinity-cms/request-access-token-for-calling-web-services
                var token = "Bearer ...";
                createItemArgs.AdditionalHeaders.Add(HeaderNames.Authorization, token);

                var createResponse = await this.service.CreateItem <Item>(createItemArgs);

                var getSingleArgs = new GetItemArgs()
                {
                    // required parameter, specifies the id of the item to update
                    Id = createResponse.Id.ToString(),

                    // required parameter, specifies the items to work with
                    Type = itemType,

                    // optional parameter, if nothing is specified, the default for the site will be used
                    Provider = provider
                };

                var getSingleResponse = await this.service.GetItem <Item>(getSingleArgs);

                var updateArgs = new UpdateArgs()
                {
                    // required parameter, specifies the id of the item to update
                    Id = getSingleResponse.Id.ToString(),

                    // required parameter, specifies the items to work with
                    Type = itemType,

                    // required parameter, specifies the data to be passed to the server
                    Data = new Item()
                    {
                        Title = "updated title",
                    },

                    // optional parameter, if nothing is specified, the default for the site will be used
                    Provider = provider
                };
                updateArgs.AdditionalHeaders.Add(HeaderNames.Authorization, token);

                await this.service.UpdateItem(updateArgs);

                var deleteArgs = new DeleteArgs()
                {
                    // required parameter, specifies the id of the item to update
                    Id = getSingleResponse.Id.ToString(),

                    // required parameter, specifies the items to work with
                    Type = itemType,

                    // optional parameter, if nothing is specified, the default for the site will be used
                    Provider = provider
                };

                deleteArgs.AdditionalHeaders.Add(HeaderNames.Authorization, token);

                await this.service.DeleteItem(deleteArgs);
            }
            catch (ErrorCodeException error)
            {
                this.logger.LogError($"Cannot create/update/delete items. Actual error is {error.Message}");
            }

            return(viewModels);
        }
Пример #7
0
 public IEnumerable <Foo> GetAll(GetAllArgs args)
 {
     IQueryable <Foo> query = ...
                              return(query.Paginate(args).ToList());
 }