Пример #1
0
        public int validate(string _assetName)
        {
            if (_type.Equals(null))
            {
                logger.Error("Invalid logic for asset: {0}, expr: {1}", _assetName, _expr.text);
                configOK = false;
                enabled = false;
                return -1;
            }
            else if (_type.ToString() == "BOOL")
            {
                //create an opc item based off of the item name or alias and save the item for evaluation purposes
                asset _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name.Equals(_assetName));

                foreach(opcitem _item in _asset.items)
                {
                    if((_item.name == _itemref) || (_item.alias == _itemref))
                    {
                        OPCItem = _item;
                        break;
                    }
                }

                if (OPCItem == null)
                {
                    logger.Error("No item reference found for asset: {0}, expr: {1}, itemref: {2}", _assetName, _expr.text, _itemref);
                    configOK = false;
                    enabled = false;
                    return -1;
                }
            }
            else if(_type.ToString() == "EXPR")
            {
                if(_expr == null)
                {
                    logger.Error("Condition with logic of type EXPR had no EXPR element defined for asset: {0}", _assetName);
                    configOK = false;
                    enabled = false;
                    return -1;
                }
                else
                {
                    try
                    {
                        if (_expr.validate(_assetName) < 0)
                        {
                            configOK = false;
                            enabled = false;
                            return -1;
                        }
                    }
                    catch (Exception e)
                    {
                        e.Data["EXPR"] = _expr.text;
                        throw e;
                    }
                }
            }

            //initialize presets
            TOF.preset = _delayoff;
            TON.preset = _delayon;

            return 0;
        }
Пример #2
0
 public IDCConfigSystemDefaults()
 {
     this._rev = new revision();
     this._item = new opcitem();
     this._plc = new plc();
 }
Пример #3
0
        //set OPCItem reference based on scope of expression variable
        public int validate(string _assetName)
        {
            //logger.Info("Validating asset: {0}, expressionvar {1}", _assetName, _name);

            //if local reference use passed in _assetName
            //if asset reference use _scoperef to find correct asset
            //if plc reference use _scoperef to find plc reference
            if (_scope.ToString() == "LOCAL")
            {
                //find asset and then find item within asset
                asset _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name.Equals(_assetName));
                if (_asset != null)
                {
                    OPCItem = _asset.items.Find(x => x.name.Equals(_itemref) || x.alias.Equals(_itemref));
                    if (OPCItem != null)
                    {
                        return 0;
                    }
                }
            }
            else if (_scope.ToString() == "ASSET")
            {
                //find asset and then find item within asset
                asset _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name.Equals(_scoperef));

                //TODO - FIX THIS!!! This is dumb that the find expression blows up here and only here for null alias references
                foreach (opcitem _item in _asset.items)
                {
                    if (_item.alias == null)
                    {
                        _item.alias = "";
                    }
                }

                if (_asset != null)
                {
                    OPCItem = _asset.items.Find(x => x.name.Equals(_itemref) || x.alias.Equals(_itemref));
                    if (OPCItem != null)
                    {
                        return 0;
                    }
                }

            }
            else if (_scope.ToString() == "PLC")
            {
                //find plc and then find item within plc
                plc _plc = IDCService.ValidateIDCConfig.model.plcs.Find(x => x.name.Equals(_scoperef));

                //TODO - FIX THIS!!! This is dumb that the find expression blows up here and only here for null alias references
                foreach (opcitem _item in _plc.items)
                {
                    if (_item.alias == null)
                    {
                        _item.alias = "";
                    }
                }

                if (_plc != null)
                {
                    OPCItem = _plc.items.Find(x => x.name.Equals(_itemref) || x.alias.Equals(_itemref));
                    if (OPCItem != null)
                    {
                        return 0;
                    }
                }
            }

            logger.Error("Cannot find associated reference for expression scope. Scoperef: {0} Itemref: {1}", _scoperef, _itemref);
            configOK = false;
            enabled = false;
            return -1;
        }
Пример #4
0
 public plc()
 {
     this._watchdogitem = new opcitem();
     this._items = new List<opcitem>();
 }
Пример #5
0
 public static bool LoadFromFile(string fileName, out opcitem obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Пример #6
0
 /// <summary>
 /// Deserializes xml markup from file into an opcitem object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output opcitem object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out opcitem obj, out System.Exception exception)
 {
     exception = null;
     obj = default(opcitem);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Пример #7
0
 public static bool Deserialize(string input, out opcitem obj)
 {
     System.Exception exception = null;
     return Deserialize(input, out obj, out exception);
 }
Пример #8
0
 /// <summary>
 /// Deserializes workflow markup into an opcitem object
 /// </summary>
 /// <param name="input">string workflow markup to deserialize</param>
 /// <param name="obj">Output opcitem object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string input, out opcitem obj, out System.Exception exception)
 {
     exception = null;
     obj = default(opcitem);
     try
     {
         obj = Deserialize(input);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }