1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright (c) 2003-2012 by AG-Software * 3 * All Rights Reserved. * 4 * Contact information for AG-Software is available at http://www.ag-software.de * 5 * * 6 * Licence: * 7 * The agsXMPP SDK is released under a dual licence * 8 * agsXMPP can be used under either of two licences * 9 * * 10 * A commercial licence which is probably the most appropriate for commercial * 11 * corporate use and closed source projects. * 12 * * 13 * The GNU Public License (GPL) is probably most appropriate for inclusion in * 14 * other open source projects. * 15 * * 16 * See README.html for details. * 17 * * 18 * For general enquiries visit our website at: * 19 * http://www.ag-software.de * 20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 21 22 using System; 23 24 namespace agsXMPP 25 { 26 public enum IdType 27 { 28 /// <summary> 29 /// Numeric Id's are generated by increasing a long value 30 /// </summary> 31 Numeric, 32 33 /// <summary> 34 /// Guid Id's are unique, Guid packet Id's should be used for server and component applications, 35 /// or apps which very long sessions (multiple days, weeks or years) 36 /// </summary> 37 Guid 38 } 39 40 /// <summary> 41 /// This class takes care anout out unique Message Ids 42 /// </summary> 43 public class Id 44 { Id()45 public Id() 46 { 47 } 48 49 private static long m_id = 0; 50 private static string m_Prefix = "agsXMPP_"; 51 private static IdType m_Type = IdType.Numeric; 52 53 public static IdType Type 54 { 55 get { return m_Type; } 56 #if !CF 57 // readyonly on CF1 58 set { m_Type = value; } 59 #endif 60 } 61 62 #if !CF GetNextId()63 public static string GetNextId() 64 { 65 if (m_Type == IdType.Numeric) 66 { 67 m_id++; 68 return m_Prefix + m_id.ToString(); 69 } 70 else 71 { 72 return m_Prefix + Guid.NewGuid().ToString(); 73 } 74 } 75 #else 76 77 // On CF 1.0 we have no GUID class, so only increasing numberical id's are supported 78 // We could create GUID's on CF 1.0 with the Crypto API if we want to. GetNextId()79 public static string GetNextId() 80 { 81 m_id++; 82 return m_Prefix + m_id.ToString(); 83 } 84 #endif 85 86 /// <summary> 87 /// Reset the id counter to agsXmpp_1 again 88 /// </summary> Reset()89 public static void Reset() 90 { 91 m_id = 0; 92 } 93 94 /// <summary> 95 /// to Save Bandwidth on Mobile devices you can change the prefix 96 /// null is also possible to optimize Bandwidth usage 97 /// </summary> 98 public static string Prefix 99 { 100 get { return m_Prefix; } 101 set 102 { 103 if (value == null) 104 m_Prefix = ""; 105 else 106 m_Prefix = value; 107 } 108 } 109 } 110 }