Пример #1
0
        public override TransitAccountActivity GetTransitInstance(ManagedSecurityContext sec)
        {
            TransitAccountActivity t_instance = base.GetTransitInstance(sec);

            DateTime limit = DateTime.UtcNow.AddDays(-14);

            // new photos (count one week of photos)

            t_instance.NewPictures = Session.CreateQuery(string.Format("SELECT COUNT(*) FROM AccountPicture p " +
                                                                       "WHERE p.Account.Id = {0} AND p.Modified > '{1}' AND p.Hidden = 0",
                                                                       mInstance.Id, limit.ToString(DateTimeFormatInfo.InvariantInfo)))
                                     .UniqueResult <int>();

            t_instance.NewDiscussionPosts = Session.CreateQuery(string.Format("SELECT COUNT(*) FROM DiscussionPost p, Discussion d, DiscussionThread t " +
                                                                              "WHERE p.AccountId = {0} AND p.Modified > '{1}' AND p.DiscussionThread.Id = t.Id and t.Discussion.Id = d.Id AND d.Personal = 0",
                                                                              mInstance.Id, limit.ToString(DateTimeFormatInfo.InvariantInfo)))
                                            .UniqueResult <int>();

            t_instance.NewSyndicatedContent = Session.CreateQuery(string.Format("SELECT COUNT(*) FROM AccountFeed f " +
                                                                                "WHERE f.Account.Id = {0} AND f.Created > '{1}'",
                                                                                mInstance.Id, limit.ToString(DateTimeFormatInfo.InvariantInfo)))
                                              .UniqueResult <int>();

            t_instance.NewFriends = Session.CreateQuery(string.Format("SELECT COUNT(*) FROM AccountFriend f " +
                                                                      "WHERE (f.Account.Id = {0} OR f.Keen.Id = {0}) AND (f.Created > '{1}')",
                                                                      mInstance.Id, limit.ToString(DateTimeFormatInfo.InvariantInfo)))
                                    .UniqueResult <int>();

            return(t_instance);
        }
Пример #2
0
 public void DeleteRecepients(ManagedSecurityContext sec)
 {
     GetACL().Check(sec, DataOperation.Update);
     Session.Delete(string.Format(
                        "FROM CampaignAccountRecepient CampaignAccountRecepient WHERE CampaignAccountRecepient.Campaign.Id = {0}",
                        mInstance.Id));
 }
Пример #3
0
        protected override void Check(TransitAccountMessage t_instance, ManagedSecurityContext sec)
        {
            base.Check(t_instance, sec);

            // existing instance doesn't need to be rechecked
            if (t_instance.Id != 0)
            {
                return;
            }

            // verified e-mail required
            sec.CheckVerified();

            // is the sender a friend of the receiver?
            int            sender_id = t_instance.GetOwner(Session, t_instance.SenderAccountId, sec).Id;
            ManagedAccount sender    = new ManagedAccount(Session, sender_id);

            if (sender.HasFriend(t_instance.RecepientAccountId))
            {
                return;
            }

            // how many messages within the last hour?
            new ManagedQuota(DefaultHourlyLimit).Check <AccountMessage, ManagedAccount.QuotaExceededException>(
                GetAcountMessages(Session, sender_id, DateTime.UtcNow.AddHours(-1)));
            // how many messages within the last 24 hours?
            ManagedQuota.GetDefaultEnabledQuota().Check <AccountMessage, ManagedAccount.QuotaExceededException>(
                GetAcountMessages(Session, sender_id, DateTime.UtcNow.AddDays(-1)));

            // check whether the sender was flagged
            new ManagedQuota(ManagedAccountFlag.DefaultAccountFlagThreshold).Check <AccountFlag, ManagedAccountFlag.AccountFlaggedException>(
                ManagedAccountFlag.GetAccountFlagsByFlaggedAccountId(Session, sender_id));
        }
Пример #4
0
 public void Check(ManagedSecurityContext sec, DataOperation op)
 {
     if (!TryCheck(sec, op))
     {
         throw new ManagedAccount.AccessDeniedException();
     }
 }
Пример #5
0
        public override PlaceChangeRequest GetInstance(ISession session, ManagedSecurityContext sec)
        {
            PlaceChangeRequest instance = base.GetInstance(session, sec);

            instance.Name        = this.Name;
            instance.Type        = ManagedPlaceType.Find(session, this.Type);
            instance.Description = this.Description;
            instance.Street      = this.Street;
            instance.Zip         = this.Zip;
            instance.CrossStreet = this.CrossStreet;
            instance.Phone       = this.Phone;
            instance.Fax         = this.Fax;
            instance.Email       = this.Email;
            if (Id == 0)
            {
                instance.Account = GetOwner(session, AccountId, sec);
            }
            instance.City = (!string.IsNullOrEmpty(City))
                ? ManagedCity.FindOrCreate(session, City, State, Country)
                : null;
            instance.Neighborhood = (!string.IsNullOrEmpty(Neighborhood) && !string.IsNullOrEmpty(City))
                ? ManagedNeighborhood.FindOrCreate(session, Neighborhood, City, State, Country)
                : null;
            if (Id == 0)
            {
                instance.Place = session.Load <Place>(PlaceId);
            }
            return(instance);
        }
Пример #6
0
        public override DataObject GetInstance(ISession session, ManagedSecurityContext sec)
        {
            DataObject instance = base.GetInstance(session, sec);

            instance.Name = this.Name;
            return(instance);
        }
Пример #7
0
        public static Discussion Find(
            ISession session,
            int accountid,
            Type type,
            int objectid,
            ManagedSecurityContext sec)
        {
            DataObject dataobject = ManagedDataObject.FindObject(session, type);

            Discussion instance = (Discussion)
                                  session.CreateCriteria(typeof(Discussion))
                                  .Add(Expression.Eq("DataObject.Id", dataobject.Id))
                                  .Add(Expression.Eq("Account.Id", accountid))
                                  .Add(Expression.Eq("ObjectId", objectid))
                                  .Add(Expression.Eq("Personal", true))
                                  .SetMaxResults(1)
                                  .UniqueResult();

            if (instance == null)
            {
                return(null);
            }

            ManagedDiscussion m_instance = new ManagedDiscussion(session, instance);

            m_instance.GetACL().Check(sec, DataOperation.Retreive);
            return(instance);
        }
Пример #8
0
        private static int GetOrCreateDiscussionId(
            ISession session,
            int accountid,
            Type type,
            int objectid,
            ManagedSecurityContext sec)
        {
            Discussion d = Find(session, accountid, type, objectid, sec);

            if (d != null)
            {
                return(d.Id);
            }

            ManagedDiscussionMapEntry mapentry = ManagedDiscussionMap.Find(type);

            TransitDiscussion td = new TransitDiscussion();

            td.AccountId    = accountid;
            td.Name         = mapentry.Name;
            td.Personal     = true;
            td.Description  = string.Empty;
            td.Created      = td.Modified = DateTime.UtcNow;
            td.ObjectId     = objectid;
            td.DataObjectId = ManagedDataObject.Find(session, type);

            // creating a discussion that belongs to a different user (commenting on someone's items)
            ManagedDiscussion      m_d   = new ManagedDiscussion(session);
            ManagedSecurityContext o_sec = new ManagedSecurityContext(session, accountid);

            return(m_d.CreateOrUpdate(td, o_sec));
        }
Пример #9
0
        public void Accept(ManagedSecurityContext sec, string message)
        {
            GetACL().Check(sec, DataOperation.Delete);

            AccountPlace place = new AccountPlace();

            place.Account     = mInstance.Account;
            place.Place       = mInstance.Place;
            place.Created     = place.Modified = DateTime.UtcNow;
            place.Type        = mInstance.Type;
            place.Description = string.Format("System-approved on {0}.", DateTime.UtcNow.ToString());
            Session.Save(place);

            if (mInstance.Account.AccountPlaces == null)
            {
                mInstance.Account.AccountPlaces = new List <AccountPlace>();
            }
            mInstance.Account.AccountPlaces.Add(place);

            if (mInstance.Place.AccountPlaces == null)
            {
                mInstance.Place.AccountPlaces = new List <AccountPlace>();
            }
            mInstance.Place.AccountPlaces.Add(place);

            ManagedAccount recepient = new ManagedAccount(Session, mInstance.Account);

            ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(Session, recepient,
                                                                      string.Format("EmailAccountPlaceRequestAccept.aspx?id={0}&message={1}", this.Id, Renderer.UrlEncode(message)));

            // delete the request when user notified
            Collection <AccountPlaceRequest> .GetSafeCollection(mInstance.Account.AccountPlaceRequests).Remove(mInstance);

            Session.Delete(mInstance);
        }
Пример #10
0
        public override Discussion GetInstance(ISession session, ManagedSecurityContext sec)
        {
            Discussion instance = base.GetInstance(session, sec);

            if (Id == 0)
            {
                instance.Account  = GetOwner(session, AccountId, sec);
                instance.Personal = this.Personal;
                instance.ObjectId = this.ObjectId;
                if (this.ObjectId != 0)
                {
                    if (this.DataObjectId != 0)
                    {
                        instance.DataObject = session.Load <DataObject>(this.DataObjectId);
                    }
                    else if (!string.IsNullOrEmpty(this.ParentObjectType))
                    {
                        instance.DataObject = ManagedDataObject.FindObject(session, this.ParentObjectType);
                    }
                }
            }

            instance.Name            = this.Name;
            instance.Description     = this.Description;
            instance.DefaultView     = this.DefaultView;
            instance.DefaultViewRows = this.DefaultViewRows;
            return(instance);
        }
Пример #11
0
        public void Move(ManagedSecurityContext sec, int disp)
        {
            GetACL().Check(sec, DataOperation.Update);
            ManagedPictureServiceImpl <PlacePicture> .Move(Session, mInstance, mInstance.Place.PlacePictures, disp);

            Session.Flush();
        }
Пример #12
0
        public override PlaceAttribute GetInstance(ISession session, ManagedSecurityContext sec)
        {
            PlaceAttribute instance = base.GetInstance(session, sec);

            instance.Url   = Url;
            instance.Value = Value;

            if (Id == 0)
            {
                if (PlaceId > 0)
                {
                    instance.Place = session.Load <Place>(PlaceId);
                }
                if (AttributeId > 0)
                {
                    instance.Attribute = session.Load <Attribute>(AttributeId);
                }
            }
            else
            {
                if (AttributeId != instance.Attribute.Id)
                {
                    throw new InvalidOperationException();
                }

                if (PlaceId != instance.Place.Id)
                {
                    throw new InvalidOperationException();
                }
            }

            return(instance);
        }
Пример #13
0
        public override void Delete(ManagedSecurityContext sec)
        {
            ManagedDiscussion.FindAndDelete(Session, mInstance.Place.Account.Id, typeof(PlacePicture), mInstance.Id, sec);
            ManagedPictureServiceImpl <PlacePicture> .Delete(Session, mInstance, mInstance.Place.PlacePictures);

            base.Delete(sec);
        }
Пример #14
0
        public override BugType GetInstance(ISession session, ManagedSecurityContext sec)
        {
            BugType instance = base.GetInstance(session, sec);

            instance.Name = this.Name;
            return(instance);
        }
Пример #15
0
        protected override void Save(ManagedSecurityContext sec)
        {
            AccountFacebook existing_facebook_account = Session.CreateCriteria(typeof(AccountFacebook))
                                                        .Add(Expression.Eq("FacebookAccountId", mInstance.FacebookAccountId))
                                                        .UniqueResult <AccountFacebook>();

            if (existing_facebook_account != null)
            {
                if (existing_facebook_account.Account.Id == mInstance.Account.Id)
                {
                    mInstance = existing_facebook_account;
                }
                else
                {
                    // hijack, since there can only be one
                    Session.Delete(existing_facebook_account);
                }
            }

            mInstance.Modified = DateTime.UtcNow;
            if (mInstance.Id == 0)
            {
                mInstance.Created = mInstance.Modified;
            }
            base.Save(sec);
        }
Пример #16
0
        public int Merge(ManagedSecurityContext sec, int id)
        {
            if (!sec.IsAdministrator())
            {
                throw new ManagedAccount.AccessDeniedException();
            }

            if (id == mInstance.Id)
            {
                throw new Exception("Cannot merge neighborhood into self");
            }

            int count = 0;

            Neighborhood merge = Session.Load <Neighborhood>(id);

            // update places
            if (merge.Places != null)
            {
                count += merge.Places.Count;
                foreach (Place place in merge.Places)
                {
                    place.Neighborhood = mInstance;
                    place.City         = mInstance.City;
                    Session.Save(place);
                }
            }

            // update accounts - TODO when extended
            // update account addresses - TODO when extended

            Session.Delete(merge);
            return(count);
        }
Пример #17
0
        public override Survey GetInstance(ISession session, ManagedSecurityContext sec)
        {
            Survey instance = base.GetInstance(session, sec);

            instance.Name = Name;
            return(instance);
        }
Пример #18
0
        public override AccountMessage GetInstance(ISession session, ManagedSecurityContext sec)
        {
            AccountMessage instance = base.GetInstance(session, sec);

            if (Id == 0)
            {
                // sent messages cannot be modified
                instance.Subject            = this.Subject;
                instance.Body               = this.Body;
                instance.Sent               = this.Sent;
                instance.SenderAccountId    = GetOwner(session, SenderAccountId, sec).Id;
                instance.RecepientAccountId = this.RecepientAccountId;
                // the oner is the recepient
                instance.Account = session.Load <Account>(RecepientAccountId);
                instance.Unread  = true;
            }
            else
            {
                instance.Unread = this.UnRead;
            }

            if (AccountMessageFolderId == 0)
            {
                instance.AccountMessageFolder = ManagedAccountMessageFolder.FindRootFolder(
                    session, instance.Account.Id, "inbox");
            }
            else
            {
                instance.AccountMessageFolder = (AccountMessageFolder)session.Load(
                    typeof(AccountMessageFolder), AccountMessageFolderId);
            }

            return(instance);
        }
Пример #19
0
        public void Reject(ManagedSecurityContext sec, string message)
        {
            GetACL().Check(sec, DataOperation.Update);

            Account requester = mInstance.Account;
            Account approver  = mInstance.Keen;

            if (!string.IsNullOrEmpty(message))
            {
                ManagedAccount recepient = new ManagedAccount(Session, requester);
                ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(Session, recepient,
                                                                          string.Format("EmailAccountFriendRequestReject.aspx?id={0}&message={1}", this.Id, Renderer.UrlEncode(message)));

                // delete the request when user notified
                Collection <AccountFriendRequest> .GetSafeCollection(mInstance.Account.AccountFriendRequests).Remove(mInstance);

                Session.Delete(mInstance);
            }
            else
            {
                // silently reject the request
                mInstance.Rejected = true;
                Session.Save(mInstance);
            }
        }
Пример #20
0
        protected override void Save(ManagedSecurityContext sec)
        {
            bool fNew = (mInstance.Id == 0);

            if (mInstance.Id == 0)
            {
                mInstance.Sent = DateTime.UtcNow;
            }

            base.Save(sec);

            Session.Flush();

            if (fNew)
            {
                ManagedAccount recepient = new ManagedAccount(Session, mInstance.RecepientAccountId);
                ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                    Session, recepient, string.Format("EmailAccountMessage.aspx?id={0}", mInstance.Id));

                // save a copy in Sent items
                AccountMessage copy = new AccountMessage();
                copy.Account = Session.Load <Account>(mInstance.SenderAccountId);
                copy.AccountMessageFolder = ManagedAccountMessageFolder.FindRootFolder(Session, mInstance.SenderAccountId, "sent");
                copy.Body = mInstance.Body;
                copy.RecepientAccountId = mInstance.RecepientAccountId;
                copy.SenderAccountId    = mInstance.SenderAccountId;
                copy.Sent    = mInstance.Sent;
                copy.Subject = mInstance.Subject;
                copy.Unread  = true;
                Session.Save(copy);
            }
        }
Пример #21
0
        protected override void Save(ManagedSecurityContext sec)
        {
            mInstance.Modified = DateTime.UtcNow;
            if (mInstance.Id == 0) mInstance.Created = mInstance.Modified;

            if (mInstance.Principal && !mInstance.Verified)
            {
                // an unverified e-mail cannot be set to principal
                throw new ManagedAccount.AccessDeniedException();
            }

            if (mInstance.Principal)
            {
                // clear principal flags if this e-mail becomes principal
                foreach (AccountEmail email in Collection<AccountEmail>.GetSafeCollection(mInstance.Account.AccountEmails))
                {
                    if (email.Principal && email.Id != mInstance.Id)
                    {
                        email.Principal = false;
                        Session.Save(email);
                    }
                }
            }

            base.Save(sec);
        }
Пример #22
0
 protected override void Check(TransitAccountEmail t_instance, ManagedSecurityContext sec)
 {
     base.Check(t_instance, sec);
     if (t_instance.Id == 0) GetQuota(sec).Check<AccountEmail, ManagedAccount.QuotaExceededException>(
             Session.CreateQuery(string.Format("SELECT COUNT(*) FROM AccountEmail instance WHERE instance.Account.Id = {0}",
                 mInstance.Account.Id)).UniqueResult<int>());
 }
Пример #23
0
        public override void Delete(ManagedSecurityContext sec)
        {
            bool canDelete = false;

            foreach (AccountEmail email in Collection<AccountEmail>.GetSafeCollection(mInstance.Account.AccountEmails))
            {
                if (email.Id == Id)
                    continue;

                if (!Verified)
                {
                    // you can delete an unverified e-mail when you have at least one other e-mail
                    canDelete = true;
                    break;
                }
                else if (email.Verified)
                {
                    // you can delete a verified e-mail when you have at least one other verified e-mail
                    canDelete = true;
                    break;
                }
            }

            if (!canDelete)
            {
                throw new Exception(
                    "You cannot delete the last verified e-mail.");
            }

            Collection<AccountEmail>.GetSafeCollection(mInstance.Account.AccountEmails).Remove(mInstance);
            mInstance.AccountEmailConfirmations = null;
            base.Delete(sec);

        }
Пример #24
0
        public ManagedAccountEmailConfirmation Confirm(ManagedSecurityContext sec)
        {
            GetACL().Check(sec, DataOperation.All);

            if (this.Verified && ! this.mInstance.Failed)
                return null;

            // find and existing pending confirmation
            foreach (AccountEmailConfirmation c in Collection<AccountEmailConfirmation>.GetSafeCollection(mInstance.AccountEmailConfirmations))
            {
                if (c.AccountEmail.Id == Id)
                {
                    ManagedAccountEmailConfirmation existingac = new ManagedAccountEmailConfirmation(Session, c);
                    existingac.Send();
                    return existingac;
                }
            }

            AccountEmailConfirmation ac = new AccountEmailConfirmation();
            ac.AccountEmail = mInstance;
            ac.Code = Guid.NewGuid().ToString();
            ac.Modified = ac.Created = DateTime.UtcNow;
            Session.Save(ac);

            if (mInstance.AccountEmailConfirmations == null)
            {
                mInstance.AccountEmailConfirmations = new List<AccountEmailConfirmation>();
            }

            mInstance.AccountEmailConfirmations.Add(ac);

            ManagedAccountEmailConfirmation mac = new ManagedAccountEmailConfirmation(Session, ac);
            mac.Send();
            return mac;
        }
        public void Accept(ManagedSecurityContext sec, string message)
        {
            GetACL().Check(sec, DataOperation.AllExceptUpdate);

            ManagedAccountGroup group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            if (!group.HasAccount(mInstance.Requester.Id))
            {
                Session.Delete(mInstance);

                throw new Exception(string.Format("Sorry, {0} is no longer member of \"{2}\".",
                                                  mInstance.Requester.Name));
            }

            // account may already a member (invited twice by different admins, etc.)
            if (!group.HasAccount(mInstance.Account.Id))
            {
                JoinGroup(sec, message);

                ManagedAccount recepient = new ManagedAccount(Session, mInstance.Requester);
                ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                    Session,
                    recepient,
                    string.Format("EmailAccountGroupAccountInvitationAccept.aspx?id={0}&aid={1}&message={2}",
                                  this.Id, sec.Account.Id, Renderer.UrlEncode(message)));
            }

            Session.Delete(mInstance);
        }
        public void JoinGroup(
            ManagedSecurityContext sec,
            string message)
        {
            ManagedAccountGroup group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            if (group.Instance.IsPrivate && !group.HasAdministratorAccount(mInstance.Requester.Id))
            {
                TransitAccountGroupAccountRequest t_request = new TransitAccountGroupAccountRequest();
                t_request.AccountGroupId = mInstance.AccountGroup.Id;
                t_request.AccountId      = mInstance.Account.Id;
                t_request.Message        = string.Format("{0} invited {1} to \"{2}\". " +
                                                         "The invitation was accepted and needs to be approved by the group administrator.\n{3}",
                                                         mInstance.Requester.Name, mInstance.Account.Name, mInstance.AccountGroup.Name, message);
                t_request.Submitted = DateTime.UtcNow;

                ManagedAccountGroupAccountRequest m_request = new ManagedAccountGroupAccountRequest(Session);
                m_request.CreateOrUpdate(t_request, sec);
            }
            else
            {
                TransitAccountGroupAccount t_account = new TransitAccountGroupAccount();
                t_account.AccountId      = mInstance.Account.Id;
                t_account.AccountGroupId = mInstance.AccountGroup.Id;
                t_account.Created        = t_account.Modified = DateTime.UtcNow;
                ManagedAccountGroupAccount m_accountgroupaccount = new ManagedAccountGroupAccount(Session);
                m_accountgroupaccount.CreateOrUpdate(t_account, sec);
            }
        }
Пример #27
0
 public void Audit(DataOperation op, ManagedSecurityContext sec)
 {
     if (this is IAuditableService)
     {
         (this as IAuditableService).TryAudit(Session, op, sec);
     }
 }
Пример #28
0
        protected virtual void Save(ManagedSecurityContext sec)
        {
            DataOperation op = (mInstance.Id == 0 ? DataOperation.Create : DataOperation.Update);

            Session.Save(mInstance);
            Audit(op, sec);
        }
Пример #29
0
 public virtual int CreateOrUpdate(TransitType t_instance, ManagedSecurityContext sec)
 {
     mInstance = (DatabaseType)t_instance.GetDbObjectInstance(Session, sec);
     CheckQuota(t_instance, sec);
     Save(sec);
     return(mInstance.Id);
 }
Пример #30
0
 public override void Delete(ManagedSecurityContext sec)
 {
     ManagedDiscussion.FindAndDelete(
         Session, mInstance.AccountFeed.Account.Id, typeof(AccountFeedItem), mInstance.Id, sec);
     ManagedFeature.Delete(Session, "AccountFeedItem", Id);
     base.Delete(sec);
 }
Пример #31
0
 public void RunCleanupMedia(ISession session, ManagedSecurityContext sec)
 {
     session.Delete(string.Format(
         "FROM AccountFeedItemMedia media " +
         " WHERE media.Modified < '{0}'", DateTime.UtcNow.AddMonths(-1).ToString(
             DateTimeFormatInfo.InvariantInfo)));
     session.Flush();
 }
Пример #32
0
 public int GetOrCreateDiscussionId(string ticket, string typename, int id)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         return ManagedDiscussion.GetOrCreateDiscussionId(session, typename, id, sec);
     }
 }
Пример #33
0
 public void RunUpdateAccountCounters(ISession session, ManagedSecurityContext sec)
 {
     ManagedAccountCounterCollection counters = new ManagedAccountCounterCollection();
     IQuery q = session.CreateQuery("FROM Account");
     IEnumerable<Account> accounts = q.Enumerable<Account>();
     IEnumerator<Account> enumerator = accounts.GetEnumerator();
     while (enumerator.MoveNext() && ! IsStopping)
     {
         Account account = enumerator.Current;
         counters.Add(account.Created);
     }
     counters.SaveAccountCounters(session);
 }
Пример #34
0
        public void RunEmailQueue(ISession session, ManagedSecurityContext sec)
        {
            IList emailmessages = session.CreateCriteria(typeof(AccountEmailMessage))
                .Add(Expression.Eq("Sent", false))
                .SetMaxResults(ChunkSize)
                .List();

            SleepInterval = emailmessages.Count >= ChunkSize ? 1 : 15;

            SmtpClient smtp = ManagedAccountEmailMessage.GetSmtpClientInstance(session);

            foreach (AccountEmailMessage m in emailmessages)
            {
                if (IsStopping)
                    break;

                try
                {
                    MailMessage message = ManagedAccountEmailMessage.GetMessageInstance(session, m);
                    smtp.Send(message);
                    m.Sent = true;
                    if (m.DeleteSent)
                    {
                        session.Delete(m);
                    }
                    else
                    {
                        session.Save(m);
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (m.Created.AddDays(1) < DateTime.UtcNow)
                    {
                        session.Delete(m);
                    }
                    else
                    {
                        m.SendError = ex.Message;
                        session.Save(m);
                    }
                }

                session.Flush();
                Thread.Sleep(1000 * InterruptInterval);
            }
        }
Пример #35
0
        public TransitAccountEvent GetAccountEventById(string ticket, int id, long utcoffsetTicks)
        {
            TransitAccountEvent t_instance = WebServiceImpl<TransitAccountEvent, ManagedAccountEvent, AccountEvent>.GetById(
                ticket, id);

            if (t_instance != null)
            {
                using (SnCore.Data.Hibernate.Session.OpenConnection())
                {
                    ISession session = SnCore.Data.Hibernate.Session.Current;
                    ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                    t_instance.CreateSchedule(session, new TimeSpan(utcoffsetTicks), sec);
                }
            }

            return t_instance;
        }
Пример #36
0
        public List<TransitAccountEvent> GetAccountEventsByAccountId(string ticket, int id, long utcoffsetTicks, ServiceQueryOptions options)
        {
            ICriterion[] expressions = { Expression.Eq("Account.Id", id) };
            List<TransitAccountEvent> result = WebServiceImpl<TransitAccountEvent, ManagedAccountEvent, AccountEvent>.GetList(
                ticket, options, expressions, null);

            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                foreach (TransitAccountEvent t_instance in result)
                {
                    t_instance.CreateSchedule(session, new TimeSpan(utcoffsetTicks), sec);
                }
            }

            return result;
        }
Пример #37
0
        public void RunSyndication(ISession session, ManagedSecurityContext sec)
        {
            IQuery query = session.CreateSQLQuery(
                "SELECT {AccountFeed.*} FROM AccountFeed" +
                " WHERE (NOT EXISTS ( SELECT AccountFeedItem_Id FROM AccountFeedItem item WHERE item.AccountFeed_Id = AccountFeed.AccountFeed_Id ))" +
                " OR ( AccountFeed.LastError NOT LIKE '' )" +
                " OR ( DATEDIFF(hour, AccountFeed.Updated, getutcdate()) > AccountFeed.UpdateFrequency )" +
                " ORDER BY AccountFeed.Updated ASC")
            .AddEntity("AccountFeed", typeof(AccountFeed));

            IList<AccountFeed> list = query.List<AccountFeed>();

            foreach(AccountFeed feed in list)
            {
                if (IsStopping)
                    break;

                try
                {
                    ManagedAccountFeed m_feed = new ManagedAccountFeed(session, feed);
                    if (IsDebug)
                    {
                        EventLogManager.WriteEntry(string.Format("Syndication service updating {0} ({1}).",
                            feed.Name, feed.Id), EventLogEntryType.Information);
                    }
                    m_feed.Update(sec);
                    m_feed.UpdateImages(sec);
                    m_feed.UpdateMedias(sec);
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    feed.LastError = ex.Message;
                    session.Save(feed);
                }

                session.Flush();
                Thread.Sleep(1000 * InterruptInterval);
            }
        }
Пример #38
0
        public void RunTagWords(ISession session, ManagedSecurityContext sec)
        {
            DateTime newRun = DateTime.UtcNow;

            ICriteria c = session.CreateCriteria(typeof(Account));
            if (mLastRun.HasValue)
            {
                // last run is updated on interval, add some safe time
                c.Add(Expression.Gt("LastLogin", mLastRun.Value.AddMinutes(-30)));
            }

            IList accounts = c.List();

            foreach (Account account in accounts)
            {
                if (IsStopping)
                    break;

                try
                {
                    ManagedAccount ma = new ManagedAccount(session, account);
                    ma.UpdateTagWords();
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch
                {

                }

                Thread.Sleep(1000 * InterruptInterval);
            }

            session.Flush();
            mLastRun = newRun;
        }
Пример #39
0
        private void RunThumbnail(ISession session, PlaceWebsite website, ManagedSecurityContext sec)
        {
            try
            {
                ManagedPlaceWebsite m_website = new ManagedPlaceWebsite(session, website);

                if (IsDebug)
                {
                    EventLogManager.WriteEntry(string.Format("Thumbnail service updating {0}: {1}, {2}",
                        website.Id, website.Name, website.Url), EventLogEntryType.Information);
                }

                m_website.UpdateThumbnail();
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception)
            {
                website.Modified = DateTime.UtcNow;
                session.Save(website);
            }
        }
Пример #40
0
 public void DeleteCampaignAccountRecepients(string ticket, int id)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedCampaign campaign = new ManagedCampaign(session, id);
         campaign.DeleteRecepients(sec);
         SnCore.Data.Hibernate.Session.Flush();
     }
 }
Пример #41
0
        public int ImportCampaignAccountRecepients(string ticket, TransitCampaignAccountRecepient[] recepients)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    foreach (TransitCampaignAccountRecepient recepient in recepients)
                    {
                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", recepient.AccountId))
                            .Add(Expression.Eq("Campaign.Id", recepient.CampaignId))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        newrecepient.CreateOrUpdate(recepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Пример #42
0
        public int ImportCampaignAccountEmails(string ticket, int campaign_id, bool verified_emails, bool unverified_emails)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    ICriteria c = session.CreateCriteria(typeof(Account));
                    IList list = c.List();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (ma.HasVerifiedEmail(sec))
                        {
                            if (!verified_emails)
                                continue;
                        }
                        else
                        {
                            if (!unverified_emails)
                                continue;
                        }

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Пример #43
0
        public override ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op)
        {
            if ((op == DataOperation.Create || op == DataOperation.Delete) && sec.Account != null)
            {
                return ACLVerdict.Allowed;
            }

            return ACLVerdict.None;
        }
Пример #44
0
 public void MovePlacePicture(string ticket, int id, int disp)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedPlacePicture m_instance = new ManagedPlacePicture(session, id);
         m_instance.Move(sec, disp);
     }
 }
Пример #45
0
        public override ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op)
        {
            if (op == DataOperation.Retreive && sec.Account != null)
            {
                return ACLVerdict.Allowed;
            }

            return ACLVerdict.None;
        }
Пример #46
0
 public override ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op)
 {
     return (op == DataOperation.Retreive) ? ACLVerdict.Allowed : ACLVerdict.None;
 }
Пример #47
0
 public abstract ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op);
Пример #48
0
 public void Check(ManagedSecurityContext sec, DataOperation op)
 {
     if (!TryCheck(sec, op))
     {
         throw new ManagedAccount.AccessDeniedException();
     }
 }
Пример #49
0
        public bool TryCheck(ManagedSecurityContext sec, DataOperation op)
        {
            ACLVerdict result = Apply(sec, op);
            switch (result)
            {
                case ACLVerdict.Denied:
                case ACLVerdict.None:
                    return false;
            }

            return true;
        }
Пример #50
0
        public ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op)
        {
            ACLVerdict current = ACLVerdict.Denied;

            foreach (IACLEntry entry in mAccessControlList)
            {
                ACLVerdict result = entry.Apply(sec, op);
                switch (result)
                {
                    case ACLVerdict.Denied:
                        return ACLVerdict.Denied;
                    case ACLVerdict.Allowed:
                        current = ACLVerdict.Allowed;
                        break;
                }
            }

            return current;
        }
Пример #51
0
        public override ACLVerdict Apply(ManagedSecurityContext sec, DataOperation op)
        {
            if (sec.Account == null)
                return ACLVerdict.None;

            if (sec.Account.Id != mAccountId)
                return ACLVerdict.None;

            if ((mOperation & (int)op) == 0)
                return ACLVerdict.None;

            return mPermission == DataOperationPermission.Allow
                ? ACLVerdict.Allowed
                : ACLVerdict.Denied;
        }
Пример #52
0
        public List<TransitPlace> SearchPlaces(string ticket, string s, ServiceQueryOptions options)
        {
            if (string.IsNullOrEmpty(s))
                return new List<TransitPlace>();

            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                IList<Place> places = InternalSearchPlaces(session, s, options);
                return WebServiceImpl<TransitPlace, ManagedPlace, Place>.GetTransformedList(session, sec, places);
            }
        }
Пример #53
0
 public void RejectAccountPlaceRequest(string ticket, int id, string message)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedAccountPlaceRequest m_request = new ManagedAccountPlaceRequest(session, id);
         m_request.Reject(sec, message);
         SnCore.Data.Hibernate.Session.Flush();
     }
 }
Пример #54
0
 public void MoveAccountBlogPost(string ticket, int postid, int targetid)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedAccountBlogPost post = new ManagedAccountBlogPost(session, postid);
         post.Move(sec, targetid);
         SnCore.Data.Hibernate.Session.Flush();
     }
 }
Пример #55
0
 public void MergePlaces(string ticket, int id, TransitPlace target)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ITransaction t = session.BeginTransaction();
         try
         {
             ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
             // update all contents of the target
             ManagedPlace m_target = new ManagedPlace(session);
             m_target.CreateOrUpdate(target, sec);
             // merge child items
             m_target.Merge(sec, id);
             SnCore.Data.Hibernate.Session.Flush();
             t.Commit();
         }
         catch
         {
             t.Rollback();
             throw;
         }
     }
 }
Пример #56
0
 public int SyndicateAccountBlog(string ticket, int id)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedAccountBlog m_blog = new ManagedAccountBlog(session, id);
         int result = m_blog.Syndicate(sec);
         SnCore.Data.Hibernate.Session.Flush();
         return result;
     }
 }
Пример #57
0
        public List<TransitDistinctPlaceNeighborhood> GetPlaceNeighborhoods(
            string ticket, string country, string state, string city, ServiceQueryOptions options)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                // todo: use the security context
                int city_id = 0;
                ManagedCity.TryGetCityId(session, city, state, country, out city_id);
                IQuery q = session.CreateQuery(
                    "SELECT n.Id, n.Name, COUNT(p) FROM Neighborhood n, Place p" +
                    " WHERE p.Neighborhood = n" +
                    " AND n.City.Id = '" + city_id.ToString() + "'" +
                    " AND p.City.Id = '" + city_id.ToString() + "'" +
                    " GROUP BY n.Id, n.Name ORDER BY n.Name");

                if (options != null)
                {
                    q.SetFirstResult(options.FirstResult);
                    q.SetMaxResults(options.PageSize);
                }

                IList neighborhoods = q.List();
                List<TransitDistinctPlaceNeighborhood> result = new List<TransitDistinctPlaceNeighborhood>(neighborhoods.Count);
                foreach (object[] nh in neighborhoods)
                {
                    TransitDistinctPlaceNeighborhood tnh = new TransitDistinctPlaceNeighborhood();
                    tnh.Name = (string)nh[1];
                    tnh.Count = (int)nh[2];
                    result.Add(tnh);
                }

                return result;
            }
        }
Пример #58
0
        public int ImportCampaignAccountPropertyValues(string ticket, int campaign_id, int pid, string value, bool unset)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    StringBuilder squery = new StringBuilder();
                    squery.Append(
                        "SELECT {Account.*} FROM {Account} WHERE Account_Id IN (" +
                        " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                        " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                        " WHERE AccountPropertyValue.AccountProperty_Id = " + pid.ToString() +
                        " AND AccountPropertyValue.Value LIKE '" + Renderer.SqlEncode(value) + "')");

                    if (unset)
                    {
                        squery.AppendFormat(
                            " OR Account_Id NOT IN (" +
                            " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                            " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                            " AND AccountPropertyValue.AccountProperty_Id = {0}" +
                            ")", pid);
                    }

                    ISQLQuery query = session.CreateSQLQuery(squery.ToString())
                        .AddEntity("Account", typeof(Account));

                    IList<Account> list = query.List<Account>();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (!ma.HasVerifiedEmail(sec))
                            continue;

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Пример #59
0
        public int ImportCampaignAccountLocation(string ticket, int campaign_id, string country, string state, string city)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                AccountActivityQueryOptions options = new AccountActivityQueryOptions();
                options.City = city;
                options.Country = country;
                options.State = state;
                options.PicturesOnly = false;
                options.BloggersOnly = false;

                int count = 0;

                try
                {
                    IQuery query = session.CreateQuery(options.CreateQuery());
                    IEnumerator<Account> enumerator = query.Enumerable<Account>().GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        ManagedAccount ma = new ManagedAccount(session, enumerator.Current);

                        if (!ma.HasVerifiedEmail(sec))
                            continue;

                        CampaignAccountRecepient existing = session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult<CampaignAccountRecepient>();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Пример #60
0
 public int MoveDiscussionPost(string ticket, int postid, int targetid)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedDiscussionPost post = new ManagedDiscussionPost(session, postid);
         int result = post.MoveToAccountBlog(sec, targetid);
         SnCore.Data.Hibernate.Session.Flush();
         return result;
     }
 }