clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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;
30 using System.Collections.Generic;
31 using System.Text;
32 using Mono.Data.SqliteClient;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35  
36 namespace OpenSim.Region.UserStatistics
37 {
38 public class Sessions_Report : IStatsController
39 {
40 #region IStatsController Members
41  
42 public string ReportName
43 {
44 get { return "Sessions"; }
45 }
46  
47 public Hashtable ProcessModel(Hashtable pParams)
48 {
49 Hashtable modeldata = new Hashtable();
50 modeldata.Add("Scenes", pParams["Scenes"]);
51 modeldata.Add("Reports", pParams["Reports"]);
52 SqliteConnection dbConn = (SqliteConnection)pParams["DatabaseConnection"];
53 List<SessionList> lstSessions = new List<SessionList>();
54 Hashtable requestvars = (Hashtable) pParams["RequestVars"];
55  
56  
57 string puserUUID = string.Empty;
58 string clientVersionString = string.Empty;
59 int queryparams = 0;
60  
61 if (requestvars != null)
62 {
63 if (requestvars.ContainsKey("UserID"))
64 {
65 UUID testUUID = UUID.Zero;
66 if (UUID.TryParse(requestvars["UserID"].ToString(), out testUUID))
67 {
68 puserUUID = requestvars["UserID"].ToString();
69  
70 }
71 }
72  
73 if (requestvars.ContainsKey("VersionString"))
74 {
75 clientVersionString = requestvars["VersionString"].ToString();
76 }
77 }
78  
79 lock (dbConn)
80 {
81 string sql =
82 "SELECT distinct a.name_f, a.name_l, a.Agent_ID, b.Session_ID, b.client_version, b.last_updated, b.start_time FROM stats_session_data a LEFT OUTER JOIN stats_session_data b ON a.Agent_ID = b.Agent_ID";
83  
84 if (puserUUID.Length > 0)
85 {
86 if (queryparams == 0)
87 sql += " WHERE";
88 else
89 sql += " AND";
90  
91 sql += " b.agent_id=:agent_id";
92 queryparams++;
93 }
94  
95 if (clientVersionString.Length > 0)
96 {
97 if (queryparams == 0)
98 sql += " WHERE";
99 else
100 sql += " AND";
101  
102 sql += " b.client_version=:client_version";
103 queryparams++;
104 }
105  
106 sql += " ORDER BY a.name_f, a.name_l, b.last_updated;";
107  
108 SqliteCommand cmd = new SqliteCommand(sql, dbConn);
109  
110 if (puserUUID.Length > 0)
111 cmd.Parameters.Add(new SqliteParameter(":agent_id", puserUUID));
112 if (clientVersionString.Length > 0)
113 cmd.Parameters.Add(new SqliteParameter(":client_version", clientVersionString));
114  
115 SqliteDataReader sdr = cmd.ExecuteReader();
116  
117 if (sdr.HasRows)
118 {
119 UUID userUUID = UUID.Zero;
120  
121 SessionList activeSessionList = new SessionList();
122 activeSessionList.user_id=UUID.Random();
123 while (sdr.Read())
124 {
125 UUID readUUID = UUID.Parse(sdr["agent_id"].ToString());
126 if (readUUID != userUUID)
127 {
128 activeSessionList = new SessionList();
129 activeSessionList.user_id = readUUID;
130 activeSessionList.firstname = sdr["name_f"].ToString();
131 activeSessionList.lastname = sdr["name_l"].ToString();
132 activeSessionList.sessions = new List<ShortSessionData>();
133 lstSessions.Add(activeSessionList);
134 }
135  
136 ShortSessionData ssd = new ShortSessionData();
137  
138 ssd.last_update = Utils.UnixTimeToDateTime((uint)Convert.ToInt32(sdr["last_updated"]));
139 ssd.start_time = Utils.UnixTimeToDateTime((uint)Convert.ToInt32(sdr["start_time"]));
140 ssd.session_id = UUID.Parse(sdr["session_id"].ToString());
141 ssd.client_version = sdr["client_version"].ToString();
142 activeSessionList.sessions.Add(ssd);
143  
144 userUUID = activeSessionList.user_id;
145 }
146 }
147 sdr.Close();
148 sdr.Dispose();
149  
150 }
151 modeldata["SessionData"] = lstSessions;
152 return modeldata;
153 }
154  
155 public string RenderView(Hashtable pModelResult)
156 {
157 List<SessionList> lstSession = (List<SessionList>) pModelResult["SessionData"];
158 Dictionary<string, IStatsController> reports = (Dictionary<string, IStatsController>)pModelResult["Reports"];
159  
160 const string STYLESHEET =
161 @"
162 <STYLE>
163 body
164 {
165 font-size:15px; font-family:Helvetica, Verdana; color:Black;
166 }
167 TABLE.defaultr { }
168 TR.defaultr { padding: 5px; }
169 TD.header { font-weight:bold; padding:5px; }
170 TD.content {}
171 TD.contentright { text-align: right; }
172 TD.contentcenter { text-align: center; }
173 TD.align_top { vertical-align: top; }
174 </STYLE>
175 ";
176  
177 StringBuilder output = new StringBuilder();
178 HTMLUtil.HtmlHeaders_O(ref output);
179 output.Append(STYLESHEET);
180 HTMLUtil.HtmlHeaders_C(ref output);
181  
182 HTMLUtil.AddReportLinks(ref output, reports, "");
183  
184 HTMLUtil.TABLE_O(ref output, "defaultr");
185 HTMLUtil.TR_O(ref output, "defaultr");
186 HTMLUtil.TD_O(ref output, "header");
187 output.Append("FirstName");
188 HTMLUtil.TD_C(ref output);
189 HTMLUtil.TD_O(ref output, "header");
190 output.Append("LastName");
191 HTMLUtil.TD_C(ref output);
192 HTMLUtil.TD_O(ref output, "header");
193 output.Append("SessionEnd");
194 HTMLUtil.TD_C(ref output);
195 HTMLUtil.TD_O(ref output, "header");
196 output.Append("SessionLength");
197 HTMLUtil.TD_C(ref output);
198 HTMLUtil.TD_O(ref output, "header");
199 output.Append("Client");
200 HTMLUtil.TD_C(ref output);
201 HTMLUtil.TR_C(ref output);
202 if (lstSession.Count == 0)
203 {
204 HTMLUtil.TR_O(ref output, "");
205 HTMLUtil.TD_O(ref output, "align_top", 1, 5);
206 output.Append("No results for that query");
207 HTMLUtil.TD_C(ref output);
208 HTMLUtil.TR_C(ref output);
209 }
210 foreach (SessionList ssnlst in lstSession)
211 {
212 int cnt = 0;
213 foreach (ShortSessionData sesdata in ssnlst.sessions)
214 {
215 HTMLUtil.TR_O(ref output, "");
216 if (cnt++ == 0)
217 {
218 HTMLUtil.TD_O(ref output, "align_top", ssnlst.sessions.Count, 1);
219 output.Append(ssnlst.firstname);
220 HTMLUtil.TD_C(ref output);
221 HTMLUtil.TD_O(ref output, "align_top", ssnlst.sessions.Count, 1);
222 output.Append(ssnlst.lastname);
223 HTMLUtil.TD_C(ref output);
224 }
225 HTMLUtil.TD_O(ref output, "content");
226 output.Append(sesdata.last_update.ToShortDateString());
227 output.Append(" - ");
228 output.Append(sesdata.last_update.ToShortTimeString());
229 HTMLUtil.TD_C(ref output);
230 HTMLUtil.TD_O(ref output, "content");
231 TimeSpan dtlength = sesdata.last_update.Subtract(sesdata.start_time);
232 if (dtlength.Days > 0)
233 {
234 output.Append(dtlength.Days);
235 output.Append(" Days ");
236 }
237 if (dtlength.Hours > 0)
238 {
239 output.Append(dtlength.Hours);
240 output.Append(" Hours ");
241 }
242 if (dtlength.Minutes > 0)
243 {
244 output.Append(dtlength.Minutes);
245 output.Append(" Minutes");
246 }
247 HTMLUtil.TD_C(ref output);
248 HTMLUtil.TD_O(ref output, "content");
249 output.Append(sesdata.client_version);
250 HTMLUtil.TD_C(ref output);
251 HTMLUtil.TR_C(ref output);
252  
253 }
254 HTMLUtil.TR_O(ref output, "");
255 HTMLUtil.TD_O(ref output, "align_top", 1, 5);
256 HTMLUtil.HR(ref output, "");
257 HTMLUtil.TD_C(ref output);
258 HTMLUtil.TR_C(ref output);
259 }
260 HTMLUtil.TABLE_C(ref output);
261 output.Append("</BODY>\n</HTML>");
262 return output.ToString();
263 }
264  
265 public class SessionList
266 {
267 public string firstname;
268 public string lastname;
269 public UUID user_id;
270 public List<ShortSessionData> sessions;
271 }
272  
273 public struct ShortSessionData
274 {
275 public UUID session_id;
276 public string client_version;
277 public DateTime last_update;
278 public DateTime start_time;
279 }
280  
281 public string RenderJson(Hashtable pModelResult)
282 {
283 return "{}";
284 }
285 #endregion
286 }
287  
288 }