using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Dynamic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace Venus_Core { public enum RecipeType { Chuck, DeChuck, Process, Clean, } public enum StepType { Time, Stable, EndPoint, OverEtch, } public enum ProcessModule { Pressure, TCP, // Transformer Coupled Plasma (转换耦合等离子) Bias, Gas, ESC, Process, Compound, } public enum GeneratorMode { Pulsing, CW, } public enum PressureUnitMode { Pressure, Valve } public class RecipeHead: INotifyPropertyChanged { private string m_name; public string Name { get { return m_name; } set { m_name = value; InvokePropertyChanged("Name"); } } private string _Version = "Test"; public string Version { get { return _Version; } set { _Version = value; InvokePropertyChanged("Version"); } } private RecipeType m_Type; [JsonConverter(typeof(StringEnumConverter))] public RecipeType Type { get { return m_Type; } set { m_Type = value; InvokePropertyChanged("Type"); } } private string m_ChunckRecipe; public string ChuckRecipe { get { return m_ChunckRecipe;} set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); } } private string m_DechuckRecipe; public string DechuckRecipe { get { return m_DechuckRecipe;} set{ m_DechuckRecipe = value;InvokePropertyChanged("DechuckRecipe");} } private string m_CreateTime; public string CreateTime { get { return m_CreateTime;} set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); } } private string m_LastModifiedBy; public string LastModifiedBy { get { return m_LastModifiedBy;} set { m_LastModifiedBy = value; InvokePropertyChanged("CreateTime"); } } private string m_Barcode; public string Barcode { get { return m_Barcode;} set { m_Barcode = value; InvokePropertyChanged("Barcode"); } } private string m_BasePressure; public string BasePressure { get { return m_BasePressure;} set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); } } private string m_ChillerTemp; public string ChillerTemp { get { return m_ChillerTemp;} set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); } } public event PropertyChangedEventHandler PropertyChanged; public void InvokePropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } public class ProcessUnitBase { [JsonIgnore] public Func checker; [JsonIgnore] public Func starter; //[JsonIgnore] //public string Name { get; set; } //[JsonIgnore] //public ProcessModule Moudle { get; set; } public RState Start() { if (starter != null) return starter(); return RState.Running; } public RState Run() { if (checker != null) return checker(); return RState.Running; } } public class RecipeStep:INotifyPropertyChanged { private StepType m_StepType; [JsonConverter(typeof(StringEnumConverter))] public StepType Type { get { return m_StepType;} set { m_StepType = value; InvokePropertyChanged("Type"); } } private int m_Time; public int Time { get { return m_Time;} set { m_Time = value; InvokePropertyChanged("Time"); } } private int m_MinEndPointTime; public int MinEndPointTime { get { return m_MinEndPointTime;} set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); } } private int m_MaxEndPointTime; public int MaxEndPointTime { get { return m_MaxEndPointTime; } set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); } } private bool m_CycleStart; public bool CycleStart { get { return m_CycleStart;} set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); } } private bool m_CycleEnd; public bool CycleEnd { get { return m_CycleEnd;} set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); } } private int m_CycleNumber; public int CycleNumber { get { return m_CycleNumber;} set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); } } public PressureUnitMode PressureUnitMode { get; set; } private ObservableCollection lstUnit = new ObservableCollection(); public ObservableCollection LstUnit { get { return lstUnit; } set { lstUnit = value; InvokePropertyChanged("LstUnit"); } } public RState Start() { //foreach(var unit in lstUnit) //{ // var state = unit.Start(); // if (state != RState.Running) // return state; //} return RState.Running; } public RState Run() { //foreach (var unit in lstUnit) //{ // var state = unit.Run(); // if (state != RState.Running) // return state; //} return RState.Running; } public void AppendUnit(ProcessUnitBase unit) { lstUnit.Append(unit); } public event PropertyChangedEventHandler PropertyChanged; public void InvokePropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } public class Recipe: INotifyPropertyChanged { private RecipeHead m_Header = new RecipeHead(); public RecipeHead Header { get { return m_Header; } set { m_Header = value; InvokePropertyChanged("Header"); } } private ObservableCollection m_Steps; public ObservableCollection Steps { get { return m_Steps; } set { m_Steps = value; InvokePropertyChanged("Steps"); } } public static Recipe Load(string recipeFile) { var recipe= JsonConvert.DeserializeObject(recipeFile); foreach (var step in recipe.Steps) { ObservableCollection unit = new ObservableCollection(); //int count = step.LstUnit.Count / 2; //for (int i = 0; i < count; i++) //{ // Type t = Type.GetType(step.LstUnit[i].ToString()); // //unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i+count].ToString())); // unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i + count].ToString())); //} for (int i=0;i< step.LstUnit.Count; i++) { //object item=step.LstUnit[i]; string value = step.LstUnit[i].ToString(); string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None); string item1= striparr[1].Remove(0, 15); string item2 = item1.Remove(item1.Length - 2, 2); //var item= value.Substring(value.IndexOf("UnitName")); //Type t = Type.GetType(value); switch (item2) { case "PressureUnitByPressureMode": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "PressureUnitByValveMode": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "TCPUnit": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "BiasUnit": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "GasControlUnit": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "ESCHVUnit": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; case "ProcessKitUnit": unit.Add(JsonConvert.DeserializeObject(step.LstUnit[i].ToString())); break; } } step.LstUnit.Clear(); unit.ToList().ForEach(x => { step.LstUnit.Add(x); }); } return recipe; } public bool Validate() { return true; } public bool Save(string recipeFile) { return true; } public event PropertyChangedEventHandler PropertyChanged; public void InvokePropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } public class RecipeUnity { public static string ConvertJsonString(string str) { JsonSerializer serializer = new JsonSerializer(); TextReader tr = new StringReader(str); JsonTextReader jtr = new JsonTextReader(tr); object obj = serializer.Deserialize(jtr); if (obj != null) { StringWriter textWriter = new StringWriter(); JsonTextWriter jsonWriter = new JsonTextWriter(textWriter) { Formatting = Newtonsoft.Json.Formatting.Indented, Indentation = 4, IndentChar = ' ' }; serializer.Serialize(jsonWriter, obj); return textWriter.ToString(); } else { return str; } } public static string RecipeToString(Recipe recipe) { return JsonConvert.SerializeObject(recipe); } public static String CreateRecipe(RecipeType recipeType) { Recipe recipe = new Recipe(); recipe.Header = new RecipeHead(); recipe.Header.CreateTime = DateTime.Now.ToString(); recipe.Header.Type = recipeType; recipe.Steps = new ObservableCollection(); recipe.Steps.Add(new RecipeStep() { LstUnit = new ObservableCollection() { new TCPUnit(){}, new BiasUnit(), new GasControlUnit(), new ESCHVUnit(), new ProcessKitUnit() } }); var recipeString = JsonConvert.SerializeObject(recipe); //var Recipe2=JsonConvert.DeserializeObject(recipeString); //string test = ""; //test = Recipe2.Steps[0].LstUnit[0].ToString(); //var tcpinit = JsonConvert.DeserializeObject(test); return recipeString; } } }