using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Aitex.Core.RT.Log;
using Aitex.Common.Util;
namespace Aitex.Triton160.RT.Routine.Process
{
///
/// Recipe head
///
public class RecipeHead
{
public string RecipeVariation { get; set; }
public string CreationTime { get; set; }
public string LastRevisionTime { get; set; }
public string CreatedBy { get; set; }
public string LastModifiedBy { get; set; }
public string PressureMode { get; set; }
public string Description { get; set; }
public string Barcode { get; set; }
public string BasePressure
{
get;
set;
}
public string PumpDownLimit
{
get;
set;
}
public string ElectrodeTemp
{
get;
set;
}
public string PurgeActive
{
get;
set;
}
public string MatchPositionC1
{
get;
set;
}
public string MatchPositionC2
{
get;
set;
}
}
public class RecipeStep
{
public string StepName;
public double StepTime;
public bool IsJumpStep;
public bool IsLoopStartStep;
public bool IsLoopEndStep;
public int LoopCount;
public string EndBy;
//public double EndByValue;
public Dictionary RecipeCommands = new Dictionary();
}
public class Recipe
{
///
/// 当前Recipe Run 记录对应的Guid
/// 每个Recipe Run 都对应有一个唯一的Guid
///
public static Guid CurrentRecipeRunGuid;
///
/// 解析工艺程序文件
///
/// 工艺程序名
/// xml格式的工艺数据内容
/// 返回解析的工艺数据变量
/// True:解析成功 | False:解析失败
public static bool Parse(string recipe, out RecipeHead recipeHead, out List recipeData)
{
recipeHead = new RecipeHead();
recipeData = new List();
try
{
//获取工艺程序文件中允许的命令字符串列表
//目的:如果工艺程序文件中含有规定之外的命令,则被禁止执行
HashSet recipeAllowedCommands = new HashSet();
XmlDocument rcpFormatDoc = new XmlDocument();
string recipeSchema = PathManager.GetCfgDir() + "RecipeFormat.xml";
rcpFormatDoc.Load(recipeSchema);
XmlNodeList rcpItemNodeList = rcpFormatDoc.SelectNodes("/Aitex/TableRecipeFormat/Catalog/Group/Step");
foreach (XmlElement item in rcpItemNodeList)
recipeAllowedCommands.Add(item.Attributes["ControlName"].Value);
//获取工艺程序文件中所有步的内容
XmlDocument rcpDataDoc = new XmlDocument();
rcpDataDoc.LoadXml(recipe);
recipeHead.PressureMode = rcpDataDoc.DocumentElement.HasAttribute("PressureMode") ? rcpDataDoc.DocumentElement.Attributes["PressureMode"].Value : "";
recipeHead.BasePressure = rcpDataDoc.DocumentElement.HasAttribute("BasePressure") ? rcpDataDoc.DocumentElement.Attributes["BasePressure"].Value : "";
recipeHead.PumpDownLimit = rcpDataDoc.DocumentElement.HasAttribute("PumpDownLimit") ? rcpDataDoc.DocumentElement.Attributes["PumpDownLimit"].Value : "";
recipeHead.ElectrodeTemp = rcpDataDoc.DocumentElement.HasAttribute("ElectrodeTemp") ? rcpDataDoc.DocumentElement.Attributes["ElectrodeTemp"].Value : "";
recipeHead.PurgeActive = rcpDataDoc.DocumentElement.HasAttribute("PurgeActive") ? rcpDataDoc.DocumentElement.Attributes["PurgeActive"].Value : "";
recipeHead.MatchPositionC1 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC1") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC1"].Value : "";
recipeHead.MatchPositionC2 = rcpDataDoc.DocumentElement.HasAttribute("MatchPositionC2") ? rcpDataDoc.DocumentElement.Attributes["MatchPositionC2"].Value : "";
recipeHead.Barcode = rcpDataDoc.DocumentElement.HasAttribute("Barcode") ? rcpDataDoc.DocumentElement.Attributes["Barcode"].Value : "";
XmlNodeList stepNodeList = rcpDataDoc.SelectNodes("/TableRecipeData/Step");
for (int i = 0; i < stepNodeList.Count; i++)
{
var recipeStep = new RecipeStep();
recipeData.Add(recipeStep);
XmlElement stepNode = stepNodeList[i] as XmlElement;
Dictionary dic = new Dictionary();
//遍历Step节点
foreach (XmlAttribute att in stepNode.Attributes)
{
if (recipeAllowedCommands.Contains(att.Name))
{
dic.Add(att.Name, att.Value);
}
}
//遍历Step子节点中所有的attribute属性节点
foreach (XmlElement subStepNode in stepNode.ChildNodes)
{
foreach (XmlAttribute att in subStepNode.Attributes)
{
if (recipeAllowedCommands.Contains(att.Name))
{
dic.Add(att.Name, att.Value);
}
}
//遍历Step子节点的子节点中所有的attribute属性节点
foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
{
foreach (XmlAttribute att in subsubStepNode.Attributes)
{
if (recipeAllowedCommands.Contains(att.Name))
{
dic.Add(att.Name, att.Value);
}
}
}
}
recipeStep.IsJumpStep = true;//!Convert.ToBoolean(dic["Ramp"]);
recipeStep.StepName = dic["Name"];
recipeStep.StepTime = TimeSpan.Parse(dic["Time"]).TotalSeconds;
string loopStr = dic["Loop"];
recipeStep.IsLoopStartStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop\x20\d+\s*$").Success;
recipeStep.IsLoopEndStep = System.Text.RegularExpressions.Regex.Match(loopStr, @"Loop End$").Success;
if (recipeStep.IsLoopStartStep)
recipeStep.LoopCount = Convert.ToInt32(loopStr.Replace("Loop", string.Empty));
else
recipeStep.LoopCount = 0;
//recipeStep.EndByValue = Convert.ToDouble(dic["EndValue"]);
recipeStep.EndBy = dic["EndBy"];
if (recipeStep.EndBy == "EndByRfTime")
{
recipeStep.StepTime = TimeSpan.Parse(dic["Rf.SetPowerOnTime"]).TotalSeconds;
if (recipeStep.StepTime <= 0)
{
LOG.Error("recipe 没有定义RF Power on的时间");
return false;
}
}
int rfPower = (int)Convert.ToDouble(dic["Rf.SetPower"]);
dic.Add("Rf.SetPowerOnOff", rfPower >0 ? "true" : "false");
//dic.Remove("Ramp");
dic.Remove("StepNo");
dic.Remove("Name");
dic.Remove("Loop");
dic.Remove("Time");
dic.Remove("EndBy");
//dic.Remove("EndValue");
dic.Remove("Rf.SetPowerOnTime");
foreach (string key in dic.Keys)
recipeStep.RecipeCommands.Add(key, dic[key]);
}
}
catch (Exception ex)
{
LOG.Write(ex);
return false;
}
return true;
}
}
}