File: QueryableDataSource.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (156 lines) | stat: -rw-r--r-- 5,293 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
namespace System.Web.UI.WebControls {
    using System;
    using System.Collections;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Resources;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Web.UI.WebControls.Expressions;

    [
    ParseChildren(true),
    PersistChildren(false)
    ]
    public abstract class QueryableDataSource : DataSourceControl, IQueryableDataSource {
        private const string DefaultViewName = "DefaultView";
        private ReadOnlyCollection<string> _viewNames;
        private QueryableDataSourceView _view;
        private readonly new IPage _page;

        internal QueryableDataSource(IPage page) {
            _page = page;
        }

        internal QueryableDataSource(QueryableDataSourceView view) {
            _view = view;
        }

        protected QueryableDataSource() {

        }

        [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification="View is used by derived types")]
        private QueryableDataSourceView View {
            get {
                if (_view == null) {
                    _view = CreateQueryableView();
                }
                return _view;
            }
        }

        internal IPage IPage {
            get {
                if (_page != null) {
                    return _page;
                }
                else {
                    Page page = Page;
                    if (page == null) {
                        throw new InvalidOperationException(AtlasWeb.Common_PageCannotBeNull);
                    }
                    return new PageWrapper(page);
                }
            }
        }

        protected abstract QueryableDataSourceView CreateQueryableView();

        protected override ICollection GetViewNames() {
            if (_viewNames == null) {
                _viewNames = new ReadOnlyCollection<string>(new[] { DefaultViewName });
            }
            return _viewNames;
        }
        
        protected override DataSourceView GetView(string viewName) {
            if (viewName == null) {
                throw new ArgumentNullException("viewName");
            }
            // viewName comes from the DataMember property on the databound control and is an empty string
            // by default.  An empty string should be treated as if it were the default view name.
            if ((viewName.Length != 0) &&
                !String.Equals(viewName, DefaultViewName, StringComparison.OrdinalIgnoreCase)) {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
                    AtlasWeb.LinqDataSource_InvalidViewName, ID, DefaultViewName), "viewName");
            }
            return View;
        }

        [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "0#")]
        protected internal override void OnInit(EventArgs e) {
            base.OnInit(e);
            IPage.LoadComplete += new EventHandler(OnPageLoadComplete);
        }

        // Used for unit testing only
        internal void SetView(QueryableDataSourceView view) {
            _view = view;
        }
        
        protected virtual void UpdateParameterVales() {
            View.WhereParameters.UpdateValues(Context, this);
            View.OrderGroupsByParameters.UpdateValues(Context, this);
            View.GroupByParameters.UpdateValues(Context, this);
            View.OrderByParameters.UpdateValues(Context, this);
            View.SelectNewParameters.UpdateValues(Context, this);
        }

        private void OnPageLoadComplete(object sender, EventArgs e) {
            UpdateParameterVales();
        }

        protected override object SaveViewState() {
            Pair myState = new Pair();
            myState.First = base.SaveViewState();
            if (_view != null) {
                myState.Second = ((IStateManager)_view).SaveViewState();
            }
            if ((myState.First == null) &&
                (myState.Second == null)) {
                return null;
            }
            return myState;
        }

        protected override void TrackViewState() {
            base.TrackViewState();
            if (_view != null) {
                ((IStateManager)_view).TrackViewState();
            }
        }

        protected override void LoadViewState(object savedState) {
            if (savedState == null) {
                base.LoadViewState(null);
            }
            else {
                Pair myState = (Pair)savedState;
                base.LoadViewState(myState.First);
                if (myState.Second != null) {
                    ((IStateManager)View).LoadViewState(myState.Second);
                }
            }
        }

        #region IQueryableDataSource Members

        public void RaiseViewChanged() {
            View.RaiseViewChanged();
        }

        public event EventHandler<QueryCreatedEventArgs> QueryCreated {
            add {
                View.QueryCreated += value;
            }
            remove {
                View.QueryCreated -= value;
            }
        }

        #endregion
    }
}