Exemplo n.º 1
0
        // Grab timer data
        private Object async_updateTimers(Object worldId)
        {
            HttpWebRequest httpRequest =
                (HttpWebRequest)
                WebRequest.Create("http://" + OverlaySettings.dataServer + "/events-request/" + worldId);

            httpRequest.Method  = "GET";
            httpRequest.Timeout = 10000;
            httpRequest.Proxy   = null;

            HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(EventsRequestResponse));
                Object deserialized = serializer.ReadObject(response.GetResponseStream());

                if (deserialized is EventsRequestResponse)
                {
                    String serverDateString = response.GetResponseHeader("Date");
                    if (serverDateString != null)
                    {
                        DateTime serverDate = DateTime.Parse(serverDateString);
                        ((EventsRequestResponse)deserialized).currentTime = GW2StuffAPI.dateToUnix(serverDate);
                    }
                }

                return(deserialized);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public void tick()
        {
            int currentTimestamp = GW2StuffAPI.getCurrentTime();

            String newDisplayMode = activeState ? "active" : "inactive";

            switch (_eventInfo.windowType)
            {
            case "countdown":
            {
                int min = _eventInfo.timestamp + _eventInfo.minWindow;
                int max = _eventInfo.timestamp + _eventInfo.maxWindow;
                if (max < min)
                {
                    max = min;
                }
                int diff;

                if (currentTimestamp > min)
                {
                    diff = max - currentTimestamp;
                    if (!activeState)
                    {
                        newDisplayMode = "window";
                    }
                }
                else
                {
                    diff = min - currentTimestamp;
                }

                eventTimer.Text = diffToTimeDisplay(diff);
            }
            break;

            case "since":
            {
                int diff = currentTimestamp - _eventInfo.timestamp;
                eventTimer.Text = diffToTimeDisplay(diff);
            }
            break;

            default:
                eventTimer.Text = "";
                break;
            }

            if (_displayMode != newDisplayMode)
            {
                _displayMode = newDisplayMode;
                updateDisplayState();
            }
        }
Exemplo n.º 3
0
 public void updateCurrentTimestamp()
 {
     currentTimestamp = GW2StuffAPI.getCurrentTime();
 }
Exemplo n.º 4
0
        /* Remote result handling */

        // Handle server responses
        private void taskQueue_taskQueueItemComplete(Object source, TaskQueueItemCompletionArgs args)
        {
            if (args.func == async_updateTimers)
            {
                // Ignore errors when fetching timer data, connections can drop
                if (args.exception != null)
                {
                    return;
                }
                if (args.result == null)
                {
                    return;
                }

                EventsRequestResponse response = (EventsRequestResponse)args.result;

                GW2StuffAPI.setCurrentTime(response.currentTime);

                if (response.dayStart > Properties.Settings.Default.dailyCompletionTime)
                {
                    Properties.Settings.Default.dailyCompletionTime = response.dayStart;
                    Properties.Settings.Default.dailyCompletionList.Clear();
                }

                foreach (EventInformation eventInfo in response.events)
                {
                    EventItem eventItem;
                    if (eventDictionary.TryGetValue(eventInfo.id, out eventItem))
                    {
                        eventItem.eventInfo = eventInfo;
                    }
                    else
                    {
                        eventItem           = new EventItem();
                        eventItem.eventInfo = eventInfo;
                        eventDictionary.Add(eventInfo.id, eventItem);
                        eventList.Add(eventItem);
                    }

                    eventItem.completed = Properties.Settings.Default.dailyCompletionList.Contains(eventInfo.id);
                }

                ((EventItemComparer)eventView.CustomSort).updateCurrentTimestamp();
                eventView.Refresh();
                eventContainer.UpdateLayout();
                limitVisibleEvents();
            }
            else if (args.func == async_getStartupInformation)
            {
                if (args.exception != null)
                {
                    this.Hide();
                    System.Windows.MessageBox.Show("Cannot retrieve startup information from the server. The program will now close.",
                                                   "GW2Stuff Overlay");
                    this.Close();
                    return;
                }

                StartupInformation response = (StartupInformation)args.result;

                worlds = response.worlds;
                Version version        = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                int     currentVersion = (version.Major * 1000000) + (version.Minor * 1000) + version.Revision;

                if (currentVersion < response.minVersion)
                {
                    this.Hide();
                    MessageBox.Show("A required update for the overlay is now available: gw2stuff.com/overlay",
                                    "GW2Stuff Overlay");
                    this.Close();
                    return;
                }

                menuItem_options.IsEnabled = true;
                menuItem_world.IsEnabled   = true;
                menuItem_world_eu.Items.Clear();
                menuItem_world_us.Items.Clear();
                foreach (WorldInformation worldInformation in worlds)
                {
                    MenuItem menuItem = new MenuItem();
                    menuItem.Header = worldInformation.name;
                    menuItem.Tag    = worldInformation;
                    menuItem.Click += menuItem_world_Click;

                    switch (worldInformation.region)
                    {
                    case "eu":
                        menuItem_world_eu.Items.Add(menuItem);
                        break;

                    case "us":
                        menuItem_world_us.Items.Add(menuItem);
                        break;
                    }
                }

                if (OverlaySettings.defaultWorldId != 0)
                {
                    setWorldId(OverlaySettings.defaultWorldId);
                }
            }
        }