Exemplo n.º 1
0
        public static CodeGenReadWriteHandler GetInstance()
        {
            if (m_CodeGenReadWriteHandler == null)
                m_CodeGenReadWriteHandler = new CodeGenReadWriteHandler();

            return m_CodeGenReadWriteHandler;
        }
        public override bool Initialize(Dictionary <CodeGenNodeID, CodeGenNodeID> childrenIDMap,
                                        CodeGenNodeManager addressSpaceMgr)
        {
            Console.WriteLine("VariableType_RoomName_627147307_0::Initialize");

            bool success = true;

            m_addressSpaceMgr = addressSpaceMgr;
            ushort namespaceIndex = 0;

            // Set attributes
            this.GetNode().UserWriteMask           = AttributeWriteMask.None;
            this.GetNode().UserAccessLevel         = AccessLevels.CurrentRead;
            this.GetNode().Timestamp               = DateTime.UtcNow;
            this.GetNode().StatusCode              = StatusCodes.Good;
            this.GetNode().OnWriteValue            = CodeGenReadWriteHandler.GetInstance().OnWrite;
            this.GetNode().OnReadValue             = CodeGenReadWriteHandler.GetInstance().OnRead;
            this.GetNode().BrowseName              = "RoomName";
            this.GetNode().DisplayName             = "RoomName";
            this.GetNode().Description             = "";
            this.GetNode().Historizing             = false;
            this.GetNode().MinimumSamplingInterval = 0;
            this.GetNode().AccessLevel             = AccessLevels.None | AccessLevels.CurrentRead;
            this.GetNode().WriteMask               = AttributeWriteMask.None



            ;

            /*********************/
            // Set Default Value
            /*********************/
            bool   setDefaultValue  = true;
            string defaultValueStr  = "String";
            string defaultValueType = "String";

            if (setDefaultValue)
            {
                try
                {
                    if (defaultValueType == "Decimal")
                    {
                        this.GetNode().Value = Convert.ToDecimal(defaultValueStr);
                    }
                    else if (defaultValueType == "Double")
                    {
                        this.GetNode().Value = Convert.ToDouble(defaultValueStr);
                    }
                    else if (defaultValueType == "Boolean")
                    {
                        this.GetNode().Value = (defaultValueStr == "1");
                    }
                    else if (defaultValueType == "SByte")
                    {
                        this.GetNode().Value = Convert.ToSByte(defaultValueStr);
                    }
                    else if (defaultValueType == "Int16")
                    {
                        this.GetNode().Value = Convert.ToInt16(defaultValueStr);
                    }
                    else if (defaultValueType == "Int32")
                    {
                        this.GetNode().Value = Convert.ToInt32(defaultValueStr);
                    }
                    else if (defaultValueType == "Int64")
                    {
                        this.GetNode().Value = Convert.ToInt64(defaultValueStr);
                    }
                    else if (defaultValueType == "Byte")
                    {
                        this.GetNode().Value = Convert.ToByte(defaultValueStr);
                    }
                    else if (defaultValueType == "UInt16")
                    {
                        this.GetNode().Value = Convert.ToUInt16(defaultValueStr);
                    }
                    else if (defaultValueType == "UInt32")
                    {
                        this.GetNode().Value = Convert.ToUInt16(defaultValueStr);
                    }
                    else if (defaultValueType == "UInt64")
                    {
                        this.GetNode().Value = Convert.ToUInt16(defaultValueStr);
                    }
                    else
                    {
                        this.GetNode().Value = defaultValueStr; //Everything else will be set as string.
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error setting node's default value to:{0} error:{1}", defaultValueStr, ex.ToString());
                }
            }

            //Create Children variables


            //Create Children properties


            return(success);
        }