Beispiel #1
0
        /// <summary>
        /// 启动程序
        /// </summary>
        /// <param name="name">任务名称</param>
        /// <param name="proccessName">进程名</param>
        /// <param name="path">程序路径</param>
        /// <param name="startParameters">启动参数</param>
        /// <returns>是否启动成功</returns>
        public bool StartApp(AutoTask model, string proccessName)
        {
            //杀死
            Helper.Instance.EndApp(proccessName);
            //启动
            System.Threading.Thread.Sleep(2000);
            if (!File.Exists(model.ApplicationPath))//不存在
            {
                return(false);
            }
            try
            {
                if (model.StartParameters.Length > 0)
                {
                    System.Diagnostics.Process.Start(model.ApplicationPath, model.StartParameters);
                }
                else
                {
                    System.Diagnostics.Process.Start(model.ApplicationPath);
                }
            }
            catch (Exception ex)
            {
                string msg = "程序启动错误,路径:" + model.ApplicationPath + (model.StartParameters.Length == 0 ? "" :
                                                                     ",参数为:" + model.StartParameters) + ex.ToString();
                Log.SaveLog("Task StartApplication", msg);
            }

            TimedTask.Model.SysLog log = new TimedTask.Model.SysLog();
            log.TaskId     = model.Id;
            log.Title      = model.Title;
            log.IsRun      = "0";
            log.RunType    = model.RunType;
            log.TaskType   = model.TaskType;
            log.CreateDate = DateTime.Now;

            #region 检测程序启动信息

            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
            {
                if (proccessName == p.ProcessName)
                {
                    log.IsRun = "1";
                    this._bllLog.Add(log);
                    return(true);
                }
            }

            return(false);

            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// 开始提醒
        /// </summary>
        /// <param name="taskType">任务类别</param>
        /// <param name="title">标题</param>
        /// <param name="remark">任务说明</param>
        /// <param name="audioName">声音名称</param>
        /// <param name="isTest">是否测试,测试关机时只提醒不关机</param>
        /// <returns></returns>
        public bool StartWarn(AutoTask model, bool isTest)
        {
            bool   result     = true;
            string msg        = "";
            string command    = "";
            bool   isShutdown = false;//是否关机

            TimedTask.Model.SysLog modLog = new TimedTask.Model.SysLog();
            modLog.TaskId     = model.Id;
            modLog.TaskType   = model.TaskType;
            modLog.RunType    = model.RunType;
            modLog.IsRun      = "1";
            modLog.Title      = model.Title;
            modLog.CreateDate = DateTime.Now;

            #region 关机/显示器/锁屏

            if (model.TaskType == ((Int32)TaskType.Shutdown).ToString())//关机
            {
                msg        = "系统将于 120 秒后关闭,此操作不能撤销,请保存好您的工作!";
                command    = "shutdown -s -t 120";
                isShutdown = true;
            }
            else if (model.TaskType == ((Int32)TaskType.TurnOffMonitor).ToString())//关闭显示器
            {
                Helper.Instance.CloseMonitor();
                this._bllLog.Add(modLog);
                return(true);
            }
            else if (model.TaskType == ((Int32)TaskType.TurnOnMonitor).ToString())//打开显示器
            {
                Helper.Instance.OpenMonitor();
                this._bllLog.Add(modLog);
                return(true);
            }
            else if (model.TaskType == ((Int32)TaskType.LockMonitor).ToString())//锁屏
            {
                if (!TimedTask.Model.PM.IsScreenLock)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        View.ScreenLock lockScreen = new View.ScreenLock();
                        lockScreen.IsTest          = isTest;
                        lockScreen.PointText       = model.Remark.Contains("⊙") ? model.Remark.Split('⊙')[1] : model.Remark;
                        lockScreen.ShowDialog();
                    }));
                }
                this._bllLog.Add(modLog);
                return(true);
            }
            #endregion

            #region 声音 POP提醒
            try
            {
                if (model.AudioEnable == null)
                {
                    model.AudioEnable = "0";
                }

                if (model.AudioEnable == "1" || model.AudioEnable.Equals("True", StringComparison.CurrentCultureIgnoreCase))
                {
                    //创建异步线程
                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        Helper.Instance.PalyAudio(model.AudioPath, model.AudioVolume);
                    });
                }
                if (!isShutdown)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        View.PopUP pop = new View.PopUP();
                        if (model.Remark.Contains(TimedTask.Model.PM.SpiderChar))
                        {
                            pop.Subject = model.Remark.Split(TimedTask.Model.PM.SpiderChar)[0];
                            pop.Info    = model.Remark.Split(TimedTask.Model.PM.SpiderChar)[1] + msg;
                        }
                        else
                        {
                            pop.Subject = model.Remark + msg;
                        }
                        pop.PopTitle = model.Title;
                        pop.Show();
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.SaveLog("Task StartWarn", ex.ToString());
                result       = false;
                modLog.IsRun = "0";
            }
            #endregion

            #region 关机

            if (!isTest)
            {
                MainWindow.TaskIcon.ShowBalloonTip("温馨提示", msg, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
                Helper.Instance.Run(command);
            }
            #endregion

            this._bllLog.Add(modLog);
            return(result);
        }