Exemple #1
0
 private static void ProcessEvent()
 {
     try
     {
         DateTime     now   = DateTime.Now;
         int          num   = (now.Hour * 60 + now.Minute) * 60;
         int          num2  = 0;
         List <Event> list  = new List <Event>();
         List <Event> list2 = new List <Event>();
         List <Event> list3 = new List <Event>();
         foreach (Event @event in EventDataContext.Instance.Event)
         {
             if (@event.StartTime == null && !(@event.StartCount > 0))
             {
                 if (@event.EndTime == null || now < @event.EndTime)
                 {
                     list.Add(@event);
                 }
                 else
                 {
                     list3.Add(@event);
                 }
             }
             else if (@event.StartTime != null)
             {
                 if (now >= @event.StartTime)
                 {
                     if (@event.EndTime == null || now < @event.EndTime)
                     {
                         if (@event.PeriodBegin == null)
                         {
                             list.Add(@event);
                         }
                         else if (now.TimeOfDay >= @event.PeriodBegin)
                         {
                             if (@event.PeriodEnd == null || now.TimeOfDay < @event.PeriodEnd)
                             {
                                 list.Add(@event);
                             }
                             else
                             {
                                 list2.Add(@event);
                             }
                         }
                         else
                         {
                             list2.Add(@event);
                         }
                     }
                     else
                     {
                         list3.Add(@event);
                     }
                 }
                 else
                 {
                     list2.Add(@event);
                 }
             }
             else if (@event.StartCount > 0)
             {
                 if (@event.StartCount <= EventDataContext.Instance.GetEventCount(@event.Name))
                 {
                     if (@event.EndTime == null || now < @event.EndTime)
                     {
                         if (@event.PeriodBegin == null)
                         {
                             list.Add(@event);
                         }
                         else if (now.TimeOfDay >= @event.PeriodBegin)
                         {
                             if (@event.PeriodEnd == null || now.TimeOfDay < @event.PeriodEnd)
                             {
                                 list.Add(@event);
                             }
                             else
                             {
                                 list2.Add(@event);
                             }
                         }
                         else
                         {
                             list2.Add(@event);
                         }
                     }
                     else
                     {
                         list3.Add(@event);
                     }
                 }
                 else
                 {
                     list2.Add(@event);
                 }
             }
         }
         foreach (Event event2 in list3)
         {
             EventDataContext.RemoveEvent(event2.Name);
         }
         foreach (Event event3 in list2)
         {
             EventDataContext.EndEvent(event3.Name);
         }
         foreach (KeyValuePair <string, Event> keyValuePair in EventDataContext.runnings)
         {
             Event value = keyValuePair.Value;
             if (value.NotifyMessage != null && value.NotifyMessage.Length > 0)
             {
                 int num3 = 1800;
                 if (value.NotifyInterval != null && value.NotifyInterval.Value >= 0)
                 {
                     num3 = value.NotifyInterval.Value;
                 }
                 num3 = num3 / 60 * 60;
                 if (num3 != 0 && num % num3 == 0)
                 {
                     Scheduler.Schedule(EventDataContext.Thread, Job.Create <string, int>(new Action <string, int>(EventDataContext.BroadcastMessage), value.NotifyMessage, -1), ++num2 * 1000);
                 }
             }
         }
         foreach (Event event4 in list)
         {
             EventDataContext.StartEvent(event4.Name, event4);
         }
         EventDataContext.processed = true;
         foreach (KeyValuePair <int, string> keyValuePair2 in EventDataContext.waitingServiceList)
         {
             Scheduler.Schedule(EventDataContext.Thread, Job.Create <int, string>(new Action <int, string>(EventDataContext.SendToFeatureMaxtrixUpdate), keyValuePair2.Key, keyValuePair2.Value), 10000);
         }
         EventDataContext.waitingServiceList.Clear();
     }
     finally
     {
         EventDataContext.ScheduleNextProcess();
     }
 }
Exemple #2
0
        public static bool RegisterEvent(string name, string template, string feature, string scriptstart, string scriptend, DateTime?startTime, DateTime?endTime, TimeSpan?periodBegin, TimeSpan?periodEnd, string msgstart, string msgnotify, string msgend, int msginterval, int startCont, string username, AdminClientServicePeer peer)
        {
            EventDataContext.StartProcessing();
            EventTemplate eventTemplate = null;
            bool          flag          = false;

            if (EventDataContext.IsRunning(name))
            {
                if (peer != null)
                {
                    string msg = EventDataContext.SendEventListAndDetail(name, "Event is Already Running !", true);
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, msg)));
                }
                return(false);
            }
            if (template != null)
            {
                eventTemplate = AdminContents.GetTemplate(template);
                if (eventTemplate == null)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Cannot Find Event Template ! - \"{0}\"", template))));
                    }
                    return(false);
                }
            }
            Event @event = EventDataContext.GetEvent(name);

            if (@event == null)
            {
                @event      = new Event();
                @event.Name = name;
                flag        = true;
            }
            if (eventTemplate != null)
            {
                @event.Feature     = eventTemplate.Feature;
                @event.StartScript = eventTemplate.StartScript;
                @event.EndScript   = eventTemplate.EndScript;
            }
            if (feature != null)
            {
                @event.Feature = feature;
            }
            if (scriptstart != null)
            {
                @event.StartScript = scriptstart;
            }
            if (scriptend != null)
            {
                @event.EndScript = scriptend;
            }
            if (startTime != null)
            {
                if (startTime < DateTime.Now)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Reservation Time Error - \"{0}\"", startTime))));
                    }
                    return(false);
                }
                @event.StartTime = startTime;
            }
            if (endTime != null)
            {
                if (endTime < DateTime.Now)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Reservation Time Error - \"{0}\"", endTime))));
                    }
                    return(false);
                }
                @event.EndTime = endTime;
            }
            if (periodBegin != null)
            {
                @event.PeriodBegin = periodBegin;
            }
            if (periodEnd != null)
            {
                @event.PeriodEnd = periodEnd;
            }
            if (msgstart != null)
            {
                @event.StartMessage = msgstart;
            }
            if (msgnotify != null)
            {
                @event.NotifyMessage = msgnotify;
            }
            if (msgend != null)
            {
                @event.EndMessage = msgend;
            }
            @event.NotifyInterval = new int?(msginterval);
            @event.StartCount     = new int?(startCont);
            @event.UserName       = username;
            if (flag)
            {
                if (feature != null)
                {
                    string text = EventDataContext.IsExistFeature(feature);
                    if (text != null)
                    {
                        if (peer != null)
                        {
                            peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("That feature is already exist ! - \"{0}\"", text))));
                        }
                        return(false);
                    }
                }
                if (!EventDataContext.AddEvent(@event))
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Event Register Failed ! - \"{0}\"", name))));
                    }
                    return(false);
                }
            }
            else if (!EventDataContext.ModifyEvent(@event))
            {
                if (peer != null)
                {
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Event Update Failed ! - \"{0}\"", name))));
                }
                return(false);
            }
            if (@event.StartTime == null && !(@event.StartCount > 0))
            {
                EventDataContext.StartEvent(name, @event);
                if (peer != null)
                {
                    string msg2 = EventDataContext.SendEventListAndDetail(name, "Event is Started !", true);
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, msg2)));
                }
            }
            else if (peer != null)
            {
                string msg3 = EventDataContext.SendEventListAndDetail(name, "Event is Reserved !", true);
                peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, msg3)));
            }
            return(true);
        }