Skip to content

Commit 2b679ed

Browse files
tweak.
1 parent 5c8e744 commit 2b679ed

4 files changed

Lines changed: 672 additions & 0 deletions

File tree

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
'**********************************************************************************
2+
'* Copyright (C) 2007,2016 Hitachi Solutions,Ltd.
3+
'**********************************************************************************
4+
5+
#Region "Apache License"
6+
'
7+
' Licensed under the Apache License, Version 2.0 (the "License");
8+
' you may not use this file except in compliance with the License.
9+
' You may obtain a copy of the License at
10+
'
11+
' http://www.apache.org/licenses/LICENSE-2.0
12+
'
13+
' Unless required by applicable law or agreed to in writing, software
14+
' distributed under the License is distributed on an "AS IS" BASIS,
15+
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
' See the License for the specific language governing permissions and
17+
' limitations under the License.
18+
'
19+
#End Region
20+
21+
'**********************************************************************************
22+
'* クラス名 :MyCmnFunction
23+
'* クラス日本語名 :Business層の共通クラス(テンプレート)
24+
'*
25+
'* 作成者 :生技 西野
26+
'* 更新履歴 :
27+
'*
28+
'* 日時 更新者 内容
29+
'* ---------- ---------------- -------------------------------------------------
30+
'* 20xx/xx/xx XX XX 新規作成(テンプレート)
31+
'* 2009/06/02 西野 大介 sln - IR版からの修正
32+
'* ・#5 : コントロール数取得処理(デフォルト値不正)
33+
'* 2009/07/21 西野 大介 コントロール取得処理の仕様変更
34+
'* 2009/08/10 西野 大介 同名のコントロール追加に対応(GridView/ItemTemplate)。
35+
'* 2010/09/24 西野 大介 ジェネリック対応(Dictionary、List、Queue、Stack<T>)
36+
'* nullチェック方法、Contains → ContainsKeyなどに注意
37+
'* 2010/10/21 西野 大介 幾つかのイベント処理の正式対応(ベースクラス2→1へ)
38+
'* 2012/06/14 西野 大介 コントロール検索の再帰処理性能の集約&効率化。
39+
'* 2014/05/16 西野 大介 キャスト可否チェックのロジックを見直した。
40+
'* 2017/01/31 西野 大介 System.Webを使用しているCalculateSessionSizeメソッドをPublicから移動
41+
'**********************************************************************************
42+
43+
Imports System.Web
44+
Imports System.Web.UI
45+
Imports System.Web.UI.WebControls
46+
47+
Imports Touryo.Infrastructure.Framework.Exceptions
48+
Imports Touryo.Infrastructure.Framework.Util
49+
Imports Touryo.Infrastructure.Public.IO
50+
Imports Touryo.Infrastructure.Public.Util
51+
52+
Namespace Touryo.Infrastructure.Business.Util
53+
''' <summary>Business層の共通クラス</summary>
54+
Public Class MyCmnFunction
55+
56+
#Region "CalculateSessionSize"
57+
58+
''' <summary>Sessionサイズ測定</summary>
59+
''' <returns>Sessionサイズ(MB)</returns>
60+
''' <remarks>シリアル化できないオブジェクトを含む場合は落ちる。</remarks>
61+
Public Shared Function CalculateSessionSizeMB() As Long
62+
'return MyCmnFunction.CalculateSessionSizeKB() / 1000;
63+
Return CLng(Math.Truncate(Math.Round(MyCmnFunction.CalculateSessionSize() / 1000000.0, 0, MidpointRounding.AwayFromZero)))
64+
65+
End Function
66+
67+
''' <summary>Sessionサイズ測定</summary>
68+
''' <returns>Sessionサイズ(KB)</returns>
69+
''' <remarks>シリアル化できないオブジェクトを含む場合は落ちる。</remarks>
70+
Public Shared Function CalculateSessionSizeKB() As Long
71+
'return MyCmnFunction.CalculateSessionSize() / 1000;
72+
Return CLng(Math.Truncate(Math.Round(MyCmnFunction.CalculateSessionSize() / 1000.0, 0, MidpointRounding.AwayFromZero)))
73+
End Function
74+
75+
''' <summary>Sessionサイズ測定</summary>
76+
''' <returns>Sessionサイズ(バイト)</returns>
77+
''' <remarks>シリアル化できないオブジェクトを含む場合は落ちる。</remarks>
78+
Public Shared Function CalculateSessionSize() As Long
79+
' ワーク変数
80+
Dim size As Long = 0
81+
82+
' SessionのオブジェクトをBinarySerializeしてサイズを取得。
83+
For Each key As String In HttpContext.Current.Session.Keys
84+
' 当該キーのオブジェクト・サイズを足しこむ。
85+
size += BinarySerialize.ObjectToBytes(HttpContext.Current.Session(key)).Length
86+
Next
87+
88+
' Sessionサイズ(バイト)
89+
Return size
90+
End Function
91+
92+
#End Region
93+
94+
' 2009/07/21-start
95+
96+
#Region "コントロール取得&イベントハンドラ設定"
97+
98+
''' <summary>コントロール取得&イベントハンドラ設定(下位互換)</summary>
99+
''' <param name="ctrl">コントロール</param>
100+
''' <param name="prefix">プレフィックス</param>
101+
''' <param name="eventHandler">イベント ハンドラ</param>
102+
''' <param name="controlHt">ディクショナリ</param>
103+
Friend Shared Sub GetCtrlAndSetClickEventHandler(ctrl As Control, prefix As String, eventHandler As Object, controlHt As Dictionary(Of String, Control))
104+
'#Region "チェック処理"
105+
106+
' コントロール指定が無い場合
107+
If ctrl Is Nothing Then
108+
' 何もしないで戻る。
109+
Return
110+
End If
111+
112+
' プレフィックス指定が無い場合
113+
If prefix Is Nothing OrElse prefix = "" Then
114+
' 何もしないで戻る。
115+
Return
116+
End If
117+
118+
'#End Region
119+
120+
'#Region "コントロール取得&イベントハンドラ設定"
121+
122+
' コントロールのIDチェック
123+
' コントロールID無し
124+
If ctrl.ID Is Nothing Then
125+
Else
126+
' コントロールID有り
127+
128+
' コントロールのID長確認
129+
If prefix.Length <= ctrl.ID.Length Then
130+
' 指定のプレフィックス
131+
If prefix = ctrl.ID.Substring(0, prefix.Length) Then
132+
' イベントハンドラを設定する。
133+
If prefix = GetConfigParameter.GetConfigValue(MyLiteral.PREFIX_OF_CHECK_BOX) Then
134+
' CHECK BOX
135+
Dim checkBox As CheckBox = Nothing
136+
137+
Try
138+
' キャストできる
139+
checkBox = DirectCast(ctrl, CheckBox)
140+
Catch ex As Exception
141+
' キャストできない
142+
Throw New FrameworkException(
143+
FrameworkExceptionMessage.CONTROL_TYPE_ERROR(0),
144+
[String].Format(FrameworkExceptionMessage.CONTROL_TYPE_ERROR(1), prefix, ctrl.[GetType]().ToString()), ex)
145+
End Try
146+
147+
AddHandler checkBox.CheckedChanged, DirectCast(eventHandler, EventHandler)
148+
149+
' ディクショナリに格納
150+
' ControlHt.Add(ctrl.ID, ctrl);
151+
' ControlHt[ctrl.ID] = ctrl;
152+
' 2011/02/12
153+
FxCmnFunction.AddControlToDic(ctrl, controlHt)
154+
End If
155+
End If
156+
End If
157+
End If
158+
159+
'#End Region
160+
161+
'#Region "再帰"
162+
163+
' 子コントロールがある場合、
164+
If ctrl.HasControls() Then
165+
' 子コントロール毎に
166+
For Each childCtrl As Control In ctrl.Controls
167+
' 再帰する。
168+
MyCmnFunction.GetCtrlAndSetClickEventHandler(childCtrl, prefix, eventHandler, controlHt)
169+
Next
170+
End If
171+
172+
'#End Region
173+
End Sub
174+
175+
''' <summary>コントロール取得&イベントハンドラ設定</summary>
176+
''' <param name="ctrl">コントロール</param>
177+
''' <param name="prefixAndEvtHndHt">プレフィックスとイベント ハンドラのディクショナリ</param>
178+
''' <param name="controlHt">コントロールのディクショナリ</param>
179+
Friend Shared Sub GetCtrlAndSetClickEventHandler2(ctrl As Control, prefixAndEvtHndHt As Dictionary(Of String, Object), controlHt As Dictionary(Of String, Control))
180+
' ループ
181+
For Each prefix As String In prefixAndEvtHndHt.Keys
182+
Dim eventHandler As Object = prefixAndEvtHndHt(prefix)
183+
184+
'#Region "チェック処理"
185+
186+
' コントロール指定が無い場合
187+
If ctrl Is Nothing Then
188+
' 何もしないで戻る。
189+
Return
190+
End If
191+
192+
' プレフィックス指定が無い場合
193+
If prefix Is Nothing OrElse prefix = "" Then
194+
' 何もしないで戻る。
195+
Return
196+
End If
197+
198+
'#End Region
199+
200+
'#Region "コントロール取得&イベントハンドラ設定"
201+
202+
' コントロールのIDチェック
203+
' コントロールID無し
204+
If ctrl.ID Is Nothing Then
205+
Else
206+
' コントロールID有り
207+
208+
' コントロールのID長確認
209+
If prefix.Length <= ctrl.ID.Length Then
210+
' 指定のプレフィックス
211+
If prefix = ctrl.ID.Substring(0, prefix.Length) Then
212+
' イベントハンドラを設定する。
213+
If prefix = GetConfigParameter.GetConfigValue(MyLiteral.PREFIX_OF_CHECK_BOX) Then
214+
' CHECK BOX
215+
Dim checkBox As CheckBox = Nothing
216+
217+
If TypeOf ctrl Is CheckBox Then
218+
' キャストできる
219+
checkBox = DirectCast(ctrl, CheckBox)
220+
Else
221+
' キャストできない
222+
Throw New FrameworkException(FrameworkExceptionMessage.CONTROL_TYPE_ERROR(0), [String].Format(FrameworkExceptionMessage.CONTROL_TYPE_ERROR(1), prefix, ctrl.[GetType]().ToString()))
223+
End If
224+
225+
AddHandler checkBox.CheckedChanged, DirectCast(eventHandler, EventHandler)
226+
227+
' ディクショナリに格納
228+
controlHt(ctrl.ID) = ctrl
229+
Exit For
230+
End If
231+
End If
232+
End If
233+
234+
'#End Region
235+
End If
236+
Next
237+
238+
'#Region "再帰"
239+
240+
' 子コントロールがある場合、
241+
If ctrl.HasControls() Then
242+
' 子コントロール毎に
243+
For Each childCtrl As Control In ctrl.Controls
244+
' 再帰する。
245+
MyCmnFunction.GetCtrlAndSetClickEventHandler2(childCtrl, prefixAndEvtHndHt, controlHt)
246+
Next
247+
End If
248+
249+
'#End Region
250+
End Sub
251+
252+
#End Region
253+
254+
' 2009/07/21-end
255+
End Class
256+
End Namespace

0 commit comments

Comments
 (0)