public DefaultJqGridConfiguration(ColumnFactory factory)
     : base(factory)
 {
     // These are executed in order; later config takes precidence over earlier.
     Defaults();
     ColumnVisibilityRules();
 }
        // run once for every configured column
        private bool IsEveryColumnValid(Configuration configuration, ApiHttpClient apiClient)
        {
            var result = true;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var c in configuration.Columns)
            {
                var column = ColumnFactory.GetColumn(c);
                result = column.IsColumnConfigurationValid(apiClient) && result;
            }
            return(result);
        }
예제 #3
0
        public static void RegisterCustomColumns()
        {
            ColumnFactory.AddColumnCreator("color", (details, columnComponents, initialCapacity) =>
            {
                IColumn <ColorColumn.ComparableColor> coreColumn = new ColorColumn();
                IUntypedColumn utc = new UntypedColumn <ColorColumn.ComparableColor>(coreColumn);

                utc.Name = details.Name;

                return(utc);
            });
        }
예제 #4
0
        public void CorrectColumnIsConstructedForType()
        {
            // Arrange
            var context = new Mock <IContextEntry>();

            context.SetupGet(c => c.UserId).Returns(1);

            var contextList = new[]
            {
                context.Object
            };

            var contexts = new Mock <ITwitterContextList>();

            contexts.SetupGet(c => c.Contexts).Returns(contextList);

            var parser = new Mock <IStreamParser>();

            var config = new Mock <IConfig>();

            config.SetupGet(c => c.General).Returns(new GeneralConfig());
            var streamingRepo = new Mock <IStreamingRepository>();

            streamingRepo.Setup(s => s.GetParser(It.Is <ColumnDefinition>(d => d.SourceAccounts.Contains((ulong)1))))
            .Returns(parser.Object);
            var factory = new ColumnFactory
            {
                Contexts      = contexts.Object,
                StreamingRepo = streamingRepo.Object,
                Configuration = config.Object
            };

            var testCases = new Dictionary <ColumnType, Type>
            {
                { ColumnType.Mentions, typeof(MentionsColumn) },
                { ColumnType.User, typeof(UserColumn) },
                { ColumnType.Timeline, typeof(TimelineColumn) }
            };

            // Act & Assert
            foreach (var kvp in testCases)
            {
                var constructed = factory.Construct(new ColumnDefinition(kvp.Key)
                {
                    SourceAccounts = new ulong[] { 1 },
                    TargetAccounts = new ulong[] { 1 }
                });
                Assert.IsNotNull(constructed);

                var type = constructed.GetType();
                Assert.IsTrue(kvp.Value.IsAssignableFrom(type));
            }
        }
예제 #5
0
파일: Board.cs 프로젝트: cheng93/Sudoku
        private void CreateUnits()
        {
            var boxFactory    = new BoxFactory();
            var columnFactory = new ColumnFactory();
            var rowFactory    = new RowFactory();

            for (int i = 0; i < 9; i++)
            {
                _boxes[i]   = boxFactory.Factory(_cells, i);
                _columns[i] = columnFactory.Factory(_cells, i);
                _rows[i]    = rowFactory.Factory(_cells, i);
            }
        }
        // run once for every type of column
        private bool IsEntireConfigurationValid(Configuration configuration)
        {
            var result = true;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (ColumnType c in Enum.GetValues(typeof(ColumnType)))
            {
                var column = ColumnFactory.GetColumn(new Configuration.Column {
                    Header = "Some_Header", Type = c
                });
                result = column.IsEntireConfigurationValid(configuration) && result;
            }
            return(result);
        }
예제 #7
0
        public void SortedColumn_Basic()
        {
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0), -10, 20);
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0), "One", "Two");
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <TimeSpan>(new ValueTypeColumn <TimeSpan>(default(TimeSpan)), 0), TimeSpan.FromMinutes(1), TimeSpan.FromHours(1));

            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), ArrayExtensions.MinimumSize + 1), -10, 20);
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), ArrayExtensions.MinimumSize + 1), "One", "Two");
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <TimeSpan>(new ValueTypeColumn <TimeSpan>(default(TimeSpan)), ArrayExtensions.MinimumSize + 1), TimeSpan.FromMinutes(1), TimeSpan.FromHours(1));

            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), ushort.MaxValue), -10, 20);
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), ushort.MaxValue), "One", "Two");
            ColumnTests.ColumnTest_Basics(() => ColumnFactory.CreateSortedColumn <TimeSpan>(new ValueTypeColumn <TimeSpan>(default(TimeSpan)), ushort.MaxValue), TimeSpan.FromMinutes(1), TimeSpan.FromHours(1));
        }
예제 #8
0
        public void IColumnExtensions_FindComponent()
        {
            IColumn <object> column = ColumnFactory.Build(new ColumnDetails("sample", "string", null), 0);

            Assert.IsNotNull(column.FindComponent <IndexedColumn>());
            Assert.IsNotNull(column.FindComponent <UntypedColumn <ByteBlock> >());
            Assert.IsNotNull(column.FindComponent <ByteBlockColumn>());
            Assert.IsNotNull(column.FindComponent <SortedColumn <ByteBlock> >());
            Assert.IsNull(column.FindComponent <ValueTypeColumn <int> >());

            IColumn c2 = new ValueTypeColumn <short>(short.MinValue);

            Assert.IsNull(c2.FindComponent <SortedColumn <short> >());
            Assert.IsNotNull(c2.FindComponent <ValueTypeColumn <short> >());
        }
예제 #9
0
        public virtual IHttpActionResult Get(PaginatedRequestCommand cmd)
        {
            cmd.FilterInternalDictionary = new Dictionary <string, object>();

            this.ListSelecting(cmd);

            var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault();

            if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);

                    var paginatedModel = list.ToPaginatedModel <TModel>(null, null);
                    SetViews(paginatedModel.Items);

                    paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                    paginatedModel.Condition         = new Condition();

                    this.ListSelected(paginatedModel);

                    return(Ok(paginatedModel));
                }
                catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
            }

            try
            {
                var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);
                var paged    = entities.ToPaginatedModel <TModel>(null, null);
                SetViews(paged.Items);

                paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                paged.Condition         = new Condition();

                this.ListSelected(paged);

                return(Ok(paged));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        private bool AreValuesValid(Csv csv)
        {
            var result = true;

            foreach (var row in csv.Values)
            {
                foreach (var c in _configuration.Columns)
                {
                    var column = ColumnFactory.GetColumn(c);
                    result =
                        column.IsValueValid(row.ContainsKey(c.Header) ? row[c.Header] as string : null, _apiClient) &&
                        result;
                }
            }
            return(result);
        }
예제 #11
0
        private void LoadColumns(XPathNavigator xml)
        {
            Columns.Clear();
            var columnNodes = xml.Select("/qdbapi/table/fields/field");

            foreach (XPathNavigator columnNode in columnNodes)
            {
                var columnId = int.Parse(columnNode.GetAttribute("id", String.Empty));
                var type     =
                    (FieldType)Enum.Parse(typeof(FieldType), columnNode.GetAttribute("field_type", String.Empty), true);
                var label = columnNode.SelectSingleNode("label").Value;

                var col = ColumnFactory.CreateInstace(columnId, label, type);
                Columns.Add(col);
            }
        }
예제 #12
0
        public void SortedColumn_Consistency()
        {
            SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0);

            c.SetSize(2);
            c[0] = 1;
            c[1] = 2;
            ColumnTests.AssertConsistent(c);
            c.SetSize(4);
            c[2] = -5;
            c[3] = -4;
            ColumnTests.AssertConsistent(c);
            c.SetSize(6);
            c[4] = 1;
            c[5] = 0;
            ColumnTests.AssertConsistent(c);
        }
예제 #13
0
        public void IndexedColumn_Where()
        {
            IColumn <ByteBlock> c = new IndexedColumn(ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0), new DefaultWordSplitter());

            // Verify no error searching empty column
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "missing"));

            c.SetSize(4);
            c[0] = "First Value";
            c[1] = "Second Value";
            c[2] = "this is a different value";
            ColumnTests.AssertConsistent(c);

            // Verify passthrough to base column
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Equals, "First Value"));

            // Verify unknown words don't match (no error)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "missing"));

            // Verify all match for shared words
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "value"));
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value"));

            // Verify prefixes match for 'Matches' and not 'MatchesExact'
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "val"));
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.MatchesExact, "val"));

            // Verify unique words return only those matches
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "first"));
            Assert.AreEqual("2", ColumnTests.GetMatches(c, Operator.Matches, "diff"));

            // Verify matches fallthrough to equals
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "First Value"));

            c[0] = "Updated Value Here";
            ColumnTests.AssertConsistent(c);

            // Verify items no longer match for removed words
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "first"));

            // Verify items continue to match for kept words
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value"));

            // Verify items match for new words
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.MatchesExact, "updated"));
        }
예제 #14
0
        public void TypedColumn_TimeSpan_Basic()
        {
            IColumn <object> c = ColumnFactory.Build(new ColumnDetails("Duration", "TimeSpan", null), 0);

            c.SetSize(10);

            c[0] = Value.Create(TimeSpan.FromMinutes(1));
            c[1] = Value.Create("01:00:00");
            c[2] = Value.Create("00:00:01");
            c[3] = Value.Create("1");

            CommitIfRequired(c);
            ShortSet longTimes = new ShortSet(c.Count);

            c.TryWhere(Operator.GreaterThan, TimeSpan.FromSeconds(30), longTimes, null);
            Assert.AreEqual("0, 1, 3", String.Join(", ", longTimes.Values));
        }
예제 #15
0
        public void SortedColumn_Strings()
        {
            SortedColumn <ByteBlock> c = ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0);

            // Set all three to default (empty)
            c.SetSize(3);
            CommitIfRequired(c);

            // Reset a value to empty (SortedIDs need to stay in order to find insertion positions properly)
            c[2] = "";
            Assert.AreEqual("0, 1, 2", ColumnTests.GetSortedIndexes(c));

            // Reset a value to something (needs to be after all other values; in this case, it'll stay in place in SortedIDs)
            c[2] = "TaoSuiteSrc";
            Assert.AreEqual("0, 1, 2", ColumnTests.GetSortedIndexes(c));

            // Add two more values (empty); empty values should insert after other empty values
            c.SetSize(5);
            CommitIfRequired(c);
            Assert.AreEqual("0, 1, 3, 4, 2", ColumnTests.GetSortedIndexes(c));

            // Set a larger ID to an existing value; needs SortedID after other copy of value
            c[3] = "TaoSuiteSrc";
            Assert.AreEqual("0, 1, 4, 2, 3", ColumnTests.GetSortedIndexes(c));

            // Set another value before existing ones; needs SortedID in value order
            c[0] = "MauiRemoval";
            Assert.AreEqual("1, 4, 0, 2, 3", ColumnTests.GetSortedIndexes(c));

            // Set a smaller ID to an existing value; needs SortedID before other copies of value
            c[1] = "TaoSuiteSrc";
            Assert.AreEqual("4, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c));

            // Add two more values; should appear after other empties
            c.SetSize(7);
            CommitIfRequired(c);
            Assert.AreEqual("4, 5, 6, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c));

            // Set two more empty duplicates - they need to be reinserted among empties in original sequence
            c[5] = "";
            c[6] = "";
            Assert.AreEqual("4, 5, 6, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c));

            ColumnTests.AssertConsistent(c);
        }
예제 #16
0
        public void Aggregator_BaseBehaviors()
        {
            AggregatorBaseBehaviors(new CountAggregator(), false);
            AggregatorBaseBehaviors(new SumAggregator());
            AggregatorBaseBehaviors(new MinAggregator());
            AggregatorBaseBehaviors(new MaxAggregator());

            // Check BaseAggregator doesn't implement unexpected types or methods
            IUntypedColumn column = ColumnFactory.Build(new ColumnDetails("ID", "bool", false), 100);
            ShortSet       sample = new ShortSet(100);

            sample.Or(new ushort[] { 1, 2, 3 });

            IAggregator aggregator = new BaseAggregator();

            Verify.Exception <NotImplementedException>(() => aggregator.Aggregate(null, sample, new IUntypedColumn[] { column }));
            Verify.Exception <NotImplementedException>(() => aggregator.Merge(null, new object[2]));
        }
예제 #17
0
        private void AssertBuild <T>(object defaultValue)
        {
            IColumn column = ColumnFactory.BuildTyped <T>((T)defaultValue);

            Assert.NotNull(column);
            Assert.True(column is IColumn <T>);

            if (defaultValue != null)
            {
                column = ColumnFactory.Build(typeof(T), null);
                Assert.NotNull(column);
                Assert.True(column is IColumn <T>);

                column = ColumnFactory.Build(typeof(T));
                Assert.NotNull(column);
                Assert.True(column is IColumn <T>);
            }
        }
예제 #18
0
        public void ColumnFactory_CanonicalTypeName()
        {
            Assert.AreEqual("guid", ColumnFactory.GetCanonicalTypeName(typeof(Guid)));
            Assert.AreEqual("datetime", ColumnFactory.GetCanonicalTypeName(typeof(DateTime)));
            Assert.AreEqual("timespan", ColumnFactory.GetCanonicalTypeName(typeof(TimeSpan)));

            Assert.AreEqual("boolean", ColumnFactory.GetCanonicalTypeName(typeof(bool)));
            Assert.AreEqual("byte", ColumnFactory.GetCanonicalTypeName(typeof(byte)));
            Assert.AreEqual("sbyte", ColumnFactory.GetCanonicalTypeName(typeof(sbyte)));
            Assert.AreEqual("short", ColumnFactory.GetCanonicalTypeName(typeof(short)));
            Assert.AreEqual("ushort", ColumnFactory.GetCanonicalTypeName(typeof(ushort)));
            Assert.AreEqual("int", ColumnFactory.GetCanonicalTypeName(typeof(int)));
            Assert.AreEqual("uint", ColumnFactory.GetCanonicalTypeName(typeof(uint)));
            Assert.AreEqual("long", ColumnFactory.GetCanonicalTypeName(typeof(long)));
            Assert.AreEqual("ulong", ColumnFactory.GetCanonicalTypeName(typeof(ulong)));
            Assert.AreEqual("float", ColumnFactory.GetCanonicalTypeName(typeof(float)));
            Assert.AreEqual("double", ColumnFactory.GetCanonicalTypeName(typeof(double)));
            Assert.AreEqual("string", ColumnFactory.GetCanonicalTypeName(typeof(string)));
        }
예제 #19
0
        public void ColumnFactory_Build()
        {
            AssertBuild <string>(null);
            AssertBuild <Uri>(null);
            AssertBuild <DateTime>(DateTime.UtcNow);
            AssertBuild <bool>(true);

            AssertBuild <byte>((byte)1);
            AssertBuild <sbyte>((sbyte)1);
            AssertBuild <ushort>((ushort)1);
            AssertBuild <short>((short)1);
            AssertBuild <uint>((uint)1);
            AssertBuild <int>((int)1);
            AssertBuild <ulong>((ulong)1);
            AssertBuild <long>((long)1);
            AssertBuild <float>((float)1);
            AssertBuild <double>((double)1);
            AssertBuild <char>((char)1);

            IColumn <IList <string> > listColumn = (IColumn <IList <string> >)ColumnFactory.Build(typeof(IList <string>), null);

            Assert.NotNull(listColumn);

            IColumn <IDictionary <string, string> > dictionaryColumn = (IColumn <IDictionary <string, string> >)(ColumnFactory.Build(typeof(IDictionary <string, string>), null));

            Assert.NotNull(dictionaryColumn);

            // Verify collections are null by default if null passed as default
            Assert.Null(listColumn[0]);
            Assert.Null(dictionaryColumn[0]);

            // Verify collections not null by default if non-null passed as default
            listColumn       = (IColumn <IList <string> >)ColumnFactory.Build(typeof(IList <string>), new object());
            dictionaryColumn = (IColumn <IDictionary <string, string> >)(ColumnFactory.Build(typeof(IDictionary <string, string>), new object()));
            Assert.NotNull(listColumn[0]);
            Assert.NotNull(dictionaryColumn[0]);

            if (!Debugger.IsAttached)
            {
                Assert.Throws <NotImplementedException>(() => ColumnFactory.Build(typeof(Decimal)));
                Assert.Throws <NotSupportedException>(() => ColumnFactory.Build(typeof(DayOfWeek), DayOfWeek.Sunday));
            }
        }
예제 #20
0
        public void UnknownColumnTypeIsNotConstructed()
        {
            // Arrange
            var context = new Mock <IContextEntry>();

            context.SetupGet(c => c.UserId).Returns(1);

            var contextList = new[]
            {
                context.Object
            };

            var contexts = new Mock <ITwitterContextList>();

            contexts.SetupGet(c => c.Contexts).Returns(contextList);

            var parser = new Mock <IStreamParser>();

            var config = new Mock <IConfig>();

            config.SetupGet(c => c.General).Returns(new GeneralConfig());
            var streamingRepo = new Mock <IStreamingRepository>();

            streamingRepo.Setup(s => s.GetParser(It.Is <ColumnDefinition>(d => d.SourceAccounts.Contains((ulong)1))))
            .Returns(parser.Object);
            var factory = new ColumnFactory
            {
                Contexts      = contexts.Object,
                StreamingRepo = streamingRepo.Object,
                Configuration = config.Object
            };

            // Act
            var constructed = factory.Construct(new ColumnDefinition(ColumnType.Unknown)
            {
                SourceAccounts = new ulong[] { 1 },
                TargetAccounts = new ulong[] { 1 }
            });

            // Assert
            Assert.IsNull(constructed);
        }
예제 #21
0
        public void IndexedColumn_HtmlSplitter()
        {
            IColumn <object> c = ColumnFactory.Build(new ColumnDetails("Description", "indexed[html]:sorted:string", null), 0);

            c.SetSize(4);
            c[0] = "<span title='nice'>First Value</span>";
            c[1] = "<div>Second <b>Value</b> &nbsp;</div>";
            c[2] = "this is a <b>different</b>&nbsp;value";
            ColumnTests.AssertConsistent(c);

            // Verify words in html don't match (Splitter Should exclude)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "span"));
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "nice"));
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "nbsp"));

            // Verify text within html does match
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "value"));
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "first"));
            Assert.AreEqual("2", ColumnTests.GetMatches(c, Operator.Matches, "different"));
        }
예제 #22
0
        public void SortedColumn_IndexOf()
        {
            SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0);

            c.SetSize(8);
            c[0] = 0;
            c[1] = 1;
            c[2] = 1;
            c[3] = 2;
            c[4] = 2;
            c[5] = 8;
            c[6] = 8;
            c[7] = 9;

            ColumnTests.AssertConsistent(c);
            Assert.AreEqual(ushort.MaxValue, ColumnTests.GetIndex(c, 10));
            Assert.AreEqual(1, ColumnTests.GetIndex(c, 1));
            Assert.AreEqual(3, ColumnTests.GetIndex(c, 2));
            Assert.AreEqual(7, ColumnTests.GetIndex(c, 9));
        }
예제 #23
0
        public void FastAddSortedColumn_InsertMax2()
        {
            SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), ushort.MaxValue);

            ushort seedLimit = ushort.MaxValue - 1;
            int    lastValue = 0;

            c.SetSize(seedLimit);
            for (ushort i = 0; i < seedLimit; ++i)
            {
                lastValue = ushort.MaxValue + (int)i * 10;
                c[i]      = lastValue;
            }
            ColumnTests.AssertConsistent(c);

            int firstValue = -1;

            c.SetSize(ushort.MaxValue);
            for (ushort i = seedLimit; i < ushort.MaxValue; ++i)
            {
                if (firstValue == -1)
                {
                    firstValue = (int)i;
                }

                c[i] = (int)i;
            }
            ColumnTests.AssertConsistent(c);

            Assert.AreEqual("65534", ColumnTests.GetMatches(c, Operator.Equals, firstValue));
            Assert.AreEqual("65533", ColumnTests.GetMatches(c, Operator.Equals, lastValue));

            IList <ushort> sortedIndexes;
            int            sortedIndexesCount;

            Assert.IsTrue(c.TryGetSortedIndexes(out sortedIndexes, out sortedIndexesCount));

            // Check sort order - lowest one was the last value added
            Assert.AreEqual("65534", sortedIndexes.First().ToString());
            Assert.AreEqual("65533", sortedIndexes.Last().ToString());
        }
예제 #24
0
        public List <Collection <IColumnBuilder> > ColumnRows()
        {
            List <Collection <IColumnBuilder> > rows = new List <Collection <IColumnBuilder> >();

            Collection <IColumnBuilder> firstRow = ColumnRowFactory.buildSplitTemplate();

            rows.Add(ColumnsFactory.equipRow(firstRow,
                                             ColumnFactory.buildColumnWithoutFooter(new AccountOwnerMainColumn()),
                                             ColumnFactory.buildColumn(new AccountOwnerSubColumn())));


            Collection <IColumnBuilder> secondRow = ColumnRowFactory.build(RowForms.SplitTemplate);

            rows.Add(ColumnsFactory.equipRow(secondRow,
                                             ColumnFactory.buildColumnWithoutFooter(new AccountMainColumn()),
                                             ColumnFactory.buildColumn(new AccountSubColumn())));



            return(rows);
        }
예제 #25
0
        public void SortedColumn_StartsWith()
        {
            SortedColumn <ByteBlock> column = ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0);

            column.SetSize(6);

            column[0] = "Active";
            column[1] = "Activate";
            column[2] = "Activity";
            column[3] = "Resolved";
            column[4] = "Resolution";
            column[5] = "State";
            CommitIfRequired(column);

            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(column, Operator.StartsWith, "Activ"));
            Assert.AreEqual("1", ColumnTests.GetMatches(column, Operator.StartsWith, "Activa"));
            Assert.AreEqual("", ColumnTests.GetMatches(column, Operator.StartsWith, "Balmy"));
            Assert.AreEqual("3, 4", ColumnTests.GetMatches(column, Operator.StartsWith, "Reso"));
            Assert.AreEqual("3", ColumnTests.GetMatches(column, Operator.StartsWith, "Resolv"));
            Assert.AreEqual("5", ColumnTests.GetMatches(column, Operator.StartsWith, "St"));
        }
예제 #26
0
        private void AggregatorBaseBehaviors(IAggregator aggregator, bool requiresColumns = true)
        {
            // Verify ToString returns the aggregator type, which matches the start of the class name
            string name = aggregator.ToString();

            Assert.AreEqual(aggregator.GetType().Name.ToLowerInvariant(), (name + "aggregator").ToLowerInvariant());

            // Verify Merge throws if the values are null
            Verify.Exception <ArgumentNullException>(() => aggregator.Merge(null, null));

            // Verify Aggregate throws if the matches or columns are null
            Verify.Exception <ArgumentNullException>(() => aggregator.Aggregate(null, null, new IUntypedColumn[1] {
                ColumnFactory.Build(new ColumnDetails("ID", "int", null), 100)
            }));

            if (requiresColumns)
            {
                ShortSet sample = new ShortSet(100);
                sample.Or(new ushort[] { 1, 2, 3 });
                Verify.Exception <ArgumentException>(() => aggregator.Aggregate(null, sample, null));
            }
        }
예제 #27
0
        public void IndexedColumn_DictionaryConversion()
        {
            IndexedColumn c = new IndexedColumn(ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0), new DefaultWordSplitter());

            c.SetSize(4);
            c[0] = "First Value";
            c[1] = "Second Value";
            c[2] = "this is a different value";
            ColumnTests.AssertConsistent(c);

            // Verify Dictionary conversion
            Dictionary <string, List <ushort> > dictionary = c.ConvertToDictionary();

            Assert.AreEqual(7, dictionary.Keys.Count);
            Assert.AreEqual("0, 1, 2", String.Join(", ", dictionary["value"]));
            Assert.AreEqual("0", String.Join(", ", dictionary["first"]));
            Assert.AreEqual("1", String.Join(", ", dictionary["second"]));
            Assert.AreEqual("2", String.Join(", ", dictionary["this"]));
            Assert.AreEqual("2", String.Join(", ", dictionary["is"]));
            Assert.AreEqual("2", String.Join(", ", dictionary["a"]));
            Assert.AreEqual("2", String.Join(", ", dictionary["different"]));
        }
예제 #28
0
        public void TypedColumn_Boolean_Basic()
        {
            IColumn <object> c = ColumnFactory.Build(new ColumnDetails("IsDuplicate", "bool", true), 0);

            c.SetSize(5);

            c[0] = Value.Create(true);
            c[1] = Value.Create(false);
            c[2] = Value.Create("True");
            c[3] = Value.Create("false");

            CommitIfRequired(c);
            ShortSet set = new ShortSet(c.Count);

            // True - set and default
            set.Clear();
            c.TryWhere(Operator.Equals, "true", set, null);
            Assert.AreEqual("0, 2, 4", String.Join(", ", set.Values));

            // False - set
            set.Clear();
            c.TryWhere(Operator.Equals, "false", set, null);
            Assert.AreEqual("1, 3", String.Join(", ", set.Values));

            // False (Matches)
            set.Clear();
            c.TryWhere(Operator.Matches, "false", set, null);
            Assert.AreEqual("1, 3", String.Join(", ", set.Values));

            // Not False
            set.Clear();
            c.TryWhere(Operator.NotEquals, "false", set, null);
            Assert.AreEqual("0, 2, 4", String.Join(", ", set.Values));

            // Values works, *including if not asking for all items in order*
            bool[] values = (bool[])c.GetValues(new ushort[] { 3, 2, 1, 0 });
            Assert.AreEqual("False, True, False, True", String.Join(", ", values));
        }
예제 #29
0
        public void NoColumnIsConstructedWhenNoContextIsFound()
        {
            // Arrange
            var context = new Mock <IContextEntry>();

            context.SetupGet(c => c.UserId).Returns(2);

            var contextList = new[]
            {
                context.Object
            };

            var contexts = new Mock <ITwitterContextList>();

            contexts.SetupGet(c => c.Contexts).Returns(contextList);

            var config = new Mock <IConfig>();

            config.SetupGet(c => c.General).Returns(new GeneralConfig());
            var streamingRepo = new Mock <IStreamingRepository>();
            var factory       = new ColumnFactory
            {
                Contexts      = contexts.Object,
                StreamingRepo = streamingRepo.Object,
                Configuration = config.Object
            };

            // Act
            var constructed = factory.Construct(new ColumnDefinition(ColumnType.User)
            {
                SourceAccounts = new ulong[] { 1 },
                TargetAccounts = new ulong[] { 1 }
            });

            // Assert
            Assert.IsNull(constructed);
        }
예제 #30
0
        public void SortedColumn_Where()
        {
            SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0);

            c.SetSize(8);
            c[0] = 0;
            c[1] = 1;
            c[2] = 1;
            c[3] = 2;
            c[4] = 2;
            c[5] = 8;
            c[6] = 8;
            c[7] = 9;
            ColumnTests.AssertConsistent(c);

            // Find a middle value
            Assert.AreEqual("3, 4", ColumnTests.GetMatches(c, Operator.Equals, 2));

            // Find the minimum value
            Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Equals, 0));

            // Find the maximum value
            Assert.AreEqual("7", ColumnTests.GetMatches(c, Operator.Equals, 9));

            // Find a value not in set (too small)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Equals, -1));

            // Find a value not in set (too big)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Equals, 10));


            // Find not of a value
            Assert.AreEqual("0, 1, 2, 5, 6, 7", ColumnTests.GetMatches(c, Operator.NotEquals, 2));

            // Find not of a value not in set
            Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.NotEquals, -1));


            // Find less than not in set (too small)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.LessThan, -1));

            // Find less than an existing value
            Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.LessThan, 2));

            // Find less than a gap between values
            Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThan, 4));

            // Find less than more than set (too big)
            Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.LessThan, 99));


            // Find less than or equal not in set (too small)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, -1));

            // Find less than or equal an existing value
            Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 2));

            // Find less than or equal a gap between values
            Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 4));

            // Find less than or equal more than set (too big)
            Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 99));


            // Find greater than not in set (too small)
            Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, -1));

            // Find greater than an existing value
            Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, 2));

            // Find greater than a gap between values
            Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, 4));

            // Find greater than more than set (too big)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.GreaterThan, 99));

            // Find greater than or equal not in set (too small)
            Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, -1));

            // Find greater than or equal an existing value
            Assert.AreEqual("3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 2));

            // Find greater than or equal a gap between values
            Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 4));

            // Find greater than or equal more than set (too big)
            Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 99));

            // Verify sorting consistency problems are detected
            ((IColumn <int>)c.InnerColumn)[0] = 8;
            ExecutionDetails d = new ExecutionDetails();

            c.VerifyConsistency(VerificationLevel.Full, d);
            Assert.IsFalse(d.Succeeded);
        }
예제 #31
0
 public JqGridConfiguration(ColumnFactory factory)
 {
     _factory = factory;
     Column = new ColumnFactoryExpression(_factory);
 }
예제 #32
0
        public virtual IHttpActionResult Get(PaginatedRequestCommand cmd)
        {
            cmd.FilterInternalDictionary = new Dictionary <string, object>();

            this.ListSelecting(cmd);

            if (this.ControllerContext.ControllerDescriptor != null)
            {
                this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get {0}", cmd.Type));
            }

            var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault();

            if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.InsertModel), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    TRequestModel requestModel = new TRequestModel();
                    BaseEntity.SetDropDownOptions <TRequestModel, IBindingModel>(requestModel, this.Container);

                    this.ListSelected(requestModel);

                    return(Ok(requestModel));
                }
                catch (Exception ex)
                {
                    if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType());
                    }

                    if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                    {
                        ReflectionTypeLoadException typeLoadException = null;
                        if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                        {
                            typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                        }
                        else
                        {
                            typeLoadException = ex as ReflectionTypeLoadException;
                        }

                        var loaderExceptins = typeLoadException.LoaderExceptions;
                        foreach (var tlex in loaderExceptins)
                        {
                            this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                        }
                    }
                    else
                    {
                        this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException);
                    }

                    //return InternalServerError(base.ErrorMessage(ex));
                    return(InternalServerError(ex));
                }
            }
            else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.UpdateModel), StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    string[] includeProperties = null;
                    if (attr != null)
                    {
                        includeProperties = attr.Include;
                    }

                    TEntity entity = this.Service.GetSingle(cmd.EntityId, includeProperties);
                    if (entity == null)
                    {
                        NotFound();
                    }
                    //return Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("{0} não encontrado(a)", typeof(TEntity).Name));

                    TUpdateRequestModel model = entity.ToModel <TUpdateRequestModel, IModel>(this.Container, false, 0);

                    this.ListSelected(model);

                    return(Ok(model));
                }
                catch (Exception ex)
                {
                    return(InternalServerError(ex));
                }
            }
            else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase))
            {
                if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get ", cmd.Type));
                }

                try
                {
                    var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);

                    var paginatedModel = list.ToPaginatedModel <TModel>(null, null);
                    SetViews(paginatedModel.Items);

                    paginatedModel.Condition         = new Condition();
                    paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();

                    this.ListSelected(paginatedModel);

                    return(Ok(paginatedModel));
                }
                catch (Exception ex)
                {
                    if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), (ex.InnerException == null) ? null : ex.InnerException.GetType());
                    }

                    if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                    {
                        ReflectionTypeLoadException typeLoadException = null;
                        if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                        {
                            typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                        }
                        else
                        {
                            typeLoadException = ex as ReflectionTypeLoadException;
                        }

                        var loaderExceptins = typeLoadException.LoaderExceptions;
                        foreach (var tlex in loaderExceptins)
                        {
                            this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                        }
                    }
                    else if (this.ControllerContext.ControllerDescriptor != null)
                    {
                        this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex);
                    }

                    return(InternalServerError(ex));
                }
            }

            try
            {
                var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null);
                var paged    = entities.ToPaginatedModel <TModel>(null, null);
                SetViews(paged.Items);

                paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray();
                paged.Condition         = new Condition();

                this.ListSelected(paged);

                return(Ok(paged));
            }
            catch (Exception ex)
            {
                if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType());
                }

                if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException))
                {
                    ReflectionTypeLoadException typeLoadException = null;
                    if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)
                    {
                        typeLoadException = ex.InnerException as ReflectionTypeLoadException;
                    }
                    else
                    {
                        typeLoadException = ex as ReflectionTypeLoadException;
                    }

                    var loaderExceptins = typeLoadException.LoaderExceptions;
                    foreach (var tlex in loaderExceptins)
                    {
                        this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source });
                    }
                }
                else if (this.ControllerContext.ControllerDescriptor != null)
                {
                    this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException);
                }

                return(InternalServerError(ex));
            }
        }