Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Objects/WarFoundryObject.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | 6da9db4a9c23 |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (WarFoundryObject.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | |
2 // | |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | |
4 | |
5 using System; | |
6 using IBBoard.WarFoundry.API.Factories; | |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects | |
9 { | |
10 /// <summary> | |
11 /// Summary description for WarFoundryObject. | |
12 /// </summary> | |
13 public abstract class WarFoundryObject : IWarFoundryObject | |
14 { | |
15 protected string id; | |
16 protected string name; | |
17 public event StringValChangedDelegate NameChanged; | |
18 | |
19 protected WarFoundryObject() | |
20 { | |
21 } | |
22 | |
23 protected WarFoundryObject(string objName) : this() | |
24 { | |
25 Name = objName; | |
26 } | |
27 | |
28 protected WarFoundryObject(string objId, string objName) : this(objName) | |
29 { | |
30 ID = objId; | |
31 } | |
32 | |
33 public virtual string ID | |
34 { | |
35 get | |
36 { | |
37 if (id == null || id == "") | |
38 { | |
39 id = GenerateID(); | |
40 } | |
41 | |
42 return id; | |
43 } | |
44 | |
45 set | |
46 { | |
47 string newId = (value == null ? "" : value.Trim()); | |
48 id = (newId == "" ? GenerateID() : newId); | |
49 } | |
50 } | |
51 | |
52 public virtual string Name | |
53 { | |
54 get | |
55 { | |
56 if (HasDefaultName()) | |
57 { | |
58 return DefaultName(); | |
59 } | |
60 else | |
61 { | |
62 return name; | |
63 } | |
64 } | |
65 set | |
66 { | |
67 string oldValue = name; | |
68 name = value; | |
69 | |
70 if (name!=oldValue) | |
71 { | |
72 OnNameChanged(oldValue, name); | |
73 } | |
74 } | |
75 } | |
76 | |
77 public bool HasDefaultName() | |
78 { | |
79 return (name == null || name == ""); | |
80 } | |
81 | |
82 protected void OnNameChanged(string oldValue, string newValue) | |
83 { | |
84 if (NameChanged!=null) | |
85 { | |
86 NameChanged(this, oldValue, newValue); | |
87 } | |
88 } | |
89 | |
90 protected virtual string DefaultName() | |
91 { | |
92 return "-"; | |
93 } | |
94 | |
95 protected string GenerateID() | |
96 { | |
97 return Name + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond; | |
98 } | |
99 } | |
100 } |