OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IOfflineIMService.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 using System;
28 using System.Collections.Generic;
29 
30 using OpenSim.Framework;
31 using OpenMetaverse;
32 
33 namespace OpenSim.Services.Interfaces
34 {
35  public interface IOfflineIMService
36  {
37  List<GridInstantMessage> GetMessages(UUID principalID);
38 
39  bool StoreMessage(GridInstantMessage im, out string reason);
40 
45  void DeleteMessages(UUID userID);
46  }
47 
48  public class OfflineIMDataUtils
49  {
50  public static GridInstantMessage GridInstantMessage(Dictionary<string, object> dict)
51  {
53 
54  if (dict.ContainsKey("BinaryBucket") && dict["BinaryBucket"] != null)
55  im.binaryBucket = OpenMetaverse.Utils.HexStringToBytes(dict["BinaryBucket"].ToString(), true);
56 
57  if (dict.ContainsKey("Dialog") && dict["Dialog"] != null)
58  im.dialog = byte.Parse(dict["Dialog"].ToString());
59 
60  if (dict.ContainsKey("FromAgentID") && dict["FromAgentID"] != null)
61  im.fromAgentID = new Guid(dict["FromAgentID"].ToString());
62 
63  if (dict.ContainsKey("FromAgentName") && dict["FromAgentName"] != null)
64  im.fromAgentName = dict["FromAgentName"].ToString();
65  else
66  im.fromAgentName = string.Empty;
67 
68  if (dict.ContainsKey("FromGroup") && dict["FromGroup"] != null)
69  im.fromGroup = bool.Parse(dict["FromGroup"].ToString());
70 
71  if (dict.ContainsKey("SessionID") && dict["SessionID"] != null)
72  im.imSessionID = new Guid(dict["SessionID"].ToString());
73 
74  if (dict.ContainsKey("Message") && dict["Message"] != null)
75  im.message = dict["Message"].ToString();
76  else
77  im.message = string.Empty;
78 
79  if (dict.ContainsKey("Offline") && dict["Offline"] != null)
80  im.offline = byte.Parse(dict["Offline"].ToString());
81 
82  if (dict.ContainsKey("EstateID") && dict["EstateID"] != null)
83  im.ParentEstateID = UInt32.Parse(dict["EstateID"].ToString());
84 
85  if (dict.ContainsKey("Position") && dict["Position"] != null)
86  im.Position = Vector3.Parse(dict["Position"].ToString());
87 
88  if (dict.ContainsKey("RegionID") && dict["RegionID"] != null)
89  im.RegionID = new Guid(dict["RegionID"].ToString());
90 
91  if (dict.ContainsKey("Timestamp") && dict["Timestamp"] != null)
92  im.timestamp = UInt32.Parse(dict["Timestamp"].ToString());
93 
94  if (dict.ContainsKey("ToAgentID") && dict["ToAgentID"] != null)
95  im.toAgentID = new Guid(dict["ToAgentID"].ToString());
96 
97  return im;
98  }
99 
100  public static Dictionary<string, object> GridInstantMessage(GridInstantMessage im)
101  {
102  Dictionary<string, object> dict = new Dictionary<string, object>();
103 
104  dict["BinaryBucket"] = OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, im.binaryBucket.Length, null);
105  dict["Dialog"] = im.dialog.ToString();
106  dict["FromAgentID"] = im.fromAgentID.ToString();
107  dict["FromAgentName"] = im.fromAgentName == null ? string.Empty : im.fromAgentName;
108  dict["FromGroup"] = im.fromGroup.ToString();
109  dict["SessionID"] = im.imSessionID.ToString();
110  dict["Message"] = im.message == null ? string.Empty : im.message;
111  dict["Offline"] = im.offline.ToString();
112  dict["EstateID"] = im.ParentEstateID.ToString();
113  dict["Position"] = im.Position.ToString();
114  dict["RegionID"] = im.RegionID.ToString();
115  dict["Timestamp"] = im.timestamp.ToString();
116  dict["ToAgentID"] = im.toAgentID.ToString();
117 
118  return dict;
119  }
120 
121  }
122 }
static GridInstantMessage GridInstantMessage(Dictionary< string, object > dict)
static Dictionary< string, object > GridInstantMessage(GridInstantMessage im)