StoreExeBean.cs 3.5 KB
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StroreManager
{
    public class StoreExeBean
    {
        public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static char spiltStr = ';';
        public StoreExeBean()
        {
            Priority = 1;
        }
        public int ID { get; set; }
        /// <summary>
        /// 进程名称,不带EXE
        /// </summary>
        public string ProcessName { get; set; }

        /// <summary>
        /// 路径+名称
        /// </summary>
        public string ExePath { get; set; }
        /// <summary>
        /// 版本号
        /// </summary>
        public string FileVersion { get; set; }

        /// <summary>
        /// 是否在运行中
        /// </summary>
        public bool IsRun { get; set; }
        public string IsRunStr
        {
            get
            {
                if (IsRun)
                {
                    return "正在运行中";
                }
                else
                {
                    return "已停止";
                }
            }
            set
            {
            }
        }
        public string StartButtonStr
        {
            get
            {
                if (IsRun)
                {
                    return "查看";
                }
                else
                {
                    return "启动";
                }
            }
            set
            {
            }
        }


        /// <summary>
        /// 进程号
        /// </summary>
        public string PID { get; set; }
        /// <summary>
        /// 使用的CPU百分率
        /// </summary>
        public string CPU { get; set; }
        /// <summary>
        /// 占用内存数
        /// </summary>
        public string UseMemory { get; set; }

        /// <summary>
        /// 是否自动运行
        /// </summary>
        public bool IsAutoRun { get; set; }

        /// <summary>
        /// 启动优先级(自动启动时才有优先级)
        /// </summary>
        public int Priority { get; set; }

        public override string ToString()
        {
            return "ID=" + ID + ",ProcessName=" + ProcessName + ",ExePath=" + ExePath + ",IsRun=" + IsRun + ",IsAutoRun=" + IsAutoRun + ",FileVersion=" + FileVersion;
        }

        /// <summary>
        /// exe的名称
        /// </summary>
        public string GetExeName()
        {
            return ProcessName + ".exe";
        }
        /// <summary>
        /// 保存到文件的字符串
        /// </summary>
        /// <returns></returns>
        public string AuToFileData()
        {
            return ProcessName + spiltStr + ExePath + spiltStr + Priority;
        }

        public static StoreExeBean ConverToBean(string str)
        {
            StoreExeBean bean = null;
            try
            {
                string[] array = str.Split(StoreExeBean.spiltStr);
                if (array.Length == 3)
                {
                    bean = new StoreExeBean();
                    bean.ProcessName = array[0];
                    bean.ExePath = array[1];
                    bean.Priority = Int32.Parse(array[2]);

                    return bean;
                }
            }
            catch (Exception ex)
            {
                LOGGER.Error("出错:", ex);
            }
            return bean;
        }
    }
}