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.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 log = "程序启动错误,路径:" + model.ApplicationPath + (model.StartParameters.Length == 0 ? "" :
                                                                     ",参数为:" + model.StartParameters) + ex.ToString();
                Log.SaveLog("Task StartApplication", log);
            }

            Entity.TaskLog modLog = new TaskLog();
            modLog.TaskId     = model.Id;
            modLog.Title      = model.Title;
            modLog.IsRun      = "0";
            modLog.TimeType   = model.TimeType;
            modLog.TaskType   = model.TaskType;
            modLog.CreateDate = DateTime.Now;

            #region 检测程序启动信息

            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
            {
                if (proccessName == p.ProcessName)
                {
                    //Log.SaveLog("success_", "任务" + model.Title + "启动成功", log);
                    modLog.IsRun = "1";
                    return(true);
                }
            }
            this._dalTaskLog.Add(modLog);

            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 tmp     = "";
            string command = "";

            Entity.TaskLog modLog = new TaskLog();
            modLog.TaskId     = model.Id;
            modLog.TaskType   = model.TaskType;
            modLog.TimeType   = model.TimeType;
            modLog.IsRun      = "1";
            modLog.Title      = model.Title;
            modLog.CreateDate = DateTime.Now;

            #region 关机/显示器/锁屏

            if (model.TaskType == ((Int32)TaskType.Shutdown).ToString())//关机
            {
                tmp     = "系统将于60秒后关闭,此操作不能撤销,请保存好您的工作!";
                command = "shutdown -s -t 60";

                //Common.HookHelper hook = new Common.HookHelper();
                //hook.HookStart();//安装钩子
            }
            else if (model.TaskType == ((Int32)TaskType.TurnOffMonitor).ToString())//关闭显示器
            {
                Helper.CloseMonitor();
                this._dalTaskLog.Add(modLog);
                return(true);
            }
            else if (model.TaskType == ((Int32)TaskType.TurnOnMonitor).ToString())//
            {
                Helper.OpenMonitor();
                this._dalTaskLog.Add(modLog);
                return(true);
            }
            else if (model.TaskType == ((Int32)TaskType.LockMonitor).ToString())//锁屏
            {
                if (!Entity.App.IsLockScreen)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        View.LockScreen lockScreen = new View.LockScreen();
                        lockScreen.IsTest          = isTest;
                        lockScreen.PointText       = model.Remark.Contains("⊙") ? model.Remark.Split('⊙')[1] : model.Remark;
                        lockScreen.ShowDialog();
                    }));
                }
                this._dalTaskLog.Add(modLog);
                return(true);
            }
            #endregion

            #region POP提醒
            try
            {
                if (model.AudioEnable == "1")
                {
                    Thread t = new Thread(new ThreadStart(() =>
                    {
                        Helper.PalyAudio(model.AudioPath, model.AudioVolume);
                    }));

                    t.IsBackground = true;
                    t.Start();
                }
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    View.PopUP pop = new View.PopUP();
                    if (model.Remark.Contains(Entity.App.SpiderChar))
                    {
                        pop.Subject = model.Remark.Split(Entity.App.SpiderChar)[0];
                        pop.Info    = model.Remark.Split(Entity.App.SpiderChar)[1] + tmp;
                    }
                    else
                    {
                        pop.Subject = model.Remark + tmp;
                    }
                    pop.PopTitle = model.Title;
                    pop.Show();
                }));
            }
            catch (Exception ex)
            {
                Log.SaveLog("Task StartWarn", ex.ToString());
                result       = false;
                modLog.IsRun = "0";
            }
            #endregion

            if (!isTest)
            {
                Helper.Speek(tmp);
                Helper.Run(command);
            }
            this._dalTaskLog.Add(modLog);
            return(result);
        }