コード例 #1
0
ファイル: UpdateTimer.cs プロジェクト: swecker/Telemachus
        public void update(object sender, UpdateTimerEventArgs timeElapsedEventArgs)
        {
            if ((timeElapsedEventArgs.Time - lastEventTime > interval) && Enabled)
            {
                if (Elapsed != null)
                {
                    Elapsed(this, timeElapsedEventArgs);
                }

                lastEventTime = timeElapsedEventArgs.Time;
            }
        }
コード例 #2
0
        public void update(object sender, UpdateTimerEventArgs timeElapsedEventArgs)
        {
            if ((timeElapsedEventArgs.Time - lastEventTime > interval) && Enabled)
            {
                if (Elapsed != null)
                {
                    Elapsed(this, timeElapsedEventArgs);
                }

                lastEventTime = timeElapsedEventArgs.Time;
            }
        }
コード例 #3
0
        private void streamData(object sender, UpdateTimerEventArgs e)
        {
            DataSources dataSources = new DataSources();

            lock (subscriptionLock)
            {
                streamTimer.Interval = streamRate;

                if (toRun.Count + subscriptions.Count > 0)
                {
                    try
                    {
                        var entries = new Dictionary <string, object>();

                        APIEntry entry = null;

                        dataSources.vessel = kspAPI.getVessel();

                        //Only parse the paused argument if the active vessel is null
                        if (dataSources.vessel != null)
                        {
                            toRun.UnionWith(subscriptions);

                            foreach (string s in toRun)
                            {
                                DataSources dataSourcesClone = dataSources.Clone();
                                string      trimedQuotes     = s.Trim();
                                string      refArg           = trimedQuotes;
                                kspAPI.parseParams(ref refArg, ref dataSourcesClone);

                                kspAPI.process(refArg, out entry);

                                if (entry != null)
                                {
                                    dataSourcesClone.setVarName(trimedQuotes);
                                    entries[dataSourcesClone.getVarName()] = entry.formatter.prepareForSerialization(entry.function(dataSourcesClone));
                                }
                            }

                            toRun.Clear();

                            WebSocketFrame frame  = new WebSocketFrame(Encoding.UTF8.GetBytes(SimpleJson.SimpleJson.SerializeObject(entries)));
                            byte[]         bFrame = frame.AsBytes();
                            dataRates.addDownLinkPoint(System.DateTime.Now, bFrame.Length * UpLinkDownLinkRate.BITS_PER_BYTE);
                            clientConnection.Send(bFrame);
                        }
                        else
                        {
                            sendNullMessage();
                        }
                    }
                    catch (NullReferenceException)
                    {
                        PluginLogger.debug("Swallowing null reference exception, potentially due to async game state change.");
                        sendNullMessage();
                    }
                    catch (Exception ex)
                    {
                        PluginLogger.debug("Closing socket due to potential client disconnect:" + ex.GetType().ToString());
                        close();
                    }
                }
                else
                {
                    sendNullMessage();
                }
            }
        }
コード例 #4
0
        private void streamData(object sender, UpdateTimerEventArgs e)
        {
            DataSources dataSources = new DataSources();

            lock (subscriptionLock)
            {
                streamTimer.Interval = streamRate;

                if (toRun.Count + subscriptions.Count > 0)
                {
                    try
                    {
                        List<string> entries = new List<string>();

                        APIEntry entry = null;

                        dataSources.vessel = kspAPI.getVessel();

                        //Only parse the paused argument if the active vessel is null
                        if (dataSources.vessel != null)
                        {
                            toRun.UnionWith(subscriptions);

                            foreach (string s in toRun)
                            {
                                DataSources dataSourcesClone = dataSources.Clone();
                                string trimedQuotes = s.Trim();
                                string refArg = trimedQuotes;
                                kspAPI.parseParams(ref refArg, ref dataSourcesClone);

                                kspAPI.process(refArg, out entry);

                                if (entry != null)
                                {
                                    dataSourcesClone.setVarName(trimedQuotes);
                                    entries.Add(entry.formatter.format(entry.function(dataSourcesClone), dataSourcesClone.getVarName()));
                                }
                            }

                            toRun.Clear();

                            if (entry != null)
                            {
                                WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes(entry.formatter.pack(entries)));
                                byte[] bFrame = frame.AsBytes();
                                dataRates.addDownLinkPoint(System.DateTime.Now, bFrame.Length * UpLinkDownLinkRate.BITS_PER_BYTE);
                                clientConnection.Send(bFrame);
                            }
                        }
                        else
                        {
                            sendNullMessage();
                        }
                    }
                    catch(NullReferenceException)
                    {
                        PluginLogger.debug("Swallowing null reference exception, potentially due to async game state change.");
                        sendNullMessage();
                    }
                    catch (Exception ex)
                    {
                        PluginLogger.debug("Closing socket due to potential client disconnect:" + ex.GetType().ToString());
                        close();
                    }
                }
                else
                {
                    sendNullMessage();
                }
            }
        }