OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IUserAccountService.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using OpenMetaverse;
31 
32 using OpenSim.Framework;
33 
34 namespace OpenSim.Services.Interfaces
35 {
36  public class UserAccount
37  {
38  public UserAccount()
39  {
40  }
41 
42  public UserAccount(UUID principalID)
43  {
44  PrincipalID = principalID;
45  }
46 
64  public UserAccount(UUID scopeID, string firstName, string lastName, string email)
65  {
66  PrincipalID = UUID.Random();
67  ScopeID = scopeID;
68  FirstName = firstName;
69  LastName = lastName;
70  Email = email;
71  ServiceURLs = new Dictionary<string, object>();
72  Created = Util.UnixTimeSinceEpoch();
73  }
74 
75  public UserAccount(UUID scopeID, UUID principalID, string firstName, string lastName, string email)
76  {
77  PrincipalID = principalID;
78  ScopeID = scopeID;
79  FirstName = firstName;
80  LastName = lastName;
81  Email = email;
82  ServiceURLs = new Dictionary<string, object>();
83  Created = Util.UnixTimeSinceEpoch();
84  }
85 
86  public string FirstName;
87  public string LastName;
88  public string Email;
89  public UUID PrincipalID;
90  public UUID ScopeID;
91  public int UserLevel;
92  public int UserFlags;
93  public string UserTitle;
94  public string UserCountry;
95  public Boolean LocalToGrid = true;
96 
97  public Dictionary<string, object> ServiceURLs;
98 
99  public int Created;
100 
101  public string Name
102  {
103  get { return FirstName + " " + LastName; }
104  }
105 
106  public UserAccount(Dictionary<string, object> kvp)
107  {
108  if (kvp.ContainsKey("FirstName"))
109  FirstName = kvp["FirstName"].ToString();
110  if (kvp.ContainsKey("LastName"))
111  LastName = kvp["LastName"].ToString();
112  if (kvp.ContainsKey("Email"))
113  Email = kvp["Email"].ToString();
114  if (kvp.ContainsKey("PrincipalID"))
115  UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
116  if (kvp.ContainsKey("ScopeID"))
117  UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID);
118  if (kvp.ContainsKey("UserLevel"))
119  UserLevel = Convert.ToInt32(kvp["UserLevel"].ToString());
120  if (kvp.ContainsKey("UserFlags"))
121  UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString());
122  if (kvp.ContainsKey("UserTitle"))
123  UserTitle = kvp["UserTitle"].ToString();
124  if (kvp.ContainsKey("UserCountry"))
125  UserCountry = kvp["UserCountry"].ToString();
126  if (kvp.ContainsKey("LocalToGrid"))
127  Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid);
128 
129  if (kvp.ContainsKey("Created"))
130  Created = Convert.ToInt32(kvp["Created"].ToString());
131  if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null)
132  {
133  ServiceURLs = new Dictionary<string, object>();
134  string str = kvp["ServiceURLs"].ToString();
135  if (str != string.Empty)
136  {
137  string[] parts = str.Split(new char[] { ';' });
138 // Dictionary<string, object> dic = new Dictionary<string, object>();
139  foreach (string s in parts)
140  {
141  string[] parts2 = s.Split(new char[] { '*' });
142  if (parts2.Length == 2)
143  ServiceURLs[parts2[0]] = parts2[1];
144  }
145  }
146  }
147  }
148 
149  public Dictionary<string, object> ToKeyValuePairs()
150  {
151  Dictionary<string, object> result = new Dictionary<string, object>();
152  result["FirstName"] = FirstName;
153  result["LastName"] = LastName;
154  result["Email"] = Email;
155  result["PrincipalID"] = PrincipalID.ToString();
156  result["ScopeID"] = ScopeID.ToString();
157  result["Created"] = Created.ToString();
158  result["UserLevel"] = UserLevel.ToString();
159  result["UserFlags"] = UserFlags.ToString();
160  result["UserTitle"] = UserTitle;
161  result["UserCountry"] = UserCountry;
162  result["LocalToGrid"] = LocalToGrid.ToString();
163 
164  string str = string.Empty;
165  foreach (KeyValuePair<string, object> kvp in ServiceURLs)
166  {
167  str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";";
168  }
169  result["ServiceURLs"] = str;
170 
171  return result;
172  }
173 
174  };
175 
176  public interface IUserAccountService
177  {
178  UserAccount GetUserAccount(UUID scopeID, UUID userID);
179  UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName);
180  UserAccount GetUserAccount(UUID scopeID, string Email);
181 
188  List<UserAccount> GetUserAccounts(UUID scopeID, string query);
189  List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where);
190 
196  bool StoreUserAccount(UserAccount data);
197 
198  void InvalidateCache(UUID userID);
199  }
200 }
UserAccount(UUID scopeID, UUID principalID, string firstName, string lastName, string email)
Dictionary< string, object > ToKeyValuePairs()
UserAccount(UUID scopeID, string firstName, string lastName, string email)
Initializes a new instance of the OpenSim.Services.Interfaces.UserAccount class. This method is used ...
Dictionary< string, object > ServiceURLs
UserAccount(Dictionary< string, object > kvp)