public async Task <IActionResult> NewScanAsync(Scan scan)
        {
            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);

            Guid key = Guid.NewGuid();
            //if our scan does not have a user friendly name we give it a default name with the code below.
            String def_name = null;

            if (String.IsNullOrEmpty(scan.name))
            {
                def_name = current.LastMode.LastSubmode.Submode.name + "'s scan";
            }
            else
            {
                def_name = scan.name;
            }
            Scan s = new Scan(key, def_name, scan.type, scan.main_aspect, scan.scan_angle, scan.scan_rate, scan.hits_per_scan);


            current.LastMode.LastSubmode.Scan = s;
            //remember we did not give a scan id to this submode, so we did not add it to db
            current.LastMode.LastSubmode.Submode.scan_id = key;
            Submode sbm = current.LastMode.LastSubmode.Submode;

            try
            {
                _session.BeginTransaction();
                await _session.SaveScan(s);

                await _session.SaveSubMode(sbm);

                await _session.Commit();

                current.message = "Both records (Submode and Scan) added to db";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }

            return(RedirectToAction("Preliminary", "AntennaScan"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> NewModeAsync(Mode mod)
        {
            Guid key = Guid.NewGuid();

            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);
            Mode     m  = new Mode(key, mod.name, current.Radar.ID);
            ModeInfo mi = new ModeInfo(m);

            mi.ListOfSubmodes = new List <SubModeInfo>();
            current.LastMode  = mi;

            try
            {
                _session.BeginTransaction();
                await _session.SaveMode(m);

                await _session.Commit();

                current.message = "New Mode added";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();

                return(View(mod));
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("NewSubmode", "Submode"));
        }
        public async Task <RedirectToActionResult> DeleteRadar()
        {
            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);

            try
            {
                _session.BeginTransaction();
                await _session.DeleteScan(current.Radar.ID);

                await _session.DeleteLocation(current.Location.ID);

                await _session.DeleteReceiver(current.Receiver.ID);

                await _session.DeleteTransmitter(current.Transmitter.ID);

                await _session.DeleteLocation(current.Location.ID);

                await _session.Commit();

                current.message = "Radar " + current.Radar.ID + " removed From Database";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }
Ejemplo n.º 4
0
        public async System.Threading.Tasks.Task <IActionResult> NewTransmitter(Transmitter transmitter_temp)
        {
            //handling user-may-occur mistakes
            if (transmitter_temp.modulation_type.StartsWith("Select"))
            {
                ViewData["message"] = "Please fill the modulation type";
                return(View(transmitter_temp));
            }

            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            foreach (KeyValuePair <Guid, Data> sds in Program.data)
            {
                if (sds.Key.Equals(sessionID))
                {
                    current = sds.Value;
                }
            }

            //If the transmitter name is null we give a default name that specifies its number
            String def_name = null;
            //because we change the default name after the Radar added we we should keep it in mind to it is a default given name
            bool isNamed = false;

            if (String.IsNullOrEmpty(transmitter_temp.name))
            {
                int count = 0;

                try
                {
                    count = await _session.GetTransmitterNumber();
                }
                catch (Exception e)
                {
                    // log exception here
                    ViewData["message"] = e.Message.ToString() + " Error";
                    await _session.Rollback();

                    count = -1;
                    return(View(transmitter_temp));
                }
                finally
                {
                    _session.CloseTransaction();
                }
                def_name = "Transmitter " + count;
                //keep it in mind
                isNamed = true;
            }
            else
            {
                def_name = transmitter_temp.name;
            }

            Guid        key         = Guid.NewGuid();
            Transmitter transmitter = new Transmitter(key, def_name, transmitter_temp.modulation_type, transmitter_temp.max_frequency, transmitter_temp.min_frequency, transmitter_temp.power);

            transmitter.Isnamed = isNamed;

            //save our transmitter to database
            try
            {
                _session.BeginTransaction();
                await _session.SaveTransmitter(transmitter);

                await _session.Commit();
            }
            catch (Exception e)
            {
                // log exception here
                ViewData["message"] = e.Message.ToString() + " Error";
                await _session.Rollback();

                return(View(transmitter));
            }
            finally
            {
                _session.CloseTransaction();
            }

            //Add our transmitter to Data model and update the dictionary so we can use its id when we're adding Radar entity
            current.Transmitter = transmitter;

            return(RedirectToAction("Preliminary", "Antenna"));
        }
        public async Task <IActionResult> NewAntennaAsync(Antenna antenna_temp)
        {
            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);

            /*we can also use below lines to get correct data
             * Data d = new Data();
             * Program.data.TryGetValue(sessionID, out d);*/

            Data current = new Data();

            foreach (KeyValuePair <Guid, Data> sds in Program.data)
            {
                if (sds.Key.Equals(sessionID))
                {
                    current = sds.Value;
                }
            }

            //control if current did not came
            if (current.Receiver == null)
            {
                //it is an error
                return(RedirectToAction("NewReceiver", "Receiver"));
            }

            //handling user-may-occur mistakes
            if (antenna_temp.type.StartsWith("Select"))
            {
                current.message     = "Please select Type";
                current.LastAntenna = antenna_temp;
                Program.data.Remove(sessionID);
                Program.data.Add(sessionID, current);
                return(RedirectToAction("Preliminary", "Antenna"));
            }

            //if our antenna does not have a user friendly name we give it a default name with the code below.
            String def_name = null;
            //because we change the default name after the Radar added we we should keep it in mind to it is a default given name
            bool isNamed = false;

            if (String.IsNullOrEmpty(antenna_temp.name))
            {
                String transmitter_or_receiver_name = null;
                //if it is a transmitter antenna define it as a transmitter antenna in its name
                if (antenna_temp.duty.ToLower().Equals("transmitter"))
                {
                    transmitter_or_receiver_name = current.Transmitter.name;
                }
                //if it is a receiver or multi tasked antenna define it as a receiver in its name
                else
                {
                    transmitter_or_receiver_name = current.Receiver.name;
                }
                //this statement is for seperating receiver and multi-tasked antennas
                if (antenna_temp.duty.ToLower().Equals("both"))
                {
                    def_name = "Monostatic radar Antenna with receiver name: " + transmitter_or_receiver_name;
                }
                else
                {
                    def_name = transmitter_or_receiver_name + "s Antenna";
                }
                isNamed = true;
            }
            else
            {
                def_name = antenna_temp.name;
            }
            //end of naming

            Guid    key     = Guid.NewGuid();
            Antenna antenna = new Antenna();

            //if the antenna is both receiver and transmitter antenna give it a receiver and a transmitter id
            //Because we need a transmitter before adding an antenna which serves as transmitter antenna we should create its transmitter first.
            //After create a transmitter we can insert our antenna to database
            //all of the insertions will execute in goToRadar and Done methods
            if (antenna_temp.duty.Equals("both"))
            {
                antenna         = new Antenna(key, def_name, antenna_temp.type, antenna_temp.horizontal_beamwidth, antenna_temp.vertical_beamwidth, antenna_temp.polarization, antenna_temp.number_of_feed, antenna_temp.horizontal_dimension, antenna_temp.vertical_dimension, antenna_temp.duty, null, current.Receiver.ID, antenna_temp.location);
                antenna.Isnamed = isNamed;
                current.message = "New Antenna added to record list";
                current.ListOfAntennas.Add(antenna);
            }
            //if the antenna is a receiver antenna give it a receiver id to build a relationship between antenna and its receiver
            else if (antenna_temp.duty.Equals("receiver"))
            {
                antenna         = new Antenna(key, def_name, antenna_temp.type, antenna_temp.horizontal_beamwidth, antenna_temp.vertical_beamwidth, antenna_temp.polarization, 1, antenna_temp.horizontal_dimension, antenna_temp.vertical_dimension, antenna_temp.duty, null, current.Receiver.ID, antenna_temp.location);
                antenna.Isnamed = isNamed;
                current.message = "New Antenna added to record list";
                current.ListOfAntennas.Add(antenna);
            }
            //if the antenna is a transmitter antenna define it's transmitter with giving an attribute transmitter id
            else
            {
                Guid transmitter_id = current.Transmitter.ID;
                antenna         = new Antenna(key, def_name, antenna_temp.type, antenna_temp.horizontal_beamwidth, antenna_temp.vertical_beamwidth, antenna_temp.polarization, antenna_temp.number_of_feed, antenna_temp.horizontal_dimension, antenna_temp.vertical_dimension, antenna_temp.duty, transmitter_id, null, antenna_temp.location);
                antenna.Isnamed = isNamed;
                current.message = "New Antenna added to record list";
                current.ListOfAntennas.Add(antenna);
            }

            if (antenna_temp.ComeFromAdd)
            {
                current.message = "New Antenna added to database";
                try
                {
                    _session.BeginTransaction();
                    await _session.SaveAntenna(antenna);

                    await _session.Commit();
                }
                catch (Exception e)
                {
                    // log exception here
                    current.message = e.Message.ToString() + " Error, plase check your database connection and restart your program, Do not forgett to delete uneccessary transmitter and receiver";
                    await _session.Rollback();

                    return(RedirectToAction("Preliminary", "Antenna"));
                }
                finally
                {
                    _session.CloseTransaction();
                }
            }
            current.LastAntenna = antenna_temp;
            return(RedirectToAction("Preliminary", "Antenna"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> NewAntennaScanParamAsync(Antenna.AntennaList ascans)
        {
            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);

            //control if current did not came
            if (current.Receiver == null) //means current == null
            {
                ViewData["message"] = "Error occured please restart the program";
                return(View(ascans));
            }

            //refresh the list to specify selected antennas
            current.ListOfAntennas = ascans.antennas;
            try
            {
                _session.BeginTransaction();

                for (int i = 0; i < ascans.antennas.Count; i++)
                {
                    Antenna antenna = ascans.antennas[i];

                    AntennaScan ascan = new AntennaScan(antenna.ID, current.LastMode.LastSubmode.Scan.ID);
                    if (antenna.IsChecked)
                    {
                        Guid temp = Guid.Empty;
                        temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, current.LastMode.LastSubmode.Scan.ID);

                        if (temp.Equals(Guid.Empty))
                        {
                            await _session.SaveAntennaScan(ascan);
                        }
                    }
                    else
                    {
                        Guid temp = Guid.Empty;
                        temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, current.LastMode.LastSubmode.Scan.ID);

                        if (!temp.Equals(Guid.Empty))
                        {
                            await _session.DeleteAntennaScan(ascan);
                        }
                    }
                }
                await _session.Commit();

                if (current.Receiver != null) //means current != null
                {
                    current.message = "New Relationship between antennas and scan added";
                }
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("Preliminary", "AntennaScan"));
        }
        public async System.Threading.Tasks.Task <IActionResult> NewReceiver(Receiver receiver)
        {
            //create new Data element for our current created radar
            Data current = new Data();

            //I think this method gives the current session id
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);

            //If the receiver name is null we give a default name that specifies its number
            //because we change the default name after the Radar added we we should keep it in mind to it is a default given name
            bool   IsNamed  = false;
            String rec_name = null;

            if (String.IsNullOrEmpty(receiver.name))
            {
                int count = 0;
                try
                {
                    count = await _session.GetReceiverNumber();
                }
                catch (Exception e)
                {
                    // log exception here
                    ViewData["Message"] = e.Message.ToString() + " Error";
                    Program.data.Remove(sessionID);
                    await _session.Rollback();

                    return(RedirectToAction("NewReceiver", "Receiver"));
                }
                finally
                {
                    _session.CloseTransaction();
                }
                rec_name = "Receiver " + count;
                //keep it in mind
                IsNamed = true;
            }
            else
            {
                rec_name = receiver.name;
            }

            Guid     key = Guid.NewGuid();
            Receiver r   = new Receiver(key, rec_name, receiver.listening_time, receiver.rest_time, receiver.recovery_time);

            r.Isnamed        = IsNamed;
            current.Receiver = r;

            try
            {
                _session.BeginTransaction();

                await _session.SaveReceiver(r);

                await _session.Commit();

                current.message = "New Receiver added";
            }
            catch (Exception e)
            {
                // log exception here
                ViewData["Message"] = e.Message.ToString() + " Error";
                Program.data.Remove(sessionID);
                await _session.Rollback();

                return(RedirectToAction("NewReceiver", "Receiver"));
            }
            finally
            {
                _session.CloseTransaction();
            }
            Program.data.Remove(sessionID);
            Program.data.Add(sessionID, current);
            return(RedirectToAction("Preliminary", "Antenna"));
        }
        public async Task <IActionResult> NewLocationAsync(Location loc)
        {
            //handling user-may-occur mistakes
            if (loc.city == null && loc.country == null && loc.geographic_latitude == null && loc.geographic_longitude == null && loc.airborne == null)
            {
                return(View(loc));

                ViewData["Message"] = "Please fill at least airborne area or Country, City, Geographic Latitude and Geographic Longitude areas";
            }

            //If the location name is null we give a default name that specifies its country, city and area number
            String def_name = null;

            if (String.IsNullOrEmpty(loc.name))
            {
                if (loc.city == null && loc.country == null && loc.geographic_latitude == null && loc.geographic_longitude == null && loc.airborne != null)
                {
                    int count = 0;

                    try
                    {
                        count = await _session.GetLocationName(loc.airborne);
                    }
                    catch (Exception e)
                    {
                        // log exception here
                        ViewData["Message"] = e.Message.ToString() + " Error";
                        await _session.Rollback();
                    }
                    finally
                    {
                        _session.CloseTransaction();
                    }
                    count    = count + 1;
                    def_name = loc.airborne + " " + count;
                }
                else if (loc.city != null && loc.country != null && loc.geographic_latitude != null && loc.geographic_longitude != null)
                {
                    int count = 0;

                    try
                    {
                        count = await _session.GetLocationName(loc.country, loc.city);
                    }
                    catch (Exception e)
                    {
                        // log exception here
                        ViewData["Message"] = e.Message.ToString() + " Error";
                        await _session.Rollback();
                    }
                    finally
                    {
                        _session.CloseTransaction();
                    }
                    count    = count + 1;
                    def_name = loc.country + " " + loc.city + " " + count;
                }
                else
                {
                    ViewData["Message"] = "Please fill at least airborne area or Country, City, Geographic Latitude and Geographic Longitude areas";
                    return(View(loc));
                }
            }
            else
            {
                def_name = loc.name;
            }
            //end of naming////////////////////////////////////////////////////////////////////////////////

            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);

            //control if current did not came
            if (current == null)
            {
                ViewData["Message"] = "Error occured please restart the program";
                return(View(loc));
            }

            //defining Radar's and Location's key here
            Guid key_location = Guid.NewGuid();
            Guid key          = Guid.NewGuid();

            current.Radar.ID = key;

            //rename Radar, Transmitter and Antennas again
            String radar_name = current.Radar.name;

            if (current.Radar.Isnamed == true)
            {
                radar_name         = "Radar in " + def_name;
                current.Radar.name = radar_name;
            }

            if (current.Transmitter.Isnamed == true)
            {
                Guid   id      = current.Transmitter.ID;
                String newName = radar_name + "'s Transmitter";
                current.Transmitter.name = newName;
                try
                {
                    _session.BeginTransaction();
                    _session.RenameTransmitter(id, newName);
                    await _session.Commit();
                }
                catch (Exception e)
                {
                    // log exception here
                    ViewData["Message"] = e.Message.ToString() + " Error";
                    await _session.Rollback();

                    return(View(loc));
                }
                finally
                {
                    _session.CloseTransaction();
                }
            }

            if (current.Receiver.Isnamed == true)
            {
                Guid   id      = current.Receiver.ID;
                String newName = radar_name + "'s Receiver";
                current.Receiver.name = newName;
                try
                {
                    _session.BeginTransaction();
                    _session.RenameReceiver(id, newName);
                    await _session.Commit();
                }
                catch (Exception e)
                {
                    // log exception here
                    ViewData["Message"] = e.Message.ToString() + " Error";
                    await _session.Rollback();

                    return(View(loc));
                }
                finally
                {
                    _session.CloseTransaction();
                }
            }

            Location location_temp = new Location(key_location, def_name, loc.country, loc.city, loc.geographic_latitude, loc.geographic_longitude, loc.airborne);
            Radar    radar_temp    = new Radar(key, radar_name, current.Radar.system, current.Radar.configuration, current.Transmitter.ID, current.Receiver.ID, key_location);

            current.Radar = radar_temp;
            //we do not need location in current because we will not use its informations

            try
            {
                _session.BeginTransaction();
                await _session.SaveLocation(location_temp);

                await _session.SaveRadar(radar_temp);

                await _session.Commit();

                current.message = "Both records (Location and Radar) saved to the db";
                Program.data.Remove(sessionID);
                Program.data.Add(sessionID, current);
                return(RedirectToAction("NewMode", "Mode"));
            }
            catch (Exception e)
            {
                // log exception here
                ViewData["Message"] = e.Message.ToString() + " Error";
                await _session.Rollback();

                return(View(loc));
            }
            finally
            {
                _session.CloseTransaction();
            }
        }