-
Notifications
You must be signed in to change notification settings - Fork 1
/
Content_Pooling.cs
206 lines (193 loc) · 7 KB
/
Content_Pooling.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#region Copyright
// *******************************************************************************
// Copyright (c) 2000-2009 Paul Stancer.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// Paul Stancer - initial implementation
// *******************************************************************************
#endregion
#region using
using System;
using System.IO;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Diagnostics;
using System.Text;
using Ximura;
using Ximura.Data;
using Ximura.Data;
using CH = Ximura.Common;
#endregion // using
namespace Ximura.Data
{
public abstract partial class Content : IXimuraPoolManagerDirectAccess, IXimuraPoolableObjectDeserializable, IXimuraPoolReturnable
{
#region Declarations
/// <summary>
/// This is the unique track id for the content used for pooling.
/// </summary>
private readonly Guid mTrackID = Guid.NewGuid();
private IXimuraPool mPool;
private IXimuraPoolManager mPoolManager;
#endregion
#region Reset()
/// <summary>
/// This is the reset method to set the content to it's default state.
/// </summary>
public virtual void Reset()
{
mPoolManager = null;
mPool = null;
mCanLoad = true;
mEntityType = "";
mEntitySubType = "";
mInfo = null;
mIDVersion = Guid.Empty;
mIDContent = Guid.Empty;
mDirty = false;
mOnInitialized = null;
mInitialized = false;
mInitializing = false;
}
#endregion
#region CanPool
/// <summary>
/// This method indicates whether the object can be pooled. By default this is set to true.
/// You should override this method to return false if you do not wish your content object to be poolable.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual bool CanPool
{
get { return true; }
}
#endregion // CanPool
#region TrackID
/// <summary>
/// This is the tracking ID for the object.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Guid TrackID
{
get { return mTrackID; }
}
#endregion // TrackID
#region CanResetWithDeserialization
/// <summary>
/// This property indicates whether the object support a deserialization reset.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual bool CanResetWithDeserialization { get { return true; } }
#endregion // CanResetWithDeserialization
#region Reset(SerializationInfo info, StreamingContext context)
/// <summary>
/// This is the reset method to set the content to the state specified in the
/// deserialization paramters.
/// </summary>
/// <param name="info">The serialization info.</param>
/// <param name="context">The serialization context.</param>
public virtual void Reset(SerializationInfo info, StreamingContext context)
{
Reset();
DeserializeIncoming(info, context);
}
#endregion // Reset(SerializationInfo info, StreamingContext context)
#region ObjectPool
/// <summary>
/// This is the object pool that the message belongs to.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IXimuraPool ObjectPool
{
get
{
return mPool;
}
set
{
mPool = value;
}
}
#endregion // ObjectPool
#region ObjectPoolCanReturn
/// <summary>
/// This property specifices whether the object can be returns to the pool.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool ObjectPoolCanReturn
{
get { return mPool != null; }
}
#endregion // ObjectPoolCanReturn
#region ObjectPoolReturn()
/// <summary>
/// This method returns the object to the pool.
/// </summary>
public virtual void ObjectPoolReturn()
{
mPool.Return(this);
}
#endregion // ObjectPoolReturn()
#region PoolManager
/// <summary>
/// This is the pool manager that can be used by the IXimuraPoolManagerDirectAccess interface.
/// Although the methods and properties are implemented in the base class the actual interface is
/// not implemented.
/// </summary>
public IXimuraPoolManager PoolManager
{
get
{
return mPoolManager;
}
set
{
mPoolManager = value;
}
}
#endregion
#region PoolGet(Type objectType)
/// <summary>
/// This method returns the specific pool manager for the type.
/// </summary>
/// <param name="objectType"></param>
/// <returns>Returns the pool for the object type.</returns>
public IXimuraPool PoolGet(Type objectType)
{
return mPoolManager.GetPoolManager(objectType);
}
#endregion
#region PoolGetObject(Type objectType)
/// <summary>
/// Returns a new object of the type specified.
/// </summary>
/// <param name="objectType">The object type required.</param>
/// <returns>Returns a poolable object of the type defined.</returns>
public object PoolGetObject(Type objectType)
{
return PoolGet(objectType).Get();
}
#endregion // PoolGetObject(Type objectType)
#region PoolGetReturn(object poolObject)
/// <summary>
/// This method returns the object to the appropriate pool.
/// </summary>
/// <param name="poolObject">The object to return.</param>
public void PoolGetReturn(object poolObject)
{
PoolGet(poolObject.GetType()).Return(poolObject);
}
#endregion // PoolGetReturn(object poolObject)
}
}