Exemplo n.º 1
0
 /// <summary>
 /// 动态移除一个LED
 /// </summary>
 public void RemoveLED(LEDScreen led)
 {
     lock (lockObj)
     {
         if (LEDThreadPool.ContainsKey(led.ID))
         {
             LEDThreadPool[led.ID].Abort();
             LEDThreadPool[led.ID] = null;
             LEDThreadPool.Remove(led.ID);
         }
     }
 }
Exemplo n.º 2
0
 public LEDScreenControl(LEDScreen model)
     : this()
 {
     LedID = model.ID;
     txtName.Text = model.Name;
     _updater = new Thread(() =>
     {
         var client = Program.GetServiceClient();
         while (true)
         {
             var program = client.GetCurrentProgram(LedID);
             PlayProgram(program);
         }
     });
     _updater.Start();
 }
Exemplo n.º 3
0
 public static void Save(LEDScreen model)
 {
     var list = GetList();
     var index = list.FindIndex(delegate(LEDScreen e) { return e.ID == model.ID; });
     //客户端发送消息会更新CustomStyle,不能重置VirtualID,所以注释掉
     //model.VirtualID = -1;//编辑或新建LED,virtualId必须重置
     if (index > -1)
     {
         list[index] = model;
     }
     else
     {
         list.Add(model);
     }
     model.CurrentProgram = null;//重置LED屏幕的当前播放节目
     DataManager.Instance.Save(list);
 }
Exemplo n.º 4
0
        public static Program GetCurrentProgram(LEDScreen led)
        {
            var dt = DbHelper.GetDataTable("select ScheduleID from ScheduleLED where LEDID=" + led.ID + " order by ID desc");
            var ids = new List<int>();
            foreach (DataRow dr in dt.Rows)
            {
                ids.Add(int.Parse(dr["ScheduleID"].ToString()));
            }

            foreach (var scheduleId in ids)
            {
                var model = GetModel(scheduleId);
                if (model == null)
                {
                    continue;
                }
                if (
                    (DateTime.Now < model.BeginTime)
                    || (model.EndTime.HasValue && DateTime.Now > model.EndTime.Value)
                    )
                {
                    continue;
                }
                var program = ProgramManager.GetModel(model.ProgramID);
                if (led.CurrentProgram != null && led.CurrentProgram.ID == program.ID)
                {
                    if (program.UpdateTime > led.CurrentProgram.UpdateTime)
                    {
                        led.LastUpdateTime = model.CreateTime;
                        return led.CurrentProgram = program;
                    }
                    return null;
                }
                led.LastUpdateTime = model.CreateTime;
                return led.CurrentProgram = program;

                ////如果屏幕当前有播放节目,并且和本次获取的节目相同,则判断该节目是否播放完一次,如果播放完成则返回program,如果没有,则返回null
                //if (led.CurrentProgram != null && led.CurrentProgram.ID == program.ID && led.CurrentProgram.HasPlayedTimes < 1)
                //{
                //    return null;
                //}
                //led.CurrentProgram = program;
                //return program;
            }
            return null;
        }
Exemplo n.º 5
0
 /// <summary>
 /// 动态添加一个LED,增加其节目播放
 /// </summary>
 public void AddLED(LEDScreen led)
 {
     lock (lockObj)
     {
         RemoveLED(led);
         OpenLED(led);
         LEDThreadPool.Add(led.ID, new Thread(() =>
         {
             while (true)
             {
                 Play(led);
                 Thread.Sleep(1000 * GetInterval());
             }
         }));
         LEDThreadPool[led.ID].Start();
     }
 }
Exemplo n.º 6
0
        private void Play(LEDScreen led)
        {
            var program = ScheduleManager.GetCurrentProgram(led);

            if (program != null)
            {
                program.PlayTime = DateTime.Now;
                var holdTime = 0;
                switch (led.Style.TextAnimation)
                {
                    case TextAnimation.立即显示:
                        holdTime = GetHoldTime() * 10;
                        break;
                    case TextAnimation.上移:
                    case TextAnimation.下移:
                    case TextAnimation.左移:
                    case TextAnimation.右移:
                        if (led.Style.IsHold)
                        {
                            holdTime = GetHoldTime() * 10;
                        }
                        break;
                }
                var sendContents = new List<string>();
                foreach (var msg in program.Messages)
                {
                    sendContents.Add(msg.Content);
                }
                try
                {
                    LEDAdapter.SetFont(new Font(led.Style.FontFamily.ToString(), led.Style.FontSize), (ContentAlignment)led.Style.TextAlignment, 1, led.VirtualID);
                    LEDAdapter.SendContent(sendContents, (int)led.Style.TextAnimation, GetAnimationSpeed(), GetFrameTime(), holdTime, led.VirtualID);
                }
                catch (KeyNotFoundException ex)
                {
                    led.CurrentProgram = null;
                    //System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    led.CurrentProgram = null;
                    LogHelper.WriteLog(ex);
                    //System.Windows.Forms.MessageBox.Show(led.Name + "节目播放失败", "驱动异常", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 7
0
 private void OpenLED(LEDScreen led)
 {
     try
     {
         LEDAdapter.Open(led.ID);
         if (led.VirtualID == -1)
         {
             led.VirtualID = LEDAdapter.CreateWindow(0, 0, led.Width, led.Height, led.ID);
         }
     }
     catch
     {
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 动态更新一个LED
 /// </summary>
 public void UpdateLED(LEDScreen led)
 {
     AddLED(led);
 }