Пример #1
0
 public void MarkAsRead(Account account)
 {
     if (account.id != this.owner.id)
     {
         throw new AccessDeniedException();
     }
     if (!this.isRead)
     {
         lock (MarkAsRead_locker) {
             //so we can safely decrease ReadPrivateMessages counter
             //Note that this code implicitly uses assumption of single-instance Common.dll; race condition is possible with more than one server
             if (!this.isRead)
             {
                 AccountIndicator indicator = AccountIndicator.LoadByAccount(this.owner);
                 ChangeSetUtil.ApplyChanges(
                     new UpdateChange(
                         TableSpec.instance,
                         new Dictionary <string, AbstractFieldValue> {
                     { TableSpec.FIELD_ISREAD, new ScalarFieldValue("1") },
                 },
                         this.id
                         ),
                     new UpdateChange(
                         AccountIndicator.TableSpec.instance,
                         new Dictionary <string, AbstractFieldValue> {
                     { AccountIndicator.TableSpec.FIELD_UNREADPRIVATEMESSAGES, new IncrementFieldValue(IncrementFieldValue.DECREMENTOR) },
                 },
                         indicator.id
                         )
                     );
             }
         }
     }
 }
Пример #2
0
 public XElement exportToXml(UserContext context)
 {
     return(new XElement("session",
                         new XElement("lastActivity", this.lastHumanActivity.ToXml()),
                         new XElement("sessionKey", this.sessionKey),
                         this.account.user.exportToXmlForViewing(context),
                         AccountIndicator.LoadByAccount(this.account).exportToXml(context)
                         ));
 }
Пример #3
0
        public static PMMessage SendPMMessage(Account sender, Account receiver, string title, string bodyUBB)
        {
            string         bodyIntermediate = UBBParser.UBBToIntermediate(bodyUBB);
            AbstractChange insertPmReceiver = new InsertChange(
                PMMessage.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { PMMessage.TableSpec.FIELD_OWNERID, new ScalarFieldValue(receiver.id.ToString()) },
                { PMMessage.TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(sender.id.ToString()) },
                { PMMessage.TableSpec.FIELD_DIRECTION, new ScalarFieldValue(PMMessage.ENUM_DIRECTION_INCOMING) },
                { PMMessage.TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { PMMessage.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { PMMessage.TableSpec.FIELD_BODY, new ScalarFieldValue(bodyIntermediate) },
                { PMMessage.TableSpec.FIELD_BODYUBB, new ScalarFieldValue(bodyUBB) },
                { PMMessage.TableSpec.FIELD_INCOMINGPMID, new ScalarFieldValue(null) },
                { PMMessage.TableSpec.FIELD_ISREAD, new ScalarFieldValue("0") },
            }
                );
            AbstractChange insertPmSender = new InsertChange(
                PMMessage.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { PMMessage.TableSpec.FIELD_OWNERID, new ScalarFieldValue(sender.id.ToString()) },
                { PMMessage.TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(receiver.id.ToString()) },
                { PMMessage.TableSpec.FIELD_DIRECTION, new ScalarFieldValue(PMMessage.ENUM_DIRECTION_OUTGOING) },
                { PMMessage.TableSpec.FIELD_POSTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { PMMessage.TableSpec.FIELD_TITLE, new ScalarFieldValue(title) },
                { PMMessage.TableSpec.FIELD_BODY, new ScalarFieldValue(bodyIntermediate) },
                { PMMessage.TableSpec.FIELD_BODYUBB, new ScalarFieldValue(bodyUBB) },
                { PMMessage.TableSpec.FIELD_INCOMINGPMID, new ReferenceFieldValue(insertPmReceiver) },
                { PMMessage.TableSpec.FIELD_ISREAD, new ScalarFieldValue("1") },
            }
                );
            AbstractChange updateConversationSender = new InsertOrUpdateChange(
                TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_OWNERID, new ScalarFieldValue(sender.id.ToString()) },
                { TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(receiver.id.ToString()) },
                { TableSpec.FIELD_TOTALMESSAGES, new ScalarFieldValue("1") },
                { TableSpec.FIELD_LASTMESSAGEID, new ReferenceFieldValue(insertPmSender) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { TableSpec.FIELD_LASTREADMESSAGEID, new ReferenceFieldValue(insertPmSender) },
            },
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_TOTALMESSAGES, new IncrementFieldValue() },
                { TableSpec.FIELD_LASTMESSAGEID, new TwoWayReferenceFieldValue(insertPmSender, TwoWayReferenceFieldValue.GREATEST) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
            },
                new ComplexCondition(
                    ConditionsJoinType.AND,
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_OWNERID),
                        ComparisonType.EQUAL,
                        sender.id.ToString()
                        ),
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_INTERLOCUTORID),
                        ComparisonType.EQUAL,
                        receiver.id.ToString()
                        )
                    )
                );
            AbstractChange updateConversationReceiver = new InsertOrUpdateChange(
                TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_OWNERID, new ScalarFieldValue(receiver.id.ToString()) },
                { TableSpec.FIELD_INTERLOCUTORID, new ScalarFieldValue(sender.id.ToString()) },
                { TableSpec.FIELD_TOTALMESSAGES, new ScalarFieldValue("1") },
                { TableSpec.FIELD_LASTMESSAGEID, new ReferenceFieldValue(insertPmReceiver) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
                { TableSpec.FIELD_LASTREADMESSAGEID, new ScalarFieldValue(null) },
            },
                new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_TOTALMESSAGES, new IncrementFieldValue() },
                { TableSpec.FIELD_LASTMESSAGEID, new TwoWayReferenceFieldValue(insertPmReceiver, TwoWayReferenceFieldValue.GREATEST) },
                { TableSpec.FIELD_LASTMESSAGEDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) },
            },
                new ComplexCondition(
                    ConditionsJoinType.AND,
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_OWNERID),
                        ComparisonType.EQUAL,
                        receiver.id.ToString()
                        ),
                    new ComparisonCondition(
                        TableSpec.instance.getColumnSpec(TableSpec.FIELD_INTERLOCUTORID),
                        ComparisonType.EQUAL,
                        sender.id.ToString()
                        )
                    )
                );
            AbstractChange updateIndicatorReceiver = new UpdateChange(
                AccountIndicator.TableSpec.instance,
                new Dictionary <string, AbstractFieldValue> {
                { AccountIndicator.TableSpec.FIELD_PRIVATEMESSAGES, new IncrementFieldValue() },
                { AccountIndicator.TableSpec.FIELD_UNREADPRIVATEMESSAGES, new IncrementFieldValue() },
            },
                AccountIndicator.LoadByAccount(receiver).id
                );

            ChangeSetUtil.ApplyChanges(
                insertPmReceiver,
                insertPmSender,
                updateConversationReceiver,
                updateConversationSender,
                updateIndicatorReceiver
                );
            return(PMMessage.LoadById(insertPmSender.getId().Value));
        }