public bool TryAudit(ISession session, DataOperation op, ManagedSecurityContext sec)
        {
            if (SuppressAccountAudit)
            {
                return(false);
            }

            IList <AccountAuditEntry> audit_entries = CreateAccountAuditEntries(session, sec, op);

            if (audit_entries == null)
            {
                return(false);
            }

            foreach (AccountAuditEntry audit_entry in audit_entries)
            {
                audit_entry.Md5 = ManagedAccountAuditEntry.GetHash(audit_entry.Description);
                session.Save(audit_entry);
            }

            return(true);
        }
示例#2
0
        public int Update(ManagedSecurityContext sec)
        {
            GetACL().Check(sec, DataOperation.Update);

            mInstance.Updated = DateTime.UtcNow;

            IList <AccountFeedItem> deleted = mInstance.AccountFeedItems;
            List <AccountFeedItem>  updated = new List <AccountFeedItem>();

            bool fUpdated = Update(RssFeed.Read(GetFeedStream()), deleted, updated);

            if (!fUpdated)
            {
                fUpdated = Update(AtomFeed.Load(GetFeedStream(),
                                                new Uri("http://www.w3.org/2005/Atom")), deleted, updated);
            }

            if (!fUpdated)
            {
                fUpdated = Update(AtomFeed.Load(GetFeedStream(),
                                                new Uri("http://purl.org/atom/ns#")), deleted, updated);
            }

            if (!fUpdated)
            {
                throw new Exception("Invalid or empty RSS or ATOM feed.");
            }

            try
            {
                if (deleted != null)
                {
                    foreach (AccountFeedItem item in deleted)
                    {
                        ManagedAccountFeedItem m_item = new ManagedAccountFeedItem(Session, item);
                        m_item.Delete(sec);
                    }
                }

                // group items for auditing
                ManagedAccountAuditEntryCollection audit_coll = new ManagedAccountAuditEntryCollection();
                audit_coll.MessageFormat = string.Format("[user:{0}] x-posted {{0}} in [feed:{1}]",
                                                         mInstance.Account.Id, mInstance.Id);

                for (int i = 0; i < updated.Count; i++)
                {
                    AccountFeedItem item = updated[i];
                    DataOperation   op   = (item.Id == 0 ? DataOperation.Create : DataOperation.Update);
                    Session.Save(item);
                    if (op == DataOperation.Create)
                    {
                        string url   = string.Format("AccountFeedItemView.aspx?id={0}", item.Id);
                        string trace = string.Format("<a href=\"{0}\">{1}</a>", url, Renderer.Render(item.Title));
                        audit_coll.Add(trace);
                    }
                }

                IEnumerable <AccountAuditEntry> audit_entries = audit_coll.GetAccountAuditEntries(
                    Session, mInstance.Account, string.Format("AccountFeedView.aspx?id={0}", mInstance.Id));

                foreach (AccountAuditEntry entry in audit_entries)
                {
                    entry.Created = entry.Updated = mInstance.Updated;
                    entry.Md5     = ManagedAccountAuditEntry.GetHash(entry.Description);
                    Session.Save(entry);
                }

                mInstance.AccountFeedItems = updated;
                mInstance.LastError        = string.Empty;
                Session.Save(mInstance);
            }
            catch (Exception ex)
            {
                mInstance.LastError = ex.Message;
                Session.Save(mInstance);
                throw;
            }

            return(updated.Count);
        }