/// <summary>
        /// Write's the specified entity to the text file
        /// </summary>
        /// <param name="entity"></param>
        public void OutputEntity(IAgEntity entity)
        {
            DateTime utcNow = DateTime.UtcNow;
            int      millisecondSinceLastWrite = (int)(utcNow - m_timeLastWrite).TotalMilliseconds;

            m_timeLastWrite = utcNow;

            OutputSettings settings;

            if (!m_settings.TryGetValue(entity.ID, out settings))
            {
                settings = new OutputSettings(Affiliation.Friendly, "SFAPMF----*****");
            }

            AgPointEntity pointEntity = entity as AgPointEntity;
            StringBuilder entry       = new StringBuilder();

            entry.Append(pointEntity.DisplayName);
            entry.Append(" ");
            entry.Append(Math.Round(pointEntity.Position.Latitude, 6));
            entry.Append(" ");
            entry.Append(Math.Round(pointEntity.Position.Longitude, 6));
            entry.Append(" ");
            entry.Append(Math.Round(pointEntity.Position.Altitude, 6));
            entry.Append(" ");
            entry.Append(settings.Affiliation);
            entry.Append(" ");
            entry.Append(settings.Symbology);
            entry.Append(" ");
            entry.Append(millisecondSinceLastWrite);

            m_textWriter.WriteLine(entry.ToString());
        }
Example #2
0
        /// <summary>
        /// ThreadFunction is where all of the actual substance happens.
        /// Using the Stream object, we read a line of data and parse
        /// it for the entity ID, Position and our meta-data.
        /// This data is in a simple format laid out as follows.
        /// Each line is 80 characters plus linefeed and carriage return
        /// Each token is seperated by a single whitespace with the order being
        /// NAME LAT LON ALT AFFILIATION MIL2525B TIMETONEXTUPDATE
        /// ReferenceProviderData.txt in the Samples\Data directory contains
        /// sample data which can be used to run the plug-in.
        /// </summary>
        public void ThreadFunction()
        {
            //If we have any subscribers, generate the start event
            if (OnProviderStart != null)
            {
                OnProviderStart(this);
            }

            while (m_active)
            {
                //Open the text file for reading
                using (TextReader textReader = new StreamReader(m_filename))
                {
                    string line = textReader.ReadLine();
                    while (m_active && (line != null))
                    {
                        //Parse a line
                        string[] elements    = textReader.ReadLine().Split(' ');
                        string   entityName  = elements[0];
                        double   latitude    = Convert.ToDouble(elements[1]);
                        double   longitude   = Convert.ToDouble(elements[2]);
                        double   altitude    = Convert.ToDouble(elements[3]);
                        string   affiliation = elements[4];
                        string   mil2525b    = elements[5];
                        int      timeDelay   = Convert.ToInt32(elements[6]);

                        //Now we'll see if the entity has already been
                        //inserted into the system.  If it has, we simply
                        //update it and call CommitUpdate, if it hasn't
                        //we need to call Add
                        bool           NewEntity = false;
                        IAgEntity      Entity;
                        IAgPointEntity PointEntity;
                        Entity = Entities.Find(entityName);
                        if (Entity == null)
                        {
                            PointEntity          = new AgPointEntity() as IAgPointEntity;
                            Entity               = PointEntity as IAgEntity;
                            Entity.ID            = entityName;
                            PointEntity.Position = new AgEntityPosition() as IAgEntityPosition;
                            NewEntity            = true;
                        }
                        else
                        {
                            PointEntity = Entity as IAgPointEntity;
                        }

                        //Our data does not have time so we always assume the
                        //position time is now.  RT3 uses UTC.
                        Entity.Time = DateTime.UtcNow;

                        //Set the position
                        PointEntity.Position.Set(latitude, longitude, altitude);

                        //Set the meta-data
                        IAgEntityMetaDataCollection metaData = Entity.MetaData;
                        metaData.Set("Affiliation", affiliation);
                        metaData.Set("Symbology", mil2525b);

                        //Call add or update
                        if (NewEntity)
                        {
                            Entities.Add(Entity);
                        }
                        else
                        {
                            PointEntity.CommitUpdate(AgEEntityUpdate.eEntityUpdate);
                        }

                        //Sleep the desired wait time
                        if (timeDelay > 0)
                        {
                            Thread.Sleep(timeDelay);
                        }
                        line = textReader.ReadLine();
                    }

                    //Since we're just reading from a file, when we hit the
                    //end we'll remove everything and then start over.
                    //This way we never run out of sample data.
                    Entities.RemoveAll();
                    Thread.Sleep(1000);
                }
            }

            //When we stop, make sure we trigger the OnProviderStop event.
            if (OnProviderStop != null)
            {
                OnProviderStop(this);
            }
        }