コード例 #1
0
        public void SetData(MetaEventStatus e)
        {
            EventName.Text = e.Name;

            DateTime then = new DateTime(1970, 1, 1).AddMilliseconds(e.Timestamp);
            TimeSpan span = DateTime.UtcNow - then;

            m_Countdown = false;

            string windowType = null;
            if (e.MinCountdown > 0)
            {
                m_Countdown = true;

                if (e.MinCountdown - span.TotalSeconds > 0)
                    span = new TimeSpan(0, 0, (int)e.MinCountdown) - span;
                else
                {
                    if (e.MaxCountdown - span.TotalSeconds > 0)
                    {
                        windowType = "window";
                        span = new TimeSpan(0, 0, (int)e.MaxCountdown) - span;
                    }
                    else
                    {
                        m_Countdown = false;
                        windowType = "behind";
                        span -= new TimeSpan(0, 0, (int)Math.Max(e.MinCountdown, e.MaxCountdown));
                    }
                }
            }

            m_EventTime = span;

            Visibility = Visibility.Visible;

            if (e.StageTypeEnum == MetaEventStage.StageType.Boss)
                Background = BOSS_GRADIENT;
            else if (e.StageTypeEnum == MetaEventStage.StageType.PreEvent)
                Background = PRE_GRADIENT;
            else
            {
                Background = null;

                if (windowType == "window")
                    EventTime.Foreground = Brushes.Blue;
                else if (windowType == "behind")
                    EventTime.Foreground = Brushes.Red;
                else
                {
                    EventTime.Foreground = null;
                    Visibility = Visibility.Collapsed;
                }
            }

            if (e.StageId < 0)
            {
                TimeSpan window = new TimeSpan(0, 0, (int)(e.MaxCountdown - e.MinCountdown));

                if (windowType == "behind")
                    EventInfo.Text = "Time Event has been Outdated";
                else if (windowType == "window")
                    EventInfo.Text = string.Format("{0}{1}Spawning Window",
                            (window.Hours > 0 ? string.Format("{0} Hour ", window.Hours) : string.Empty),
                            (window.Minutes > 0 ? string.Format("{0} Minute ", window.Minutes) : string.Empty));
                else
                    EventInfo.Text = string.Empty;
            }
            else
                EventInfo.Text = e.StageName;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: nexaddo/GuildWars2
        public static void WorkerThread(object sender, ElapsedEventArgs e)
        {
            // attempt to set the sync, if another of us is running, just exit
            if (Interlocked.CompareExchange(ref m_TimerSync, 1, 0) != 0)
                return;

            // wrap in a try-catch so we can release our interlock if something fails
            try
            {
                EventsResponse response = new EventsRequest(1007).Execute();

                long timestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;

                HashSet<EventState> metaEvents = new HashSet<EventState>(response.Events.Where(es => MetaEventDefinitions.EventList.Contains(es.EventId)));

                foreach (MetaEvent meta in MetaEventDefinitions.MetaEvents)
                {
                    if (m_EventStatus.ContainsKey(meta.Id))
                    {
                        int stageId = meta.GetStageId(metaEvents, m_EventStatus[meta.Id].StageId);

                        MetaEventStatus oldevs = m_EventStatus[meta.Id];
                        MetaEventStatus newevs = new MetaEventStatus()
                            {
                                Id = meta.Id,
                                StageId = stageId,
                                StageTypeEnum = (stageId >= 0 ? meta.Stages.ElementAt(stageId).Type : MetaEventStage.StageType.Invalid),
                                Timestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds
                            };

                        if (stageId < 0 && oldevs.StageId >= 0)
                            newevs.StageName = meta.Stages.ElementAt(oldevs.StageId).IsFailed(metaEvents).ToString();

                        if (oldevs.StageTypeEnum == MetaEventStage.StageType.Invalid &&
                            newevs.StageTypeEnum != MetaEventStage.StageType.Invalid)
                        {
                            DateTime epoch = new DateTime(1970, 1, 1);
                            DateTime oldTIme = epoch.AddMilliseconds((double)oldevs.Timestamp);
                            DateTime newTIme = epoch.AddMilliseconds((double)newevs.Timestamp);

                            EventSpawnData spawnData = new EventSpawnData()
                                {
                                    ev_id = meta.Id,
                                    spawn_time = newTIme - oldTIme,
                                    failed = oldevs.StageName
                                };

                            m_Data.Add(spawnData);
                        }

                        if (oldevs.StageId != newevs.StageId)
                        {
                            m_EventStatus[meta.Id] = newevs;
                        }
                    }
                }
            }
            catch (Exception)
            { }

            // reset sync to 0
            Interlocked.Exchange(ref m_TimerSync, 0);
        }