コード例 #1
0
 private string sconnConfigToStringVal(sconnConfigMapper map, ipcDeviceConfig config)
 {
     try
     {
         if (map.ConfigType == ipcDefines.mAdrInput)
         {
             return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
         }
         else if (map.ConfigType == ipcDefines.mAdrOutput)
         {
             return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
         }
         else if (map.ConfigType == ipcDefines.mAdrRelay)
         {
             return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
         }
         else
         {
             return(config.memCFG[map.ConfigType].ToString());    //direct value
         }
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return("");
     }
 }
コード例 #2
0
 private string ParameterNameForMapper(sconnConfigMapper maper)
 {
     try
     {
         if (maper.ConfigType == ipcDefines.mAdrInput)
         {
             return("Input");
         }
         else if (maper.ConfigType == ipcDefines.mAdrOutput)
         {
             return("Output");
         }
         else if (maper.ConfigType == ipcDefines.mAdrRelay)
         {
             return("Relay");
         }
         else
         {
             return("Unknown");
         }
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return("");
     }
 }
コード例 #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
 private int ConfigAddrForMapperInfo(sconnConfigMapper map)
 {
     try
     {
         if (map.ConfigType == ipcDefines.mAdrInput)
         {
             return(ipcDefines.mAdrInput + (ipcDefines.mAdrInputMemSize * map.SeqNumber) + ipcDefines.mAdrInputVal);
         }
         else if (map.ConfigType == ipcDefines.mAdrOutput)
         {
             return(ipcDefines.mAdrOutput + ipcDefines.mAdrOutputMemSize * map.SeqNumber + ipcDefines.mAdrOutputVal);
         }
         else if (map.ConfigType == ipcDefines.mAdrRelay)
         {
             return(ipcDefines.mAdrRelay + ipcDefines.RelayMemSize * map.SeqNumber + ipcDefines.mAdrRelayVal);
         }
         else
         {
             return(0);    //direct value
         }
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(0);
     }
 }
コード例 #5
0
        private void LoadConfigToDevice(Device dev)
        {
            int devAddr = IndexForHostDevice();


            //Reload properties and actions if they changed


            //Update

            int inputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrInputsNO];

            for (int i = 0; i < inputs; i++)
            {
                DeviceProperty prop = new DeviceProperty();
                prop.PropertyName = "Input" + i;    //TODO read from name cfg
                DeviceParameter   param = new DeviceParameter();
                sconnConfigMapper maper = new sconnConfigMapper();
                maper.ConfigType  = ipcDefines.mAdrInput;
                maper.SeqNumber   = i;
                param.sconnMapper = maper;
                param.Value       = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                prop.ResultParameters.Add(param);
                dev.Properties.Add(prop);
            }

            int outputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrOutputsNO];

            for (int i = 0; i < outputs; i++)
            {
                DeviceAction action = new DeviceAction();
                action.ActionName = "Output" + i;    //TODO read from name cfg
                DeviceParameter inparam = new DeviceParameter();
                //DeviceParameter outparam = new DeviceParameter();
                sconnConfigMapper maper = new sconnConfigMapper();
                maper.ConfigType    = ipcDefines.mAdrOutput;
                maper.SeqNumber     = i;
                inparam.sconnMapper = maper;
                inparam.Value       = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                action.ResultParameters.Add(inparam);
                dev.Actions.Add(action);
            }

            int relays = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrRelayNO];

            for (int i = 0; i < relays; i++)
            {
                DeviceAction action = new DeviceAction();
                action.ActionName = "Relay" + i;    //TODO read from name cfg
                DeviceParameter inparam = new DeviceParameter();
                //DeviceParameter outparam = new DeviceParameter();
                sconnConfigMapper maper = new sconnConfigMapper();
                maper.ConfigType    = ipcDefines.mAdrRelay;
                maper.SeqNumber     = i;
                inparam.sconnMapper = maper;
                inparam.Value       = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                action.ResultParameters.Add(inparam);
                dev.Actions.Add(action);
            }
        }
コード例 #6
0
 private ParameterType ParamTypeForSconnMapper(sconnConfigMapper mapper)
 {
     try
     {
         iotConnector connector = new iotConnector();
         return(connector.TypeForName(ParameterNameForMapper(mapper))); //ParameterType.TypeForName(ParameterNameForMapper(mapper), cont);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new ParameterType());
     }
 }
コード例 #7
0
 private string ParameterNameForMapper(sconnConfigMapper maper)
 {
     if (maper.ConfigType == ipcDefines.mAdrInput)
     {
         return("Input");
     }
     else if (maper.ConfigType == ipcDefines.mAdrOutput)
     {
         return("Output");
     }
     else if (maper.ConfigType == ipcDefines.mAdrRelay)
     {
         return("Relay");
     }
     else
     {
         return("Unknown");
     }
 }
コード例 #8
0
 private string sconnConfigToStringVal(sconnConfigMapper map, ipcDataType.ipcDeviceConfig config)
 {
     if (map.ConfigType == ipcDefines.mAdrInput)
     {
         return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
     }
     else if (map.ConfigType == ipcDefines.mAdrOutput)
     {
         return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
     }
     else if (map.ConfigType == ipcDefines.mAdrRelay)
     {
         return(config.memCFG[ConfigAddrForMapperInfo(map)].ToString());
     }
     else
     {
         return(config.memCFG[map.ConfigType].ToString());    //direct value
     }
 }
コード例 #9
0
 private int ConfigAddrForMapperInfo(sconnConfigMapper map)
 {
     if (map.ConfigType == ipcDefines.mAdrInput)
     {
         return(ipcDefines.mAdrInput + (ipcDefines.mAdrInputMemSize * map.SeqNumber) + ipcDefines.mAdrInputVal);
     }
     else if (map.ConfigType == ipcDefines.mAdrOutput)
     {
         return(ipcDefines.mAdrOutput + ipcDefines.mAdrOutputMemSize * map.SeqNumber + ipcDefines.mAdrOutputVal);
     }
     else if (map.ConfigType == ipcDefines.mAdrRelay)
     {
         return(ipcDefines.mAdrRelay + ipcDefines.RelayMemSize * map.SeqNumber + ipcDefines.mAdrRelayVal);
     }
     else
     {
         return(0);    //direct value
     }
 }
コード例 #10
0
        private void AddActionForMapperAndDevice(sconnConfigMapper maper, Device edited, int DevNo)
        {
            try
            {
                DeviceAction action = new DeviceAction();
                action.ActionName         = "Output" + maper.SeqNumber; //TODO read from name cfg
                action.Device             = edited;
                action.LastActivationTime = DateTime.Now;
                var qry = connector.ActionAdd(action);


                //copy maper for action
                sconnConfigMapper actionMaper = new sconnConfigMapper();
                actionMaper.ConfigType = maper.ConfigType;
                actionMaper.SeqNumber  = maper.SeqNumber;

                ParameterType paramtype = ParamTypeForSconnMapper(actionMaper);

                ActionParameter inparam = new ActionParameter();
                inparam.Value           = sconnConfigToStringVal(actionMaper, site.siteCfg.deviceConfigs[DevNo]);
                inparam.Type            = paramtype;
                inparam.Action          = action;
                actionMaper.ActionParam = inparam;
                qry = connector.ActionParamAdd(inparam);


                //create parameter and bind mapper to it
                DeviceParameter param = new DeviceParameter();
                param.Value  = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[DevNo]);
                param.Type   = paramtype;
                param.Action = action;
                qry          = connector.ParameterAdd(param);


                maper.Parameter = param;
                qry             = connector.MapperAdd(maper);
            }
            catch (Exception e)
            {
            }
        }
コード例 #11
0
        private bool LoadConfigToDevice(int devId)
        {
            try
            {
                //iotConnector connt = new iotConnector();
                //Device edited = connt.DeviceList().Where(n => n.Id == dev.Id).First();
                //iotRepository<Device> devrep = new iotRepository<Device>();
                Stopwatch watch = new Stopwatch();


                watch.Start();
                iotContext cont = new iotContext();
                //cont.Configuration.LazyLoadingEnabled = false;
                //Device edited = cont.Devices.Where(d => d.Id == dev.Id)
                //    .Include(d => d.Actions.Select(a => a.ResultParameters.Select(r => r.sconnMappers)))
                //    .Include(d => d.Properties.Select(p => p.ResultParameters.Select(r => r.sconnMappers)))
                //    .First();
                Device edited = cont.Devices.First(d => d.Id == devId);


                watch.Stop();
                Debug.WriteLine("Execution time : " + watch.ElapsedMilliseconds + " ms @ device query");
                watch.Reset();

                int devAddr = 0;
                if (site.siteCfg.deviceNo == 0)
                {
                    return(false);
                }

                //Reload properties and actions if they changed
                //Update

                int inputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrInputsNO];
                if (edited.Properties.Count != inputs)
                {
                    watch.Start();

                    //clear current properies
                    for (int i = 0; i < edited.Properties.Count; i++)
                    {
                        cont.Properties.Remove(edited.Properties[i]);
                    }
                    cont.SaveChanges();

                    //load
                    for (int i = 0; i < inputs; i++)
                    {
                        sconnPropertyMapper maper = new sconnPropertyMapper();
                        maper.ConfigType = ipcDefines.mAdrInput;
                        maper.SeqNumber  = i;
                        AddPropertyForMapperAndDevice(maper, edited, devAddr);
                    }

                    watch.Stop();
                    Debug.WriteLine("Execution time : " + watch.ElapsedMilliseconds + " ms @ readd prop");
                    watch.Reset();
                }
                else //update
                {
                    watch.Reset();
                    watch.Start();

                    foreach (var item in edited.Properties)
                    {
                        //get parameter
                        Stopwatch watch4 = new Stopwatch();
                        watch4.Start();
                        DeviceParameter param = item.ResultParameters.FirstOrDefault();

                        watch4.Stop();
                        Debug.WriteLine("Execution time : " + watch4.ElapsedMilliseconds + " ms @ prop update dev param query");

                        watch4.Restart();
                        param.Value = sconnConfigToStringVal(param.sconnMappers.FirstOrDefault(), site.siteCfg.deviceConfigs[devAddr]);
                        watch4.Stop();
                        Debug.WriteLine("Execution time : " + watch4.ElapsedMilliseconds + " ms @ prop update dev param parse");
                        watch4.Reset();

                        if (param != null)
                        {
                            //get input mapper
                            Stopwatch watch2 = new Stopwatch();
                            watch2.Start();
                            sconnConfigMapper maper = param.sconnMappers.FirstOrDefault();
                            watch2.Stop();
                            Debug.WriteLine("Execution time : " + watch2.ElapsedMilliseconds + " ms @ prop update mapper query");
                            watch2.Reset();

                            Stopwatch watch3 = new Stopwatch();
                            watch3.Start();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                            }
                            watch3.Stop();
                            Debug.WriteLine("Execution time : " + watch3.ElapsedMilliseconds + " ms @ prop update cfg to str");
                            watch3.Reset();
                        }
                    }

                    Stopwatch watch1 = new Stopwatch();
                    watch1.Start();
                    cont.SaveChanges(); //apply
                    watch1.Stop();
                    Debug.WriteLine("Execution time : " + watch1.ElapsedMilliseconds + " ms @ prop update save");
                    watch1.Reset();

                    watch.Stop();
                    Debug.WriteLine("Execution time : " + watch.ElapsedMilliseconds + " ms @ prop update");
                    watch.Reset();
                }

                int outputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrOutputsNO];
                int relays  = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrRelayNO];
                if (edited.Actions.Count != outputs + relays)
                {
                    watch.Start();

                    //remove existing
                    if (edited.Actions.Count > 0)
                    {
                        for (int i = 0; i < edited.Actions.Count; i++)
                        {
                            cont.Actions.Remove(edited.Actions[i]);
                        }
                        cont.SaveChanges();
                    }

                    for (int i = 0; i < outputs; i++)
                    {
                        sconnActionResultMapper maper = new sconnActionResultMapper();
                        maper.ConfigType = ipcDefines.mAdrOutput;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }

                    for (int i = 0; i < relays; i++)
                    {
                        sconnActionResultMapper maper = new sconnActionResultMapper();
                        maper.ConfigType = ipcDefines.mAdrRelay;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }

                    watch.Stop();
                    Debug.WriteLine("Execution time : " + watch.ElapsedMilliseconds + " ms @ action readd");
                    watch.Reset();
                }
                else
                {
                    watch.Start();

                    foreach (var item in edited.Actions)
                    {
                        //get action
                        DeviceActionResult param = (from par in item.ResultParameters
                                                    select par).FirstOrDefault();
                        if (param != null)
                        {
                            //get input mapper
                            sconnConfigMapper maper = (from cm in param.sconnMappers
                                                       select cm).FirstOrDefault();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                                param.Type  = param.Type;
                            }
                        }
                    }
                    cont.SaveChanges(); //save updates

                    watch.Stop();
                    Debug.WriteLine("Execution time : " + watch.ElapsedMilliseconds + " ms @ action update");
                    watch.Reset();
                }
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }

            return(true);
        }
コード例 #12
0
        private bool LoadConfigToDevice(Device dev)
        {
            try
            {
                //iotConnector connt = new iotConnector();
                //Device edited = connt.DeviceList().Where(n => n.DeviceId == dev.DeviceId).First();
                iotRepository <Device> devrep = new iotRepository <Device>();
                Device edited = devrep.GetById(dev.DeviceId);

                int devAddr = IndexForHostDevice();
                //Reload properties and actions if they changed
                //Update

                int inputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrInputsNO];
                if (edited.Properties.Count != inputs)
                {
                    //clear current properies


                    //load
                    for (int i = 0; i < inputs; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrInput;
                        maper.SeqNumber  = i;
                        AddPropertyForMapperAndDevice(maper, edited, devAddr);
                    }
                }
                else //update
                {
                    foreach (var item in edited.Properties)
                    {
                        //get parameter
                        // List<DeviceParameter> propparams = (from par in item.ResultParameters
                        //                         select par).ToList();
                        DeviceParameter param = item.ResultParameters.ElementAt(0);
                        param.Value = sconnConfigToStringVal(param.sconnMappers.ElementAt(0), site.siteCfg.deviceConfigs[devAddr]);

                        //iotRepository<DeviceParameter> repo = new iotRepository<DeviceParameter>();
                        //repo.Update(param);
                        //cont.SaveChanges();

                        if (param != null)
                        {
                            //get input mapper
                            sconnConfigMapper maper = (from cm in param.sconnMappers
                                                       select cm).FirstOrDefault();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                                // cont.SaveChanges();
                            }
                        }
                    }
                }

                int outputs = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrOutputsNO];
                int relays  = site.siteCfg.deviceConfigs[devAddr].memCFG[ipcDefines.mAdrRelayNO];
                if (edited.Actions.Count != outputs + relays)
                {
                    //remove existing
                    if (edited.Actions.Count > 0)
                    {
                        iotRepository <DeviceAction> actrep = new iotRepository <DeviceAction>();
                        List <DeviceAction>          acts   = actrep.GetAll().ToList();
                        for (int i = 0; i < acts.Count; i++)
                        {
                            actrep.Delete(acts.ElementAt(i));
                        }
                    }

                    for (int i = 0; i < outputs; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrOutput;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }

                    for (int i = 0; i < relays; i++)
                    {
                        sconnConfigMapper maper = new sconnConfigMapper();
                        maper.ConfigType = ipcDefines.mAdrRelay;
                        maper.SeqNumber  = i;
                        AddActionForMapperAndDevice(maper, edited, devAddr);
                    }
                }
                else
                {
                    foreach (var item in edited.Actions)
                    {
                        //get action
                        DeviceParameter param = (from par in item.ResultParameters
                                                 select par).FirstOrDefault();
                        if (param != null)
                        {
                            //get input mapper
                            sconnConfigMapper maper = (from cm in param.sconnMappers
                                                       select cm).FirstOrDefault();
                            if (maper != null)
                            {
                                param.Value = sconnConfigToStringVal(maper, site.siteCfg.deviceConfigs[devAddr]);
                                param.Type  = param.Type;
                                // cont.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }

            return(true);
        }
コード例 #13
0
        private ParameterType ParamTypeForSconnMapper(sconnConfigMapper mapper)
        {
            var task = connector.TypeForName(ParameterNameForMapper(mapper)); //ParameterType.TypeForName(ParameterNameForMapper(mapper), cont);

            return(task);
        }
コード例 #14
0
 private string sconnConfigToStringVal(sconnConfigMapper map, ipcDataType.ipcDeviceConfig config)
 {
     return("");
 }
コード例 #15
0
 private int ConfigAddrForMapperInfo(sconnConfigMapper info)
 {
     return(0);
 }