~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/CollectionStore/.svn/text-base/Domain.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 | Author: Mike Lasky <mlasky@novell.com>
22
 
 |***************************************************************************/
23
 
 
24
 
 
25
 
using System;
26
 
using System.Xml;
27
 
 
28
 
using Simias.Client;
29
 
using Simias.Sync;
30
 
 
31
 
namespace Simias.Storage
32
 
{
33
 
        /// <summary>
34
 
        /// Class that represents a Domain object in the Collection Store.
35
 
        /// </summary>
36
 
        public class Domain : Collection
37
 
        {
38
 
                #region Class Members
39
 
                /// <summary>
40
 
                /// Defines the different types of synchronization configurations.
41
 
                /// </summary>
42
 
                public enum ConfigurationType
43
 
                {
44
 
                        /// <summary>
45
 
                        /// Doesn't sychronize.
46
 
                        /// </summary>
47
 
                        None,
48
 
 
49
 
                        /// <summary>
50
 
                        /// Workgroup (e.g. Rendevous, Gaim, etc)
51
 
                        /// </summary>
52
 
                        Workgroup,
53
 
 
54
 
                        /// <summary>
55
 
                        /// Client/Server (e.g. Enterprise, SimpleServer, etc)
56
 
                        /// </summary>
57
 
                        ClientServer
58
 
                }
59
 
 
60
 
                /// <summary>
61
 
                /// Configuration section name where enterprise key value pairs are stored.
62
 
                /// </summary>
63
 
                static public string SectionName = "Domain";
64
 
                static public string AdminDNTag = "AdminDN";
65
 
                static public string Encoding = "Encoding";
66
 
 
67
 
                /// <summary>
68
 
                /// Current version of the domain.
69
 
                /// </summary>
70
 
                public static readonly Version CurrentDomainVersion = new Version( "1.0.0.0" );
71
 
 
72
 
                #endregion
73
 
 
74
 
                #region Properties
75
 
                /// <summary>
76
 
                /// Gets the domain configuration type.
77
 
                /// </summary>
78
 
                public ConfigurationType ConfigType
79
 
                {
80
 
                        get 
81
 
                        { 
82
 
                                Property p = properties.FindSingleValue( PropertyTags.DomainType );
83
 
                                return ( p != null ) ? ( ConfigurationType )p.Value : ConfigurationType.None;
84
 
                        }
85
 
                }
86
 
 
87
 
                /// <summary>
88
 
                /// Gets or sets the domain description.
89
 
                /// </summary>
90
 
                public string Description
91
 
                {
92
 
                        get 
93
 
                        { 
94
 
                                Property p = properties.GetSingleProperty( PropertyTags.Description );
95
 
                                return ( p != null ) ? p.Value as String : null;
96
 
                        }
97
 
 
98
 
                        set { properties.ModifyNodeProperty( PropertyTags.Description, value ); }
99
 
                }
100
 
 
101
 
#if ( !REMOVE_OLD_INVITATION )
102
 
                /// <summary>
103
 
                /// Used to determine if the domain supports the new invitation model.
104
 
                /// </summary>
105
 
                public bool SupportsNewInvitation
106
 
                {
107
 
                        get { return ( DomainVersion >= CurrentDomainVersion ) ? true : false; }
108
 
                }
109
 
#endif
110
 
                /// <summary>
111
 
                /// Gets or sets the version of this domain.
112
 
                /// </summary>
113
 
                public Version DomainVersion
114
 
                {
115
 
                        get
116
 
                        {
117
 
                                Property p = properties.GetSingleProperty( PropertyTags.DomainVersion );
118
 
                                return ( p != null ) ? new Version( p.Value as String ) : new Version( "0.0.0.0" );
119
 
                        }
120
 
 
121
 
                        set { properties.ModifyNodeProperty( PropertyTags.DomainVersion, value.ToString() ); }
122
 
                }
123
 
                #endregion
124
 
 
125
 
                #region Constructors
126
 
                /// <param name="store">Store object.</param>
127
 
                /// <param name="domainName">Name of the domain.</param>
128
 
                /// <param name="domainID">Well known unique identifier for the domain.</param>
129
 
                /// <param name="description">String that describes this domain.</param>
130
 
                /// <param name="role">The type of synchronization role this domain has.</param>
131
 
                /// <param name="configType">The synchronization configuration type for this domain.</param>
132
 
                public Domain( Store store, string domainName, string domainID, string description, SyncRoles role, ConfigurationType configType ) :
133
 
                        base ( store, domainName, domainID, NodeTypes.DomainType, domainID )
134
 
                {
135
 
                        // Add the description attribute.
136
 
                        if ( ( description != null ) && ( description.Length > 0 ) )
137
 
                        {
138
 
                                properties.AddNodeProperty( PropertyTags.Description, description );
139
 
                        }
140
 
 
141
 
                        // Set the current domain version.
142
 
                        DomainVersion = CurrentDomainVersion;
143
 
 
144
 
                        // Add the sync role for this collection.
145
 
                        Role = role;
146
 
                        
147
 
                        // Add the configuration type.
148
 
                        Property p = new Property( PropertyTags.DomainType, configType );
149
 
                        p.LocalProperty = true;
150
 
                        properties.AddNodeProperty( p );
151
 
                        
152
 
                        // When sync the policy node (always sync is initiated from slave) is syned from master to slave
153
 
                        // the master is overwritten to slave, the slave changes will be lost
154
 
                        // when there is no change in master, the slave changes will be synced to master
155
 
                        // This is to ensure that the master policy over rides the slave policy.                        
156
 
                        // Ideally we should have a master policy which is read only in slave and
157
 
                        // slave specific policy which should not be synced to master.                  
158
 
                        CollisionPolicy = CollisionPolicy.ServerWins;
159
 
                }
160
 
 
161
 
                /// <summary>
162
 
                /// Constructor to create an existing Domain object from a Node object.
163
 
                /// </summary>
164
 
                /// <param name="storeObject">Store object that this collection belongs to.</param>
165
 
                /// <param name="node">Node object to construct this object from.</param>
166
 
                public Domain( Store storeObject, Node node ) :
167
 
                        base( storeObject, node )
168
 
                {
169
 
                }
170
 
 
171
 
                /// <summary>
172
 
                /// Constructor for creating an existing Domain object from a ShallowNode.
173
 
                /// </summary>
174
 
                /// <param name="storeObject">Store object that this collection belongs to.</param>
175
 
                /// <param name="shallowNode">A ShallowNode object.</param>
176
 
                public Domain( Store storeObject, ShallowNode shallowNode ) :
177
 
                        base( storeObject, shallowNode )
178
 
                {
179
 
                }
180
 
 
181
 
                /// <summary>
182
 
                /// Constructor to create an existing Domain object from an Xml document object.
183
 
                /// </summary>
184
 
                /// <param name="storeObject">Store object that this collection belongs to.</param>
185
 
                /// <param name="document">Xml document object to construct this object from.</param>
186
 
                internal Domain( Store storeObject, XmlDocument document ) :
187
 
                        base( storeObject, document )
188
 
                {
189
 
                }
190
 
                #endregion
191
 
 
192
 
                #region Public Methods
193
 
                /// <summary>
194
 
                /// Returns if the specified user's login is disabled.
195
 
                /// </summary>
196
 
                /// <param name="userID">User ID for the member to check.</param>
197
 
                /// <returns>True if the login for the specified user is disabled.</returns>
198
 
                public bool IsLoginDisabled( string userID )
199
 
                {
200
 
                        Member member = GetMemberByID( userID );
201
 
                        if ( member == null )
202
 
                        {
203
 
                                throw new DoesNotExistException( "The specified user does not exist." );
204
 
                        }
205
 
 
206
 
                        Property p = member.Properties.GetSingleProperty( PropertyTags.LoginDisabled );
207
 
                        return ( p != null ) ? ( bool )p.Value : false;
208
 
                }
209
 
 
210
 
                /// <summary>
211
 
                /// Sets the specified user's login disabled status.
212
 
                /// </summary>
213
 
                /// <param name="userID">User ID for the member to set the status for.</param>
214
 
                /// <param name="disable">True to disable login or False to enable login.</param>
215
 
                public void SetLoginDisabled( string userID, bool disable )
216
 
                {
217
 
                        Member member = GetMemberByID( userID );
218
 
                        if ( member == null )
219
 
                        {
220
 
                                throw new DoesNotExistException( "The specified user does not exist." );
221
 
                        }
222
 
 
223
 
                        if ( disable )
224
 
                        {
225
 
                                Property p = new Property( PropertyTags.LoginDisabled, true );
226
 
                                p.LocalProperty = true;
227
 
                                member.Properties.ModifyNodeProperty( p );
228
 
                                Commit( member );
229
 
                        }
230
 
                        else
231
 
                        {
232
 
                                Property p = member.Properties.GetSingleProperty( PropertyTags.LoginDisabled );
233
 
                                if ( p != null )
234
 
                                {
235
 
                                        p.DeleteProperty();
236
 
                                        Commit( member );
237
 
                                }
238
 
                        }
239
 
                }
240
 
 
241
 
                /// <summary>
242
 
                /// Obtains the string representation of this instance.
243
 
                /// </summary>
244
 
                /// <returns>The friendly name of the domain.</returns>
245
 
                public override string ToString()
246
 
                {
247
 
                        return Name;
248
 
                }
249
 
                #endregion
250
 
        }
251
 
}