Ejemplo n.º 1
0
        private String argumentsParse(String args, DataSources dataSources)
        {
            APIEntry currentEntry = null;
            var      APIResults   = new Dictionary <string, object>();

            String[] argsSplit = args.Split(ARGUMENTS_DELIMETER);

            foreach (String arg in argsSplit)
            {
                string refArg = arg;
                PluginLogger.fine(refArg);
                kspAPI.parseParams(ref refArg, ref dataSources);
                currentEntry = argumentParse(refArg, dataSources);
                APIResults[dataSources.getVarName()] = currentEntry.formatter.prepareForSerialization(currentEntry.function(dataSources));

                //Only parse the paused argument if the active vessel is null
                if (dataSources.vessel == null)
                {
                    break;
                }
            }

            return(SimpleJson.SimpleJson.SerializeObject(APIResults));
        }
Ejemplo n.º 2
0
        private String argumentsParse(String args, DataSources dataSources)
        {
            APIEntry      currentEntry = null;
            List <string> APIResults   = new List <string>();

            String[] argsSplit = args.Split(ARGUMENTS_DELIMETER);

            foreach (String arg in argsSplit)
            {
                string refArg = arg;
                PluginLogger.fine(refArg);
                kspAPI.parseParams(ref refArg, ref dataSources);
                currentEntry = argumentParse(refArg, dataSources);
                APIResults.Add(currentEntry.formatter.format(currentEntry.function(dataSources)));

                //Only parse the paused argument if the active vessel is null
                if (dataSources.vessel == null)
                {
                    break;
                }
            }

            return(currentEntry.formatter.pack(APIResults));
        }
Ejemplo n.º 3
0
        private void streamData(object sender, ElapsedEventArgs e)
        {
            streamTimer.Interval = streamRate;

            DataSources dataSources = new DataSources();

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

                    APIEntry entry = null;

                    lock (subscriptionLock)
                    {
                        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();
            }
        }