Ejemplo n.º 1
0
        private List <Dictionary <string, object> > GetRelayList(string source, RelayType type)
        {
            string search = "SELECT `relays`.`target`, `relays`.`modes` FROM `relays` " +
                            "INNER JOIN `servers` " +
                            "ON `relays`.`server_id` = `servers`.`id` " +
                            "WHERE `servers`.`name` = {0} AND `relays`.`source` = {1} AND `relays`.`type` = {2}";

            return(Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, source, (int)type }));
        }
Ejemplo n.º 2
0
        private void advPropertyGrid1_PropertyValueChanging(object sender, PropertyValueChangingEventArgs e)
        {
            //var item = GetObjAndField(e.PropertyPath);
            //var obj= item.Item1;
            //var propertyName = item.Item2;
            if (e.PropertyName.EqualIgnoreCase("ModularDevices"))
            {
                var ModularDeviceID = ModularDevice.FindAllByName(e.NewValue.ToString())[0].ID;
                selectObj.Item1.SetItem("ModularDeviceID", ModularDeviceID);
            }
            else if (e.PropertyName.EqualIgnoreCase("Sensors"))
            {
                var SensorId = Sensor.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID;
                selectObj.Item1.SetItem("SensorId", SensorId);
            }
            else if (e.PropertyName.EqualIgnoreCase("ControlJobTypes"))
            {
                var ControlJobTypeId = ControlJobType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Id;
                selectObj.Item1.SetItem("ControlJobTypeId", ControlJobTypeId);
            }
            else if (e.PropertyName.EqualIgnoreCase("RelayTypes"))
            {
                var RelayTypeId = RelayType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Id;
                selectObj.Item1.SetItem("RelayTypeId", RelayTypeId);
            }
            else if (e.PropertyName.EqualIgnoreCase("DeviceTypes"))
            {
                var DeviceTypeSerialnum = DeviceType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Serialnum;
                selectObj.Item1.SetItem("DeviceTypeSerialnum", DeviceTypeSerialnum);
            }

            else if (e.PropertyName.EqualIgnoreCase("ShowDeviceTypes"))
            {
                var ShowDeviceTypeID = ShowDeviceType.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID;
                selectObj.Item1.SetItem("ShowDeviceTypeID", ShowDeviceTypeID);
            }
            else if (e.PropertyName.EqualIgnoreCase("CommunicateDevices"))
            {
                var CommunicateDeviceID = CommunicateDevice.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID;
                selectObj.Item1.SetItem("CommunicateDeviceID", CommunicateDeviceID);
            }
            else if (e.PropertyName.EqualIgnoreCase("Farms"))
            {
                var FarmID = Farm.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID;
                selectObj.Item1.SetItem("FarmID", FarmID);
            }
            else if (e.PropertyName.EqualIgnoreCase("FacilityTypes"))
            {
                var FacilityTypeSerialnum = FacilityType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Serialnum;
                selectObj.Item1.SetItem("FacilityTypeSerialnum", FacilityTypeSerialnum);
            }
            else
            {
                selectObj.Item1.SetItem(e.PropertyName, e.NewValue);
            }
        }
Ejemplo n.º 3
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var types = RelayType.FindAll();
            var names = new ArrayList();

            if (types != null && types.Count > 0)
            {
                names.AddRange(types);
            }
            return(new StandardValuesCollection(names));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new Relay on an IDigitalOutputPort. Allows you
        /// to use any peripheral that exposes ports that conform to the
        /// IDigitalOutputPort, such as the MCP23008.
        /// </summary>
        /// <param name="port"></param>
        /// <param name="type"></param>
        public Relay(IDigitalOutputPort port, RelayType type = RelayType.NormallyOpen)
        {
            // if it's normally closed, we have to invert the "on" value
            this.Type = type;
            if (this.Type == RelayType.NormallyClosed)
            {
                _onValue = false;
            }

            DigitalOut = port;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化继电器类型
        /// </summary>
        private void InitRelayType()
        {
            var relayTypeList = RelayType.FindAll().ToList();

            if (relayTypeList.Any() && relayTypeList.Count > 0)
            {
                this.cbRelay.DataSource    = relayTypeList;
                this.cbRelay.DisplayMember = "Remark";
                this.cbRelay.ValueMember   = "ID";
            }
        }
Ejemplo n.º 6
0
        public Relay(H.Cpu.Pin pin, RelayType type = RelayType.NormallyOpen)
        {
            // if it's normally closed, we have to invert the "on" value
            this.Type = type;
            if (this.Type == RelayType.NormallyClosed)
            {
                _onValue = false;
            }

            // initialize the pin as whatever off is.
            this.DigitalOut = new Microsoft.SPOT.Hardware.OutputPort(pin, !_onValue);
        }
Ejemplo n.º 7
0
        private void ProcessRelay(string source, RelayType type, string message, List <UserModeInfo> userModes = null, List <ChannelModeInfo> channelModes = null)
        {
            List <Dictionary <string, object> > relays = GetRelayList(source, type);

            switch (type)
            {
            case RelayType.Mode:
                for (int i = 0; i < relays.Count; i++)
                {
                    string modeStr   = relays[i]["modes"].ToString();
                    char[] modes     = modeStr.ToCharArray();
                    bool   modeFound = false;
                    foreach (char mode in modes)
                    {
                        if (userModes != null)
                        {
                            if (userModes.Exists(info => info.Mode.ToString() == mode.ToString()))
                            {
                                modeFound = true;
                                break;
                            }
                        }
                        if (channelModes != null)
                        {
                            if (channelModes.Exists(info => info.Mode.ToString() == mode.ToString()))
                            {
                                modeFound = true;
                                break;
                            }
                        }
                    }
                    if (!modeFound)
                    {
                        relays.RemoveAt(i);
                        i--;
                    }
                }
                break;

            default:
                break;
            }
            foreach (Dictionary <string, object> relay in relays)
            {
                string      target  = relay["target"].ToString();
                MessageType msgType = MessageType.Channel;
                if (!Channel.IsChannel(target))
                {
                    msgType = MessageType.Query;
                }
                SendResponse(msgType, target, target, message);
            }
        }
Ejemplo n.º 8
0
        public Relay(H.Cpu.Pin pin, RelayType type = RelayType.NormallyOpen)
        {
            // if it's normally closed, we have to invert the "on" value
            this.Type = type;
            if (this.Type == RelayType.NormallyClosed)
            {
                _onValue = false;
            }

            // create a digital output port shim
            DigitalOut = new GPIO.SPOT.DigitalOutputPort(pin, !_onValue);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 在客显上显示金额
        /// </summary>
        /// <param name="_text">数值</param>
        /// <param name="_type">显示类型</param>
        public static void Switch(string _PORT_NAME, short _Address, int _Line, RelayType _type)
        {
            PORT_NAME = _PORT_NAME;
            Address   = _Address;
            Line      = _Line;
            type      = _type;

            Thread thread = new Thread(new ThreadStart(Switch));

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Ejemplo n.º 10
0
        private void EditRelay(CommandMessage command)
        {
            string     source     = command.Arguments.ContainsKey("Source") ? command.Arguments["Source"] : command.Location;
            string     target     = command.Arguments.ContainsKey("Target") ? command.Arguments["Target"] : command.Nick.Nickname;
            string     type       = command.Arguments.ContainsKey("Type") ? command.Arguments["Type"] : "Message";
            string     modes      = command.Arguments.ContainsKey("Modes") ? command.Arguments["Modes"] : string.Empty;
            string     chanAccess = GetOptionValue("Channel Access").ToString();
            AccessType access     = AccessType.User;

            Enum.TryParse(chanAccess, out access);

            // verify access in source and target
            if (!CheckAccess(source, command.Nick.Nickname, access))
            {
                string invalid = string.Format("You do not have permission to use '{0}' as a source.", source);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid, true);
                return;
            }
            if (Channel.IsChannel(target) && !CheckAccess(target, command.Nick.Nickname, access))
            {
                string invalid = string.Format("You do not have permission to use '{0}' as a target.", source);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid, true);
                return;
            }

            RelayType relayType = RelayType.Message;

            Enum.TryParse(type, true, out relayType);

            int num = HasValidID(command);

            if (num > 0)
            {
                List <Dictionary <string, object> > results = GetRelayList(command.Nick.Nickname);
                int    id    = Convert.ToInt32(results[num - 1]["id"]);
                string query = "UPDATE `relays` SET " +
                               "`source` = {0}, " +
                               "`target` = {1}, " +
                               "`type` = {2}, " +
                               "`modes` = {3} " +
                               "WHERE `id` = {4}";
                Bot.Database.Execute(query, new object[] { source, target, (int)relayType, modes, id });
                string relayMessage = string.Format("Updated relay \u0002{0}\u0002 to be from \u0002{1}\u0002 to \u0002{2}\u0002.", num, source, target);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, relayMessage);
            }
            else
            {
                string invalid = "Invalid relay ID.";
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid, true);
            }
        }
Ejemplo n.º 11
0
        private void AddRelay(CommandMessage command)
        {
            string     source     = command.Arguments.ContainsKey("Source") ? command.Arguments["Source"] : command.Location;
            string     target     = command.Arguments.ContainsKey("Target") ? command.Arguments["Target"] : command.Nick.Nickname;
            string     type       = command.Arguments.ContainsKey("Type") ? command.Arguments["Type"] : "Message";
            string     modes      = command.Arguments.ContainsKey("Modes") ? command.Arguments["Modes"] : string.Empty;
            string     chanAccess = GetOptionValue("Channel Access").ToString();
            AccessType access     = AccessType.User;

            Enum.TryParse(chanAccess, out access);

            // verify access in source and target
            if (!CheckAccess(source, command.Nick.Nickname, access))
            {
                string invalid = string.Format("You do not have permission to use '{0}' as a source.", source);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid, true);
                return;
            }
            if (Channel.IsChannel(target) && !CheckAccess(target, command.Nick.Nickname, access))
            {
                string invalid = string.Format("You do not have permission to use '{0}' as a target.", source);
                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid, true);
                return;
            }

            RelayType relayType = RelayType.Message;

            Enum.TryParse(type, true, out relayType);

            AddNick(command.Nick);
            string query = "INSERT INTO `relays` SET " +
                           "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                           "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
                           "`source` = {3}, " +
                           "`target` = {4}, " +
                           "`type` = {5}, " +
                           "`modes` = {6}, " +
                           "`date_added` = {7}";

            Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, command.Nick.Nickname, source, target, (int)relayType, modes, command.TimeStamp });
            List <Dictionary <string, object> > results = GetRelayList(command.Nick.Nickname);
            string relayMessage = string.Format("Added relay from \u0002{0}\u0002 to \u0002{1}\u0002.  You now have \u0002{2}\u0002 relays created.", source, target, results.Count);

            SendResponse(command.MessageType, command.Location, command.Nick.Nickname, relayMessage);
        }
Ejemplo n.º 12
0
 private void BaseConfig_Load(object sender, EventArgs e)
 {
     if (ClassName.EqualIgnoreCase("CommunicateDeviceType"))
     {
         this.Name = "CommunicateDeviceType";
         var types = CommunicateDeviceType.FindAll();
         this.dataGridViewX1.DataSource = types;
     }
     if (ClassName.EqualIgnoreCase("Sensor"))
     {
         this.Name = "Sensor";
         this.dataGridViewX1.DataSource = Sensor.FindAll();
     }
     if (ClassName.EqualIgnoreCase("RelayType"))
     {
         this.Name = "RelayType";
         this.dataGridViewX1.DataSource = RelayType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ControlJobType"))
     {
         this.Name = "ControlJobType";
         this.dataGridViewX1.DataSource = ControlJobType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("DeviceType"))
     {
         this.Name = "DeviceType";
         this.dataGridViewX1.DataSource = DeviceType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("FacilityType"))
     {
         this.Name = "FacilityType";
         this.dataGridViewX1.DataSource = FacilityType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ProtocalType"))
     {
         this.Name = "ProtocalType";
         this.dataGridViewX1.DataSource = ProtocalType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ShowDeviceType"))
     {
         this.Name = "ShowDeviceType";
         this.dataGridViewX1.DataSource = ShowDeviceType.FindAll();
     }
 }
Ejemplo n.º 13
0
        //创建命令
        public static byte[] CreateCMD(short _Address, int _Line, RelayType _type)
        {
            byte[] command = new byte[8];
            command[0] = (byte)ProtocolHead;
            command[1] = (byte)(_Address % 256);
            command[2] = (byte)_type;
            command[3] = 0;
            command[4] = 0;
            command[5] = (byte)(_Line >> 8);
            command[6] = (byte)_Line;
            int sum = 0;

            for (int i = 0; i <= 6; i++)
            {
                sum = sum + command[i];
            }
            command[7] = (byte)(sum % 256);
            return(command);
        }
Ejemplo n.º 14
0
 //创建命令
 public static byte[] CreateCMD(short _Address, int _Line, RelayType _type)
 {
     byte[] command = new byte[8];
     command[0] = (byte)ProtocolHead;
     command[1] = (byte)(_Address % 256);
     command[2] = (byte)_type;
     command[3] = 0;
     command[4] = 0;
     command[5] = (byte)(_Line >> 8);
     command[6] = (byte)_Line;
     int sum = 0;
     for (int i = 0; i <= 6; i++)
     {
         sum = sum + command[i];
     }
     command[7] = (byte)(sum % 256);
     return command;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 开关切换
        /// </summary>
        /// <param name="_PORT_NAME">端口</param>
        /// <param name="_Address">地址</param>
        /// _Line 第几路  _type  操作类型
        public static void Switch(string _PORT_NAME, short _Address, int _Line, RelayType _type)
        {
            PORT_NAME = _PORT_NAME;
            Address = _Address;
            Line = _Line;
            type = _type;

            Thread thread = new Thread(new ThreadStart(Switch));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
 /// <summary>
 /// Creates new service bus relay in the given name.
 /// </summary>
 /// <param name="namespaceName">The namespace name</param>
 /// <param name="name">The relay name</param>
 /// <param name="type">The relay type</param>
 /// <returns>The relay description object</returns>
 public virtual RelayDescription CreateRelay(string namespaceName, string name, RelayType type)
 {
     return CreateNamespaceManager(namespaceName).CreateRelayAsync(name, type).Result;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates new service bus relay in the given name.
 /// </summary>
 /// <param name="namespaceName">The namespace name</param>
 /// <param name="name">The relay name</param>
 /// <param name="type">The relay type</param>
 /// <returns>The relay description object</returns>
 public virtual RelayDescription CreateRelay(string namespaceName, string name, RelayType type)
 {
     return(CreateNamespaceManager(namespaceName).CreateRelayAsync(name, type).Result);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// 继电器控制
 /// </summary>
 /// <param name="PORT_NAME">端口</param>
 /// <param name="Address">地址</param>
 /// <param name="Line">线路</param>
 /// <param name="type">类型</param>
 public static void Relay(string PORT_NAME, short Address, int Line, RelayType type)
 {
     DevExt.Relay.Switch(PORT_NAME, Address, Line, type);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// 向指定端口发送指令
        /// </summary>
        /// <param name="_Address"></param>
        /// <param name="_Line"></param>
        /// <param name="_type"></param>
        private void SendCMD(short _Address, int _Line, RelayType _type)
        {
            byte[] tempCMD = new byte[8];
            tempCMD = Relay.CreateCMD(_Address, _Line, _type);
            SendCMDToBUS(tempCMD);

        }
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.ServiceBus.Messaging.RelayDescription" /> class.</summary>
 /// <param name="relayPath">The path of the relay.</param>
 /// <param name="type">The relay type.</param>
 public RelayDescriptionXml(string relayPath, RelayType type)
 {
     this.Path      = relayPath;
     this.RelayType = type;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 继电器控制
 /// </summary>
 /// <param name="PORT_NAME">端口</param>
 /// <param name="Address">地址</param>
 /// <param name="Line">线路</param>
 /// <param name="type">类型</param>
 public static void Relay(string PORT_NAME, short Address, int Line, RelayType type)
 {
     DevExt.Relay.Switch(PORT_NAME, Address, Line, type);
 }
Ejemplo n.º 22
0
        private void GroupAllSwitch(ListView.ListViewItemCollection Items,RelayType SW)
        {
            Delay(100);
            foreach (short addr in CurrentAddr)
            {
                int uLine = 0;
                foreach (DevListViewItem item in Items)
                {
                    if (item.uAddress == addr)
                    {
                        uLine += 1 << (item.uLine - 1);
                        //MessageBox.Show(uLine.ToString());

                        if ((Transport == 1) && (SW == RelayType.GROUPON))
                        {
                            item.ImageIndex = 3 * item.ImgGroup + 1;
                        }
                        if ((Transport == 1) && (SW == RelayType.GROUPOFF))
                        {
                            item.ImageIndex = 3 * item.ImgGroup + 0;
                        }
                    }
                }

                SendCMD(addr, uLine, SW);
            }
        }
 /// <summary>Initializes a new instance of the <see cref="T:Microsoft.ServiceBus.Messaging.RelayDescription" /> class.</summary>
 /// <param name="relayPath">The path of the relay.</param>
 /// <param name="type">The relay type.</param>
 public RelayDescription(string relayPath, RelayType type)
 {
     this.xml = new RelayDescriptionXml(relayPath, type);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 向指定端口发送指令
 /// </summary>
 /// <param name="_Address"></param>
 /// <param name="_Line"></param>
 /// <param name="_type"></param>
 private void SendCMD(short _Address, int _Line, RelayType _type)
 {
     byte[] tempCMD = new byte[8];
     tempCMD = Relay.CreateCMD(_Address, _Line, _type);
     clientSendMsg(tempCMD);
 }