Exemplo n.º 1
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(UserGroupMember from, UserGroupMember to)
 {
     if (to.IsPersisted)
     {
         if (from.IsAccessDeniedModified && !to.IsAccessDeniedModified)
         {
             to.AccessDenied           = from.AccessDenied;
             to.IsAccessDeniedModified = true;
         }
         if (from.IsActivityNotificationModified && !to.IsActivityNotificationModified)
         {
             to.ActivityNotification           = from.ActivityNotification;
             to.IsActivityNotificationModified = true;
         }
         if (from.IsSubscribedToModified && !to.IsSubscribedToModified)
         {
             to.SubscribedTo           = from.SubscribedTo;
             to.IsSubscribedToModified = true;
         }
     }
     else
     {
         to.IsPersisted                    = from.IsPersisted;
         to.UserGroupID                    = from.UserGroupID;
         to.UserID                         = from.UserID;
         to.AccessDenied                   = from.AccessDenied;
         to.IsAccessDeniedModified         = from.IsAccessDeniedModified;
         to.ActivityNotification           = from.ActivityNotification;
         to.IsActivityNotificationModified = from.IsActivityNotificationModified;
         to.SubscribedTo                   = from.SubscribedTo;
         to.IsSubscribedToModified         = from.IsSubscribedToModified;
     }
 }
Exemplo n.º 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(UserGroupMember other)
 {
     if (other == null)
     {
         return(false);
     }
     else
     {
         return(UserGroupID == other.UserGroupID && UserID == other.UserID);
     }
 }
Exemplo n.º 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(UserGroupMember from, UserGroupMember to)
 {
     if (to.IsPersisted)
     {
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.UserGroupID = from.UserGroupID;
         to.UserID      = from.UserID;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Internal use
        /// </summary>
        public UserGroupMember ShallowCopy(bool allData = false)
        {
            UserGroupMember e = new UserGroupMember();

            e.IsInitializing  = true;
            e.UserGroupID     = UserGroupID;
            e.UserID          = UserID;
            e.DistinctString  = GetDistinctString(true);
            e.IsPersisted     = true;
            e.IsEntityChanged = false;
            e.IsInitializing  = false;
            return(e);
        }
Exemplo n.º 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(UserGroupMember other)
 {
     if (other == null)
     {
         return(false);
     }
     if (UserGroupID != other.UserGroupID)
     {
         return(false);
     }
     if (UserID != other.UserID)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Internal use
        /// </summary>
        public UserGroupMember ShallowCopy(bool allData = false, bool preserveState = false)
        {
            UserGroupMember e = new UserGroupMember();

            e.StartAutoUpdating = false;
            e.UserGroupID       = UserGroupID;
            e.UserID            = UserID;
            e.AccessDenied      = AccessDenied;
            if (preserveState)
            {
                e.IsAccessDeniedModified = IsAccessDeniedModified;
            }
            else
            {
                e.IsAccessDeniedModified = false;
            }
            e.ActivityNotification = ActivityNotification;
            if (preserveState)
            {
                e.IsActivityNotificationModified = IsActivityNotificationModified;
            }
            else
            {
                e.IsActivityNotificationModified = false;
            }
            e.SubscribedTo = SubscribedTo;
            if (preserveState)
            {
                e.IsSubscribedToModified = IsSubscribedToModified;
            }
            else
            {
                e.IsSubscribedToModified = false;
            }
            e.DistinctString = GetDistinctString(true);
            e.IsPersisted    = IsPersisted;
            if (preserveState)
            {
                e.IsEntityChanged = IsEntityChanged;
            }
            else
            {
                e.IsEntityChanged = false;
            }
            e.StartAutoUpdating = true;
            return(e);
        }
Exemplo n.º 7
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(UserGroupMember newdata)
        {
            int cnt = 0;

            if (AccessDenied != newdata.AccessDenied)
            {
                AccessDenied           = newdata.AccessDenied;
                IsAccessDeniedModified = true;
                cnt++;
            }
            if (ActivityNotification != newdata.ActivityNotification)
            {
                ActivityNotification           = newdata.ActivityNotification;
                IsActivityNotificationModified = true;
                cnt++;
            }
            if (SubscribedTo != newdata.SubscribedTo)
            {
                SubscribedTo           = newdata.SubscribedTo;
                IsSubscribedToModified = true;
                cnt++;
            }
            IsEntityChanged = cnt > 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(UserGroupMember from, UserGroupMember to)
 {
     if (to.IsPersisted)
     {
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.UserGroupID = from.UserGroupID;
         to.UserID = from.UserID;
     }
 }
 /// <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(UserGroupMember other)
 {
     if (other == null)
         return false;
     else
         return UserGroupID == other.UserGroupID &&  UserID == other.UserID;
 }              
Exemplo n.º 10
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(UserGroupMember other)
 {
     if (other == null)
         return false;
     if (UserGroupID != other.UserGroupID)
         return false;
     if (UserID != other.UserID)
         return false;
     return true;
 }              
 /// <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(UserGroupMember from, UserGroupMember to)
 {
     if (to.IsPersisted)
     {
         if (from.IsAccessDeniedModified && !to.IsAccessDeniedModified)
         {
             to.AccessDenied = from.AccessDenied;
             to.IsAccessDeniedModified = true;
         }
         if (from.IsActivityNotificationModified && !to.IsActivityNotificationModified)
         {
             to.ActivityNotification = from.ActivityNotification;
             to.IsActivityNotificationModified = true;
         }
         if (from.IsSubscribedToModified && !to.IsSubscribedToModified)
         {
             to.SubscribedTo = from.SubscribedTo;
             to.IsSubscribedToModified = true;
         }
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.UserGroupID = from.UserGroupID;
         to.UserID = from.UserID;
         to.AccessDenied = from.AccessDenied;
         to.IsAccessDeniedModified = from.IsAccessDeniedModified;
         to.ActivityNotification = from.ActivityNotification;
         to.IsActivityNotificationModified = from.IsActivityNotificationModified;
         to.SubscribedTo = from.SubscribedTo;
         to.IsSubscribedToModified = from.IsSubscribedToModified;
     }
 }
 public static async Task<dynamic> Unsubscribe(string userId, string groupId)
 {
     var cntx = Cntx;
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
     if (uig != null && (!uig.SubscribedTo.HasValue || !uig.SubscribedTo.Value))
         return new { ok = false, msg = ResourceUtils.GetString("735f81aa93cc3430592d2cc2a57b1cd7", "You are not a subscriber yet!") };
     if (uig == null)
     {
         uig = new UserGroupMember
         {
             UserID = userId,
             UserGroupID = groupId,
             SubscribedTo = false,
             ActivityNotification = false
         };
     }
     else
         uig.SubscribedTo = false;
     await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
     return new { ok = true, msg = "" };
 }
 public static async Task<dynamic> Subscribe(string userId, string groupId)
 {
     var cntx = Cntx;
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
     if (uig != null && uig.SubscribedTo.HasValue && uig.SubscribedTo.Value)
         return new { ok = false, msg = ResourceUtils.GetString("73cca337310dc88725934ac22120ffaf", "You are already a subscriber!") };
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>();
     qexpr.OrderTks.Add(new QToken { TkName = "UserGroupID" });
     qexpr.FilterTks = new List<QToken>();
     qexpr.FilterTks.Add(new QToken
     {
         TkName = "UserID == \"" + userId + "\" && SubscribedTo is not null && SubscribedTo == true"
     });
     var uigs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);
     if (uigs.Count() >= MaxSubscriptions)
     {
         return new
         {
             ok = false,
             msg = ResourceUtils.GetString("06200770094b57284bc7b16e0c7ea274", "You number of subscriptions exeeds the allowed limit, please unsubscribe from some of the existing ones first.")
         };
     }
     if (uig == null)
     {
         uig = new UserGroupMember
         {
             UserID = userId,
             UserGroupID = groupId,
             SubscribedTo = true,
             ActivityNotification = false
         };
     }
     else
         uig.SubscribedTo = true;
     await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
     return new { ok = true, msg = "" };
 }
Exemplo n.º 14
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(UserGroupMember newdata)
 {
     int cnt = 0;
     IsEntityChanged = cnt > 0;
 }
Exemplo n.º 15
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(UserGroupMember newdata)
        {
            int cnt = 0;

            IsEntityChanged = cnt > 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(UserGroupMember newdata)
 {
     int cnt = 0;
     if (AccessDenied != newdata.AccessDenied)
     {
         AccessDenied = newdata.AccessDenied;
         IsAccessDeniedModified = true;
         cnt++;
     }
     if (ActivityNotification != newdata.ActivityNotification)
     {
         ActivityNotification = newdata.ActivityNotification;
         IsActivityNotificationModified = true;
         cnt++;
     }
     if (SubscribedTo != newdata.SubscribedTo)
     {
         SubscribedTo = newdata.SubscribedTo;
         IsSubscribedToModified = true;
         cnt++;
     }
     IsEntityChanged = cnt > 0;
 }
 /// <summary>
 /// Internal use
 /// </summary>
 public UserGroupMember ShallowCopy(bool allData = false, bool preserveState = false)
 {
     UserGroupMember e = new UserGroupMember();
     e.StartAutoUpdating = false;
     e.UserGroupID = UserGroupID;
     e.UserID = UserID;
     e.AccessDenied = AccessDenied;
     if (preserveState)
         e.IsAccessDeniedModified = IsAccessDeniedModified;
     else
         e.IsAccessDeniedModified = false;
     e.ActivityNotification = ActivityNotification;
     if (preserveState)
         e.IsActivityNotificationModified = IsActivityNotificationModified;
     else
         e.IsActivityNotificationModified = false;
     e.SubscribedTo = SubscribedTo;
     if (preserveState)
         e.IsSubscribedToModified = IsSubscribedToModified;
     else
         e.IsSubscribedToModified = false;
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = IsPersisted;
     if (preserveState)
         e.IsEntityChanged = IsEntityChanged;
     else
         e.IsEntityChanged = false;
     e.StartAutoUpdating = true;
     return e;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Internal use
 /// </summary>
 public UserGroupMember ShallowCopy(bool allData = false)
 {
     UserGroupMember e = new UserGroupMember();
     e.IsInitializing = true;
     e.UserGroupID = UserGroupID;
     e.UserID = UserID;
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = true;
     e.IsEntityChanged = false;
     e.IsInitializing = false;
     return e;
 }
 public static async Task<ChatRoomVM> LoadChatRoom(string hubId, string groupId, string userId, int maxMessages, bool dialog = false)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var cntx = Cntx;
     ChatRoomVM m = new ChatRoomVM() { RoomExists = false, DialogMode = dialog };
     if (!string.IsNullOrEmpty(groupId))
     {
         var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);
         if (g != null)
         {
             m.RoomExists = true;
             m.ID = groupId;
             m.RoomPath = g.DistinctString.Split('/');
             m.RoomInfo = await gsvc.LoadEntityGroupDescriptionAsync(cntx, g.ID);
             UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy();
             UserGroupMember uig = await gmsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
             if (uig == null)
             {
                 uig = new UserGroupMember
                 {
                     UserID = userId,
                     UserGroupID = groupId,
                     SubscribedTo = false,
                     ActivityNotification = false
                 };
                 await gmsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
             }
             cntx.DirectDataAccess = true;
             MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy();
             var qexpr = getConnectedGroupMemberFilter(hubId, g.ID);
             var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray();
             List<string> jsonPeers = new List<string>();
             if (peers.Length > 0)
             {
                 for (int i = 0; i < peers.Length; i++)
                 {
                     // retrieve the related entity graph
                     peers[i] = await cbsv.LoadEntityGraphRecursAsync(cntx, groupId, hubId, AppId, peers[i].UserID, null, null);
                     jsonPeers.Add(GetJsonPeer(peers[i]));
                 }
             }
             m.ActivePeers = jsonPeers.ToArray();
             cntx.DirectDataAccess = false;
             ShortMessageServiceProxy msgsvc = new ShortMessageServiceProxy();
             var cond = new ShortMessageSetConstraints
             {
                 ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId },
                 TypeIDWrap = new ForeignKeyData<int> { KeyValue = ApplicationContext.ChatShortMsgTypeId },
                 GroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId }
             };
             UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserID" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserGroupID == \"" + g.ID + "\" && SubscribedTo is not null && SubscribedTo == true"  }
             });
             m.Subscribers = (int)(await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr));
             var svc = new MembershipPlusServiceProxy();
             DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow);
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "CreatedDate" },
                 new QToken { TkName = "desc" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] {
                 new QToken { TkName = "ToID is null && CreatedDate > " + svc.FormatRepoDateTime(dt) }
             });
             if (dialog)
             {
                 qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" });
             }
             var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray();
             List<string> jsonMsgs = new List<string>();
             if (msgs.Length > 0)
             {
                 for (int i = msgs.Length - 1; i >= 0; i--)
                 {
                     EntitySetType[] excludes;
                     if (dialog)
                     {
                         excludes = new EntitySetType[]
                         {
                             EntitySetType.UserGroup,
                             //EntitySetType.ShortMessageAudience,
                             EntitySetType.ShortMessageAttachment
                         };
                     }
                     else
                     {
                         excludes = new EntitySetType[]
                         {
                             EntitySetType.UserGroup,
                             //EntitySetType.ShortMessageAudience,
                             EntitySetType.ShortMessageAttachment,
                             EntitySetType.ShortMessage
                         };
                     }
                     msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null);
                     jsonMsgs.Add(GetJsonMessage(msgs[i], userId, g, dialog));
                 }
             }
             m.RecentMsgs = jsonMsgs.ToArray();
         }
     }
     return m;
 }