Exemple #1
0
        public ReportRetrieveResponse Retrieve(ReportRetrieveRequest request)
        {
            request.CheckNotNull();

            if (request.ReportKey.IsEmptyOrNull())
            {
                throw new ArgumentNullException("reportKey");
            }

            var reportInfo = ReportRegistry.GetReport(request.ReportKey);

            if (reportInfo == null)
            {
                throw new ArgumentOutOfRangeException("reportKey");
            }

            if (reportInfo.Permission != null)
            {
                Authorization.ValidatePermission(reportInfo.Permission);
            }

            var response = new ReportRetrieveResponse();

            response.Properties = PropertyItemHelper.GetPropertyItemsFor(reportInfo.Type);
            response.ReportKey  = reportInfo.Key;
            response.Title      = reportInfo.Title;
            var reportInstance = Activator.CreateInstance(reportInfo.Type);

            response.InitialSettings  = reportInstance;
            response.IsDataOnlyReport = reportInstance is IDataOnlyReport;

            return(response);
        }
        public void IgnoresFieldDeclarations()
        {
            var actual   = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithField));
            var expected = new PropertyItem[0];

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
        public void Date_Property_With_Local_Kind_Attribute_Should_Have_Use_Utc_True()
        {
            var list = PropertyItemHelper.GetPropertyItemsFor(typeof(DateTimeTestForm));
            var item = list.FirstOrDefault(x => x.Name == "MyLocal");

            Assert.NotNull(item);
            Assert.NotNull(item.EditorParams);
            Assert.Contains("useUtc", item.EditorParams.Keys);
            Assert.True((bool)item.EditorParams["useUtc"]);
        }
        public void Returns_One_Element_List_For_ClassWithOneSimpleProperty()
        {
            var actual   = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithOneSimpleProperty));
            var expected = new PropertyItem[]
            {
                new PropertyItem {
                    Name = "Property", Title = "Property", Width = 80
                }
            };

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
        public void Date_Property_With_Unspecified_Kind_Attribute_Should_Not_Have_Use_Utc_False()
        {
            var list = PropertyItemHelper.GetPropertyItemsFor(typeof(DateTimeTestForm));
            var item = list.FirstOrDefault(x => x.Name == "MyUnspecified");

            Assert.NotNull(item);
            object useUtc;

            if (item.EditorParams != null && item.EditorParams.TryGetValue("useUtc", out useUtc))
            {
                Assert.False((bool)useUtc);
            }
        }
Exemple #6
0
        public List <ReportColumn> GetColumnList()
        {
            var list = new List <ReportColumn>();

            if (!ColumnList.Any())
            {
                return(list);
            }

            IDictionary <string, PropertyItem> propertyItems = null;
            IDictionary <string, PropertyInfo> propertyInfos = null;
            Row basedOnRow = null;

            if (ColumnsType != null)
            {
                propertyItems = LocalCache.Get("DynamicDataReport:Columns:" + ColumnsType.FullName, TimeSpan.Zero,
                                               () => PropertyItemHelper.GetPropertyItemsFor(ColumnsType).ToDictionary(x => x.Name));

                propertyInfos = ColumnsType.GetProperties().ToDictionary(x => x.Name);

                var basedOnAttr = ColumnsType.GetCustomAttribute <BasedOnRowAttribute>();
                if (basedOnAttr != null &&
                    basedOnAttr.RowType != null &&
                    typeof(Row).IsAssignableFrom(basedOnAttr.RowType))
                {
                    basedOnRow = (Row)Activator.CreateInstance(basedOnAttr.RowType);
                }
            }

            foreach (var columnName in ColumnList)
            {
                PropertyItem item;
                if (!propertyItems.TryGetValue(columnName, out item))
                {
                    continue;
                }

                var basedOnField = basedOnRow == null ? (Field)null :
                                   (basedOnRow.FindField(columnName) ?? basedOnRow.FindFieldByPropertyName(columnName));

                PropertyInfo p;
                if (propertyInfos == null || !propertyInfos.TryGetValue(columnName, out p))
                {
                    p = null;
                }

                list.Add(FromPropertyItem(item, basedOnField, p));
            }

            return(list);
        }
        public void PreservesDeclarationOrderingFor_ClassWithUnorderedProperties()
        {
            var actual = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithUnorderedProperties));

            var expected = new PropertyItem[]
            {
                new PropertyItem {
                    Name = "Property3", Title = "Property3", Width = 80
                },
                new PropertyItem {
                    Name = "Property1", Title = "Property1", Width = 80
                },
                new PropertyItem {
                    Name = "Property2", Title = "Property2", Width = 80
                }
            };

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
        public void Returns_Empty_Array_For_ClassWithNoProperties()
        {
            var actual = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithNoProperties));

            Assert.Equal(new List <PropertyItem>(), actual);
        }