using Aitex.Core.UI.MVVM;
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.Device.ResistivityProbe;
using MECF.Framework.Common.Device.Rinse;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.Persistent.Rinse;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.Common.ToolLayout;
using MECF.Framework.Common.Utilities;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
namespace PunkHPX8_MainPages.ViewModels
{
    internal class RinseHomePageViewModel : BindableBase
    {
        #region 常量
        private const string RINSE_DATA = "RinseData";
        private const string RINSE = "rinse";
        private const string PERSISTENT_VALUE = "PersistentValue";
        private const string RESISTIVITYVALUE = "Resistivity";
        #endregion
        #region 内部变量
        #region Common
        /// 
        /// 模块名称
        /// 
        private string _module;
        /// 
        /// StateMachine
        /// 
        private string _stateMachine;
        /// 
        /// Status
        /// 
        private string _status;
        /// 
        /// 数据
        /// 
        private RinseData _rinseCommonData;
        /// 
        /// 当前选择Recipe节点
        /// 
        private RecipeNode _selectedRecipeNode;
        /// 
        /// Persistent
        /// 
        private RinsePersistentValue _rinsePersistent;
        /// 
        /// RinseItem
        /// 
        private RinseItem _rinseItem;
        #endregion
        #region Wafer Holder
        /// SeqRecipe
        /// 
        private string _seqRecipe;
        #endregion
        #region 系统数据
        /// 
        /// 定时器
        /// 
        DispatcherTimer _timer;
        /// 
        /// 查询后台数据集合
        /// 
        private List _rtDataKeys = new List();
        /// 
        /// rt查询key数值字典
        /// 
        private Dictionary _rtDataValueDic = new Dictionary();
        #endregion
        #region Rinse1
        /// 
        /// RecipeContent
        /// 
        private string _recipeContent;
        /// 
        /// TimeRemaining 
        /// 
        private double _timeRemaining;
        /// 
        /// OfTotalTime 
        /// 
        private double _totalTime;
        /// 
        /// OperatingMode 
        /// 
        private string _operatingMode;
        /// 
        /// State
        /// 
        private string _state;
        /// 
        /// RecipeMode 
        /// 
        private string _recipeMode;
        #endregion
        #region QDR recipe
        /// 
        /// RecipeModuleName
        /// 
        private string _recipeModuleName;
        /// 
        /// RecipeType
        /// 
        private string _recipeType;
        /// 
        /// AchievedRunRecipeCycle
        /// 
        private int _achievedRunRecipeCycle;
        /// 
        /// 当前Recipe
        /// 
        private string _currentRecipe;
        #endregion
        #region UI Related
        /// 
        /// ClampStatus
        /// 
        private string _clampStatus;
        /// 
        /// InterLock
        /// 
        private bool _interLock;
        /// 
        /// IsErrorState 用于腔体变红
        /// 
        private bool _isErrorState;
        /// 
        /// 用于UI水位的高度
        /// 
        private double _uIWaterLevel;
        /// 
        /// 页面功能启用
        /// 
        private bool _isEnabled;
        /// 
        /// AutoMode页面功能启用
        /// 
        private bool _isAutoEnabled;
        /// 
        /// 是否存在WaferHolder
        /// 
        private bool _isWaferHolder;
        #endregion
        #endregion
        #region 属性
        #region Common
        /// 
        /// 模块名称
        /// 
        public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
        /// 
        /// StateMachine
        /// 
        public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
        /// 
        /// Status
        /// 
        public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
        /// 
        /// Commondata
        /// 
        public RinseData RinseCommonData
        {
            get { return _rinseCommonData; }
            set { SetProperty(ref _rinseCommonData, value); }
        }
        /// 
        /// Threshold
        /// 
        public RinsePersistentValue RinsePersistent
        {
            get { return _rinsePersistent; }
            set { SetProperty(ref _rinsePersistent, value); }
        }
        /// 
        /// RinseItem
        /// 
        public RinseItem Rinseitem
        {
            get { return _rinseItem; }
            set { SetProperty(ref _rinseItem, value); }
        }
        public RecipeNode SelectedRecipeNode
        {
            get { return _selectedRecipeNode; }
            set { SetProperty(ref _selectedRecipeNode, value); }
        }
        #endregion
        #region Rinse1
        /// 
        /// RecipeContent
        /// 
        public string RecipeContent
        {
            get { return _recipeContent; }
            set { SetProperty(ref _recipeContent, value); }
        }
        /// 
        /// TimeRemaining 
        /// 
        public double TimeRemaining
        {
            get { return _timeRemaining; }
            set { SetProperty(ref _timeRemaining, value); }
        }
        /// 
        /// TotalTime  
        /// 
        public double TotalTime
        {
            get { return _totalTime; }
            set { SetProperty(ref _totalTime, value); }
        }
        /// 
        /// OperatingMode
        /// 
        public string OperatingMode
        {
            get { return _operatingMode; }
            set { SetProperty(ref _operatingMode, value); }
        }
        /// 
        /// State
        /// 
        public string State
        {
            get { return _state; }
            set { SetProperty(ref _state, value); }
        }
        /// 
        /// RecipeMode
        /// 
        public string RecipeMode
        {
            get { return _recipeMode; }
            set { SetProperty(ref _recipeMode, value); }
        }
        #endregion
        #region QDR recipe
        /// 
        /// RecipeModuleName
        /// 
        public string RecipeModuleName
        {
            get { return _recipeModuleName; }
            set { SetProperty(ref _recipeModuleName, value); }
        }
        /// 
        /// RecipeType
        /// 
        public string RecipeType
        {
            get { return _recipeType; }
            set { SetProperty(ref _recipeType, value); }
        }
        /// 
        /// Run Recipe已经完成的次数
        /// 
        public int AchievedRunRecipeCycle
        {
            get { return _achievedRunRecipeCycle; }
            set { SetProperty(ref _achievedRunRecipeCycle, value); }
        }
        /// 
        /// 当前Recipe
        /// 
        public string CurrentRecipe
        {
            get { return _currentRecipe; }
            set { SetProperty(ref _currentRecipe, value); }
        }
        #endregion
        #region Wafer Holder
        
        /// 
        /// SeqRecipe
        /// 
        public string SeqRecipe
        {
            get { return _seqRecipe; }
            set { SetProperty(ref _seqRecipe, value); }
        }
        #endregion
        #region UI Related
        /// 
        /// ClampStatus
        /// 
        public string ClampStatus
        {
            get { return _clampStatus; }
            set { SetProperty(ref _clampStatus, value); }
        }
        /// 
        /// IsErrorState
        /// 
        public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
        /// 
        /// ClampStatus
        /// 
        public bool InterLock
        {
            get { return _interLock; }
            set { SetProperty(ref _interLock, value); }
        }
        public double UIWaterLevel { get { return _uIWaterLevel; } set { SetProperty(ref _uIWaterLevel, value); } }
        /// 
        /// 页面功能启用
        /// 
        public bool IsEnabled
        {
            get { return _isEnabled; }
            set { SetProperty(ref _isEnabled, value); }
        }
        /// 
        /// AutoMode页面功能启用
        /// 
        public bool IsAutoEnabled
        {
            get { return _isAutoEnabled; }
            set { SetProperty(ref _isAutoEnabled, value); }
        }
        /// 
        /// 是否存在WaferHolder
        /// 
        public bool IsWaferHolder { get { return _isWaferHolder; } set { SetProperty(ref _isWaferHolder, value); } }
        #endregion
        #endregion
        #region Command指令
        public ICommand InitializeCommand { get; set; }
        #endregion
        /// 
        /// 构造函数
        /// 
        public RinseHomePageViewModel()
        {
            InitializeCommand = new DelegateCommand