/// <summary>
 /// <see cref="UserGroupMember.UserGroupRef" /> is not initialized when the entity is created. Clients could call this method to load it provided a proper delegate <see cref="UserGroupMember.DelLoadUserGroupRef" /> was setup
 /// before calling it.
 /// </summary>
 public void LoadUserGroupRef()
 {
     if (_UserGroupRef != null)
         return;
     if (DelLoadUserGroupRef != null)
         _UserGroupRef = DelLoadUserGroupRef();
 }
Пример #2
0
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers.
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityTheSame(UserGroup other)
 {
     if (other == null)
         return false;
     else
         return ID == other.ID;
 }              
Пример #3
0
 /// <summary>
 /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />.
 /// </summary>
 /// <param name="from">The "old" entity acting as merging source.</param>
 /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param>
 /// <returns>
 /// </returns>
 public static void MergeChanges(UserGroup from, UserGroup to)
 {
     if (to.IsPersisted)
     {
         if (from.IsGroupDescriptionModified && !to.IsGroupDescriptionModified)
         {
             to.GroupDescription = from.GroupDescription;
             to.IsGroupDescriptionModified = true;
         }
         if (from.IsGroupNameModified && !to.IsGroupNameModified)
         {
             to.GroupName = from.GroupName;
             to.IsGroupNameModified = true;
         }
         if (from.IsGroupPassphraseModified && !to.IsGroupPassphraseModified)
         {
             to.GroupPassphrase = from.GroupPassphrase;
             to.IsGroupPassphraseModified = true;
         }
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.ID = from.ID;
         to.GroupDescription = from.GroupDescription;
         to.IsGroupDescriptionModified = from.IsGroupDescriptionModified;
         to.GroupName = from.GroupName;
         to.IsGroupNameModified = from.IsGroupNameModified;
         to.GroupPassphrase = from.GroupPassphrase;
         to.IsGroupPassphraseModified = from.IsGroupPassphraseModified;
         to.ApplicationID = from.ApplicationID;
         to.GroupTypeID = from.GroupTypeID;
         to.ParentID = from.ParentID;
     }
 }
Пример #4
0
 /// <summary>
 /// <see cref="UserGroup.UpperRef" /> is not initialized when the entity is created. Clients could call this method to load it provided a proper delegate <see cref="UserGroup.DelLoadUpperRef" /> was setup
 /// before calling it.
 /// </summary>
 public void LoadUpperRef()
 {
     if (ParentID == null || _UpperRef != null)
         return;
     if (DelLoadUpperRef != null)
         _UpperRef = DelLoadUpperRef();
 }
Пример #5
0
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s).
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityIdentical(UserGroup other)
 {
     if (other == null)
         return false;
     if (ID != other.ID)
         return false;
     return true;
 }              
Пример #6
0
 /// <summary>
 /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating.
 /// </summary>
 /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param>
 /// <returns>
 /// </returns>
 public void UpdateChanges(UserGroup newdata)
 {
     int cnt = 0;
     if (GroupDescription != newdata.GroupDescription)
     {
         GroupDescription = newdata.GroupDescription;
         IsGroupDescriptionModified = true;
         cnt++;
     }
     if (GroupName != newdata.GroupName)
     {
         GroupName = newdata.GroupName;
         IsGroupNameModified = true;
         cnt++;
     }
     if (GroupPassphrase != newdata.GroupPassphrase)
     {
         GroupPassphrase = newdata.GroupPassphrase;
         IsGroupPassphraseModified = true;
         cnt++;
     }
     IsEntityChanged = cnt > 0;
 }
Пример #7
0
 /// <summary>
 /// Internal use
 /// </summary>
 public UserGroup ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false)
 {
     UserGroup e = new UserGroup();
     e.StartAutoUpdating = false;
     e.ID = ID;
     e.GroupName = GroupName;
     if (preserveState)
         e.IsGroupNameModified = IsGroupNameModified;
     else
         e.IsGroupNameModified = false;
     e.GroupPassphrase = GroupPassphrase;
     if (preserveState)
         e.IsGroupPassphraseModified = IsGroupPassphraseModified;
     else
         e.IsGroupPassphraseModified = false;
     e.ApplicationID = ApplicationID;
     e.GroupTypeID = GroupTypeID;
     e.ParentID = ParentID;
     if (allData)
     {
         if (!checkLoadState || IsGroupDescriptionLoaded)
             e.GroupDescription = GroupDescription;
         if (preserveState)
             e.IsGroupDescriptionModified = IsGroupDescriptionModified;
         else
             e.IsGroupDescriptionModified = false;
         e.IsGroupDescriptionLoaded = IsGroupDescriptionLoaded;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = IsPersisted;
     if (preserveState)
         e.IsEntityChanged = IsEntityChanged;
     else
         e.IsEntityChanged = false;
     e.StartAutoUpdating = true;
     return e;
 }
Пример #8
0
 /// <summary>
 /// Internal use
 /// </summary>
 public UserGroup ShallowCopy(bool allData = false)
 {
     UserGroup e = new UserGroup();
     e.IsInitializing = true;
     e.ID = ID;
     e.GroupName = GroupName;
     e.GroupTypeID = GroupTypeID;
     e.ParentID = ParentID;
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = true;
     e.IsEntityChanged = false;
     e.IsInitializing = false;
     return e;
 }
Пример #9
0
 /// <summary>
 /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating.
 /// </summary>
 /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param>
 /// <returns>
 /// </returns>
 public void UpdateChanges(UserGroup newdata)
 {
     int cnt = 0;
     if (GroupName != newdata.GroupName)
     {
         GroupName = newdata.GroupName;
         IsGroupNameModified = true;
         cnt++;
     }
     IsEntityChanged = cnt > 0;
 }
Пример #10
0
 /// <summary>
 /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />.
 /// </summary>
 /// <param name="from">The "old" entity acting as merging source.</param>
 /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param>
 /// <returns>
 /// </returns>
 public static void MergeChanges(UserGroup from, UserGroup to)
 {
     if (to.IsPersisted)
     {
         if (from.IsGroupNameModified && !to.IsGroupNameModified)
         {
             to.GroupName = from.GroupName;
             to.IsGroupNameModified = true;
         }
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.ID = from.ID;
         to.GroupName = from.GroupName;
         to.IsGroupNameModified = from.IsGroupNameModified;
         to.GroupTypeID = from.GroupTypeID;
         to.ParentID = from.ParentID;
     }
 }
 public static string GetJsonMessage(ShortMessage msg, string userId, UserGroup g, bool dialog, string matchId = null)
 {
     string json = "{ ";
     json += @"""id"": """ + msg.ID + @""", ";
     json += @"""from"": " + GetJsonUser(msg.User_FromID) + @", ";
     json += @"""groupNodes"": [ ";
     string grp = "";
     string path = "";
     foreach (var gn in g.DistinctString.Split('/'))
     {
         if (gn.Trim().Length > 0)
         {
             path += (path == "" ? "" : "/") + gn;
             grp += @"{ ""name"": """ + gn + @""", ""path"": """ + path + @""" }, ";
         }
     }
     if (grp != "")
         json += grp.TrimEnd(" ,".ToCharArray()) + " ";
     json +=  "], ";
     json += @"""groupId"": """ + g.ID + @""", ";
     json += @"""replyToId"": """ + (msg.ReplyToID == null ? "" : msg.ReplyToID) + @""", ";
     json += @"""date"": " + GroupChatContext.getUnixJsonTime(msg.CreatedDate) + @", ";
     json += @"""self"": " + (msg.FromID == userId ? "true" : "false") + @", ";
     json += @"""lead"": """ + GroupChatContext.GetLeadText(msg.MsgText).Replace("\"", "\\\"") + @""", ";
     json += @"""text"": """ + msg.MsgText.Replace("\"", "\\\"") + @""", ";
     json += @"""isMatch"": " + (matchId == msg.ID ? "true" : "false") + ", ";
     json += @"""score"": ";
     if (msg.ChangedShortMessageAudiences != null)
     {
         int cnt = 0;
         foreach (var v in msg.ChangedShortMessageAudiences)
             cnt += v.VoteCount;
         json += cnt;
     }
     else
         json += "0";
     if (dialog)
     {
         json += @", ""replies"": [ ";
         if (msg.ChangedShortMessages != null)
         {
             string subjson = "";
             foreach (var r in from d in msg.ChangedShortMessages orderby d.CreatedDate ascending select d)
                 subjson += GetJsonMessage(r, userId, g, true, matchId) + ", ";
             json += subjson.TrimEnd(" ,".ToCharArray()) + " ";
         }
         json += "]";
     }
     json += " }";
     return json;
 }
 public static string GetJsonMessage(ShortMessage msg, string userId, UserGroup g, bool dialog)
 {
     string json = "{ ";
     json += @"""id"": """ + msg.ID + @""", ";
     json += @"""from"": """ + msg.User_FromID.Username + @""", ";
     json += @"""fromId"": """ + msg.FromID + @""", ";
     json += @"""group"": """ + g.DistinctString + @""", ";
     json += @"""groupId"": """ + g.ID + @""", ";
     json += @"""replyToId"": """ + (msg.ReplyToID == null ? "" : msg.ReplyToID) + @""", ";
     json += @"""date"": " + getUnixJsonTime(msg.CreatedDate) + @", ";
     json += @"""self"": " + (msg.FromID == userId ? "true" : "false") + @", ";
     json += @"""lead"": """ + GetLeadText(msg.MsgText).Replace("\"", "\\\"") + @""", ";
     json += @"""text"": """ + msg.MsgText.Replace("\"", "\\\"") + @""", ";
     json += @"""score"": ";
     if (msg.ChangedShortMessageAudiences != null)
     {
         int cnt = 0;
         foreach (var v in msg.ChangedShortMessageAudiences)
             cnt += v.VoteCount;
         json += cnt;
     }
     else
         json += "0";
     if (dialog)
     {
         json += @", ""replies"": [ ";
         if (msg.ChangedShortMessages != null)
         {
             string subjson = "";
             foreach (var r in from d in msg.ChangedShortMessages orderby d.CreatedDate ascending select d)
                 subjson += GetJsonMessage(r, userId, g, true) + ", ";
             json += subjson.TrimEnd(" ,".ToCharArray());
         }
         json += " ]";
     }
     json += " }";
     return json;
 }