public SpringieState(int planetID, ReminderEvent reminderEvent, string offensiveFactionName)
 {
     PlanetID = planetID;
     ReminderEvent = reminderEvent;
     OffensiveFactionName = offensiveFactionName;
     LastUpdate = DateTime.Now;
 }
Example #2
0
 public SpringieState(int planetID, ReminderEvent reminderEvent, string offensiveFactionName)
 {
     PlanetID             = planetID;
     ReminderEvent        = reminderEvent;
     OffensiveFactionName = offensiveFactionName;
     LastUpdate           = DateTime.Now;
 }
Example #3
0
        private void AddEvent(ReminderEvent ev)
        {
            //Retreive the events for this note
            IList events = noteEvents[ev.Note] as IList;

            if (events == null)
            {
                //No previous events for this note, create a new list
                events = new ArrayList();
                noteEvents[ev.Note] = events;
            }
            else if (events.Contains(ev))
            {
                return;
            }

            //Add the new events fo rthe note
            events.Add(ev);

            ev.Start();
        }
        private void _DispatchReminderEvent(int reminderId, ReminderEvent action)
        {
            string Event = null;

            switch (action)
            {
            case ReminderEvent.Create:
                Event = Globals.ApplicationEvent.NewReminder;
                break;

            case ReminderEvent.Update:
                Event = Globals.ApplicationEvent.ReminderUpdate;
                break;

            case ReminderEvent.Delete:
                Event = Globals.ApplicationEvent.ReminderDeleted;
                break;
            }

            if (action == ReminderEvent.Delete)
            {
                ApplicationEvent.Instance.DispatchOfficeEvent(Event, _user.OfficeId, new { ReminderId = reminderId });
            }
            else
            {
                Reminder reminder = GetReminder(reminderId);

                if (reminder.Public)
                {
                    ApplicationEvent.Instance.DispatchOfficeEvent(Event, _user.OfficeId, reminder.Serialize());
                }
                else
                {
                    ApplicationEvent.Instance.DispatchUserEvent(Event, new List <int>()
                    {
                        reminder.SetFor
                    }, reminder);
                }
            }
        }
Example #5
0
        private void AddEvent(ReminderEvent ev)
        {
            //Retreive the events for this note
            IList events = noteEvents[ev.Note] as IList;
            if(events == null) {
                //No previous events for this note, create a new list
                events = new ArrayList();
                noteEvents[ev.Note] = events;
            }
            else if(events.Contains(ev))
                return;

            //Add the new events fo rthe note
            events.Add(ev);

            ev.Start();
        }
Example #6
0
        public void RunSystemReminders(ISession session, ManagedSecurityContext sec)
        {
            // get reminders
            IList reminders = session.CreateCriteria(typeof(Reminder))
                .Add(Expression.Eq("Enabled", true))
                .List();

            foreach (Reminder reminder in reminders)
            {
                if (IsStopping)
                    break;

                reminder.LastRun = DateTime.UtcNow;
                reminder.LastRunError = string.Empty;
                session.Save(reminder);

                ManagedReminder mr = new ManagedReminder(session, reminder);

                try
                {
                    // get the type of the object seeked
                    Type objecttype = Assembly.GetAssembly(typeof(DataObject))
                        .GetType(reminder.DataObject.Name, true);

                    // todo: currently this works with date-based fields only

                    // anything older than this time
                    DateTime timeboundary = DateTime.UtcNow.AddHours(-reminder.DeltaHours);

                    // find all records matching the property
                    IList objects = session.CreateCriteria(objecttype)
                        .Add(Expression.Le(reminder.DataObjectField, timeboundary))
                        .List();

                    // currently only support account identities
                    // the object is either an Account object or has an AccountId property
                    string accountidproperty = (reminder.DataObject.Name == "Account") ? "Id" : "AccountId";

                    PropertyInfo accountidpropertyinfo = objecttype.GetProperty(accountidproperty);

                    if (accountidpropertyinfo == null)
                    {
                        throw new Exception(string.Format("Object {0} does not have a property {1}.",
                            reminder.DataObject.Name, accountidproperty));
                    }

                    foreach (object o in objects)
                    {
                        if (IsStopping)
                            break;

                        int accountid = (int)accountidpropertyinfo.GetValue(o, null);

                        ReminderEvent reminderevent = (ReminderEvent)session.CreateCriteria(typeof(ReminderEvent))
                            .Add(Expression.Eq("Reminder.Id", reminder.Id))
                            .Add(Expression.Eq("Account.Id", accountid))
                            .UniqueResult();

                        Account acct = session.Load<Account>(accountid);
                        ManagedAccount ma = new ManagedAccount(session, acct);

                        try
                        {
                            if (reminderevent == null)
                            {
                                reminderevent = new ReminderEvent();
                                reminderevent.Account = acct;
                                reminderevent.Reminder = reminder;
                                reminderevent.Created = reminderevent.Modified = DateTime.UtcNow;
                            }
                            else
                            {
                                if (reminderevent.Modified >= timeboundary)
                                {
                                    // this field was already noticed and event was fired in a prior run
                                    continue;
                                }

                                if (!reminder.Recurrent)
                                {
                                    // this reminder has already been sent but is not recurrent
                                    continue;
                                }

                                reminderevent.Modified = DateTime.UtcNow;
                            }

                            if (!mr.CanSend(acct))
                                continue;

                            ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                                session, ma, string.Format("{0}?id={1}", reminder.Url, ma.Id));

                            session.Save(reminderevent);
                        }
                        catch (ThreadAbortException)
                        {
                            throw;
                        }
                        catch (Exception ex)
                        {
                            EventLogManager.WriteEntry(string.Format("Error sending a reminder at {0} to account id {1}: {2}",
                                reminder.Url, accountid, ex.Message), EventLogEntryType.Warning);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    reminder.LastRunError = ex.Message;
                    session.Save(reminder);
                }

                Thread.Sleep(1000 * InterruptInterval);
            }
        }
Example #7
0
        public void RunSystemReminders(ISession session, ManagedSecurityContext sec)
        {
            // get reminders
            IList reminders = session.CreateCriteria(typeof(Reminder))
                              .Add(Expression.Eq("Enabled", true))
                              .List();

            foreach (Reminder reminder in reminders)
            {
                if (IsStopping)
                {
                    break;
                }

                reminder.LastRun      = DateTime.UtcNow;
                reminder.LastRunError = string.Empty;
                session.Save(reminder);

                ManagedReminder mr = new ManagedReminder(session, reminder);

                try
                {
                    // get the type of the object seeked
                    Type objecttype = Assembly.GetAssembly(typeof(DataObject))
                                      .GetType(reminder.DataObject.Name, true);

                    // todo: currently this works with date-based fields only

                    // anything older than this time
                    DateTime timeboundary = DateTime.UtcNow.AddHours(-reminder.DeltaHours);

                    // find all records matching the property
                    IList objects = session.CreateCriteria(objecttype)
                                    .Add(Expression.Le(reminder.DataObjectField, timeboundary))
                                    .List();

                    // currently only support account identities
                    // the object is either an Account object or has an AccountId property
                    string accountidproperty = (reminder.DataObject.Name == "Account") ? "Id" : "AccountId";

                    PropertyInfo accountidpropertyinfo = objecttype.GetProperty(accountidproperty);

                    if (accountidpropertyinfo == null)
                    {
                        throw new Exception(string.Format("Object {0} does not have a property {1}.",
                                                          reminder.DataObject.Name, accountidproperty));
                    }

                    foreach (object o in objects)
                    {
                        if (IsStopping)
                        {
                            break;
                        }

                        int accountid = (int)accountidpropertyinfo.GetValue(o, null);

                        ReminderEvent reminderevent = (ReminderEvent)session.CreateCriteria(typeof(ReminderEvent))
                                                      .Add(Expression.Eq("Reminder.Id", reminder.Id))
                                                      .Add(Expression.Eq("Account.Id", accountid))
                                                      .UniqueResult();

                        Account        acct = session.Load <Account>(accountid);
                        ManagedAccount ma   = new ManagedAccount(session, acct);

                        try
                        {
                            if (reminderevent == null)
                            {
                                reminderevent          = new ReminderEvent();
                                reminderevent.Account  = acct;
                                reminderevent.Reminder = reminder;
                                reminderevent.Created  = reminderevent.Modified = DateTime.UtcNow;
                            }
                            else
                            {
                                if (reminderevent.Modified >= timeboundary)
                                {
                                    // this field was already noticed and event was fired in a prior run
                                    continue;
                                }

                                if (!reminder.Recurrent)
                                {
                                    // this reminder has already been sent but is not recurrent
                                    continue;
                                }

                                reminderevent.Modified = DateTime.UtcNow;
                            }

                            if (!mr.CanSend(acct))
                            {
                                continue;
                            }

                            ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                                session, ma, string.Format("{0}?id={1}", reminder.Url, ma.Id));

                            session.Save(reminderevent);
                        }
                        catch (ThreadAbortException)
                        {
                            throw;
                        }
                        catch (Exception ex)
                        {
                            EventLogManager.WriteEntry(string.Format("Error sending a reminder at {0} to account id {1}: {2}",
                                                                     reminder.Url, accountid, ex.Message), EventLogEntryType.Warning);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    reminder.LastRunError = ex.Message;
                    session.Save(reminder);
                }

                Thread.Sleep(1000 * InterruptInterval);
            }
        }
Example #8
0
            public override bool Equals(object o)
            {
                ReminderEvent ev = o as ReminderEvent;

                return(note.Equals(ev.Note) && date == ev.Date);
            }
Example #9
0
 public ICollection <string> GetPlayersToNotify(AuthInfo springieLogin, string mapName, ReminderEvent reminderEvent)
 {
     return(s.GetPlayersToNotify(springieLogin, mapName, reminderEvent));
 }
Example #10
0
 public bool SetReminderOptions(ReminderEvent reminderEvent, ReminderLevel reminderLevel, ReminderRoundInitiative reminderRoundInitiative, AuthInfo authorization, out string message)
 {
     return(s.SetReminderOptions(reminderEvent, reminderLevel, reminderRoundInitiative, authorization, out message));
 }
		public ICollection<string> GetPlayersToNotify(AuthInfo springieLogin, string mapName, ReminderEvent reminderEvent)
		{
			return s.GetPlayersToNotify(springieLogin, mapName, reminderEvent);
		}
		public bool SetReminderOptions(ReminderEvent reminderEvent, ReminderLevel reminderLevel, ReminderRoundInitiative reminderRoundInitiative, AuthInfo authorization, out string message)
		{
			return s.SetReminderOptions(reminderEvent, reminderLevel, reminderRoundInitiative, authorization, out message);
		}
		public ICollection<string> GetPlayersToNotify(AuthInfo springieLogin, string mapName, ReminderEvent reminderEvent)
		{
			if (mapName == null) {
				throw new ArgumentNullException("mapName");
			}
			var planet = Galaxy.Planets.Single(p => p.MapName == mapName);
			if (planet == null) {
				throw new Exception(mapName + " is used by any planet.");
			}

			/* -------------- multiple autohost support ---------------- */
			SpringieState springiestate;
			if (!SpringieStates.TryGetValue(springieLogin.Login, out springiestate)) {
				springiestate = new SpringieState(planet.ID, reminderEvent, Galaxy.OffensiveFaction.Name);
				SpringieStates[springieLogin.Login] = springiestate;
			}
			if (reminderEvent == ReminderEvent.OnBattleStarted) {
				springiestate.GameStartedStatus = springiestate.BinaryClone();
			}
			springiestate.PlanetID = planet.ID;
			springiestate.ReminderEvent = reminderEvent;
			springiestate.OffensiveFactionName = Galaxy.OffensiveFaction.Name;
			springiestate.LastUpdate = DateTime.Now;

			/* ---------------------------------------------------------- */

			var q = from p in Galaxy.Players
			        where (p.ReminderEvent & reminderEvent) == reminderEvent
			        where p.ReminderLevel != ReminderLevel.MyPlanet || p.Name == planet.OwnerName
			        let IsOffensivePlayer = p.FactionName == Galaxy.OffensiveFaction.Name
			        let IsAttackSet =
			        	(p.ReminderRoundInitiative & ReminderRoundInitiative.Offense) == ReminderRoundInitiative.Offense
			        let IsDefenseSet =
			        	(p.ReminderRoundInitiative & ReminderRoundInitiative.Defense) == ReminderRoundInitiative.Defense
			        where (IsAttackSet && IsOffensivePlayer) || (IsDefenseSet && !IsOffensivePlayer)
			        select p.Name;

			if (reminderEvent == ReminderEvent.OnBattleStarted) {
				ForceSaveState();
			}

			return q.ToArray();
		}
		public bool SetReminderOptions(ReminderEvent reminderEvent,
		                               ReminderLevel reminderLevel,
		                               ReminderRoundInitiative reminderRoundInitiative,
		                               AuthInfo authorization,
		                               out string message)
		{
			if (authorization == null) {
				throw new ArgumentNullException("authorization");
			}
			if (!ValidateLogin(authorization)) {
				message = "Wrong username or password.";
				return false;
			}
			var player = Galaxy.GetPlayer(authorization.Login);
			player.ReminderEvent = reminderEvent;
			player.ReminderLevel = reminderLevel;
			player.ReminderRoundInitiative = reminderRoundInitiative;
			message = "Success";
			SaveState();
			return true;
		}