public ActionResult <LocateData> Location(LocateData data)
        {
            var outlocation = _location.AddLocation(data); //ruft die Funktion der klasse Locator auf um die daten in ein Dictionary mit IMEI als key zu speichern

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //Gibt Modelstate zurück
            }

            if (outlocation == null)
            {
                return(NotFound());
            }
            string path = @"Your Path";

            ;

            string text = "IMEI= " + data.IMEI + "  " + "Longitude= " + data.Longetude + "  " + "Latitude= " + data.Latetude + "  " + "Time= " + DateTime.Now.ToString("HH:mm:ss") + "|";

            using (var tw = new StreamWriter(path, true))
            {
                tw.WriteLine(text);
                tw.Close();
            }
            return(null);
        }
        public ActionResult <Dictionary <string, LocateData> > GetLocation(String id)
        {
            Dictionary <string, LocateData> output = new Dictionary <string, LocateData>();
            string imei = "";
            string lng  = "";
            string lat  = "";

            string filePath = "Your Path"
            ;
            var         filestream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            const Int32 BufferSize = 128;

            using (var fileStream = System.IO.File.OpenRead("LocationSaves.txt"))
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        if (_location.getBetween(line, "IMEI= ", " ") == id)
                        {
                            imei = _location.getBetween(line, "IMEI= ", " ");
                            lng  = _location.getBetween(line, "Longitude= ", "  ");
                            lat  = _location.getBetween(line, "Latitude= ", "  ");
                        }
                    }
                }
            LocateData temp = new LocateData();

            temp.IMEI      = imei;
            temp.Latetude  = lat;
            temp.Longetude = lng;

            string key = id;

            var locationdata = _location.GetLocation();

            output.Add(temp.IMEI, temp);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //Gibt Modelstate zurück
            }
            else
            {
                return(output);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Funktion zum Hinzufügen von Datein (IMEI, Longitude, Latetude) als Objekt in ein Dictionary
        /// </summary>
        /// <param name="data">
        /// Objekt der Klasse LocateData mit:
        /// string IMEI
        /// string Longetude
        /// string Latetude
        /// </param>
        /// <returns>
        /// Das Objekt data mit den Elementen
        /// </returns>
        public LocateData AddLocation(LocateData data)
        {
            try
            {
                if (_location.ContainsKey(data.IMEI)) //falls Key bze IMEI oder IP schon Vorhanden ist, wird der Standort des Gerätes geupdatet
                {
                    _location[data.IMEI] = data;
                }
                else
                {
                    _location.Add(data.IMEI, data); //falls Key bzw IMEI oder IP nicht voranden ist, wird es hinzugefügt
                }
#pragma warning disable CS0168                      // Variable is declared but never used
            }
            catch (ArgumentNullException ignore) { }
#pragma warning restore CS0168 // Variable is declared but never used
            return(data);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Inicio");

            try
            {
                string err_msg = null;
                _callbacks = new FLCallbackHandler();
                context    = new InstanceContext(_callbacks);
                _client    = new fwlsServiceClient(context);

                Console.WriteLine("Ejecutando: SessionCreate");
                _session = _client.SessionCreate(out err_msg, "WIS", "wis", "wis");

                if (string.IsNullOrEmpty(err_msg) && _session != null)
                {
                    Console.WriteLine("SessionCreate: OK");
                    Guid externalId = new Guid();
                    int  value      = _client.ServerAlive();

                    Coords coords = new Coords
                    {
                        x = -3.695736,
                        y = 40.426104
                    };

                    List <Coords> coordsList = new List <Coords>
                    {
                        coords
                    };

                    LocateData locateData = new LocateData
                    {
                        coords           = coordsList,
                        maxHierarchy     = 0,
                        maxSnapTolerance = 2500
                    };

                    Console.WriteLine("Ejecutando LocateOverNetworkAsync");
                    _client.LocateOverNetworkAsync(_session, externalId, locateData, null);

                    Console.WriteLine("Ejecutando GetProblemSolutionAsync");
                    _client.GetProblemSolutionAsync(_session, externalId, true, null);
                }
                else
                {
                    Console.WriteLine("SessionCreate ERROR: " + err_msg);
                }

                Console.WriteLine("Service Wait");
                string serive_wait = Console.ReadLine();

                Console.WriteLine("Presione una tecla para terminar");
                string input_fin = Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION");
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (_session != null && _client != null)
                {
                    string errmsg = null;
                    _client.SessionClose(out errmsg, _session);
                    if (!string.IsNullOrEmpty(errmsg))
                    {
                        Console.WriteLine("ERROR SessionClose: " + errmsg);
                    }
                    else
                    {
                        Console.WriteLine("SessionClose: OK");
                    }
                }
            }

            string end = Console.ReadLine();
        }