示例#1
0
        /// <summary>
        /// Loads the templates.
        /// </summary>
        /// <param name="strFilename">The string filename.</param>
        private void LoadTemplates(string strFilename)
        {
            this.Cursor = Cursors.Wait;

            ClearTemplates();

            try
            {
                XDocument xdoc = XDocument.Load(strFilename);

                foreach (XElement eTemplate in xdoc.Root.Elements("RFDevice"))
                {
                    RFDevice device = RFDevice.FromXml(eTemplate);

                    if (device != null)
                    {
                        this.RFDeviceTemplateCollection.Add(new RFDeviceTemplate(device));
                    }
                }
            }
            catch (Exception ex)
            {
                MB.Error(ex);
            }

            this.Cursor = Cursors.Arrow;
        }
        /// <summary>
        /// Mains the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static public void Main(string[] args)
        {
            Properties.Settings settings = Properties.Settings.Default;

            IPEndPoint epReceive = new IPEndPoint(IPAddress.Parse(settings.UDPServerHost), settings.UDPPortReceiving);
            UdpClient  ucReceive = new UdpClient(settings.UDPPortReceiving);

            Socket     sSenderSocket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint epSenderEndPoint = new IPEndPoint(IPAddress.Parse(settings.UDPServerHost), settings.UDPPortSending);

            Console.Out.WriteLine("Listening To {0}:{1} And Waiting For Incoming Data ...", settings.UDPServerHost, settings.UDPPortReceiving);

            // A neverending story ...
            while (true)
            {
                byte[] baReceived = ucReceive.Receive(ref epReceive);

                string strReceived = Encoding.Default.GetString(baReceived);
                string strDateTime = DateTime.Now.Fmt_YYYYMMDD_HHMMSSFFF();

                Console.Out.WriteLine(DIVIDER);
                Console.Out.WriteLine("{0}: Received {1} Bytes.", strDateTime, strReceived.Length);

                try
                {
                    XDocument xDevice = XDocument.Parse(strReceived);
                    RFDevice  device  = RFDevice.FromXml(xDevice.Root);

                    Console.Out.WriteLine("Id        : {0}", device.Id);
                    Console.Out.WriteLine("Name      : {0}", device.Name);
                    Console.Out.WriteLine("Latitude  : {0}", device.Latitude);
                    Console.Out.WriteLine("Longitude : {0}", device.Longitude);
                    Console.Out.WriteLine("StartTime : {0}", device.StartTime);

                    // ----------------------------------------------------

                    GeoLocalizationResult gcr = new GeoLocalizationResult
                    {
                        Id               = device.Id,
                        Latitude         = device.Latitude,
                        Longitude        = device.Longitude,
                        Altitude         = 0,
                        LocalizationTime = DateTime.Now.Ticks
                    };

                    XElement eGeoLocalizationResult = gcr.ToXml();

                    byte[] baMessage = Encoding.Default.GetBytes(eGeoLocalizationResult.ToDefaultString());

                    sSenderSocket.SendTo(baMessage, epSenderEndPoint);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.Message);
                }
            }
        }
        /// <summary>
        /// Opens the file.
        /// </summary>
        /// <param name="strInputFilename">The string input filename.</param>
        internal void LoadFile(string strInputFilename)
        {
            this.Cursor = Cursors.Wait;

            this.CurrentFile = strInputFilename;

            try
            {
                XDocument xdoc = XDocument.Load(strInputFilename);

                //---------------------------------------------------------

                XElement eGeneralSettings = xdoc.Root.Element("GeneralSettings");
                this.Zoom = eGeneralSettings.GetDoubleFromNode("Zoom") ?? this.Zoom;
                //ShowCenter = eGeneralSettings.GetBoolFromNode("ShowCenter") ?? ShowCenter;
                //this.ScenarioDescription = eGeneralSettings.GetStringFromCData( "ScenarioDescription" );

                string strMapProvider = eGeneralSettings.GetStringFromNode("MapProvider") ?? this.MapProvider.Name;
                this.MapProvider = GetProviderFromString(strMapProvider);

                XElement eCenterPosition = eGeneralSettings.Element("CenterPosition");
                this.Latitude  = eCenterPosition.GetDoubleFromNodePoint("Latitude") ?? this.Latitude;
                this.Longitude = eCenterPosition.GetDoubleFromNodePoint("Longitude") ?? this.Longitude;

                //---------------------------------------------------------

                // Create not an new instance, only load the data into the existing one ...
                this.MetaInformation.LoadFromXml(xdoc.Root);

                // Ist ja noch nix passiert ...
                this.DescriptionMarkdownChanged   = false;
                this.DescriptionStylesheetChanged = false;

                //this.tecDescription.Text = this.MetaInformation.Description;
                //this.tecStyleSheet.Text = this.MetaInformation.Stylesheet;

                //---------------------------------------------------------

                XElement eRFDeviceCollection = xdoc.Root.Element("RFDeviceCollection");

                foreach (XElement e in eRFDeviceCollection.Elements())
                {
                    AddRFDevice(RFDevice.FromXml(e));
                }

                AddFileHistory(strInputFilename);
            }
            catch (Exception ex)
            {
                MB.Error(ex);
            }

            this.Cursor = Cursors.Arrow;
        }
        public void Test000_ExportAndImportRFDeviceXml()
        {
            SIGENCEScenarioToolTestCaseHelper.ShowTestCaseInformation();

            //-----------------------------------------------------------------

            RFDevice source = new RFDevice
            {
                Id                    = -42,
                RxTxType              = RxTxTypes.IdealSDR,
                AntennaType           = AntennaType.Unknown,
                StartTime             = 42,
                Latitude              = 15,
                Longitude             = 10,
                Altitude              = 1974,
                CenterFrequency_Hz    = 90000,
                Bandwidth_Hz          = 10000,
                Gain_dB               = 5,
                SignalToNoiseRatio_dB = 263,
                Roll                  = -42,
                Pitch                 = -42,
                Yaw                   = -42,
                XPos                  = -1,
                YPos                  = -2,
                ZPos                  = -3,
                Name                  = "Han Solo",
                Remark                = "A Star Wars Story.",
            };

            XElement e = source.ToXml();

            Assert.NotNull(e);

            string strFilename =
                $"{Path.GetTempPath()}nunit_rfdevice.{DateTime.Now.ToString( "yyyyMMdd_HHmmssfff" )}.xml";

            e.SaveDefault(strFilename);

            Assert.True(File.Exists(strFilename));

            //-----------------------------------------------------------------

            XDocument xdoc = XDocument.Load(strFilename);

            Assert.NotNull(xdoc);

            RFDevice destination = RFDevice.FromXml(xdoc.Root);

            Assert.NotNull(destination);

            Assert.True(destination.Equals(source));
        }