-
-
Notifications
You must be signed in to change notification settings - Fork 407
/
Copy pathCslaDataSourceDesigner.cs
162 lines (147 loc) · 4.14 KB
/
CslaDataSourceDesigner.cs
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
157
158
159
160
161
162
//-----------------------------------------------------------------------
// <copyright file="CslaDataSourceDesigner.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Implements designer support for CslaDataSource.</summary>
//-----------------------------------------------------------------------
using System.Web.UI;
using System.Web.UI.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
namespace Csla.Web.Design
{
/// <summary>
/// Implements designer support for CslaDataSource.
/// </summary>
public class CslaDataSourceDesigner : DataSourceDesigner
{
private DataSourceControl _control = null;
private CslaDesignerDataSourceView _view = null;
/// <summary>
/// Initialize the designer component.
/// </summary>
/// <param name="component">The CslaDataSource control to
/// be designed.</param>
public override void Initialize(IComponent component)
{
base.Initialize(component);
_control = (DataSourceControl)component;
}
internal ISite Site
{
get
{
return _control.Site;
}
}
/// <summary>
/// Returns the default view for this designer.
/// </summary>
/// <param name="viewName">Ignored</param>
/// <remarks>
/// This designer supports only a "Default" view.
/// </remarks>
public override DesignerDataSourceView GetView(string viewName) =>
_view ??= new CslaDesignerDataSourceView(this, "Default");
/// <summary>
/// Return a list of available views.
/// </summary>
/// <remarks>
/// This designer supports only a "Default" view.
/// </remarks>
public override string[] GetViewNames()
{
return ["Default"];
}
/// <summary>
/// Refreshes the schema for the data.
/// </summary>
/// <param name="preferSilent"></param>
/// <remarks></remarks>
public override void RefreshSchema(bool preferSilent)
{
OnSchemaRefreshed(EventArgs.Empty);
}
/// <summary>
/// Get a value indicating whether the control can
/// refresh its schema.
/// </summary>
public override bool CanRefreshSchema
{
get
{
return true;
}
}
/// <summary>
/// Invoke the design time configuration
/// support provided by the control.
/// </summary>
public override void Configure()
{
InvokeTransactedChange(_control, ConfigureCallback, null, "ConfigureDataSource");
}
private bool ConfigureCallback(object context)
{
bool result = false;
string oldTypeName;
if (string.IsNullOrEmpty(DataSourceControl.TypeAssemblyName))
oldTypeName = DataSourceControl.TypeName;
else
oldTypeName = $"{DataSourceControl.TypeName}, {DataSourceControl.TypeAssemblyName}";
IUIService uiService = (IUIService)_control.Site.GetService(typeof(IUIService));
CslaDataSourceConfiguration cfg = new CslaDataSourceConfiguration(_control, oldTypeName);
if (uiService.ShowDialog(cfg) == System.Windows.Forms.DialogResult.OK)
{
SuppressDataSourceEvents();
try
{
DataSourceControl.TypeAssemblyName = string.Empty;
DataSourceControl.TypeName = cfg.TypeName;
OnDataSourceChanged(EventArgs.Empty);
result = true;
}
finally
{
ResumeDataSourceEvents();
}
}
cfg.Dispose();
return result;
}
/// <summary>
/// Get a value indicating whether this control
/// supports design time configuration.
/// </summary>
public override bool CanConfigure
{
get
{
return true;
}
}
/// <summary>
/// Get a value indicating whether the control can
/// be resized.
/// </summary>
public override bool AllowResize
{
get
{
return false;
}
}
/// <summary>
/// Get a reference to the CslaDataSource control being
/// designed.
/// </summary>
internal CslaDataSource DataSourceControl
{
get
{
return (CslaDataSource)_control;
}
}
}
}