Пример #1
0
        /// <summary>
        /// Returns the names of all builds for the specified project, sorted s.t. the newest build is first in the array
        /// </summary>
        public string[] GetBuildNames(string projectName)
        {
            DataListResponse resp = cruiseServer.GetBuildNames(GenerateProjectRequest(projectName));

            ValidateResponse(resp);
            return(resp.Data.ToArray());
        }
        public async Task <IActionResult> GetPast()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var user = await GetCurrentUser();

                DataListResponse <AppointDom> resp = new DataListResponse <AppointDom>();
                resp.DataList = _svc.GetPast(user.Id);

                if (resp == null)
                {
                    return(NotFound());
                }

                return(Ok(resp));
            }
            catch (Exception ex)
            {
                return(StatusCode(416, ex));
            }
        }
        /// <summary>
        /// Processes a message for a server.
        /// </summary>
        /// <param name="serverSpecifer">The server the request is for.</param>
        /// <param name="action">The action to process.</param>
        /// <param name="message">The message containing the details of the request.</param>
        /// <returns>The response to the request.</returns>
        public string ProcessMessage(IServerSpecifier serverSpecifer, string action, string message)
        {
            // Normally this method just passes the request onto the remote server, but some messages
            // need to be intercepted and handled at the web dashboard level
            switch (action)
            {
            case "ListServers":
                // Generate the list of available servers - this is from the dashboard level
                var serverList = new DataListResponse
                {
                    Data = new List <string>()
                };
                foreach (var serverLocation in this.ServerLocations)
                {
                    serverList.Data.Add(serverLocation.Name);
                }

                // Return the XML of the list
                return(serverList.ToString());

            default:
                // Pass the request on
                var client   = this.GetCruiseManager(serverSpecifer, null);
                var response = client.ProcessMessage(action, message);
                return(response);
            }
        }
Пример #4
0
        public async Task GetOptionListAsync()
        {
            DataListResponse <PickListOption> response = await _service.GetOptionListAsync(
                PickListId, 0, JamaOptions.MaxResultsMax);

            Assert.IsNotNull(response);
        }
Пример #5
0
        public void GetMostRecentBuildNames()
        {
            DataListResponse response = new DataListResponse();

            response.Result = ResponseResult.Success;
            CruiseServerClient client = new CruiseServerClient(
                new ServerStub("GetMostRecentBuildNames", typeof(BuildListRequest), "Project #1", response));

            client.GetMostRecentBuildNames("Project #1", 5);
        }
Пример #6
0
        /// <summary>
        /// Returns the names of the buildCount most recent builds for the specified project, sorted s.t. the newest build is first in the array
        /// </summary>
        public string[] GetMostRecentBuildNames(string projectName, int buildCount)
        {
            BuildListRequest request = new BuildListRequest(null, projectName);

            request.NumberOfBuilds = buildCount;
            DataListResponse resp = cruiseServer.GetMostRecentBuildNames(request);

            ValidateResponse(resp);
            return(resp.Data.ToArray());
        }
Пример #7
0
        public void InitialiseResponseFromRequestSetsTheDefaultValues()
        {
            DateTime         now      = DateTime.Now;
            ServerRequest    request  = new ServerRequest();
            DataListResponse response = new DataListResponse(request);

            Assert.AreEqual(ResponseResult.Unknown, response.Result, "Result wasn't set to failure");
            Assert.AreEqual(request.Identifier, response.RequestIdentifier, "RequestIdentifier wasn't set to the identifier of the request");
            Assert.IsTrue((now <= response.Timestamp), "Timestamp was not set");
        }
Пример #8
0
        public void ToStringSerialisesDefaultValues()
        {
            DataListResponse response = new DataListResponse();
            string           actual   = response.ToString();
            string           expected = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<dataListResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
                                                      "timestamp=\"{1:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" result=\"{0}\" />",
                                                      response.Result,
                                                      response.Timestamp);

            XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
        }
Пример #9
0
        private void LoadTags(DataListResponse <BlogPostModel> response)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            var tags = repository
                       .AsQueryable <PageTag>(pt => pageIds.Contains(pt.Page.Id))
                       .Select(pt => new { PageId = pt.Page.Id, TagName = pt.Tag.Name })
                       .OrderBy(o => o.TagName)
                       .ToList();

            response.Items.ToList().ForEach(page => { page.Tags = tags.Where(tag => tag.PageId == page.Id).Select(tag => tag.TagName).ToList(); });
        }
Пример #10
0
        public void InitialiseNewResponseSetsTheDefaultValues()
        {
            DateTime         now      = DateTime.Now;
            DataListResponse response = new DataListResponse();

            Assert.AreEqual(ResponseResult.Unknown, response.Result, "Result wasn't set to failure");
            Assert.IsTrue((now <= response.Timestamp), "Timestamp was not set");

            var data = new List <string>();

            response.Data = data;
            Assert.AreSame(data, response.Data);
        }
Пример #11
0
        public void InitialiseResponseFromResponseSetsTheDefaultValues()
        {
            DateTime         now       = DateTime.Now;
            DataListResponse response1 = new DataListResponse();

            response1.Result            = ResponseResult.Success;
            response1.RequestIdentifier = "original id";
            response1.Timestamp         = DateTime.Now.AddMinutes(-1);
            DataListResponse response2 = new DataListResponse(response1);

            Assert.AreEqual(ResponseResult.Success, response2.Result, "Result wasn't set to failure");
            Assert.AreEqual("original id", response2.RequestIdentifier, "RequestIdentifier wasn't set to the identifier of the request");
            Assert.IsTrue((response1.Timestamp == response2.Timestamp), "Timestamp was not set");
        }
Пример #12
0
        public virtual DataListResponse GetResponse(DataListContext context)
        {
            var resp = new DataListResponse()
            {
                Data = Data,
            };

            if (context.ListRequest.RequestType == DataListRequestType.SchemaWithData)
            {
                resp.Fields        = context.Fields;
                resp.IdColumn      = context.IdColumn;
                resp.ItemViewField = context.ItemViewField;
            }
            return(resp);
        }
Пример #13
0
        public override async Task <DataListResponse> GetTestData(DataSourceProtoRequest dataSourceProtoRequest, ServerCallContext context)
        {
            // Deserialise the Telerik DataSourceRequest object
            DataSourceRequest dataSourceRequest = dataSourceProtoRequest.FromProto();

            // Create the Protobuf object that is sent back to the client
            var response = new DataListResponse()
            {
                Result = new ResultModel()
            };

            try
            {
                // Get the generated data
                // Note: There is currently an issue with grouping and EF Core 5.0. Adding ToList() fixes it but impacts performance on large datasets
                var data = from t in _dataContext.TestData
                           select new TestDataModel()
                {
                    Id               = t.Id,
                    ColumnInt32      = t.ColumnInt32,
                    ColumnDouble     = t.ColumnDouble,
                    ColumnFloat      = (float)t.ColumnFloat,
                    ColumnBool       = t.ColumnBool,
                    ColumnString     = t.ColumnString,
                    ColumnBytes      = ByteString.CopyFrom(t.ColumnBytes),
                    ColumnTestObject = new TestObjectModel()
                    {
                        Id = t.ObjectId, Description = t.ObjectDescription
                    },
                    Created  = t.Created,
                    Modified = t.Modified
                };

                // Add filtering, paging and grouping
                DataSourceResult dataSourceResult = await data.ToList().ToDataSourceResultAsync(dataSourceRequest);

                // Convert the result. The grouped object structure needs some processing and utilises the callback function below
                ControllerHelper.ConvertDataSourceResult(response, dataSourceResult, new DataGroupModelCallBack(CreateDataGroupModel));
            }
            catch (Exception ex)
            {
                response.Result.ErrorMessage = $"Error in GetTestData: {ex.Message}";
            }

            return(response);
        }
Пример #14
0
        public static void ConvertDataSourceResult(DataListResponse response, DataSourceResult dataSourceResult, DataGroupModelCallBack callBack)
        {
            response.GridData = new DataGroupModel();
            if (dataSourceResult.Data is List <AggregateFunctionsGroup> )
            {
                // Process the grouped Data
                response.GridData.SubGroups.AddRange(AddFunctionsGroup(dataSourceResult.Data, callBack));
                response.Result.TotalRecords = dataSourceResult.Total;
            }
            else
            {
                // Process the flat item list
                callBack(dataSourceResult.Data, response.GridData);
                response.GridData.GridGroupModel = new TelerikGroupModel()
                {
                    ItemCount = dataSourceResult.Total,
                    Member    = string.Empty
                };

                response.Result.TotalRecords = dataSourceResult.Total;
            }
        }
Пример #15
0
        private async Task <Project> FindProject(string key)
        {
            Project  project  = null;
            int      startAt  = 0;
            PageInfo pageInfo = null;

            do
            {
                DataListResponse <Project> dataListResponse = await _service.GetListAsync(
                    startAt, JamaOptions.MaxResultsMax);

                project = dataListResponse.Data
                          .SingleOrDefault(p => p.ProjectKey.Equals(key, StringComparison.InvariantCultureIgnoreCase));
                if (project != null)
                {
                    break;
                }

                pageInfo = dataListResponse.Meta.PageInfo;
                startAt  = pageInfo.StartIndex + pageInfo.ResultCount;
            }while (startAt < pageInfo.TotalResults);
            return(project);
        }
Пример #16
0
        private void LoadOptions(DataListResponse <PageModel> response)
        {
            var layoutIds           = response.Items.Select(i => i.LayoutId).Distinct().ToArray();
            var layoutOptionsFuture =
                repository.AsQueryable <LayoutOption>(l => layoutIds.Contains(l.Layout.Id))
                .Select(layout => new { LayoutId = layout.Layout.Id, Option = layout })
                .ToFuture();

            var pageIds     = response.Items.Select(i => i.Id).Distinct().ToArray();
            var pageOptions =
                repository.AsQueryable <PageOption>(p => pageIds.Contains(p.Page.Id)).Select(page => new { PageId = page.Page.Id, Option = page }).ToFuture().ToList();

            var layoutOptions = layoutOptionsFuture.ToList();

            response.Items.ForEach(
                page =>
            {
                var options      = layoutOptions.Where(lo => lo.LayoutId == page.LayoutId).Select(lo => lo.Option).ToList();
                var optionValues = pageOptions.Where(po => po.PageId == page.Id).Select(po => po.Option).ToList();

                if (options.Count > 0 || optionValues.Count > 0)
                {
                    page.Options =
                        optionService.GetMergedOptionValuesForEdit(options, optionValues)
                        .Select(
                            o =>
                            new OptionModel
                    {
                        Key          = o.OptionKey,
                        Value        = o.OptionValue,
                        DefaultValue = o.OptionDefaultValue,
                        Type         = ((Root.OptionType)(int) o.Type)
                    })
                        .ToList();
                }
            });
        }
Пример #17
0
        public void ToStringSerialisesAllValues()
        {
            DataListResponse response = new DataListResponse();

            response.ErrorMessages.Add(new ErrorMessage("Error 1"));
            response.ErrorMessages.Add(new ErrorMessage("Error 2"));
            response.RequestIdentifier = "request";
            response.Result            = ResponseResult.Success;
            response.Timestamp         = DateTime.Now;
            response.Data.Add("new data");
            string actual   = response.ToString();
            string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<dataListResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
                                            "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" +
                                            "<error>Error 1</error>" +
                                            "<error>Error 2</error>" +
                                            "<data>{3}</data>" +
                                            "</dataListResponse>",
                                            response.RequestIdentifier,
                                            response.Result,
                                            response.Timestamp,
                                            response.Data[0]);

            XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected));
        }
Пример #18
0
        private void LoadOptionsAndTags(DataListResponse <PageModel> response, bool includeOptions, bool includeTags)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable <LayoutWithOption> layoutOptionsFuture = null;
            IEnumerable <PageWithOption>   pageOptionsFuture   = null;

            if (includeOptions)
            {
                var layoutIds = response.Items.Select(i => i.LayoutId).Distinct().ToArray();
                layoutOptionsFuture = repository
                                      .AsQueryable <LayoutOption>(l => layoutIds.Contains(l.Layout.Id))
                                      .Select(layout => new LayoutWithOption {
                    LayoutId = layout.Layout.Id, Option = layout
                })
                                      .ToFuture();

                pageOptionsFuture = repository
                                    .AsQueryable <PageOption>(p => pageIds.Contains(p.Page.Id))
                                    .Select(page => new PageWithOption {
                    PageId = page.Page.Id, Option = page
                })
                                    .ToFuture();
            }

            if (includeTags)
            {
                var tags = repository
                           .AsQueryable <PageTag>(pt => pageIds.Contains(pt.Page.Id))
                           .Select(pt => new { PageId = pt.Page.Id, TagName = pt.Tag.Name })
                           .OrderBy(o => o.TagName)
                           .ToFuture()
                           .ToList();

                response.Items.ToList().ForEach(page => { page.Tags = tags.Where(tag => tag.PageId == page.Id).Select(tag => tag.TagName).ToList(); });
            }

            if (includeOptions)
            {
                var layoutOptions = layoutOptionsFuture.ToList();
                var pageOptions   = pageOptionsFuture.ToList();

                response.Items.ForEach(
                    page =>
                {
                    var options      = layoutOptions.Where(lo => lo.LayoutId == page.LayoutId).Select(lo => lo.Option).ToList();
                    var optionValues = pageOptions.Where(po => po.PageId == page.Id).Select(po => po.Option).ToList();

                    if (options.Count > 0 || optionValues.Count > 0)
                    {
                        page.Options =
                            optionService.GetMergedOptionValuesForEdit(options, optionValues)
                            .Select(
                                o =>
                                new OptionModel
                        {
                            Key          = o.OptionKey,
                            Value        = o.OptionValue,
                            DefaultValue = o.OptionDefaultValue,
                            Type         = ((Root.OptionType)(int) o.Type)
                        })
                            .ToList();
                    }
                });
            }
        }
Пример #19
0
        private void LoadTags(DataListResponse <BlogPostModel> response, bool includeTags, bool includeAccessRules)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable <TagModel> tagsFuture;

            if (includeTags)
            {
                tagsFuture =
                    repository.AsQueryable <PageTag>(pt => pageIds.Contains(pt.Page.Id))
                    .Select(pt => new TagModel {
                    PageId = pt.Page.Id, TagName = pt.Tag.Name
                })
                    .OrderBy(o => o.TagName)
                    .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable <AccessRuleModelEx> rulesFuture;

            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable <Module.Root.Models.Page>()
                               from accessRule in page.AccessRules
                               where pageIds.Contains(page.Id)
                               orderby accessRule.IsForRole, accessRule.Identity
                               select new AccessRuleModelEx
                {
                    AccessRule = new AccessRuleModel
                    {
                        AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                        Identity = accessRule.Identity,
                        IsForRole = accessRule.IsForRole
                    },
                    PageId = page.Id
                })
                              .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }


            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(
                    page =>
                {
                    page.Tags = tags
                                .Where(tag => tag.PageId == page.Id)
                                .Select(tag => tag.TagName)
                                .ToList();
                });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.AccessRules = rules
                                       .Where(rule => rule.PageId == page.Id)
                                       .Select(rule => rule.AccessRule)
                                       .ToList();
                });
            }
        }
Пример #20
0
        private void LoadOptionsAndTags(DataListResponse<PageModel> response, bool includeOptions, bool includeTags)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable<LayoutWithOption> layoutOptionsFuture = null;
            IEnumerable<PageWithOption> pageOptionsFuture = null;

            if (includeOptions)
            {
                var layoutIds = response.Items.Select(i => i.LayoutId).Distinct().ToArray();
                layoutOptionsFuture = repository
                    .AsQueryable<LayoutOption>(l => layoutIds.Contains(l.Layout.Id))
                    .Select(layout => new LayoutWithOption { LayoutId = layout.Layout.Id, Option = layout })
                    .ToFuture();

                pageOptionsFuture = repository
                    .AsQueryable<PageOption>(p => pageIds.Contains(p.Page.Id))
                    .Select(page => new PageWithOption { PageId = page.Page.Id, Option = page })
                    .ToFuture();
            }

            if (includeTags)
            {
                var tags = repository
                    .AsQueryable<PageTag>(pt => pageIds.Contains(pt.Page.Id))
                    .Select(pt => new { PageId = pt.Page.Id, TagName = pt.Tag.Name })
                    .OrderBy(o => o.TagName)
                    .ToFuture()
                    .ToList();

                response.Items.ToList().ForEach(page => { page.Tags = tags.Where(tag => tag.PageId == page.Id).Select(tag => tag.TagName).ToList(); });
            }

            if (includeOptions)
            {
                var layoutOptions = layoutOptionsFuture.ToList();
                var pageOptions = pageOptionsFuture.ToList();

                response.Items.ForEach(
                    page =>
                        {
                            var options = layoutOptions.Where(lo => lo.LayoutId == page.LayoutId).Select(lo => lo.Option).ToList();
                            var optionValues = pageOptions.Where(po => po.PageId == page.Id).Select(po => po.Option).ToList();

                            if (options.Count > 0 || optionValues.Count > 0)
                            {
                                page.Options =
                                    optionService.GetMergedOptionValuesForEdit(options, optionValues)
                                                 .Select(
                                                     o =>
                                                     new OptionModel
                                                         {
                                                             Key = o.OptionKey,
                                                             Value = o.OptionValue,
                                                             DefaultValue = o.OptionDefaultValue,
                                                             Type = ((Root.OptionType)(int)o.Type)
                                                         })
                                                 .ToList();
                            }
                        });
            }
        }
Пример #21
0
        private void LoadTags(DataListResponse<BlogPostModel> response, bool includeTags, bool includeAccessRules)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable<TagModel> tagsFuture;
            if (includeTags)
            {
                tagsFuture =
                    repository.AsQueryable<PageTag>(pt => pageIds.Contains(pt.Page.Id))
                        .Select(pt => new TagModel { PageId = pt.Page.Id, TagName = pt.Tag.Name })
                        .OrderBy(o => o.TagName)
                        .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable<AccessRuleModelEx> rulesFuture;
            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable<Module.Root.Models.Page>()
                               from accessRule in page.AccessRules
                               where pageIds.Contains(page.Id)
                               orderby accessRule.IsForRole, accessRule.Identity
                               select new AccessRuleModelEx
                               {
                                   AccessRule = new AccessRuleModel
                                   {
                                       AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                                       Identity = accessRule.Identity,
                                       IsForRole = accessRule.IsForRole
                                   },
                                   PageId = page.Id
                               })
                    .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }


            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(
                    page =>
                    {
                        page.Tags = tags
                            .Where(tag => tag.PageId == page.Id)
                            .Select(tag => tag.TagName)
                            .ToList();
                    });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.AccessRules = rules
                        .Where(rule => rule.PageId == page.Id)
                        .Select(rule => rule.AccessRule)
                        .ToList();
                });
            }
        }
Пример #22
0
        private void LoadInnerCollections(DataListResponse <PageModel> response, bool includeOptions, bool includeTags, bool includeAccessRules, bool includeCategories)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable <TagModel> tagsFuture;

            if (includeTags)
            {
                tagsFuture = repository.AsQueryable <PageTag>(pt => pageIds.Contains(pt.Page.Id))
                             .Select(pt => new TagModel {
                    PageId = pt.Page.Id, Tag = pt.Tag.Name
                })
                             .OrderBy(o => o.Tag)
                             .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable <AccessRuleModelEx> rulesFuture;

            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable <Module.Root.Models.Page>()
                               from accessRule in page.AccessRules
                               where pageIds.Contains(page.Id)
                               orderby accessRule.IsForRole, accessRule.Identity
                               select new AccessRuleModelEx
                {
                    AccessRule = new AccessRuleModel
                    {
                        AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                        Identity = accessRule.Identity,
                        IsForRole = accessRule.IsForRole
                    },
                    PageId = page.Id
                })
                              .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }

            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.Tags = tags
                                .Where(tag => tag.PageId == page.Id)
                                .Select(tag => tag.Tag)
                                .ToList();
                });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.AccessRules = rules
                                       .Where(rule => rule.PageId == page.Id)
                                       .Select(rule => rule.AccessRule)
                                       .ToList();
                });
            }

            if (includeOptions)
            {
                response.Items.ForEach(
                    page =>
                {
                    page.Options = optionService
                                   .GetMergedMasterPagesOptionValues(page.Id, page.MasterPageId, page.LayoutId)
                                   .Select(o => new OptionValueModel
                    {
                        Key                  = o.OptionKey,
                        Value                = o.OptionValue,
                        DefaultValue         = o.OptionDefaultValue,
                        Type                 = ((Root.OptionType)(int) o.Type),
                        UseDefaultValue      = o.UseDefaultValue,
                        CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null
                    })
                                   .ToList();
                });
            }

            if (includeCategories)
            {
                response.Items.ForEach(page =>
                {
                    page.Categories = (from pagePr in repository.AsQueryable <PageProperties>()
                                       from category in pagePr.Categories
                                       where pagePr.Id == page.Id && !category.IsDeleted
                                       select new CategoryModel
                    {
                        Id = category.Category.Id,
                        Version = category.Version,
                        CreatedBy = category.CreatedByUser,
                        CreatedOn = category.CreatedOn,
                        LastModifiedBy = category.ModifiedByUser,
                        LastModifiedOn = category.ModifiedOn,
                        Name = category.Category.Name
                    }).ToList();
                });
            }
        }
Пример #23
0
        private void LoadInnerCollections(DataListResponse<PageModel> response, bool includeOptions, bool includeTags, bool includeAccessRules)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable<TagModel> tagsFuture;
            if (includeTags)
            {
                tagsFuture = repository.AsQueryable<PageTag>(pt => pageIds.Contains(pt.Page.Id))
                        .Select(pt => new TagModel { PageId = pt.Page.Id, Tag = pt.Tag.Name })
                        .OrderBy(o => o.Tag)
                        .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable<AccessRuleModelEx> rulesFuture;
            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable<Module.Root.Models.Page>()
                    from accessRule in page.AccessRules
                    where pageIds.Contains(page.Id)
                    orderby accessRule.IsForRole, accessRule.Identity
                    select new AccessRuleModelEx
                           {
                               AccessRule = new AccessRuleModel
                               {
                                   AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                                   Identity = accessRule.Identity,
                                   IsForRole = accessRule.IsForRole
                               },
                               PageId = page.Id
                           })
                    .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }

            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(page => 
                { 
                    page.Tags = tags
                        .Where(tag => tag.PageId == page.Id)
                        .Select(tag => tag.Tag)
                        .ToList();
                });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page => 
                {
                    page.AccessRules = rules
                        .Where(rule => rule.PageId == page.Id)
                        .Select(rule => rule.AccessRule)
                        .ToList();
                });
            }

            if (includeOptions)
            {
                response.Items.ForEach(
                    page =>
                        {
                            page.Options = optionService
                                .GetMergedMasterPagesOptionValues(page.Id, page.MasterPageId, page.LayoutId)
                                .Select(o => new OptionModel
                                    {
                                        Key = o.OptionKey,
                                        Value = o.OptionValue,
                                        DefaultValue = o.OptionDefaultValue,
                                        Type = ((Root.OptionType)(int)o.Type)
                                    })
                                .ToList();
                        });
            }
        }
Пример #24
0
        private void LoadOptions(DataListResponse<PageModel> response)
        {
            var layoutIds = response.Items.Select(i => i.LayoutId).Distinct().ToArray();
            var layoutOptionsFuture =
                repository.AsQueryable<LayoutOption>(l => layoutIds.Contains(l.Layout.Id))
                          .Select(layout => new { LayoutId = layout.Layout.Id, Option = layout })
                          .ToFuture();

            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();
            var pageOptions =
                repository.AsQueryable<PageOption>(p => pageIds.Contains(p.Page.Id)).Select(page => new { PageId = page.Page.Id, Option = page }).ToFuture().ToList();

            var layoutOptions = layoutOptionsFuture.ToList();

            response.Items.ForEach(
                page =>
                    {
                        var options = layoutOptions.Where(lo => lo.LayoutId == page.LayoutId).Select(lo => lo.Option).ToList();
                        var optionValues = pageOptions.Where(po => po.PageId == page.Id).Select(po => po.Option).ToList();

                        if (options.Count > 0 || optionValues.Count > 0)
                        {
                            page.Options =
                                optionService.GetMergedOptionValuesForEdit(options, optionValues)
                                             .Select(
                                                 o =>
                                                 new OptionModel
                                                     {
                                                         Key = o.OptionKey,
                                                         Value = o.OptionValue,
                                                         DefaultValue = o.OptionDefaultValue,
                                                         Type = ((Root.OptionType)(int)o.Type)
                                                     })
                                             .ToList();
                        }
                    });
        }
Пример #25
0
        private void LoadInnerCollections(DataListResponse<PageModel> response, bool includeOptions, bool includeTags, bool includeAccessRules, bool includeCategories)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable<TagModel> tagsFuture;
            if (includeTags)
            {
                tagsFuture = repository.AsQueryable<PageTag>(pt => pageIds.Contains(pt.Page.Id))
                        .Select(pt => new TagModel { PageId = pt.Page.Id, Tag = pt.Tag.Name })
                        .OrderBy(o => o.Tag)
                        .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable<AccessRuleModelEx> rulesFuture;
            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable<Module.Root.Models.Page>()
                               from accessRule in page.AccessRules
                               where pageIds.Contains(page.Id)
                               orderby accessRule.IsForRole, accessRule.Identity
                               select new AccessRuleModelEx
                                      {
                                          AccessRule = new AccessRuleModel
                                          {
                                              AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                                              Identity = accessRule.Identity,
                                              IsForRole = accessRule.IsForRole
                                          },
                                          PageId = page.Id
                                      })
                    .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }

            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.Tags = tags
                        .Where(tag => tag.PageId == page.Id)
                        .Select(tag => tag.Tag)
                        .ToList();
                });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.AccessRules = rules
                        .Where(rule => rule.PageId == page.Id)
                        .Select(rule => rule.AccessRule)
                        .ToList();
                });
            }

            if (includeOptions)
            {
                response.Items.ForEach(
                    page =>
                    {
                        page.Options = optionService
                            .GetMergedMasterPagesOptionValues(page.Id, page.MasterPageId, page.LayoutId)
                            .Select(o => new OptionValueModel
                                {
                                    Key = o.OptionKey,
                                    Value = o.OptionValue,
                                    DefaultValue = o.OptionDefaultValue,
                                    Type = ((Root.OptionType)(int)o.Type),
                                    UseDefaultValue = o.UseDefaultValue,
                                    CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null
                                })
                            .ToList();
                    });
            }

            if (includeCategories)
            {
                response.Items.ForEach( page =>
                                        {
                                            page.Categories = (from pagePr in repository.AsQueryable<PageProperties>()
                                                               from category in pagePr.Categories
                                                               where pagePr.Id == page.Id && !category.IsDeleted
                                                               select new CategoryModel
                                                                {
                                                                    Id = category.Category.Id,
                                                                    Version = category.Version,
                                                                    CreatedBy = category.CreatedByUser,
                                                                    CreatedOn = category.CreatedOn,
                                                                    LastModifiedBy = category.ModifiedByUser,
                                                                    LastModifiedOn = category.ModifiedOn,
                                                                    Name = category.Category.Name
                                                                }).ToList();
                                        });
            }

        }
Пример #26
0
        private void LoadInnerCollections(DataListResponse <PageModel> response, bool includeOptions, bool includeTags, bool includeAccessRules)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();

            IEnumerable <TagModel> tagsFuture;

            if (includeTags)
            {
                tagsFuture = repository.AsQueryable <PageTag>(pt => pageIds.Contains(pt.Page.Id))
                             .Select(pt => new TagModel {
                    PageId = pt.Page.Id, Tag = pt.Tag.Name
                })
                             .OrderBy(o => o.Tag)
                             .ToFuture();
            }
            else
            {
                tagsFuture = null;
            }

            IEnumerable <AccessRuleModelEx> rulesFuture;

            if (includeAccessRules)
            {
                rulesFuture = (from page in repository.AsQueryable <Module.Root.Models.Page>()
                               from accessRule in page.AccessRules
                               where pageIds.Contains(page.Id)
                               orderby accessRule.IsForRole, accessRule.Identity
                               select new AccessRuleModelEx
                {
                    AccessRule = new AccessRuleModel
                    {
                        AccessLevel = (AccessLevel)(int)accessRule.AccessLevel,
                        Identity = accessRule.Identity,
                        IsForRole = accessRule.IsForRole
                    },
                    PageId = page.Id
                })
                              .ToFuture();
            }
            else
            {
                rulesFuture = null;
            }

            if (tagsFuture != null)
            {
                var tags = tagsFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.Tags = tags
                                .Where(tag => tag.PageId == page.Id)
                                .Select(tag => tag.Tag)
                                .ToList();
                });
            }

            if (rulesFuture != null)
            {
                var rules = rulesFuture.ToList();
                response.Items.ToList().ForEach(page =>
                {
                    page.AccessRules = rules
                                       .Where(rule => rule.PageId == page.Id)
                                       .Select(rule => rule.AccessRule)
                                       .ToList();
                });
            }

            if (includeOptions)
            {
                response.Items.ForEach(
                    page =>
                {
                    page.Options = optionService
                                   .GetMergedMasterPagesOptionValues(page.Id, page.MasterPageId, page.LayoutId)
                                   .Select(o => new OptionModel
                    {
                        Key          = o.OptionKey,
                        Value        = o.OptionValue,
                        DefaultValue = o.OptionDefaultValue,
                        Type         = ((Root.OptionType)(int) o.Type)
                    })
                                   .ToList();
                });
            }
        }
Пример #27
0
        private void LoadTags(DataListResponse<SitemapModel> response, bool includeTags)
        {
            var pageIds = response.Items.Select(i => i.Id).Distinct().ToArray();
            if (includeTags)
            {
                var tags = repository
                    .AsQueryable<SitemapTag>(pt => pageIds.Contains(pt.Sitemap.Id))
                    .Select(pt => new { PageId = pt.Sitemap.Id, TagName = pt.Tag.Name })
                    .OrderBy(o => o.TagName)
                    .ToFuture()
                    .ToList();

                response.Items.ToList().ForEach(page => { page.Tags = tags.Where(tag => tag.PageId == page.Id).Select(tag => tag.TagName).ToList(); });
            }
        }