Removed 1.1 code and NET_2_0 ifdefs
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AccessDataSource.cs
1 //
2 // System.Web.UI.WebControls.AccessDataSource.cs
3 //
4 // Authors:
5 //   Sanjay Gupta (gsanjay@novell.com)
6 //
7 // Copyright (C) 2004-2010 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.IO;
30 using System.ComponentModel;
31 using System.Data.Common;
32 using System.Drawing;
33 using System.Security.Permissions;
34
35 namespace System.Web.UI.WebControls
36 {
37         // CAS
38         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40         // attributes
41         [DesignerAttribute ("System.Web.UI.Design.WebControls.AccessDataSourceDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42         [ToolboxBitmap ("")]
43         public class AccessDataSource : SqlDataSource
44         {
45                 const string PROVIDER_NAME = "System.Data.OleDb";
46                 const string PROVIDER_STRING = "Microsoft.Jet.OLEDB.4.0";
47
48                 //string dataFile;
49                 string connectionString;
50
51                 public AccessDataSource () : base ()
52                 {
53                         base.ProviderName = PROVIDER_NAME;
54                 }
55
56                 public AccessDataSource (string dataFile, string selectCommand) : 
57                         base (String.Empty, selectCommand)
58                 {
59                         //this.dataFile = dataFile;
60                         this.ProviderName = PROVIDER_NAME;
61                 }
62
63                 protected override SqlDataSourceView CreateDataSourceView (string viewName)
64                 {
65                         AccessDataSourceView view = new AccessDataSourceView (this, viewName, this.Context);
66                         if (IsTrackingViewState)
67                                 ((IStateManager) view).TrackViewState ();                               
68                         return view;
69                 }
70
71                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
72                 [Browsable (false)]
73                 [MonoTODO("AccessDataSource does not support SQL Cache Dependencies")]
74                 public override string SqlCacheDependency {
75                         get { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
76                         set { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
77                 }
78
79                 [MonoTODO ("why override?  maybe it doesn't call DbProviderFactories.GetFactory?")]
80                 protected override DbProviderFactory GetDbProviderFactory ()
81                 {
82                         return DbProviderFactories.GetFactory (PROVIDER_NAME);
83                 }
84
85                 string GetPhysicalDataFilePath ()
86                 {
87                         if (String.IsNullOrEmpty (DataFile))
88                                 return String.Empty;
89
90                         // more here?  how do we handle |DataDirectory|?
91                         return HttpContext.Current.Request.MapPath (DataFile);
92                 }
93
94                 [BrowsableAttribute (false), 
95                 DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
96                 public override string ConnectionString {
97                         get {
98                                 if (connectionString == null) {
99                                         connectionString = String.Concat ("Provider=", PROVIDER_STRING, "; Data Source=", GetPhysicalDataFilePath ());
100                                 }
101
102                                 return connectionString;
103                         }
104                         set {
105                                 throw new InvalidOperationException 
106                                         ("The ConnectionString is automatically generated for AccessDataSource and hence cannot be set."); 
107                         }
108                 }
109
110                 [UrlPropertyAttribute]
111                 [DefaultValueAttribute ("")]
112                 [WebCategoryAttribute ("Data")]
113                 [WebSysDescriptionAttribute ("MS Office Access database file name")]
114                 [EditorAttribute ("System.Web.UI.Design.MdbDataFileEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
115                 public string DataFile {
116                         get { return ViewState.GetString ("DataFile", String.Empty); }
117                         set {
118                                 ViewState ["DataFile"] = value;
119                                 connectionString = null;
120                         }
121                 }
122
123                 [BrowsableAttribute (false), 
124                 DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]                      
125                 public override string ProviderName {
126                         get { return base.ProviderName; }
127                         set { throw new InvalidOperationException
128                                 ("Setting ProviderName on an AccessDataSource is not allowed");
129                         }
130                 }
131         }
132 }
133