Exemplo n.º 1
0
        public async Task <IActionResult> NewSubmodeAsync(Submode sm)
        {
            //get session id (we will use it when updating data and handling errors)
            String sessionID_s = HttpContext.Session.GetString("Session");
            Guid   sessionID   = Guid.Parse(sessionID_s);
            Data   current     = new Data();

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

            for (int i = 0; i < current.ListOfAntennas.Count; i++)
            {
                current.ListOfAntennas[i].IsChecked = false;
            }
            Guid key_submode = Guid.NewGuid();

            //if our submode does not have a user friendly name we give it a default name with the code below.
            String def_name = null;

            if (String.IsNullOrEmpty(sm.name))
            {
                def_name = current.LastMode.Mode.name + "'s submode " + current.LastMode.ListOfSubmodes.Count;
            }
            else
            {
                def_name = sm.name;
            }

            Submode     sbm     = new Submode(key_submode, def_name, current.LastMode.Mode.ID, sm.PRI, sm.PW, sm.max_frequency, sm.min_frequency);
            SubModeInfo sbmINFO = new SubModeInfo(sbm);

            current.LastMode.ListOfSubmodes.Add(sbmINFO);
            //specify current submode as lastSubmode. So it helps us find scanID during creation of antenna scan relationship
            current.LastMode.LastSubmode = sbmINFO;
            return(RedirectToAction("NewScan", "Scan"));
        }
Exemplo n.º 2
0
        //below functions are for edit pages
        public async Task <IActionResult> BeforeEdit(Guid id, String?message)
        {
            //error case
            if (!String.IsNullOrEmpty(message as string))
            {
                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = new Submode();
                modal.Scan           = new Scan();
                modal.ListOfAntennas = new List <Antenna>();
                ViewData["Message"]  = message as string;
                return(View(modal));
            }

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

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

            if (current != null)
            {
                //Because we use the same view before and after edit process we should handle the view messages with the following conditions
                if (current.edited)
                {
                    ViewData["Message"] = "Update completed successfully";
                    current.edited      = false;
                }
                if (current.message != null)
                {
                    ViewData["Message"] = current.message;
                    current.message     = null;
                }

                //Get submode's informations and shows it in edit page
                Submode sbm = await _session.Submode.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Scan scan = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                for (int j = 0; j < current.LastMode.ListOfSubmodes.Count; j++)
                {
                    if (current.LastMode.ListOfSubmodes[j].Submode.ID.Equals(id))
                    {
                        //specify current submode as last submode. It helps us in scan pages
                        current.LastMode.LastSubmode = current.LastMode.ListOfSubmodes[j];
                    }
                }

                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = sbm;
                modal.Scan           = scan;
                modal.ListOfAntennas = current.ListOfAntennas;
                return(View(modal));
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }
Exemplo n.º 3
0
        public async Task EditSubmode(Submode entity)
        {
            ISQLQuery query = _session.CreateSQLQuery("UPDATE Submode SET name = :name, PW = :PW, PRI = :PRI, min_frequency = :min_frequency, max_frequency = :max_frequency WHERE ID = :ID");

            query.SetParameter("ID", entity.ID);
            query.SetParameter("name", entity.name);
            query.SetParameter("PW", entity.PW);
            query.SetParameter("PRI", entity.PRI);
            query.SetParameter("min_frequency", entity.min_frequency);
            query.SetParameter("max_frequency", entity.max_frequency);
            query.ExecuteUpdate();
        }
        //below functions are for edit pages
        public async Task <IActionResult> BeforeEdit(Guid id)
        {
            //get session id (we will use it when updating data and handling errors)
            String sessionID_s = HttpContext.Session.GetString("Session");
            Guid   sessionID   = Guid.Parse(sessionID_s);
            Data   current     = new Data();

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

            if (current.Receiver != null)
            {
                //Because we use the same view before and after edit process we should handle the view messages with the following conditions
                if (current.edited)
                {
                    ViewData["Message"] = "Update completed successfully";
                    current.edited      = false;
                }
                if (current.message != null)
                {
                    ViewData["Message"] = current.message;
                    current.message     = null;
                }

                //Get scan's informations and shows it in edit page
                Scan scan = await _session.Scan.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Submode sbm = await _session.Submode.Where(b => b.scan_id.Equals(id)).FirstOrDefaultAsync();

                SubModeInfo info = new SubModeInfo();
                info.Scan           = scan;
                info.Submode        = sbm;
                info.ListOfAntennas = new List <Antenna>();
                //because we do not have an attribute that specifies if the antenna is checked
                //(because an antenna might be used from a lot of scans)
                //we should find if the antenna is working with this scan using AntennaScan tables
                for (int i = 0; i < current.ListOfAntennas.Count; i++)
                {
                    Guid temp = Guid.Empty;
                    temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, id);

                    if (!temp.Equals(Guid.Empty))
                    {
                        info.ListOfAntennas.Add(current.ListOfAntennas[i]);
                    }
                }
                current.LastMode.LastSubmode = info;
                return(View(info));
            }
            //else
            String message = "Update cannot be completed, please restart the program to solve this issue. If it continues please report it";

            return(RedirectToAction("BeforeEdit", "Submode", new { id = Guid.Empty, message = message }));
        }
        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"));
        }
Exemplo n.º 6
0
        public async Task SaveSubMode(Submode entity)
        {
            ISQLQuery query = _session.CreateSQLQuery("INSERT INTO Submode VALUES(:ID, :name, :mode_id, :PW, :PRI, :min_frequency, :max_frequency, :scan_id)");

            query.SetParameter("ID", entity.ID);
            query.SetParameter("name", entity.name);
            query.SetParameter("mode_id", entity.mode_id);
            query.SetParameter("PW", entity.PW);
            query.SetParameter("PRI", entity.PRI);
            query.SetParameter("min_frequency", entity.min_frequency);
            query.SetParameter("max_frequency", entity.max_frequency);
            query.SetParameter("scan_id", entity.scan_id);
            query.ExecuteUpdate();
        }
Exemplo n.º 7
0
        //below functions are for display pages
        public async Task <IActionResult> Show(Guid id, String message)
        {
            //get session id (we will use it when updating data and handling errors)
            String sessionID_s = HttpContext.Session.GetString("Session");
            Guid   sessionID   = Guid.Parse(sessionID_s);
            Data   current     = new Data();

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

            if (!String.IsNullOrEmpty(message))
            {
                ViewData["message"] = message;
            }

            if (current.Receiver != null)
            {
                //Get submode's informations and shows it in edit page
                Submode sbm = await _session.Submode.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Scan scan = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                for (int j = 0; j < current.LastMode.ListOfSubmodes.Count; j++)
                {
                    if (current.LastMode.ListOfSubmodes[j].Submode.ID.Equals(id))
                    {
                        //specify current submode as last submode. It helps us in scan pages
                        current.LastMode.LastSubmode = current.LastMode.ListOfSubmodes[j];
                    }
                }

                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = sbm;
                modal.Scan           = scan;
                modal.ListOfAntennas = current.ListOfAntennas;
                return(View(modal));
            }
            return(RedirectToAction("RadarList", "UserRadarList"));
        }