Exemple #1
0
        public string New(string name, string locId)
        {
            try
            {
                string    domainId = DomainSession.GetContextDomain(this.HttpContext);
                iotDomain d        = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
                int       locIdnum = int.Parse(locId);
                Location  loc      = d.Locations.First(l => l.Id == locIdnum);
                if (loc != null)
                {
                    Site site = new Site();
                    site.SiteName     = name;
                    site.siteLocation = loc;
                    site.Domain       = d;
                    Icont.Sites.Add(site);
                    Icont.SaveChanges();
                }
                else
                {
                    return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Location not found.", RequestStatus.Warning));
                }
            }
            catch (Exception e)
            {
                return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Add error.", RequestStatus.Failure));
            }

            return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Add success.", RequestStatus.Success));
        }
Exemple #2
0
 public async Task <ActionResult> Edit(AddSiteViewModel model)
 {
     try
     {
         if (model.SiteName != null)
         {
             string    domainId = DomainSession.GetContextDomain(this.HttpContext);
             iotDomain d        = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
             Location  loc      = d.Locations.First(l => l.Id == d.Id);
             if (loc != null)
             {
                 model.site.siteLocation = loc;
                 model.site.Domain       = d;
                 Icont.Sites.Add(model.site);
                 Icont.SaveChanges();
                 var stored = Icont.Sites.First(s => s.SiteName.Equals(model.site.SiteName));
                 model.Result = StatusResponseGenerator.GetStatusResponseResultForReturnParam(stored);
             }
             return(View(model));
         }
         else
         {
             model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
         }
     }
     catch (Exception e)
     {
         model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
     }
     return(View(model));
 }
        public string New(string Name, string Lat, string Lng)
        {
            try
            {
                string username           = User.Identity.Name;
                ApplicationDbContext cont = new ApplicationDbContext();
                var user = (from u in cont.Users
                            where u.UserName == username
                            select u).First();


                IIotContextBase icont    = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
                string          domainId = DomainSession.GetContextDomain(this.HttpContext);
                iotDomain       d        = icont.Domains.First(dm => dm.DomainName.Equals(domainId));

                Location loc = new Location();
                loc.Domain       = d;
                loc.LocationName = Name;
                loc.Lng          = double.Parse(Lng, CultureInfo.InvariantCulture);
                loc.Lat          = double.Parse(Lat, CultureInfo.InvariantCulture);
                d.Locations.Add(loc);
                icont.SaveChanges();
                return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Location added sucessfully.", RequestStatus.Success));
            }
            catch (Exception e)
            {
                return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Location add failed.", RequestStatus.Failure));
            }
        }
Exemple #4
0
        public async Task <ActionResult> AddType(DeviceAddTypeModel model)
        {
            try
            {
                if (model.Type != null)
                {
                    var       cont     = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
                    string    domainId = DomainSession.GetContextDomain(this.HttpContext);
                    iotDomain domain   = cont.Domains.First(d => d.DomainName.Equals(domainId));
                    domain.DeviceTypes.Add(model.Type);
                    await cont.SaveChangesAsync();

                    model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Success.",
                                                                                       RequestStatus.Success);
                }
                else
                {
                    model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
                }
            }
            catch (Exception e)
            {
                model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
            }
            return(View(model));
        }
 public void TestEntityDbReadLoad()
 {
     try
     {
         int  ReadTestInterations = 250;
         int  maxQueryTimeMs      = 25;
         bool ReadSuccess         = false;
         int  FailCount           = 0;
         TestRepoCreate();
         Stopwatch watch = new Stopwatch();
         iotRepository <iotDomain> repo    = new iotRepository <iotDomain>();
         List <iotDomain>          domains = repo.GetAll().ToList();
         iotDomain domain = domains.First();
         watch.Start();
         for (int i = 0; i < ReadTestInterations; i++)
         {
             ReadSuccess = TestRepoSingleRead(domain.Id);
             if (!ReadSuccess)
             {
                 FailCount++;
             }
         }
         watch.Stop();
         double TimePerQueryMs = watch.ElapsedMilliseconds / ReadTestInterations;
         Assert.IsTrue(TimePerQueryMs < maxQueryTimeMs);
     }
     catch (Exception ex)
     {
         Assert.Fail();
     }
 }
Exemple #6
0
 static public iotDomain AppDomainForUserContext(HttpContextBase cont)
 {
     try
     {
         IPrincipal      seesionAuth = cont.User;
         string          username    = seesionAuth.Identity.Name;
         ApplicationUser user        = GetUserWithName(username);
         if (user != null)
         {
             //DeviceRestfulService cl = new DeviceRestfulService();
             iotContext dbcont   = new iotContext();
             string     domainId = DomainSession.GetContextDomain(cont);
             iotDomain  domain   = dbcont.Domains.First(d => d.DomainName.Equals(domainId));//cl.GetDomainWithName(domainId);
             return(domain);
         }
         else
         {
             return(new iotDomain());
         }
     }
     catch (Exception e)
     {
         return(new iotDomain());
     }
 }
        public ActionResult Index()
        {
            IIotContextBase       icont    = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
            string                domainId = DomainSession.GetContextDomain(this.HttpContext);
            iotDomain             d        = icont.Domains.First(dm => dm.DomainName.Equals(domainId));
            List <Location>       locs     = d.Locations.ToList();
            LocationListViewModel model    = new LocationListViewModel(locs);

            return(View(model));
        }
        public ActionResult ActionStat(int actionId)
        {
            var          icont               = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
            string       domainId            = DomainSession.GetContextDomain(this.HttpContext);
            iotDomain    d                   = icont.Domains.First(dm => dm.DomainName.Equals(domainId));
            DeviceAction prop                = icont.Actions.First(a => a.Id == actionId);
            DeviceActionStatisticModel model = new DeviceActionStatisticModel(prop);

            return(View(model));
        }
        public ActionResult PropertyStat(int propertyId)
        {
            var            icont               = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
            string         domainId            = DomainSession.GetContextDomain(this.HttpContext);
            iotDomain      d                   = icont.Domains.First(dm => dm.DomainName.Equals(domainId));
            DeviceProperty prop                = icont.Properties.First(p => p.Id == propertyId);
            DevicePropertyStatisticModel model = new DevicePropertyStatisticModel(prop);

            return(View(model));
        }
        public ActionResult Edit(int Id)
        {
            var                cont     = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
            string             domainId = DomainSession.GetContextDomain(this.HttpContext);
            iotDomain          domain   = cont.Domains.First(d => d.DomainName.Equals(domainId));
            var                type     = domain.DeviceTypes.FirstOrDefault(t => t.Id == Id);
            DeviceAddTypeModel model    = new DeviceAddTypeModel();

            model.Type = type;
            return(View(model));
        }
Exemple #11
0
 public ActionResult AddSite(Site site)
 {
     if (site != null)
     {
         string    domainId = DomainSession.GetContextDomain(this.HttpContext);
         iotDomain d        = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
         d.Sites.Add(site);
         Icont.SaveChanges();
     }
     //show status
     return(View());
 }
Exemple #12
0
 public IotRoleModel(iotDomain domain) : this()
 {
     try
     {
         Sites              = domain.Sites.ToList();
         Devices            = Sites.FirstOrDefault().Devices.ToList();
         this.Role.DomainId = domain.Id;
     }
     catch (Exception e)
     {
     }
 }
 public UserListModel(iotDomain domain)
 {
     try
     {
         ApplicationDbContext ucont = new ApplicationDbContext();
         var userMan = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
         Users = userMan.Users.Where(u => u.DomainId == domain.Id).ToList();
     }
     catch (Exception e)
     {
         return;
     }
 }
        public void TestRepoCreate()
        {
            iotRepository <iotDomain> locrepo = new iotRepository <iotDomain>();
            iotDomain dm = new iotDomain();

            dm.DomainName = Guid.NewGuid().ToString();
            dm.Sites      = new List <Site>();
            locrepo.Add(dm);
            List <iotDomain> locs = locrepo.GetAll().ToList();

            Assert.IsTrue(locs.Contains(dm));
            locrepo.Delete(dm);
        }
 static public bool AddDomain(iotDomain domain)
 {
     try
     {
         cont.Domains.Add(domain);
         cont.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemple #16
0
 public RoleListModel(iotDomain domain)
 {
     try
     {
         ApplicationDbContext ucont = new ApplicationDbContext();
         var roleManager            = new RoleManager <IotUserRole>(new RoleStore <IotUserRole>(ucont));
         Roles = roleManager.Roles.Where(r => r.DomainId == domain.Id).ToList();
     }
     catch (Exception e)
     {
         return;
     }
 }
        public UserCreateModel(iotDomain domain)
        {
            User = new ApplicationUser();
            ApplicationDbContext ucont = new ApplicationDbContext();
            var roleManager            = new RoleManager <IotUserRole>(new RoleStore <IotUserRole>(ucont));
            var roleList = roleManager.Roles.Where(r => r.DomainId == domain.Id).ToList();

            Roles = roleList;
            foreach (var role in this.Roles)
            {
                role.Active = false;    //use activation as user role enable and default all to false
            }
            User.DomainId = domain.Id;
        }
        /*********************** Delete ***********************/


        public bool DomainRemove(iotDomain domain)
        {
            try
            {
                iotRepository <iotDomain> repo = new iotRepository <iotDomain>();
                repo.Delete(domain);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
        /*********************** Delete ***********************/


        public bool DomainRemove(iotDomain domain)
        {
            try
            {
                iotSharedEntityContext <iotDomain> propCont = new iotSharedEntityContext <iotDomain>();
                propCont.Delete(domain);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
Exemple #20
0
 public ActionResult View(int siteId)
 {
     try
     {
         string              domainId = DomainSession.GetContextDomain(this.HttpContext);
         iotDomain           d        = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
         DeviceListViewModel model    = new DeviceListViewModel(d.Sites.First(s => s.Id == siteId));
         return(View(model));
     }
     catch (Exception e)
     {
     }
     return(View());
 }
Exemple #21
0
 static public iotDomain GetDomainForHttpContext(HttpContextBase hcontext)
 {
     try
     {
         var       cont     = (iotContext)hcontext.Session["iotcontext"];
         string    domainId = DomainSession.GetContextDomain(hcontext);
         iotDomain d        = cont.Domains.First(dm => dm.DomainName.Equals(domainId));
         return(d);
     }
     catch (Exception e)
     {
         throw;
     }
 }
 static public bool RemoveDomain(iotDomain domain)
 {
     try
     {
         iotDomain existing = cont.Domains.First(d => d.Id.Equals(domain.Id));
         cont.Domains.Remove(existing);
         cont.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemple #23
0
 public ActionResult Add()
 {
     try
     {
         string           domainId  = DomainSession.GetContextDomain(this.HttpContext);
         iotDomain        d         = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
         List <Location>  locations = d.Locations.ToList();
         AddSiteViewModel model     = new AddSiteViewModel(locations);
         return(View(model));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
        /*********************** Update ***********************/


        public bool DomainUpdate(iotDomain domain)
        {
            try
            {
                iotSharedEntityContext <iotDomain> cont = new iotSharedEntityContext <iotDomain>();
                iotDomain updated = cont.GetById(domain.Id); //db.GetById(domain.DomainName);
                cont.UpdateWithHistory(domain);              //db.UpdateById(domain, domain.DomainName);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
Exemple #25
0
 public SiteController(HttpContextBase contBase)
 {
     try
     {
         DomainSession.LoadDataContextForUserContext(contBase);
         IIotContextBase cont = (IIotContextBase)contBase.Session["iotcontext"];
         this.Icont = cont;
         string    domainId = DomainSession.GetContextDomain(contBase);
         iotDomain d        = Icont.Domains.First(dm => dm.DomainName.Equals(domainId));
         this._provider = new SiteProvider(this.Icont);
     }
     catch (Exception e)
     {
     }
 }
Exemple #26
0
 public ActionResult Add()
 {
     try
     {
         var       cont     = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
         string    domainId = DomainSession.GetContextDomain(this.HttpContext);
         iotDomain d        = cont.Domains.First(dm => dm.DomainName.Equals(domainId));
         var       model    = new IotRoleModel(d);
         return(View(model));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
     }
 }
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!_authorize)
            {
                return(true);
            }

            try
            {
                bool basicAuthed = base.AuthorizeCore(httpContext);
                if (basicAuthed)
                {
                    //check domain access
                    string url           = httpContext.Request.RawUrl;
                    var    urlcomponents = url.Split('/');
                    string appdomain     = urlcomponents[1]; //first component after slash
                    if (appdomain != null)
                    {
                        string username           = httpContext.User.Identity.Name;
                        ApplicationDbContext cont = new ApplicationDbContext();
                        var user = (from u in cont.Users
                                    where u.UserName == username
                                    select u).First();

                        var icont = (IIotContextBase)System.Web.HttpContext.Current.Session["iotcontext"];
                        if (icont == null)
                        {
                            icont = UserIotContextFactory.GetContextForUser(user);
                            System.Web.HttpContext.Current.Session["iotcontext"] = icont;
                        }

                        iotDomain domain = icont.Domains.First(dm => dm.DomainName.Equals(appdomain));
                        if (domain != null)
                        {
                            if (domain.DomainName.Equals(appdomain))
                            {
                                return(true);    //user allowed to access domain
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            return(false);
        }
 public bool DomainAdd(iotDomain domain)
 {
     try
     {
         //iotSharedEntityContext<iotDomain> cont = new iotSharedEntityContext<iotDomain>();
         iotContext cont = new iotContext();
         cont.Domains.Add(domain);
         cont.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        public ActionResult IOT()
        {
            try
            {
                string userDomain = (string)Session["AppDomain"];
                if ((userDomain != null) && !userDomain.Equals(String.Empty))
                {
                    return(RedirectToAction("Index", "Dashboard", new { app = userDomain }));
                }
                else
                {
                    //get user domain
                    var user = UserManager.FindById(User.Identity.GetUserId());

                    if (user != null)
                    {
                        //store user domain session
                        ApplicationDbContext cont = new ApplicationDbContext();
                        var currentUser           = (from u in cont.Users
                                                     where u.UserName.Equals(user.UserName)
                                                     select u).First();


                        IIotContextBase dcont  = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];   //new iotContext();
                        iotDomain       domain = dcont.Domains.First(d => d.Id == currentUser.DomainId);
                        if (domain != null)
                        {
                            Session["AppDomain"] = domain.DomainName;
                            return(RedirectToAction("Index", "Dashboard", new { app = domain.DomainName }));  //userDomain
                        }
                        else
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                    }
                    else
                    {
                        //error
                        return(RedirectToAction("Login", "Account"));
                    }
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        // GET: DeviceTypes
        public ActionResult Index()
        {
            DeviceTypesListModel model = new DeviceTypesListModel();

            try
            {
                var       cont     = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
                string    domainId = DomainSession.GetContextDomain(this.HttpContext);
                iotDomain domain   = cont.Domains.First(d => d.DomainName.Equals(domainId));
                model = new DeviceTypesListModel(domain.DeviceTypes);
            }
            catch (Exception e)
            {
                model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
            }
            return(View(model));
        }