forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractStore.cs
More file actions
694 lines (632 loc) · 24.2 KB
/
AbstractStore.cs
File metadata and controls
694 lines (632 loc) · 24.2 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System.ComponentModel;
using System.Web.UI;
using Ext.Net.Utilities;
namespace Ext.Net
{
/// <summary>
/// AbstractStore is a superclass of Ext.data.Store and Ext.data.TreeStore. It's never used directly, but offers a set of methods used by both of those subclasses.
/// We've left it here in the docs for reference purposes, but unless you need to make a whole new type of Store, what you're probably looking for is Ext.data.Store. If you're still interested, here's a brief description of what AbstractStore is and is not.
/// AbstractStore provides the basic configuration for anything that can be considered a Store. It expects to be given a Model that represents the type of data in the Store. It also expects to be given a Proxy that handles the loading of data into the Store.
/// AbstractStore provides a few helpful methods such as load and sync, which load and save data respectively, passing the requests through the configured proxy. Both built-in Store subclasses add extra behavior to each of these functions. Note also that each AbstractStore subclass has its own way of storing data - in Ext.data.Store the data is saved as a flat MixedCollection, whereas in TreeStore we use a Ext.data.Tree to maintain the data's hierarchy.
/// The store provides filtering and sorting support. This sorting/filtering can happen on the client side or can be completed on the server. This is controlled by the remoteSort and remoteFilter config options. For more information see the sort and filter methods.
/// </summary>
[Meta]
[Description("")]
public abstract partial class AbstractStore : Observable
{
protected override void OnBeforeClientInit(Observable sender)
{
if (this.SyncUrl.IsNotEmpty())
{
if (this.Proxy.Count > 0 && this.Proxy.Primary is ServerProxy)
{
((ServerProxy)this.Proxy.Primary).API.Sync = this.SyncUrl;
}
else if (this.ModelInstance != null && this.ModelInstance.Proxy.Count > 0 && this.ModelInstance.Proxy.Primary is ServerProxy)
{
((ServerProxy)this.ModelInstance.Proxy.Primary).API.Sync = this.SyncUrl;
}
else if (this.ServerProxy.Count > 0)
{
if (this.ServerProxy.Primary is ServerProxy)
{
((ServerProxy)this.ServerProxy.Primary).API.Sync = this.SyncUrl;
}
}
else
{
this.ServerProxy.Add(new AjaxProxy
{
API =
{
Sync = this.SyncUrl
}
});
}
}
base.OnBeforeClientInit(sender);
}
/// <summary>
///
/// </summary>
[Description("")]
protected internal override bool IsIdRequired
{
get
{
return !this.IsGeneratedID || !(this.IsSelfRender || this.IsPageSelfRender || this.IsDynamic || this.IsMVC) || this.ForceIdRendering;
}
}
/// <summary>
///
/// </summary>
[ConfigOption("storeId")]
[DefaultValue("")]
[Description("")]
protected override string ConfigIDProxy
{
get
{
return base.ConfigIDProxy;
}
}
/// <summary>
///
/// </summary>
protected virtual string StoreType
{
get
{
return "";
}
}
/// <summary>
///
/// </summary>
[ConfigOption("type")]
[DefaultValue("")]
protected string StoreTypeProxy
{
get
{
return this.IsLazy ? this.StoreType : "";
}
}
/// <summary>
///
/// </summary>
[Description("")]
protected override bool RemoveContainer
{
get
{
return true;
}
}
/// <summary>
/// true to destroy the store when the component the store is bound to is destroyed (defaults to false). Note: this should be set to true when using stores that are bound to only 1 component.
/// </summary>
[Meta]
[ConfigOption]
[Category("3. AbstractStore")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("true to destroy the store when the component the store is bound to is destroyed (defaults to false). Note: this should be set to true when using stores that are bound to only 1 component.")]
public virtual bool AutoDestroy
{
get
{
return this.State.Get<bool>("AutoDestroy", false);
}
set
{
this.State.Set("AutoDestroy", value);
}
}
/// <summary>
/// If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method. Defaults to false.
/// </summary>
[Meta]
[Category("3. AbstractStore")]
[DefaultValue(true)]
[Description("If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method. Defaults to false.")]
public virtual bool AutoLoad
{
get
{
return this.State.Get<bool>("AutoLoad", true);
}
set
{
this.State.Set("AutoLoad", value);
}
}
/// <summary>
///
/// </summary>
public virtual bool IsAutoLoadUndefined
{
get
{
return this.State.Get<bool>("AutoLoad", true);
}
}
/// <summary>
///
/// </summary>
[ConfigOption("autoLoad")]
[DefaultValue(false)]
[Description("")]
protected virtual bool AutoLoadProxy
{
get
{
if (this.AutoLoadParams.Count == 0)
{
return this.AutoLoad;
}
return false;
}
}
private ParameterCollection autoParams;
/// <summary>
/// If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method.
/// </summary>
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on auto load HTTP request.")]
public virtual ParameterCollection AutoLoadParams
{
get
{
return this.autoParams ?? (this.autoParams = new ParameterCollection { Owner = this });
}
}
/// <summary>
///
/// </summary>
[ConfigOption("autoLoad", typeof(AutoLoadParamsJsonConverter))]
[Description("")]
protected ParameterCollection AutoLoadParamsProxy
{
get
{
if (this.AutoLoad == false)
{
return new ParameterCollection();
}
return this.AutoLoadParams;
}
}
private StoreParameterCollection parameters;
/// <summary>
/// An object containing properties which are to be sent as parameters on any HTTP request.
/// </summary>
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on any HTTP request.")]
public virtual StoreParameterCollection Parameters
{
get
{
return this.parameters ?? (this.parameters = new StoreParameterCollection {Owner = this});
}
}
/// <summary>
///
/// </summary>
[DefaultValue("")]
[ConfigOption("readParameters", JsonMode.Raw)]
protected virtual string ParametersProxy
{
get
{
return this.Parameters.Count == 0 ? "" : this.Parameters.Serialize(true, false);
}
}
private StoreParameterCollection syncParameters;
/// <summary>
/// An object containing properties which are to be sent as parameters on sync request.
/// </summary>
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on sync request.")]
public virtual StoreParameterCollection SyncParameters
{
get
{
return this.syncParameters ?? (this.syncParameters = new StoreParameterCollection { Owner = this });
}
}
/// <summary>
///
/// </summary>
[DefaultValue("")]
[ConfigOption("writeParameters", JsonMode.Raw)]
protected virtual string SyncParametersProxy
{
get
{
return this.SyncParameters.Count == 0 ? "" : this.SyncParameters.Serialize(true, true);
}
}
/// <summary>
/// True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.
/// </summary>
[Meta]
[ConfigOption]
[Category("3. AbstractStore")]
[DefaultValue(false)]
[Description("True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.")]
public virtual bool AutoSync
{
get
{
return this.State.Get<bool>("AutoSync", false);
}
set
{
this.State.Set("AutoSync", value);
}
}
private ProxyCollection proxy;
/// <summary>
/// The Proxy to use for this Store.
/// </summary>
[Meta]
[ConfigOption("proxy>Primary")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The Proxy to use for this Store.")]
public virtual ProxyCollection Proxy
{
get
{
return this.proxy ?? (this.proxy = new ProxyCollection());
}
}
/// <summary>
///
/// </summary>
[Meta]
[Category("3. AbstractStore")]
[DefaultValue("")]
[Description("")]
public virtual string SyncUrl
{
get
{
return this.State.Get<string>("SyncUrl", "");
}
set
{
this.State.Set("SyncUrl", value);
}
}
private ProxyCollection serverProxy;
/// <summary>
/// The Proxy to use for reload or sync actions when Memory proxy is used for initial data
/// </summary>
[Meta]
[ConfigOption("serverProxy>Primary")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The Proxy to use for this Store.")]
public virtual ProxyCollection ServerProxy
{
get
{
return this.serverProxy ?? (this.serverProxy = new ProxyCollection());
}
}
/// <summary>
/// Sets the updating behavior based on batch synchronization. 'operation' (the default) will update the Store's internal representation of the data after each operation of the batch has completed, 'complete' will wait until the entire batch has been completed before updating the Store's data. 'complete' is a good choice for local storage proxies, 'operation' is better for remote proxies, where there is a comparatively high latency.
/// </summary>
[Meta]
[ConfigOption(JsonMode.ToLower)]
[DefaultValue(BatchUpdateMode.Operation)]
[Description("Sets the updating behavior based on batch synchronization.")]
public virtual BatchUpdateMode BatchUpdateMode
{
get
{
return this.State.Get<BatchUpdateMode>("BatchUpdateMode", BatchUpdateMode.Operation);
}
set
{
this.State.Set("BatchUpdateMode", value);
}
}
/// <summary>
/// If true, any filters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, ignored if remoteFilter is true
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[Description("If true, any filters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, ignored if remoteFilter is true")]
public virtual bool FilterOnLoad
{
get
{
return this.State.Get<bool>("FilterOnLoad", true);
}
set
{
this.State.Set("FilterOnLoad", value);
}
}
private DataFilterCollection filters;
/// <summary>
/// The collection of Filters currently applied to this Store
/// </summary>
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The collection of Filters currently applied to this Store")]
public virtual DataFilterCollection Filters
{
get
{
return this.filters ?? (this.filters = new DataFilterCollection());
}
}
/// <summary>
/// If true, any sorters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, igored if remoteSort is true
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[Description("If true, any sorters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, igored if remoteSort is true")]
public virtual bool SortOnLoad
{
get
{
return this.State.Get<bool>("SortOnLoad", true);
}
set
{
this.State.Set("SortOnLoad", value);
}
}
/// <summary>
/// The field name by which to sort the store's data (defaults to '').
/// </summary>
[Meta]
[ConfigOption]
[Category("3. Store")]
[DefaultValue("")]
[Description("The field name by which to sort the store's data (defaults to '').")]
public virtual string SortRoot
{
get
{
return this.State.Get<string>("SortRoot", "");
}
set
{
this.State.Set("SortRoot", value);
}
}
private DataSorterCollection sorters;
/// <summary>
/// The collection of Sorters currently applied to this Store
/// </summary>
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The collection of Sorters currently applied to this Store")]
public virtual DataSorterCollection Sorters
{
get
{
return this.sorters ?? (this.sorters = new DataSorterCollection());
}
}
/// <summary>
/// Show warning if request fail.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("Show a Window with error message is DirectEvent request fails.")]
public bool ShowWarningOnFailure
{
get
{
return this.State.Get<bool>("ShowWarningOnFailure", true);
}
set
{
this.State.Set("ShowWarningOnFailure", value);
}
}
/// <summary>
/// The Ext.data.Model associated with this store
/// </summary>
[Meta]
[ConfigOption("model")]
[DefaultValue(null)]
[Description("The Ext.data.Model associated with this store")]
public virtual string ModelName
{
get
{
return this.State.Get<string>("ModelName", null);
}
set
{
this.modelInstance = null;
this.State.Set("ModelName", value);
}
}
private ModelCollection model;
/// <summary>
///
/// </summary>
[Meta]
[ConfigOption("model>Primary", 1)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("")]
public virtual ModelCollection Model
{
get
{
if (this.model == null)
{
this.model = new ModelCollection();
this.model.AfterItemAdd += this.AfterItemAdd;
this.model.AfterItemRemove += this.AfterItemRemove;
}
return this.model;
}
}
private Model modelInstance;
/// <summary>
///
/// </summary>
public virtual Model ModelInstance
{
get
{
if (this.DesignMode)
{
return null;
}
if (this.modelInstance != null)
{
return this.modelInstance;
}
if (this.Model.Primary != null)
{
return this.Model.Primary;
}
if (this.ModelName.IsEmpty() && !this.DesignMode)
{
return null;
//throw new Exception("Model is not defined for the store");
}
if (!Ext.Net.Model.IsRegistered(this.ModelName) && !this.DesignMode)
{
return null;
//throw new Exception("Model with name '{0}' doesn't exist".FormatWith(this.ModelName));
}
this.modelInstance = Ext.Net.Model.Get(this.ModelName);
return this.modelInstance;
}
}
/// <summary>
/// Loads data into the Store via the configured proxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required.
/// </summary>
/// <param name="options">config object, passed into the Ext.data.Operation object before loading. Additionally addRecords: true can be specified to add these records to the existing records, default is to remove the Store's existing records first.</param>
[Meta]
public virtual void LoadProxy(object options)
{
this.Call("load", options);
}
/// <summary>
/// Loads data into the Store via the configured proxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required.
/// </summary>
[Meta]
public virtual void LoadProxy()
{
this.Call("load");
}
/// <summary>
/// Reloads the Store.
/// </summary>
[Meta]
public virtual void Reload()
{
this.Call("reload");
}
/// <summary>
/// Reloads the Store.
/// </summary>
/// <param name="options">Optional config object. This is passed into the Operation object that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function</param>
[Meta]
public virtual void Reload(object options)
{
this.Call("reload", options);
}
/// <summary>
/// Reloads the Store.
/// </summary>
/// <param name="options">Optional config object. This is passed into the Operation object that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function</param>
/// <param name="proxy">The new Proxy, which is an instance</param>
[Meta]
public virtual void Reload(object options, AbstractProxy proxy)
{
this.Call("reload", options, new ClientConfig().Serialize(proxy, true));
}
/// <summary>
/// Reloads the Store.
/// </summary>
/// <param name="parameters">Optional config object. This is passed into the Operation object as the options.params that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function</param>
[Meta]
public virtual void Reload(ParameterCollection parameters)
{
this.Reload(new
{
@params = JRawValue.From(parameters.ToJson())
});
}
/// <summary>
/// Sets the Store's Proxy by string
/// </summary>
/// <param name="proxyType">The new Proxy, which is a type string</param>
[Meta]
public virtual void SetProxy(string proxyType)
{
this.Call("setProxy", proxyType);
}
/// <summary>
/// Sets the Store's Proxy by instance
/// </summary>
/// <param name="proxy">The new Proxy, which is an instance</param>
[Meta]
public virtual void SetProxy(AbstractProxy proxy)
{
this.Call("setProxy", new ClientConfig().Serialize(proxy, true));
}
/// <summary>
/// Synchronizes the Store with its Proxy. This asks the Proxy to batch together any new, updated and deleted records in the store, updating the Store's internal representation of the records as each operation completes.
/// </summary>
[Meta]
public virtual void Sync()
{
this.Call("sync");
}
/// <summary>
/// Resumes automatically syncing the Store with its Proxy. Only applicable if autoSync is true
/// </summary>
[Meta]
public virtual void ResumeAutoSync()
{
this.Call("resumeAutoSync");
}
/// <summary>
/// Suspends automatically syncing the Store with its Proxy. Only applicable if autoSync is true
/// </summary>
[Meta]
public virtual void SuspendAutoSync()
{
this.Call("suspendAutoSync");
}
}
}