public void Tick(Trigger trigger)
        {
            var now = CommonTime.GetTimeOfDay(_dateTime.Now);

            var onOrOff = (now, trigger.TriggerType) switch
            {
                (_, TriggerType.OnButtonPressed) => true,
                (_, TriggerType.OffButtonPressed) => false,
                (CommonTimes.Morning, TriggerType.DoorOpened) => true,
                (CommonTimes.Evening, TriggerType.DoorOpened) => true,
                (CommonTimes.Evening, TriggerType.DoorClosed) => false,
                (CommonTimes.Night, TriggerType.MotionDetected) => true,
                _ => false
            };

            _light.Set(onOrOff);
        }
        public void Tick(Trigger trigger)
        {
            var now   = CommonTime.GetTimeOfDay(DateTime.Now);
            var light = new Light();

            if (trigger.TriggerType == TriggerType.OnButtonPressed)
            {
                light.Set(true);
            }

            if (now == CommonTimes.Morning)
            {
                if (trigger.TriggerType == TriggerType.DoorOpened)
                {
                    light.Set(true);
                }
            }

            if (now == CommonTimes.Evening)
            {
                if (trigger.TriggerType == TriggerType.DoorOpened)
                {
                    light.Set(true);
                }
                else if (trigger.TriggerType == TriggerType.DoorClosed)
                {
                    light.Set(true);
                }
            }

            if (now == CommonTimes.Night)
            {
                if (trigger.TriggerType == TriggerType.MotionDetected)
                {
                    light.Set(true);
                }
            }
        }
Exemplo n.º 3
0
 private string MakeRecordFilePath(string extName = "")
 {
     return(string.Format("[{0}] {1}", RoomID, CommonTime.GetSaveTimeString() + extName));
 }
Exemplo n.º 4
0
        private string MakeSaveDir()
        {
            string roomdir = string.Format("[{0}] {1}", RoomID, CommonTime.GetDayTimeString());

            return(roomdir);
        }
Exemplo n.º 5
0
        private static void StartDanmuRecord(object obj)
        {
            Operator op = (Operator)obj;
            DySocket s  = new DySocket();

            s.login(op.RoomID);
            op.StartDanmu = true;

            //打开弹幕文件
            FileStream fs = new FileStream(op.RecordFilePath + ".danmu",
                                           FileMode.OpenOrCreate
                                           );

            long LastTime = CommonTime.GetTimeStamp();

            while (true)
            {
                s.keeplive();
                if (op.StartDanmu == false)
                {
                    break;
                }

                byte[] resraw = s.recv(4);
                if (resraw == null)
                {
                    op.LogError("Recv Timeout");
                    break;
                }

                int len = BitConverter.ToInt32(resraw, 0);
                if (len <= 0)
                {
                    continue;
                }

                resraw = s.recv(8);
                short type = BitConverter.ToInt16(resraw, 4);

                if (type != 690)
                {
                    continue;
                }

                // 正式获取消息
                resraw = s.recv(len - 8);

                string resstr = System.Text.Encoding.UTF8.GetString(resraw);

                // 弹幕
                if (resstr.Contains("type@=chatmsg") &&
                    resstr.Contains("txt@=") &&
                    resstr.Contains("nn@=")
                    )
                {
                    long   timeCount = CommonTime.GetTimeStamp() - LastTime;
                    var    dict      = DyMsg.GetDict(resstr);
                    string outDanmu  = null;
                    if (dict.ContainsKey("col"))
                    {
                        outDanmu = string.Format("TimeCount={0},user={1},text={2},col={3}",
                                                 timeCount, dict["nn"], dict["txt"], dict["col"]) + Environment.NewLine;
                    }
                    else
                    {
                        outDanmu = string.Format("TimeCount={0},user={1},text={2}",
                                                 timeCount, dict["nn"], dict["txt"]) + Environment.NewLine;
                    }
                    byte[] bDanmu = Encoding.UTF8.GetBytes(outDanmu);
                    try
                    {
                        fs.Write(bDanmu, 0, bDanmu.Length);
                    }
                    catch (Exception e)
                    {
                        op.LogError("Danmu:" + e.Message, true);
                    }
                    op.RecordDanmu(resstr);
                }
            }
            fs.Close();
            s.logout();
            s.release();
            op.RecordDanmuClosing();
        }