Пример #1
0
        public void TestRepoUpdate()
        {
            iotRepository <Location> repo = new iotRepository <Location>();
            //get
            List <Location> locs = repo.GetAll().ToList();
            //add if required
            Location loc = new Location();

            if (locs != null)
            {
                loc.LocationName = Guid.NewGuid().ToString();
                loc.Lat          = 0;
                loc.Lng          = 0;
                repo.Add(loc);
                //update
                locs = repo.GetAll().ToList();
                loc  = locs.Where(l => { return(l.LocationName == loc.LocationName); }).First();
                Location StoredBefore = repo.GetById(loc.Id);
                StoredBefore.Lat = 53.325241;
                repo.Update(StoredBefore);
                //verify
                Location stored = repo.GetById(loc.Id);
                Assert.IsTrue(loc.Lat == stored.Lat);
            }
        }
Пример #2
0
        /****  LOAD ****/

        public void TestEntityDbWriteLoad()
        {
            try
            {
                int       ReadTestInterations = 5;
                int       maxQueryTimeMs      = 25;
                Stopwatch watch = new Stopwatch();
                watch.Start();
                for (int i = 0; i < ReadTestInterations; i++)
                {
                    iotRepository <Location> locrepo = new iotRepository <Location>();
                    Location loc = new Location();
                    loc.LocationName = Guid.NewGuid().ToString();
                    loc.Lat          = 0;
                    loc.Lng          = 0;
                    locrepo.Add(loc);
                }
                watch.Stop();
                double TimePerQueryMs = watch.ElapsedMilliseconds / ReadTestInterations;
                Assert.IsTrue(TimePerQueryMs < maxQueryTimeMs);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
        }
Пример #3
0
        private void AddPropertyForMapperAndDevice(sconnConfigMapper maper, Device edited, int DevNo)
        {
            try
            {
                iotRepository <DeviceProperty> proprepo = new iotRepository <DeviceProperty>();
                DeviceProperty prop = new DeviceProperty();
                prop.PropertyName   = "Input" + maper.SeqNumber;  //TODO read from name cfg
                prop.Device         = edited;
                prop.LastUpdateTime = DateTime.Now;
                proprepo.Add(prop);
                List <DeviceProperty> storeprops = proprepo.GetAll().ToList();
                DeviceProperty        storedProp = (from s in storeprops
                                                    where s.PropertyName == prop.PropertyName
                                                    select s).First();

                //create parameter and bind mapper to it
                iotRepository <DeviceParameter> paramrepo = new iotRepository <DeviceParameter>();
                DeviceParameter param = new DeviceParameter();
                param.Value    = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]);
                param.Type     = ParamTypeForSconnMapper(maper);
                param.Property = storedProp;
                paramrepo.Add(param);
                List <DeviceParameter> storeparams = paramrepo.GetAll().ToList();
                DeviceParameter        storedParam = (from p in storeparams
                                                      where p.Property == param.Property
                                                      select p).First();

                maper.Parameter = storedParam;
                iotRepository <sconnConfigMapper> mapperRepo = new iotRepository <sconnConfigMapper>();
                mapperRepo.Add(maper);
            }
            catch (Exception e)
            {
            }
        }
Пример #4
0
 public int AddDevice(Device Device)
 {
     try
     {
         iotRepository <Device> repo = new iotRepository <Device>();
         repo.Add(Device);
         return(Device.Id);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Пример #5
0
        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);
        }
Пример #6
0
 public bool ActionAdd(DeviceAction action)
 {
     try
     {
         iotRepository <DeviceAction> repo = new iotRepository <DeviceAction>();
         repo.Add(action);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #7
0
 public bool SiteAdd(Site site)
 {
     try
     {
         iotRepository <Site> repo = new iotRepository <Site>();
         repo.Add(site);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #8
0
 public bool DomainAdd(iotDomain domain)
 {
     try
     {
         iotRepository <iotDomain> repo = new iotRepository <iotDomain>();
         repo.Add(domain);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #9
0
 public bool EndpointAdd(EndpointInfo endp)
 {
     try
     {
         iotRepository <EndpointInfo> repo = new iotRepository <EndpointInfo>();
         repo.Add(endp);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #10
0
 public bool DeviceCredentialsAdd(DeviceCredentials creds)
 {
     try
     {
         iotRepository <DeviceCredentials> repo = new iotRepository <DeviceCredentials>();
         repo.Add(creds);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #11
0
 public bool ReqParamAdd(ActionParameter param)
 {
     try
     {
         iotRepository <ActionParameter> repo = new iotRepository <ActionParameter>();
         repo.Add(param);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #12
0
 public bool LocationAdd(Location loc)
 {
     try
     {
         iotRepository <Location> repo = new iotRepository <Location>();
         repo.Add(loc);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #13
0
 public bool PropertyAdd(DeviceProperty prop)
 {
     try
     {
         iotRepository <DeviceProperty> repo = new iotRepository <DeviceProperty>();
         repo.Add(prop);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
Пример #14
0
        /******************* Add ***********************/

        public bool DeviceAdd(Device dev)
        {
            try
            {
                iotRepository <Device> repo = new iotRepository <Device>();
                repo.Add(dev);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
Пример #15
0
 static public void StoreParamChange(DeviceParameter param)
 {
     try
     {
         //add history only if param already in DB
         iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
         DeviceParameter stparam = repo.GetById(param.Id);
         if (stparam != null)
         {
             ParameterChangeHistory hist = new ParameterChangeHistory();
             hist.Date     = DateTime.Now;
             hist.Property = param;
             hist.Value    = param.Value;
             iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>();
             histrepo.Add(hist);
         }
     }
     catch (Exception e)
     {
     }
 }
Пример #16
0
        public virtual void UpdateWithHistory(T entity)
        {
            try
            {
                if (entity.GetType() == typeof(Device))
                {
                    Device edited = (Device)(object)entity;
                    iotRepository <DeviceParameter> repo    = new iotRepository <DeviceParameter>();
                    iotRepository <Device>          devrepo = new iotRepository <Device>();
                    Device devbefore = devrepo.GetById(edited.Id);

                    foreach (var item in edited.Actions)
                    {
                        foreach (var param in item.ResultParameters)
                        {
                            DeviceParameter stparam = repo.GetById(param.Id);
                            if (stparam != null)
                            {
                                if (!stparam.Value.Equals(param.Value))
                                {
                                    ActionChangeHistory hist = new ActionChangeHistory();
                                    hist.Date     = DateTime.Now;
                                    hist.Property = param;
                                    hist.Value    = param.Value;
                                    iotRepository <ActionChangeHistory> histrepo = new iotRepository <ActionChangeHistory>();
                                    histrepo.Add(hist);
                                }
                            }
                        }
                    }


                    foreach (var item in edited.Properties)
                    {
                        foreach (var param in item.ResultParameters)
                        {
                            DeviceParameter stparam = repo.GetById(param.Id);
                            if (stparam != null)
                            {
                                if (!stparam.Value.Equals(param.Value))
                                {
                                    ParameterChangeHistory hist = new ParameterChangeHistory();
                                    hist.Date     = DateTime.Now;
                                    hist.Property = param;
                                    hist.Value    = param.Value;
                                    iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>();
                                    histrepo.Add(hist);
                                }
                            }
                        }
                    }
                }
                else if (entity.GetType() == typeof(DeviceAction))
                {
                    iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
                    DeviceAction item = (DeviceAction)(object)entity;
                    foreach (var param in item.ResultParameters)
                    {
                        DeviceParameter stparam = repo.GetById(param.Id);
                        if (stparam != null)
                        {
                            if (!stparam.Value.Equals(param.Value))
                            {
                                ActionChangeHistory hist = new ActionChangeHistory();
                                hist.Date     = DateTime.Now;
                                hist.Property = param;
                                hist.Value    = param.Value;
                                iotRepository <ActionChangeHistory> histrepo = new iotRepository <ActionChangeHistory>();
                                histrepo.Add(hist);
                            }
                        }
                    }
                }
                else if (entity.GetType() == typeof(DeviceProperty))
                {
                    iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
                    DeviceProperty item = (DeviceProperty)(object)entity;

                    foreach (var param in item.ResultParameters)
                    {
                        DeviceParameter stparam = repo.GetById(param.Id);
                        if (stparam != null)
                        {
                            if (!stparam.Value.Equals(param.Value))
                            {
                                ParameterChangeHistory hist = new ParameterChangeHistory();
                                hist.Date     = DateTime.Now;
                                hist.Property = param;
                                hist.Value    = param.Value;
                                iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>();
                                histrepo.Add(hist);
                            }
                        }
                    }
                }

                DbSet.Attach(entity);
            }
            catch (Exception e)
            {
                _logger.Error(e, e.Message);
            }
        }
Пример #17
0
        public virtual void UpdateWithHistory(T entity)
        {
            try
            {
                if (entity.GetType() == typeof(Device))
                {
                    Device edited = (Device)(object)entity;
                    iotRepository <DeviceParameter> repo    = new iotRepository <DeviceParameter>();
                    iotRepository <Device>          devrepo = new iotRepository <Device>();
                    Device devbefore = devrepo.GetById(edited.Id);

                    foreach (var item in edited.Actions)
                    {
                        foreach (var param in item.ResultParameters)
                        {
                            DeviceParameter stparam = repo.GetById(param.Id);
                            if (stparam != null)
                            {
                                if (!stparam.Value.Equals(param.Value))
                                {
                                    ActionChangeHistory hist = new ActionChangeHistory();
                                    hist.Date     = DateTime.Now;
                                    hist.Property = param;
                                    hist.Value    = param.Value;
                                    iotRepository <ActionChangeHistory> histrepo = new iotRepository <ActionChangeHistory>();
                                    histrepo.Add(hist);
                                }
                            }
                        }
                    }


                    foreach (var item in edited.Properties)
                    {
                        foreach (var param in item.ResultParameters)
                        {
                            DeviceParameter stparam = repo.GetById(param.Id);
                            if (stparam != null)
                            {
                                if (!stparam.Value.Equals(param.Value))
                                {
                                    ParameterChangeHistory hist = new ParameterChangeHistory();
                                    hist.Date     = DateTime.Now;
                                    hist.Property = param;
                                    hist.Value    = param.Value;
                                    iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>();
                                    histrepo.Add(hist);
                                }
                            }
                        }
                    }
                }
                else if (entity.GetType() == typeof(DeviceAction))
                {
                    iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
                    DeviceAction item = (DeviceAction)(object)entity;
                    foreach (var param in item.ResultParameters)
                    {
                        DeviceParameter stparam = repo.GetById(param.Id);
                        if (stparam != null)
                        {
                            if (!stparam.Value.Equals(param.Value))
                            {
                                ActionChangeHistory hist = new ActionChangeHistory();
                                hist.Date     = DateTime.Now;
                                hist.Property = param;
                                hist.Value    = param.Value;
                                iotRepository <ActionChangeHistory> histrepo = new iotRepository <ActionChangeHistory>();
                                histrepo.Add(hist);
                            }
                        }
                    }
                }
                else if (entity.GetType() == typeof(DeviceProperty))
                {
                    iotRepository <DeviceParameter> repo = new iotRepository <DeviceParameter>();
                    DeviceProperty item = (DeviceProperty)(object)entity;

                    foreach (var param in item.ResultParameters)
                    {
                        DeviceParameter stparam = repo.GetById(param.Id);
                        if (stparam != null)
                        {
                            if (!stparam.Value.Equals(param.Value))
                            {
                                ParameterChangeHistory hist = new ParameterChangeHistory();
                                hist.Date     = DateTime.Now;
                                hist.Property = param;
                                hist.Value    = param.Value;
                                iotRepository <ParameterChangeHistory> histrepo = new iotRepository <ParameterChangeHistory>();
                                histrepo.Add(hist);
                            }
                        }
                    }
                }

                DbEntityEntry dbEntityEntry = iotGenericGlobalContext <T> .DbContext.Entry(entity);

                if (dbEntityEntry.State == EntityState.Detached)
                {
                    iotGenericGlobalContext <T> .DbSet.Attach(entity);
                }
                dbEntityEntry.State = EntityState.Modified;
                //iotGenericGlobalContext<T>.DbContext.SaveChanges();
            }
            catch (Exception exc)
            {
                throw;
            }
        }