RecipeFileManager.cs 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.Utilities;
  7. using Aitex.Core.WCF;
  8. using MECF.Framework.Common.Properties;
  9. using MECF.Framework.Common.RecipeCenter;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Xml;
  17. using System.Xml.Schema;
  18. namespace Aitex.Core.RT.RecipeCenter
  19. {
  20. public class RecipeFileManager : Singleton<RecipeFileManager>
  21. {
  22. //sequence文件 统一放在 Recipes/Sequence 文件夹下面
  23. public const string SequenceFolder = "Sequence";
  24. public const string SourceModule = "Recipe";
  25. public const string WaferFlowFolder = "WaferFlow";
  26. string _chamberId;
  27. private bool _recipeIsValid;
  28. private List<string> _validationErrors = new List<string>();
  29. private List<string> _validationWarnings = new List<string>();
  30. IRecipeFileContext _rcpContext;
  31. private ISequenceFileContext _seqContext;
  32. public RecipeFileManager()
  33. {
  34. _chamberId = SC.GetStringValue("System.Recipe.RecipeChamberType");
  35. if (_chamberId == null)
  36. _chamberId = "Furnace";
  37. }
  38. public void Initialize(IRecipeFileContext context)
  39. {
  40. Initialize(context, null, true);
  41. }
  42. public void Initialize(IRecipeFileContext context, bool enableService)
  43. {
  44. Initialize(context, null, enableService);
  45. }
  46. public void Initialize(IRecipeFileContext rcpContext, ISequenceFileContext seqContext, bool enableService)
  47. {
  48. _rcpContext = rcpContext == null ? new DefaultRecipeFileContext() : rcpContext;
  49. _seqContext = seqContext == null ? new DefaultSequenceFileContext() : seqContext;
  50. CultureSupported.UpdateCoreCultureResource(CultureSupported.English);
  51. if (enableService)
  52. {
  53. Singleton<WcfServiceManager>.Instance.Initialize(new Type[]
  54. {
  55. typeof(RecipeService)
  56. });
  57. }
  58. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), SequenceFolder);
  59. DirectoryInfo di = new DirectoryInfo(dir);
  60. if (!di.Exists)
  61. {
  62. di.Create();
  63. }
  64. }
  65. private void ValidationEventHandler(object sender, ValidationEventArgs e)
  66. {
  67. switch (e.Severity)
  68. {
  69. case XmlSeverityType.Error:
  70. _validationErrors.Add(e.Message);
  71. _recipeIsValid = false;
  72. break;
  73. case XmlSeverityType.Warning:
  74. _validationWarnings.Add(e.Message);
  75. break;
  76. }
  77. }
  78. /// <summary>
  79. /// XML schema checking
  80. /// </summary>
  81. /// <param name="chamId"></param>
  82. /// <param name="recipeName"></param>
  83. /// <param name="recipeContent"></param>
  84. /// <param name="reason"></param>
  85. /// <returns></returns>
  86. public bool ValidateRecipe(string chamberId, string recipeName, string recipeContent, out List<string> reason)
  87. {
  88. try
  89. {
  90. XmlDocument document = new XmlDocument();
  91. document.LoadXml(recipeContent);
  92. MemoryStream schemaStream = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(GetRecipeSchema(chamberId)));
  93. XmlReader xmlSchemaReader = XmlReader.Create(schemaStream);
  94. XmlSchema schema1 = XmlSchema.Read(xmlSchemaReader, ValidationEventHandler);
  95. document.Schemas.Add(schema1);
  96. document.LoadXml(recipeContent);
  97. ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
  98. _recipeIsValid = true;
  99. _validationErrors = new List<string>();
  100. _validationWarnings = new List<string>();
  101. // Validates recipe.
  102. document.Validate(eventHandler);
  103. }
  104. catch (Exception ex)
  105. {
  106. LOG.Write(ex.Message);
  107. _recipeIsValid = false;
  108. }
  109. if (!_recipeIsValid && _validationErrors.Count == 0)
  110. {
  111. _validationErrors.Add(Resources.RecipeFileManager_ValidateRecipe_XMLSchemaValidateFailed);
  112. }
  113. reason = _validationErrors;
  114. return _recipeIsValid;
  115. }
  116. /// <summary>
  117. /// Check recipe content
  118. /// </summary>
  119. /// <param name="chamId"></param>
  120. /// <param name="recipeContent"></param>
  121. /// <param name="reasons"></param>
  122. /// <returns></returns>
  123. public bool CheckRecipe(string chamberId, string recipeName, out List<string> reasons)
  124. {
  125. reasons = new List<string>();
  126. string chamberType = chamberId.Split('\\')[0];
  127. string processType = chamberId.Split('\\')[1];
  128. string recipeContent = LoadRecipe(chamberId, recipeName, false);
  129. var xmlRecipe = new XmlDocument();
  130. try
  131. {
  132. if (string.IsNullOrEmpty(recipeContent))
  133. throw new Exception("invalid recipe file.");
  134. xmlRecipe.LoadXml(recipeContent);
  135. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  136. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  137. switch (processType)
  138. {
  139. case "WaferFlow":
  140. CheckWaferFlowRecipe(nodeConfig, nodeSteps, out reasons);
  141. break;
  142. case "COT":
  143. CheckSpinRecipe(nodeConfig, nodeSteps, true, out reasons);
  144. break;
  145. case "DEV":
  146. CheckSpinRecipe(nodeConfig, nodeSteps, false, out reasons);
  147. break;
  148. case "ADH":
  149. CheckADHRecipe(nodeSteps, out reasons);
  150. break;
  151. case "Oven":
  152. CheckOvenRecipe(nodeSteps, out reasons);
  153. break;
  154. }
  155. }
  156. catch (Exception ex)
  157. {
  158. reasons.Add(ex.Message);
  159. LOG.Write(ex);
  160. return false;
  161. }
  162. XmlElement nodeData = xmlRecipe.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  163. bool bResult = reasons.Count == 0;
  164. if (bResult)
  165. {
  166. nodeData.SetAttribute("CheckResult", "Correct");
  167. }
  168. else
  169. {
  170. nodeData.SetAttribute("CheckResult", "Error");
  171. }
  172. SaveRecipe(chamberId, recipeName, xmlRecipe.OuterXml, false, false);
  173. return bResult;
  174. }
  175. /// <summary>
  176. /// Check recipe content
  177. /// </summary>
  178. /// <param name="chamId"></param>
  179. /// <param name="recipeContent"></param>
  180. /// <param name="reasons"></param>
  181. /// <returns></returns>
  182. public bool CheckRestoreRecipe(string chamberId, string recipeName, out List<string> reasons)
  183. {
  184. reasons = new List<string>();
  185. string chamberType = chamberId.Split('\\')[0];
  186. string processType = chamberId.Split('\\')[1];
  187. string recipeContent = LoadRestoreRecipe(chamberId, recipeName, false);
  188. var xmlRecipe = new XmlDocument();
  189. try
  190. {
  191. if (string.IsNullOrEmpty(recipeContent))
  192. throw new Exception("invalid recipe file.");
  193. xmlRecipe.LoadXml(recipeContent);
  194. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  195. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  196. switch (processType)
  197. {
  198. case "WaferFlow":
  199. CheckWaferFlowRecipe(nodeConfig, nodeSteps, out reasons);
  200. break;
  201. case "COT":
  202. CheckSpinRecipe(nodeConfig, nodeSteps, true, out reasons);
  203. break;
  204. case "DEV":
  205. CheckSpinRecipe(nodeConfig, nodeSteps, false, out reasons);
  206. break;
  207. case "ADH":
  208. CheckADHRecipe(nodeSteps, out reasons);
  209. break;
  210. case "Oven":
  211. CheckOvenRecipe(nodeSteps, out reasons);
  212. break;
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. reasons.Add(ex.Message);
  218. LOG.Write(ex);
  219. return false;
  220. }
  221. XmlElement nodeData = xmlRecipe.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  222. bool bResult = reasons.Count == 0;
  223. if (bResult)
  224. {
  225. nodeData.SetAttribute("CheckResult", "Correct");
  226. }
  227. else
  228. {
  229. nodeData.SetAttribute("CheckResult", "Error");
  230. }
  231. SaveRestoreRecipe(chamberId, recipeName, xmlRecipe.OuterXml, false, false);
  232. return bResult;
  233. }
  234. void CheckWaferFlowRecipe(XmlNode nodeConfig, XmlNodeList nodeSteps, out List<string> reasons)
  235. {
  236. reasons = new List<string>();
  237. if (nodeSteps.Count <= 0)
  238. {
  239. reasons.Add("steps count is 0");
  240. return;
  241. }
  242. if (nodeSteps.Count < 5)
  243. {
  244. reasons.Add("steps count is less than 5");
  245. return;
  246. }
  247. int beginStepIndex = 0;
  248. int endStepIndex = 1;
  249. for (int i = 0; i < nodeSteps.Count; i++)
  250. {
  251. if (nodeSteps[i].Attributes["ModuleName"].Value.Contains("End UNC"))
  252. {
  253. int.TryParse(nodeSteps[i].Attributes["StepNo"].Value, out endStepIndex);
  254. break;
  255. }
  256. }
  257. endStepIndex--;
  258. if (endStepIndex <= 0)
  259. {
  260. reasons.Add($"Current recipe muste contains end step");
  261. return;
  262. }
  263. for (int i = beginStepIndex; i <= endStepIndex; i++)
  264. {
  265. int stepNo = i + 1;
  266. string strModuleName = nodeSteps[i].Attributes["ModuleName"].Value;
  267. if (!string.IsNullOrEmpty(strModuleName))
  268. strModuleName = strModuleName.Split(',')[0].Split(' ')[1];
  269. else
  270. {
  271. reasons.Add($"Step{stepNo} module name is empty");
  272. return;
  273. }
  274. if (i == 0)//check step1
  275. {
  276. string moduleName = "UNC";
  277. if (!strModuleName.Equals(moduleName))
  278. {
  279. reasons.Add($"Step{stepNo} module muste be {moduleName}");
  280. }
  281. continue;
  282. }
  283. if (i == 1)//check step2
  284. {
  285. string moduleName = "TRS,TCP";
  286. if (!moduleName.Contains(strModuleName))
  287. {
  288. reasons.Add($"Step{stepNo} module muste be {moduleName} module");
  289. }
  290. }
  291. if (i == endStepIndex - 1)//check last second step
  292. {
  293. string moduleName = "TRS,TCP";
  294. if (!moduleName.Contains(strModuleName))
  295. {
  296. reasons.Add($"Step{stepNo} module muste be {moduleName} module");
  297. }
  298. if (strModuleName == nodeSteps[1].Attributes["ModuleName"].Value)
  299. {
  300. reasons.Add($"Step{stepNo} module muste be different with step1 module");
  301. }
  302. }
  303. if (i == endStepIndex)//check last step
  304. {
  305. string moduleName = "UNC";
  306. if (!strModuleName.Equals(moduleName))
  307. {
  308. reasons.Add($"Step{stepNo} module muste be {moduleName}");
  309. }
  310. continue;
  311. }
  312. //check linked recipe
  313. string unCheckModuleName = "SHU,TRS,SUB,EIS";
  314. if (!unCheckModuleName.Contains(strModuleName))
  315. {
  316. string ovenModuleName = "CPL,HHP,LHP,CHP,TCP";
  317. if (ovenModuleName.Contains(strModuleName))
  318. strModuleName = "Oven";
  319. string linkRecipeName = nodeSteps[i].Attributes["RecipeName"].Value;
  320. if (string.IsNullOrEmpty(linkRecipeName))
  321. {
  322. reasons.Add($"Step{stepNo} link recipe is empty.");
  323. }
  324. else
  325. {
  326. string[] subRecipeNames = linkRecipeName.Split(',');
  327. foreach (var item in subRecipeNames)
  328. {
  329. string subRecipeName = string.Empty;
  330. string[] subRecipeNameStrings = item.Split(':');
  331. if (subRecipeNameStrings.Length > 1)
  332. {
  333. subRecipeName = subRecipeNameStrings[1];
  334. }
  335. else
  336. {
  337. subRecipeName = subRecipeNameStrings[0];
  338. }
  339. if (!CheckRecipe($"{_chamberId}\\{strModuleName}", subRecipeName, out List<string> subReasons))
  340. {
  341. reasons.Add($"Step{stepNo} linked recipe check fail.");
  342. }
  343. }
  344. }
  345. }
  346. }
  347. //check system reicpe
  348. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  349. if (!string.IsNullOrEmpty(strSystemReicpeName))
  350. {
  351. if (!CheckRecipe($"{_chamberId}\\System", strSystemReicpeName, out List<string> subReasons))
  352. {
  353. reasons.Add($"Linked system recipe check fail.");
  354. }
  355. }
  356. else
  357. {
  358. reasons.Add($"Must link system recipe.");
  359. }
  360. }
  361. public string LoadRecipeByFullPath(string fullPath)
  362. {
  363. string rcp = string.Empty;
  364. try
  365. {
  366. using (StreamReader fs = new StreamReader(fullPath))
  367. {
  368. rcp = fs.ReadToEnd();
  369. fs.Close();
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. try
  375. {
  376. using (StreamReader fs = new StreamReader(fullPath))
  377. {
  378. rcp = fs.ReadToEnd();
  379. fs.Close();
  380. }
  381. }
  382. catch
  383. {
  384. LOG.Write(ex, $"load recipe file failed, {fullPath}");
  385. rcp = string.Empty;
  386. };
  387. }
  388. return rcp;
  389. }
  390. void CheckSpinRecipe(XmlNode nodeConfig, XmlNodeList nodeSteps, bool checkPumpRecipe, out List<string> reasons)
  391. {
  392. reasons = new List<string>();
  393. if (nodeSteps.Count <= 0)
  394. {
  395. reasons.Add("steps count is 0.");
  396. return;
  397. }
  398. List<int> loopStartStepsNo = new List<int>();
  399. List<int> loopEndStepsNo = new List<int>();
  400. bool hasDispense = false;
  401. List<bool> arm1HasMove = new List<bool>();
  402. List<bool> arm2HasMove = new List<bool>();
  403. for (int i = 0; i < nodeSteps.Count; i++)
  404. {
  405. int stepNo = i + 1;
  406. if (nodeSteps[i].Attributes["Loop"].Value.Contains("Start"))
  407. {
  408. loopStartStepsNo.Add(stepNo);
  409. }
  410. if (nodeSteps[i].Attributes["Loop"].Value.Contains("End"))
  411. {
  412. loopEndStepsNo.Add(stepNo);
  413. }
  414. string strDispense = nodeSteps[i].Attributes["Dispense"].Value;
  415. if (strDispense.Contains("Resist"))
  416. {
  417. hasDispense = true;
  418. }
  419. //check dispens
  420. if (!string.IsNullOrEmpty(strDispense))
  421. {
  422. bool bDispenseHasError = false;
  423. string[] strDispenseValues = strDispense.Split(',');
  424. string strFirstDispenseValue = strDispenseValues[0];
  425. foreach (var item in strDispenseValues)
  426. {
  427. if (strFirstDispenseValue.Split(' ')[0] != item.Split(' ')[0])
  428. bDispenseHasError = true;
  429. }
  430. if (bDispenseHasError)
  431. reasons.Add($"Step{stepNo} dispense must select same module.");
  432. }
  433. if (i > 0)
  434. {
  435. string arm1CurrentPosition = nodeSteps[i].Attributes["Arm1"].Value.Split(',')[2].Split(':')[1];
  436. string arm1PreviousPosition = nodeSteps[i - 1].Attributes["Arm1"].Value.Split(',')[2].Split(':')[1];
  437. if (!string.IsNullOrEmpty(arm1CurrentPosition))
  438. {
  439. if (arm1CurrentPosition.Equals(arm1PreviousPosition))
  440. arm1HasMove.Add(false);
  441. else
  442. arm1HasMove.Add(true);
  443. }
  444. string arm2CurrentPosition = nodeSteps[i].Attributes["Arm2"].Value.Split(',')[2].Split(':')[1];
  445. string arm2PreviousPosition = nodeSteps[i - 1].Attributes["Arm2"].Value.Split(',')[2].Split(':')[1];
  446. if (!string.IsNullOrEmpty(arm2CurrentPosition))
  447. {
  448. if (arm2CurrentPosition.Equals(arm2PreviousPosition))
  449. arm2HasMove.Add(false);
  450. else
  451. arm2HasMove.Add(true);
  452. }
  453. }
  454. }
  455. //check loop
  456. if (loopStartStepsNo.Count != loopEndStepsNo.Count) //判断个数
  457. {
  458. reasons.Add("loop set is incorrect");
  459. }
  460. //check pump recipe
  461. if (checkPumpRecipe && hasDispense)
  462. {
  463. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  464. if (string.IsNullOrEmpty(pumpRecipeName))
  465. reasons.Add("pump recipe is null");
  466. else
  467. {
  468. if (!CheckRecipe($"{_chamberId}\\Pump", pumpRecipeName, out List<string> subReasons))
  469. {
  470. reasons.Add($"Linked pump recipe check fail.");
  471. }
  472. }
  473. }
  474. //check arm move
  475. for (int i = 0; i < arm1HasMove.Count; i++)
  476. {
  477. if (arm1HasMove[i] && arm2HasMove[i])//同时移动
  478. reasons.Add($"step{i + 2} arm1 and arm2 move at the same time");
  479. }
  480. }
  481. void CheckADHRecipe(XmlNodeList nodeSteps, out List<string> reasons)
  482. {
  483. reasons = new List<string>();
  484. if (nodeSteps.Count <= 0)
  485. {
  486. reasons.Add("steps count is 0.");
  487. return;
  488. }
  489. for (int i = 0; i < nodeSteps.Count; i++)
  490. {
  491. int stepNo = i + 1;
  492. //check dispense
  493. if (!nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Process") && !string.IsNullOrEmpty(nodeSteps[i].Attributes["Dispense"].Value))
  494. {
  495. reasons.Add($"Step{stepNo} only position is process can select dispense.");
  496. }
  497. //check plate temp
  498. if (nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Process") && string.IsNullOrEmpty(nodeSteps[i].Attributes["PlateTemp"].Value))
  499. {
  500. reasons.Add($"Step{stepNo} must set plate temp.");
  501. }
  502. //check alrm
  503. double.TryParse(nodeSteps[i].Attributes["AlarmMax"].Value, out double alarmMax);
  504. double.TryParse(nodeSteps[i].Attributes["AlarmMin"].Value, out double alarmMin);
  505. double.TryParse(nodeSteps[i].Attributes["WarnMax"].Value, out double warnMax);
  506. double.TryParse(nodeSteps[i].Attributes["WarnMin"].Value, out double warnMin);
  507. bool bRightRange = false;
  508. if (alarmMax == 0 && alarmMin == 0 && warnMax == 0 && warnMin == 0) continue;
  509. if (alarmMax == 0 && alarmMin == 0)
  510. {
  511. bRightRange = warnMax > warnMin;
  512. if (!bRightRange)
  513. {
  514. reasons.Add($"Step{stepNo} warnMax>warnMin?");
  515. }
  516. }
  517. else if (warnMax == 0 && warnMax == 0)
  518. {
  519. bRightRange = alarmMax > alarmMin;
  520. if (!bRightRange)
  521. {
  522. reasons.Add($"Step{stepNo} alarmMax>alarmMin?");
  523. }
  524. }
  525. else
  526. {
  527. bRightRange = alarmMax > warnMax && warnMax > warnMin && warnMin > alarmMin;
  528. if (!bRightRange)
  529. {
  530. reasons.Add($"Step{stepNo} alarmMax>warnMax>warnMin>alarmMin?");
  531. }
  532. }
  533. }
  534. }
  535. void CheckOvenRecipe(XmlNodeList nodeSteps, out List<string> reasons)
  536. {
  537. reasons = new List<string>();
  538. if (nodeSteps.Count <= 0)
  539. {
  540. reasons.Add("steps count is 0.");
  541. return;
  542. }
  543. for (int i = 0; i < nodeSteps.Count; i++)
  544. {
  545. int stepNo = i + 1;
  546. //check plate temp
  547. if (nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Heat") && string.IsNullOrEmpty(nodeSteps[i].Attributes["PlateTemp"].Value))
  548. {
  549. reasons.Add($"Step{stepNo} must set plate temp.");
  550. }
  551. //check alrm
  552. double.TryParse(nodeSteps[i].Attributes["AlarmMax"].Value, out double alarmMax);
  553. double.TryParse(nodeSteps[i].Attributes["AlarmMin"].Value, out double alarmMin);
  554. double.TryParse(nodeSteps[i].Attributes["WarnMax"].Value, out double warnMax);
  555. double.TryParse(nodeSteps[i].Attributes["WarnMin"].Value, out double warnMin);
  556. bool bRightRange = false;
  557. if (alarmMax == 0 && alarmMin == 0 && warnMax == 0 && warnMin == 0) continue;
  558. if (alarmMax == 0 && alarmMin == 0)
  559. {
  560. bRightRange = warnMax > warnMin;
  561. if (!bRightRange)
  562. {
  563. reasons.Add($"Step{stepNo} warnMax>warnMin?");
  564. }
  565. }
  566. else if (warnMax == 0 && warnMax == 0)
  567. {
  568. bRightRange = alarmMax > alarmMin;
  569. if (!bRightRange)
  570. {
  571. reasons.Add($"Step{stepNo} alarmMax>alarmMin?");
  572. }
  573. }
  574. else
  575. {
  576. bRightRange = alarmMax > warnMax && warnMax > warnMin && warnMin > alarmMin;
  577. if (!bRightRange)
  578. {
  579. reasons.Add($"Step{stepNo} alarmMax>warnMax>warnMin>alarmMin?");
  580. }
  581. }
  582. }
  583. }
  584. public string LoadRecipe(string chamberId, string recipeName, bool needValidation)
  585. {
  586. string rcp = string.Empty;
  587. try
  588. {
  589. using (StreamReader fs = new StreamReader(GenerateRecipeFilePath(chamberId, recipeName)))
  590. {
  591. rcp = fs.ReadToEnd();
  592. fs.Close();
  593. }
  594. //if (needValidation)
  595. //{
  596. // List<string> reason;
  597. // if (!ValidateRecipe(chamberId, recipeName, rcp, out reason))
  598. // {
  599. // rcp = string.Empty;
  600. // LOG.Write("校验recipe file 出错, " + string.Join(",", reason.ToArray()));
  601. // }
  602. //}
  603. }
  604. catch (Exception ex)
  605. {
  606. LOG.Write(ex, $"load recipe file failed, {recipeName}");
  607. rcp = string.Empty;
  608. }
  609. return rcp;
  610. }
  611. /// <summary>
  612. /// Get recipe list
  613. /// </summary>
  614. /// <param name="chamId"></param>
  615. /// <param name="includingUsedRecipe"></param>
  616. /// <returns></returns>
  617. public IEnumerable<string> GetRecipes(string chamberId, bool includingUsedRecipe)
  618. {
  619. return _rcpContext.GetRecipes(chamberId, includingUsedRecipe);
  620. }
  621. /// <summary>
  622. /// Get recipe list in xml format
  623. /// </summary>
  624. /// <param name="chamId"></param>
  625. /// <param name="includingUsedRecipe"></param>
  626. /// <returns></returns>
  627. public string GetXmlRecipeList(string chamberId, bool includingUsedRecipe)
  628. {
  629. XmlDocument doc = new XmlDocument();
  630. var baseFolderPath = getRecipeDirPath(chamberId);
  631. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  632. doc.AppendChild(GenerateRecipeList(chamberId, curFolderInfo, doc, includingUsedRecipe));
  633. return doc.OuterXml;
  634. }
  635. public void SaveRecipeHistory(string chamberId, string recipeName, string recipeContent, bool needSaveAs = true)
  636. {
  637. try
  638. {
  639. if (!string.IsNullOrEmpty(recipeName) && needSaveAs)
  640. {
  641. string newRecipeName = string.Format("HistoryRecipe\\{0}\\{1}", DateTime.Now.ToString("yyyyMM"), recipeName);
  642. SaveRecipe(chamberId, newRecipeName, recipeContent, true, false);
  643. LOG.Write(string.Format("{0}通知TM保存工艺程序{1}", chamberId, recipeName));
  644. }
  645. }
  646. catch (Exception ex)
  647. {
  648. LOG.Write(ex, string.Format("保存{0}工艺程序{1}发生错误", chamberId, recipeName));
  649. }
  650. }
  651. /// <summary>
  652. /// generate recipe list information in current directory
  653. /// </summary>
  654. /// <param name="chamId"></param>
  655. /// <param name="currentDir"></param>
  656. /// <param name="doc"></param>
  657. /// <returns></returns>
  658. XmlElement GenerateRecipeList(string chamberId, DirectoryInfo currentDir, XmlDocument doc, bool includingUsedRecipe)
  659. {
  660. int trimLength = getRecipeDirPath(chamberId).Length;
  661. XmlElement folderEle = doc.CreateElement("Folder");
  662. folderEle.SetAttribute("Name", currentDir.FullName.Substring(trimLength));
  663. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  664. foreach (DirectoryInfo dirInfo in dirInfos)
  665. {
  666. if (!includingUsedRecipe && dirInfo.Name == "HistoryRecipe")
  667. continue;
  668. folderEle.AppendChild(GenerateRecipeList(chamberId, dirInfo, doc, includingUsedRecipe));
  669. }
  670. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  671. foreach (FileInfo fileInfo in fileInfos)
  672. {
  673. XmlElement fileNd = doc.CreateElement("File");
  674. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  675. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  676. fileNd.SetAttribute("Name", fileStr);
  677. folderEle.AppendChild(fileNd);
  678. }
  679. return folderEle;
  680. }
  681. XmlElement GeneratelRestoreRecipeList(string chamberId, DirectoryInfo currentDir, XmlDocument doc, bool includingUsedRecipe)
  682. {
  683. int trimLength = getRecipeBackupDirPath(chamberId).Length;
  684. XmlElement folderEle = doc.CreateElement("Folder");
  685. var name = currentDir.FullName.Substring(trimLength);
  686. folderEle.SetAttribute("Name", name);
  687. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  688. foreach (DirectoryInfo dirInfo in dirInfos)
  689. {
  690. if (!includingUsedRecipe && dirInfo.Name == "HistoryRecipe")
  691. continue;
  692. folderEle.AppendChild(GeneratelRestoreRecipeList(chamberId, dirInfo, doc, includingUsedRecipe));
  693. }
  694. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  695. foreach (FileInfo fileInfo in fileInfos)
  696. {
  697. XmlElement fileNd = doc.CreateElement("File");
  698. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  699. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  700. fileNd.SetAttribute("Name", fileStr);
  701. folderEle.AppendChild(fileNd);
  702. }
  703. return folderEle;
  704. }
  705. /// <summary>
  706. /// Delete a recipe by recipe name
  707. /// </summary>
  708. /// <param name="chamId"></param>
  709. /// <param name="recipeName"></param>
  710. /// <returns></returns>
  711. public bool DeleteRecipe(string chamberId, string recipeName)
  712. {
  713. try
  714. {
  715. File.Delete(GenerateRecipeFilePath(chamberId, recipeName));
  716. InfoDialog(string.Format(Resources.RecipeFileManager_DeleteRecipe_RecipeFile0DeleteSucceeded, recipeName));
  717. }
  718. catch (Exception ex)
  719. {
  720. LOG.Write(ex, "删除recipe file 出错");
  721. WarningDialog(string.Format(Resources.RecipeFileManager_DeleteRecipe_RecipeFile0DeleteFailed, recipeName));
  722. return false;
  723. }
  724. return true;
  725. }
  726. /// <summary>
  727. /// Rename recipe
  728. /// </summary>
  729. /// <param name="chamId"></param>
  730. /// <param name="oldName"></param>
  731. /// <param name="newName"></param>
  732. /// <returns></returns>
  733. public bool RenameRecipe(string chamId, string oldName, string newName)
  734. {
  735. try
  736. {
  737. if (File.Exists(GenerateRecipeFilePath(chamId, newName)))
  738. {
  739. WarningDialog(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0FileExisted, oldName));
  740. return false;
  741. }
  742. else
  743. {
  744. File.Move(GenerateRecipeFilePath(chamId, oldName), GenerateRecipeFilePath(chamId, newName));
  745. InfoDialog(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0Renamed, oldName, newName));
  746. }
  747. }
  748. catch (Exception ex)
  749. {
  750. LOG.Write(ex, "重命名recipe file 出错");
  751. WarningDialog(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0RenameFailed, oldName, newName));
  752. return false;
  753. }
  754. return true;
  755. }
  756. public bool BackupRecipe(string fileOriginalPath, string fileDestinationPath, bool isSaveLinkRecipe, List<string> recipeNames)
  757. {
  758. try
  759. {
  760. string filePath = getRecipeBackupDirPath(fileOriginalPath);
  761. foreach (var item in recipeNames)
  762. {
  763. string sourceFilePath = GenerateRecipeFilePath(fileOriginalPath, item);
  764. string destFilePath = GenerateBackupRecipeFilePath(fileDestinationPath, item);
  765. if (item.Contains("\\"))
  766. {
  767. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  768. if (!di.Exists) di.Create();
  769. }
  770. File.Copy(sourceFilePath, destFilePath, true);
  771. if (isSaveLinkRecipe)
  772. {
  773. string recipeContent = LoadRecipe(fileOriginalPath, item, false);
  774. var xmlRecipe = new XmlDocument();
  775. try
  776. {
  777. string chamberType = fileOriginalPath.Split('\\')[0];
  778. string processType = fileOriginalPath.Split('\\')[1];
  779. if (string.IsNullOrEmpty(recipeContent))
  780. continue;
  781. xmlRecipe.LoadXml(recipeContent);
  782. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  783. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  784. switch (processType)
  785. {
  786. case "WaferFlow":
  787. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  788. if (!string.IsNullOrEmpty(strSystemReicpeName))
  789. {
  790. if (CheckRecipe($"{_chamberId}\\System", strSystemReicpeName, out List<string> subReasons))
  791. {
  792. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\System", strSystemReicpeName);
  793. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\System", strSystemReicpeName);
  794. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  795. if (!di.Exists) di.Create();
  796. File.Copy(subSourceFilePath, subDestFilePath, true);
  797. }
  798. }
  799. break;
  800. case "COT":
  801. case "DEV":
  802. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  803. if (!string.IsNullOrEmpty(pumpRecipeName))
  804. {
  805. if (CheckRecipe($"{_chamberId}\\Pump", pumpRecipeName, out List<string> subReasons))
  806. {
  807. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipeName);
  808. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", pumpRecipeName);
  809. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  810. if (!di.Exists) di.Create();
  811. File.Copy(subSourceFilePath, subDestFilePath, true);
  812. }
  813. }
  814. break;
  815. case "ADH":
  816. case "Oven":
  817. break;
  818. }
  819. }
  820. catch (Exception ex)
  821. {
  822. LOG.Write(ex);
  823. continue;
  824. }
  825. }
  826. }
  827. }
  828. catch (Exception ex)
  829. {
  830. LOG.Write(ex, "Backup Recipe file error");
  831. }
  832. return true;
  833. }
  834. public bool CheckBackRecipeIsLinkRecipe(string fileOriginalPath, List<string> recipeNames)
  835. {
  836. string chamberType = fileOriginalPath.Split('\\')[0];
  837. string processType = fileOriginalPath.Split('\\')[1];
  838. foreach (var item in recipeNames)
  839. {
  840. string recipeContent = LoadRestoreRecipe(fileOriginalPath, item, false);
  841. var xmlRecipe = new XmlDocument();
  842. try
  843. {
  844. if (string.IsNullOrEmpty(recipeContent))
  845. continue;
  846. xmlRecipe.LoadXml(recipeContent);
  847. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  848. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  849. switch (processType)
  850. {
  851. case "WaferFlow":
  852. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  853. if (!string.IsNullOrEmpty(strSystemReicpeName))
  854. {
  855. //if (CheckRecipe($"{_chamberId}\\System", strSystemReicpeName, out List<string> subReasons))
  856. //{
  857. return true;
  858. //}
  859. }
  860. break;
  861. case "COT":
  862. case "DEV":
  863. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  864. if (!string.IsNullOrEmpty(pumpRecipeName))
  865. {
  866. //if (CheckRecipe($"{_chamberId}\\Pump", pumpRecipeName, out List<string> subReasons))
  867. //{
  868. return true;
  869. //}
  870. }
  871. break;
  872. case "ADH":
  873. case "Oven":
  874. break;
  875. }
  876. }
  877. catch (Exception ex)
  878. {
  879. LOG.Write(ex);
  880. return false;
  881. }
  882. }
  883. return false;
  884. }
  885. public string GetXmlRestoreRecipeList(string chamberId, bool includingUsedRecipe)
  886. {
  887. XmlDocument doc = new XmlDocument();
  888. var baseFolderPath = getRecipeBackupDirPath(chamberId);
  889. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  890. doc.AppendChild(GeneratelRestoreRecipeList(chamberId, curFolderInfo, doc, includingUsedRecipe));
  891. return doc.OuterXml;
  892. }
  893. public List<string> RestoreRecipeFolderList()
  894. {
  895. List<string> folderList = new List<string>();
  896. var recipeBackupPath = PathManager.GetRecipeBackupDir();
  897. DirectoryInfo directoryInfo = new DirectoryInfo(recipeBackupPath);
  898. DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
  899. foreach (var item in directoryInfos)
  900. {
  901. folderList.Add(item.Name);
  902. }
  903. return folderList;
  904. }
  905. public string LoadRestoreRecipe(string chamberId, string recipeName, bool needValidation)
  906. {
  907. string rcp = string.Empty;
  908. try
  909. {
  910. using (StreamReader fs = new StreamReader(GenerateBackupRecipeFilePath(chamberId, recipeName)))
  911. {
  912. rcp = fs.ReadToEnd();
  913. fs.Close();
  914. }
  915. }
  916. catch (Exception ex)
  917. {
  918. LOG.Write(ex, $"load recipe file failed, {recipeName}");
  919. rcp = string.Empty;
  920. }
  921. return rcp;
  922. }
  923. public bool SigRestoreRecipe(string chamId, List<string> recipeNames)
  924. {
  925. try
  926. {
  927. string filePath = getRecipeBackupDirPath(chamId);
  928. foreach (var item in recipeNames)
  929. {
  930. string strdest = chamId;
  931. string destFilePath = GenerateRecipeFilePath(strdest, item);
  932. string sourceFilePath = GenerateBackupRecipeFilePath(chamId, item);
  933. if (item.Contains("\\"))
  934. {
  935. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  936. if (!di.Exists) di.Create();
  937. }
  938. File.Copy(sourceFilePath, destFilePath, true);
  939. }
  940. }
  941. catch (Exception ex)
  942. {
  943. LOG.Write(ex, "Backup Recipe file error");
  944. }
  945. return true;
  946. }
  947. public bool RestoreRecipe(string chamId, bool isSaveLink, List<string> recipeNames)
  948. {
  949. try
  950. {
  951. string filePath = getRecipeBackupDirPath(chamId);
  952. foreach (var item in recipeNames)
  953. {
  954. string strdest = chamId.Remove(5, 14);
  955. string destFilePath = GenerateRecipeFilePath(strdest, item);
  956. string sourceFilePath = GenerateBackupRecipeFilePath(chamId, item);
  957. if (item.Contains("\\"))
  958. {
  959. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  960. if (!di.Exists) di.Create();
  961. }
  962. File.Copy(sourceFilePath, destFilePath, true);
  963. if (isSaveLink)
  964. {
  965. string recipeContent = LoadRestoreRecipe(chamId, item, false);
  966. var xmlRecipe = new XmlDocument();
  967. try
  968. {
  969. string chamberType = chamId.Split('\\')[0];
  970. string processType = chamId.Split('\\')[1];
  971. if (string.IsNullOrEmpty(recipeContent))
  972. continue;
  973. xmlRecipe.LoadXml(recipeContent);
  974. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  975. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  976. switch (processType)
  977. {
  978. case "WaferFlow":
  979. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  980. if (!string.IsNullOrEmpty(strSystemReicpeName))
  981. {
  982. if (CheckRestoreRecipe($"{ chamId.Split('\\')[0]}\\System", strSystemReicpeName, out List<string> subReasons))
  983. {
  984. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\System", strSystemReicpeName);
  985. string subDestFilePath = GenerateRecipeFilePath($"{_chamberId}\\System", strSystemReicpeName);
  986. if (item.Contains("\\"))
  987. {
  988. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  989. if (!di.Exists) di.Create();
  990. }
  991. File.Copy(subSourceFilePath, subDestFilePath, true);
  992. }
  993. }
  994. break;
  995. case "COT":
  996. case "DEV":
  997. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  998. if (!string.IsNullOrEmpty(pumpRecipeName))
  999. {
  1000. if (CheckRestoreRecipe($"{_chamberId}\\Pump", pumpRecipeName, out List<string> subReasons))
  1001. {
  1002. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", pumpRecipeName);
  1003. string subDestFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipeName);
  1004. if (item.Contains("\\"))
  1005. {
  1006. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1007. if (!di.Exists) di.Create();
  1008. }
  1009. File.Copy(subSourceFilePath, subDestFilePath, true);
  1010. }
  1011. }
  1012. break;
  1013. case "ADH":
  1014. case "Oven":
  1015. break;
  1016. }
  1017. }
  1018. catch (Exception ex)
  1019. {
  1020. LOG.Write(ex);
  1021. continue;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. catch (Exception ex)
  1027. {
  1028. LOG.Write(ex, "Backup Recipe file error");
  1029. }
  1030. return true;
  1031. }
  1032. //private void EventInfo(string message)
  1033. //{
  1034. // _rcpContext.PostInfoEvent(message);
  1035. //}
  1036. //private void EventWarning(string message)
  1037. //{
  1038. // _rcpContext.PostWarningEvent(message);
  1039. //}
  1040. //private void EventAlarm(string message)
  1041. //{
  1042. // _rcpContext.PostAlarmEvent(message);
  1043. //}
  1044. private void InfoDialog(string message)
  1045. {
  1046. _rcpContext.PostInfoDialogMessage(message);
  1047. }
  1048. private void WarningDialog(string message)
  1049. {
  1050. _rcpContext.PostWarningDialogMessage(message);
  1051. }
  1052. //private void AlarmDialog(string message)
  1053. //{
  1054. // _rcpContext.PostAlarmDialogMessage(message);
  1055. //}
  1056. private void EventDialog(string message, List<string> reason)
  1057. {
  1058. string msg = message;
  1059. foreach (var r in reason)
  1060. {
  1061. msg += "\r\n" + r;
  1062. }
  1063. _rcpContext.PostDialogEvent(msg);
  1064. }
  1065. /// <summary>
  1066. /// get recipe's file path
  1067. /// </summary>
  1068. /// <param name="recipeName"></param>
  1069. /// <returns></returns>
  1070. private string GenerateRecipeFilePath(string chamId, string recipeName)
  1071. {
  1072. return getRecipeDirPath(chamId) + recipeName + ".rcp";
  1073. }
  1074. private string GenerateBackupRecipeFilePath(string chamId, string recipeName)
  1075. {
  1076. return getRecipeBackupDirPath(chamId) + recipeName + ".rcp";
  1077. }
  1078. private string GenerateSequenceFilePath(string chamId, string recipeName)
  1079. {
  1080. return getRecipeDirPath(chamId) + recipeName + ".seq";
  1081. }
  1082. /// <summary>
  1083. /// get recipe's dir path
  1084. /// </summary>
  1085. /// <param name="recipeName"></param>
  1086. /// <returns></returns>
  1087. private string getRecipeDirPath(string chamId)
  1088. {
  1089. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), chamId);
  1090. DirectoryInfo di = new DirectoryInfo(dir);
  1091. if (!di.Exists) di.Create();
  1092. return dir;
  1093. }
  1094. /// <summary>
  1095. /// get recipe's dir path
  1096. /// </summary>
  1097. /// <param name="recipeName"></param>
  1098. /// <returns></returns>
  1099. private string getRecipeBackupDirPath(string chamId)
  1100. {
  1101. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeBackupDir(), chamId);
  1102. DirectoryInfo di = new DirectoryInfo(dir);
  1103. if (!di.Exists) di.Create();
  1104. return dir;
  1105. }
  1106. /// <summary>
  1107. /// delete a recipe folder
  1108. /// </summary>
  1109. /// <param name="chamId"></param>
  1110. /// <param name="folderName"></param>
  1111. /// <returns></returns>
  1112. public bool DeleteFolder(string chamId, string folderName)
  1113. {
  1114. try
  1115. {
  1116. Directory.Delete(getRecipeDirPath(chamId) + folderName, true);
  1117. InfoDialog(string.Format(Resources.RecipeFileManager_DeleteFolder_RecipeFolder0DeleteSucceeded, folderName));
  1118. }
  1119. catch (Exception ex)
  1120. {
  1121. LOG.Write(ex, "删除recipe folder 出错");
  1122. WarningDialog(string.Format("recipe folder {0} delete failed", folderName));
  1123. return false;
  1124. }
  1125. return true;
  1126. }
  1127. /// <summary>
  1128. /// save as recipe content
  1129. /// </summary>
  1130. /// <param name="chamId"></param>
  1131. /// <param name="recipeName"></param>
  1132. /// <param name="recipeContent"></param>
  1133. /// <returns></returns>
  1134. public bool SaveAsRecipe(string chamId, string recipeName, string recipeContent)
  1135. {
  1136. var path = GenerateRecipeFilePath(chamId, recipeName);
  1137. if (File.Exists(path))
  1138. {
  1139. WarningDialog(string.Format(Resources.RecipeFileManager_SaveAsRecipe_RecipeFile0savefailed, recipeName));
  1140. return false;
  1141. }
  1142. return SaveRecipe(chamId, recipeName, recipeContent, true, true);
  1143. }
  1144. /// <summary>
  1145. /// save recipe content
  1146. /// </summary>
  1147. /// <param name="chamId"></param>
  1148. /// <param name="recipeName"></param>
  1149. /// <param name="recipeContent"></param>
  1150. /// <returns></returns>
  1151. public bool SaveRecipe(string chamId, string recipeName, string recipeContent, bool clearBarcode, bool notifyUI)
  1152. {
  1153. //validate recipe format when saving a recipe file
  1154. //var reasons1 = new List<string>();
  1155. //var reasons2 = new List<string>();
  1156. //ValidateRecipe(chamId, recipeName, recipeContent, out reasons1);
  1157. //CheckRecipe(chamId, recipeContent, out reasons2);
  1158. //reasons1.AddRange(reasons2);
  1159. //if (reasons1.Count > 0)
  1160. //{
  1161. // EventDialog(string.Format( Resources.RecipeFileManager_SaveRecipe_SaveRecipeContentError, recipeName), reasons1);
  1162. //}
  1163. bool ret = true;
  1164. try
  1165. {
  1166. var path = GenerateRecipeFilePath(chamId, recipeName);
  1167. FileInfo fi = new FileInfo(path);
  1168. if (!fi.Directory.Exists)
  1169. fi.Directory.Create();
  1170. XmlDocument xml = new XmlDocument();
  1171. xml.LoadXml(recipeContent);
  1172. XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);
  1173. writer.Formatting = Formatting.Indented;
  1174. xml.Save(writer);
  1175. writer.Close();
  1176. if (notifyUI)
  1177. {
  1178. InfoDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  1179. }
  1180. else
  1181. {
  1182. EV.PostMessage("System", EventEnum.GeneralInfo, string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  1183. }
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. LOG.Write(ex, "保存recipe file 出错");
  1188. if (notifyUI)
  1189. {
  1190. WarningDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveFailed, recipeName));
  1191. }
  1192. ret = false;
  1193. }
  1194. return ret;
  1195. }
  1196. /// <summary>
  1197. /// save recipe content
  1198. /// </summary>
  1199. /// <param name="chamId"></param>
  1200. /// <param name="recipeName"></param>
  1201. /// <param name="recipeContent"></param>
  1202. /// <returns></returns>
  1203. public bool SaveRestoreRecipe(string chamId, string recipeName, string recipeContent, bool clearBarcode, bool notifyUI)
  1204. {
  1205. //validate recipe format when saving a recipe file
  1206. //var reasons1 = new List<string>();
  1207. //var reasons2 = new List<string>();
  1208. //ValidateRecipe(chamId, recipeName, recipeContent, out reasons1);
  1209. //CheckRecipe(chamId, recipeContent, out reasons2);
  1210. //reasons1.AddRange(reasons2);
  1211. //if (reasons1.Count > 0)
  1212. //{
  1213. // EventDialog(string.Format( Resources.RecipeFileManager_SaveRecipe_SaveRecipeContentError, recipeName), reasons1);
  1214. //}
  1215. bool ret = true;
  1216. try
  1217. {
  1218. var path = GenerateBackupRecipeFilePath(chamId, recipeName);
  1219. FileInfo fi = new FileInfo(path);
  1220. if (!fi.Directory.Exists)
  1221. fi.Directory.Create();
  1222. XmlDocument xml = new XmlDocument();
  1223. xml.LoadXml(recipeContent);
  1224. XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);
  1225. writer.Formatting = Formatting.Indented;
  1226. xml.Save(writer);
  1227. writer.Close();
  1228. if (notifyUI)
  1229. {
  1230. InfoDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  1231. }
  1232. else
  1233. {
  1234. EV.PostMessage("System", EventEnum.GeneralInfo, string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  1235. }
  1236. }
  1237. catch (Exception ex)
  1238. {
  1239. LOG.Write(ex, "保存recipe file 出错");
  1240. if (notifyUI)
  1241. {
  1242. WarningDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveFailed, recipeName));
  1243. }
  1244. ret = false;
  1245. }
  1246. return ret;
  1247. }
  1248. /// <summary>
  1249. /// create a new recipe folder
  1250. /// </summary>
  1251. /// <param name="chamId"></param>
  1252. /// <param name="folderName"></param>
  1253. /// <returns></returns>
  1254. public bool CreateFolder(string chamId, string folderName)
  1255. {
  1256. try
  1257. {
  1258. Directory.CreateDirectory(getRecipeDirPath(chamId) + folderName);
  1259. InfoDialog(string.Format(Resources.RecipeFileManager_CreateFolder_RecipeFolder0Created, folderName));
  1260. }
  1261. catch (Exception ex)
  1262. {
  1263. LOG.Write(ex, "create recipe folder failed");
  1264. WarningDialog(string.Format(Resources.RecipeFileManager_CreateFolder_RecipeFolder0CreateFailed, folderName));
  1265. return false;
  1266. }
  1267. return true;
  1268. }
  1269. /// <summary>
  1270. /// Rename recipe folder name
  1271. /// </summary>
  1272. /// <param name="chamId"></param>
  1273. /// <param name="oldName"></param>
  1274. /// <param name="newName"></param>
  1275. /// <returns></returns>
  1276. public bool RenameFolder(string chamId, string oldName, string newName)
  1277. {
  1278. try
  1279. {
  1280. string oldPath = getRecipeDirPath(chamId) + oldName;
  1281. string newPath = getRecipeDirPath(chamId) + newName;
  1282. Directory.Move(oldPath, newPath);
  1283. InfoDialog(string.Format(Resources.RecipeFileManager_RenameFolder_RecipeFolder0renamed, oldName, newName));
  1284. }
  1285. catch (Exception ex)
  1286. {
  1287. LOG.Write(ex, "Rename recipe folder failed");
  1288. WarningDialog(string.Format(Resources.RecipeFileManager_RenameFolder_RecipeFolder0RenameFailed, oldName, newName));
  1289. return false;
  1290. }
  1291. return true;
  1292. }
  1293. public XmlDocument RecipeDom = new XmlDocument();
  1294. private string GetRecipeBody(string chamberId, string nodePath)
  1295. {
  1296. if (_rcpContext == null)
  1297. return string.Empty;
  1298. string schema = _rcpContext.GetRecipeDefiniton(chamberId);
  1299. RecipeDom = new XmlDocument();
  1300. RecipeDom.LoadXml(schema);
  1301. XmlNode node = RecipeDom.SelectSingleNode(nodePath);
  1302. return node.OuterXml;
  1303. }
  1304. public string RecipeChamberType
  1305. {
  1306. get;
  1307. set;
  1308. }
  1309. public string RecipeVersion
  1310. {
  1311. get;
  1312. set;
  1313. }
  1314. public Dictionary<string, ObservableCollection<RecipeTemplateColumnBase>> GetGroupRecipeTemplate()
  1315. {
  1316. try
  1317. {
  1318. XmlNode nodeRoot = RecipeDom.SelectSingleNode("Aitex/TableRecipeFormat");
  1319. RecipeChamberType = nodeRoot.Attributes["RecipeChamberType"].Value;
  1320. RecipeVersion = nodeRoot.Attributes["RecipeVersion"].Value;
  1321. }
  1322. catch (Exception ex)
  1323. {
  1324. LOG.Write(ex);
  1325. return null;
  1326. }
  1327. var columns = new Dictionary<string, ObservableCollection<RecipeTemplateColumnBase>>();
  1328. RecipeTemplateColumnBase col = null;
  1329. XmlNodeList nodes = RecipeDom.SelectNodes("Aitex/TableRecipeFormat/Catalog/Group");
  1330. foreach (XmlNode node in nodes)
  1331. {
  1332. var sigcolumns = new ObservableCollection<RecipeTemplateColumnBase>();
  1333. XmlNodeList childNodes = node.SelectNodes("Step");
  1334. foreach (XmlNode step in childNodes)
  1335. {
  1336. //step number
  1337. if (step.Attributes["ControlName"].Value == "StepNo")
  1338. {
  1339. col = new RecipeTemplateColumnBase()
  1340. {
  1341. DisplayName = "Step",
  1342. ControlName = "StepNo",
  1343. };
  1344. sigcolumns.Add(col);
  1345. continue;
  1346. }
  1347. switch (step.Attributes["InputType"].Value)
  1348. {
  1349. case "TextInput":
  1350. col = new RecipeTemplateColumnBase()
  1351. {
  1352. ValueType = "TextInput",
  1353. ModuleName = step.Attributes["ModuleName"].Value,
  1354. ControlName = step.Attributes["ControlName"].Value,
  1355. DisplayName = step.Attributes["DisplayName"].Value,
  1356. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  1357. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1358. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1359. };
  1360. sigcolumns.Add(col);
  1361. break;
  1362. case "NumInput":
  1363. col = new RecipeTemplateColumnBase()
  1364. {
  1365. ValueType = "NumInput",
  1366. ModuleName = step.Attributes["ModuleName"].Value,
  1367. ControlName = step.Attributes["ControlName"].Value,
  1368. DisplayName = step.Attributes["DisplayName"].Value,
  1369. InputMode = step.Attributes["InputMode"].Value,
  1370. Minimun = double.Parse(step.Attributes["Min"].Value),
  1371. Maximun = double.Parse(step.Attributes["Max"].Value),
  1372. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  1373. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1374. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1375. };
  1376. sigcolumns.Add(col);
  1377. break;
  1378. case "DoubleInput":
  1379. col = new RecipeTemplateColumnBase()
  1380. {
  1381. ValueType = "DoubleInput",
  1382. ModuleName = step.Attributes["ModuleName"].Value,
  1383. ControlName = step.Attributes["ControlName"].Value,
  1384. DisplayName = step.Attributes["DisplayName"].Value,
  1385. InputMode = step.Attributes["InputMode"].Value,
  1386. Minimun = double.Parse(step.Attributes["Min"].Value),
  1387. Maximun = double.Parse(step.Attributes["Max"].Value),
  1388. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  1389. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1390. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1391. };
  1392. sigcolumns.Add(col);
  1393. break;
  1394. case "EditableSelection":
  1395. col = new RecipeTemplateColumnBase()
  1396. {
  1397. ValueType = "EditableSelection",
  1398. ModuleName = step.Attributes["ModuleName"].Value,
  1399. Default = step.Attributes["Default"] != null ? step.Attributes["Default"].Value : "",
  1400. ControlName = step.Attributes["ControlName"].Value,
  1401. DisplayName = step.Attributes["DisplayName"].Value,
  1402. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  1403. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1404. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1405. };
  1406. XmlNodeList items = step.SelectNodes("Item");
  1407. foreach (XmlNode item in items)
  1408. {
  1409. Option opt = new Option();
  1410. opt.ControlName = item.Attributes["ControlName"].Value;
  1411. opt.DisplayName = item.Attributes["DisplayName"].Value;
  1412. ((RecipeTemplateColumnBase)col).Options.Add(opt);
  1413. }
  1414. sigcolumns.Add(col);
  1415. break;
  1416. case "ReadOnlySelection":
  1417. case "LoopSelection":
  1418. col = new RecipeTemplateColumnBase()
  1419. {
  1420. ValueType = "LoopSelection",
  1421. IsReadOnly = bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  1422. ModuleName = step.Attributes["ModuleName"].Value,
  1423. ControlName = step.Attributes["ControlName"].Value,
  1424. DisplayName = step.Attributes["DisplayName"].Value,
  1425. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1426. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1427. };
  1428. XmlNodeList options = step.SelectNodes("Item");
  1429. foreach (XmlNode item in options)
  1430. {
  1431. Option opt = new Option();
  1432. opt.ControlName = item.Attributes["ControlName"].Value;
  1433. opt.DisplayName = item.Attributes["DisplayName"].Value;
  1434. ((RecipeTemplateColumnBase)col).Options.Add(opt);
  1435. }
  1436. sigcolumns.Add(col);
  1437. break;
  1438. case "PopSetting":
  1439. col = new RecipeTemplateColumnBase()
  1440. {
  1441. ValueType = "LoopSelection",
  1442. ModuleName = step.Attributes["ModuleName"].Value,
  1443. ControlName = step.Attributes["ControlName"].Value,
  1444. DisplayName = step.Attributes["DisplayName"].Value,
  1445. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  1446. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  1447. };
  1448. sigcolumns.Add(col);
  1449. break;
  1450. }
  1451. }
  1452. columns.Add(node.Attributes["DisplayName"].Value, sigcolumns);
  1453. }
  1454. return columns;
  1455. }
  1456. /// <summary>
  1457. /// get reactor's recipe format define file
  1458. /// </summary>
  1459. /// <param name="chamId"></param>
  1460. /// <returns></returns>
  1461. public string GetRecipeFormatXml(string chamberId)
  1462. {
  1463. var rtn = GetRecipeBody(chamberId, "/Aitex/TableRecipeFormat");
  1464. return rtn;
  1465. }
  1466. /// <summary>
  1467. /// get reactor's template recipe file
  1468. /// </summary>
  1469. /// <param name="chamId"></param>
  1470. /// <returns></returns>
  1471. public string GetRecipeTemplate(string chamberId)
  1472. {
  1473. if (_rcpContext != null)
  1474. return _rcpContext.GetRecipeTemplate(chamberId);
  1475. return GetRecipeBody(chamberId, "/Aitex/TableRecipeData");
  1476. }
  1477. /// <summary>
  1478. /// get reactor's template recipe file
  1479. /// </summary>
  1480. /// <param name="chamId"></param>
  1481. /// <returns></returns>
  1482. public string GetRecipeSchema(string chamberId)
  1483. {
  1484. if (_rcpContext == null)
  1485. return string.Empty;
  1486. string schema = _rcpContext.GetRecipeDefiniton(chamberId);
  1487. XmlDocument dom = new XmlDocument();
  1488. dom.LoadXml(schema);
  1489. XmlNode node = dom.SelectSingleNode("/Aitex/TableRecipeSchema");
  1490. return node.InnerXml;
  1491. }
  1492. public string GetRecipeByBarcode(string chamberId, string barcode)
  1493. {
  1494. try
  1495. {
  1496. string recipePath = PathManager.GetRecipeDir() + chamberId + "\\";
  1497. var di = new DirectoryInfo(recipePath);
  1498. var fis = di.GetFiles("*.rcp", SearchOption.AllDirectories);
  1499. XmlDocument xml = new XmlDocument();
  1500. foreach (var fi in fis)
  1501. {
  1502. string str = fi.FullName.Substring(recipePath.Length);
  1503. if (!str.Contains("HistoryRecipe\\"))
  1504. {
  1505. xml.Load(fi.FullName);
  1506. if (xml.SelectSingleNode(string.Format("/TableRecipeData[@Barcode='{0}']", barcode)) != null)
  1507. {
  1508. return str.Substring(0, str.LastIndexOf('.'));
  1509. }
  1510. }
  1511. }
  1512. return string.Empty;
  1513. }
  1514. catch (Exception ex)
  1515. {
  1516. LOG.Write(ex);
  1517. return string.Empty;
  1518. }
  1519. }
  1520. public List<string> ExpertLayoutRecipeParse(string chamberId, string recipeFile)
  1521. {
  1522. var layoutRecipe = new List<string>();
  1523. string content = LoadRecipe(chamberId, recipeFile, false);
  1524. if (string.IsNullOrEmpty(content))
  1525. {
  1526. //reason = $"{recipeFile} is not a valid recipe file";
  1527. return layoutRecipe;
  1528. }
  1529. try
  1530. {
  1531. XmlDocument rcpDataDoc = new XmlDocument();
  1532. rcpDataDoc.LoadXml(content);
  1533. XmlNode nodeModule;
  1534. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Expert']");
  1535. if (nodeModule == null)
  1536. {
  1537. return layoutRecipe;
  1538. }
  1539. else
  1540. {
  1541. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  1542. XmlElement stepNode = nodeModule as XmlElement;
  1543. //遍历Step节点
  1544. foreach (XmlAttribute att in stepNode.Attributes)
  1545. {
  1546. if (att.Name != "Name")
  1547. {
  1548. if (att.Value.ToLower() == "xd")
  1549. {
  1550. layoutRecipe.Add("XD");
  1551. }
  1552. else if (att.Value.ToLower() == "t")
  1553. {
  1554. layoutRecipe.Add("T");
  1555. }
  1556. else
  1557. {
  1558. layoutRecipe.Add("");
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. catch (Exception ex)
  1565. {
  1566. LOG.Write(ex);
  1567. return layoutRecipe;
  1568. }
  1569. return layoutRecipe;
  1570. }
  1571. public List<string> LayoutExpertRecipeParse(/*string chamberId, */string recipeContent, string slotCount, string cassetteSlotCount)
  1572. {
  1573. var layoutRecipe = new List<string>();
  1574. try
  1575. {
  1576. XmlDocument rcpDataDoc = new XmlDocument();
  1577. rcpDataDoc.LoadXml(recipeContent);
  1578. XmlNode nodeModule;
  1579. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Normal']");
  1580. if (nodeModule == null)
  1581. {
  1582. //reason = "Recipe file does not contains step content for Normal";
  1583. return layoutRecipe;
  1584. }
  1585. else
  1586. {
  1587. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  1588. XmlElement stepNode = nodeModule as XmlElement;
  1589. //遍历Step节点
  1590. foreach (XmlAttribute att in stepNode.Attributes)
  1591. {
  1592. if (att.Name != "Name")
  1593. {
  1594. recipeData[att.Name] = att.Value;
  1595. }
  1596. }
  1597. // 获取SlotCount
  1598. int iSlotCount = 0;
  1599. int.TryParse(slotCount, out iSlotCount);
  1600. // 获取CassetteSlotCount;
  1601. int iCassetteSlotCount = 0;
  1602. int.TryParse(cassetteSlotCount, out iCassetteSlotCount);
  1603. // 先往List里面添加SlotcCount数量的空值,后续再往里面insert具体的值
  1604. for (int i = 0; i < iSlotCount; i++)
  1605. {
  1606. layoutRecipe.Add(string.Empty);
  1607. }
  1608. // 获取DummyUpperSlot
  1609. int iDummyUpperSlot;
  1610. iDummyUpperSlot = 0;
  1611. if (recipeData.ContainsKey("DummyUpperSlot"))
  1612. {
  1613. int.TryParse(recipeData["DummyUpperSlot"], out iDummyUpperSlot);
  1614. if (iDummyUpperSlot == 0)
  1615. {
  1616. return layoutRecipe;
  1617. }
  1618. }
  1619. else
  1620. {
  1621. return layoutRecipe;
  1622. }
  1623. // insert Upper Dummy
  1624. for (int i = 0; i < iDummyUpperSlot; i++)
  1625. {
  1626. layoutRecipe[i] = "XD";
  1627. }
  1628. // 获取DummyLowerSlot
  1629. int iDummyLowerSlot;
  1630. iDummyLowerSlot = 0;
  1631. if (recipeData.ContainsKey("DummyLowerSlot"))
  1632. {
  1633. int.TryParse(recipeData["DummyLowerSlot"], out iDummyLowerSlot);
  1634. if (iDummyLowerSlot == 0)
  1635. {
  1636. return layoutRecipe;
  1637. }
  1638. }
  1639. else
  1640. {
  1641. return layoutRecipe;
  1642. }
  1643. // insert Lower Dummy
  1644. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  1645. {
  1646. layoutRecipe[i] = "XD";
  1647. }
  1648. }
  1649. }
  1650. catch (Exception ex)
  1651. {
  1652. LOG.Write(ex);
  1653. return layoutRecipe;
  1654. }
  1655. return layoutRecipe;
  1656. }
  1657. public List<string> LayoutRecipeParse(/*string chamberId, */string recipeContent, string slotCount, string cassetteSlotCount)
  1658. {
  1659. var layoutRecipe = new List<string>();
  1660. //string content = loadrecipe(chamberid, recipefile, false);
  1661. //if (string.isnullorempty(content))
  1662. //{
  1663. // reason = $"{recipefile} is not a valid recipe file";
  1664. // return layoutrecipe;
  1665. //}
  1666. try
  1667. {
  1668. XmlDocument rcpDataDoc = new XmlDocument();
  1669. rcpDataDoc.LoadXml(recipeContent);
  1670. XmlNode nodeModule;
  1671. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Normal']");
  1672. if (nodeModule == null)
  1673. {
  1674. //reason = "Recipe file does not contains step content for Normal";
  1675. return layoutRecipe;
  1676. }
  1677. else
  1678. {
  1679. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  1680. XmlElement stepNode = nodeModule as XmlElement;
  1681. //遍历Step节点
  1682. foreach (XmlAttribute att in stepNode.Attributes)
  1683. {
  1684. if (att.Name != "Name")
  1685. {
  1686. recipeData[att.Name] = att.Value;
  1687. }
  1688. }
  1689. // 获取SlotCount
  1690. int iSlotCount = 0;
  1691. int.TryParse(slotCount, out iSlotCount);
  1692. // 获取CassetteSlotCount;
  1693. int iCassetteSlotCount = 0;
  1694. int.TryParse(cassetteSlotCount, out iCassetteSlotCount);
  1695. // 先往List里面添加SlotcCount数量的空值,后续再往里面insert具体的值
  1696. for (int i = 0; i < iSlotCount; i++)
  1697. {
  1698. layoutRecipe.Add(string.Empty);
  1699. }
  1700. // 获取DummyUpperSlot
  1701. int iDummyUpperSlot;
  1702. iDummyUpperSlot = 0;
  1703. if (recipeData.ContainsKey("DummyUpperSlot"))
  1704. {
  1705. int.TryParse(recipeData["DummyUpperSlot"], out iDummyUpperSlot);
  1706. if (iDummyUpperSlot == 0)
  1707. {
  1708. return layoutRecipe;
  1709. }
  1710. }
  1711. else
  1712. {
  1713. return layoutRecipe;
  1714. }
  1715. // insert Upper Dummy
  1716. for (int i = 0; i < iDummyUpperSlot; i++)
  1717. {
  1718. layoutRecipe[i] = "Dummy";
  1719. }
  1720. // 获取DummyLowerSlot
  1721. int iDummyLowerSlot;
  1722. iDummyLowerSlot = 0;
  1723. if (recipeData.ContainsKey("DummyLowerSlot"))
  1724. {
  1725. int.TryParse(recipeData["DummyLowerSlot"], out iDummyLowerSlot);
  1726. if (iDummyLowerSlot == 0)
  1727. {
  1728. return layoutRecipe;
  1729. }
  1730. }
  1731. else
  1732. {
  1733. return layoutRecipe;
  1734. }
  1735. // insert Lower Dummy
  1736. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  1737. {
  1738. layoutRecipe[i] = "Dummy";
  1739. }
  1740. string strPitch, strProductPos, strProductSlotNo, strMonitorPos, strMonitorSlotNo, strMonitorBetweenCasseteNo;
  1741. string strPWaferShort, strSDRule, strCassetteInBatchShort, strWaferInCasseteShort, strEDShort, strBoatRule;
  1742. strPitch = string.Empty;
  1743. strProductPos = string.Empty;
  1744. strProductSlotNo = string.Empty;
  1745. strMonitorPos = string.Empty;
  1746. strMonitorSlotNo = string.Empty;
  1747. strMonitorBetweenCasseteNo = string.Empty;
  1748. strPWaferShort = string.Empty;
  1749. strSDRule = string.Empty;
  1750. strCassetteInBatchShort = string.Empty;
  1751. strWaferInCasseteShort = string.Empty;
  1752. strEDShort = string.Empty;
  1753. strBoatRule = string.Empty;
  1754. // 获取配置
  1755. if (recipeData.ContainsKey("Pitch"))
  1756. {
  1757. strPitch = recipeData["Pitch"];
  1758. }
  1759. if (recipeData.ContainsKey("ProductPosition"))
  1760. {
  1761. strProductPos = recipeData["ProductPosition"];
  1762. }
  1763. if (recipeData.ContainsKey("ProductSlotNo"))
  1764. {
  1765. strProductSlotNo = recipeData["ProductSlotNo"];
  1766. }
  1767. if (recipeData.ContainsKey("MonitorPosition"))
  1768. {
  1769. strMonitorPos = recipeData["MonitorPosition"];
  1770. }
  1771. if (recipeData.ContainsKey("MonitorSlotNo"))
  1772. {
  1773. strMonitorSlotNo = recipeData["MonitorSlotNo"];
  1774. }
  1775. if (recipeData.ContainsKey("MonitorBetweenCassetteNo"))
  1776. {
  1777. strMonitorBetweenCasseteNo = recipeData["MonitorBetweenCassetteNo"];
  1778. }
  1779. if (recipeData.ContainsKey("WhenPWaferShort"))
  1780. {
  1781. strPWaferShort = recipeData["WhenPWaferShort"];
  1782. }
  1783. if (recipeData.ContainsKey("SDRule"))
  1784. {
  1785. strSDRule = recipeData["SDRule"];
  1786. }
  1787. if (recipeData.ContainsKey("WhenCassetteInBatchAreShort"))
  1788. {
  1789. strCassetteInBatchShort = recipeData["WhenCassetteInBatchAreShort"];
  1790. }
  1791. if (recipeData.ContainsKey("WhenWaferInCassetteAreShort"))
  1792. {
  1793. strWaferInCasseteShort = recipeData["WhenWaferInCassetteAreShort"];
  1794. }
  1795. if (recipeData.ContainsKey("WhenEDAreShort"))
  1796. {
  1797. strEDShort = recipeData["WhenEDAreShort"];
  1798. }
  1799. if (recipeData.ContainsKey("RuleOfSpaceInBoat"))
  1800. {
  1801. strBoatRule = recipeData["RuleOfSpaceInBoat"];
  1802. }
  1803. // insert Production and Monitor and ExtraDummy
  1804. if (strProductPos == "Auto")
  1805. {
  1806. if (strMonitorPos == "BetweenCassette")
  1807. {
  1808. if (strPitch == "DoublePitch")
  1809. {
  1810. layoutRecipe = ProductAutoMonitorBetweenCassetteDoublePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorBetweenCasseteNo, strBoatRule);
  1811. }
  1812. else if (strPitch == "TriplePitch")
  1813. {
  1814. layoutRecipe = ProductAutoMonitorBetweenCassetteTriplePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorBetweenCasseteNo, strBoatRule);
  1815. }
  1816. else
  1817. {
  1818. layoutRecipe = ProductAutoMonitorBetweenCassetteStandardPitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorBetweenCasseteNo, strBoatRule);
  1819. }
  1820. }
  1821. else if (strMonitorPos == "Slot")
  1822. {
  1823. if (strPitch == "DoublePitch")
  1824. {
  1825. layoutRecipe = ProductAutoMonitorSlotDoublePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorSlotNo, strBoatRule);
  1826. }
  1827. else if (strPitch == "TriplePitch")
  1828. {
  1829. layoutRecipe = ProductAutoMonitorSlotTriplePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorSlotNo, strBoatRule);
  1830. }
  1831. else
  1832. {
  1833. layoutRecipe = ProductAutoMonitorSlotStandardPitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strMonitorSlotNo, strBoatRule);
  1834. }
  1835. }
  1836. else
  1837. {
  1838. //reason = "MonitorPosition is invalid";
  1839. return layoutRecipe;
  1840. }
  1841. }
  1842. else if (strProductPos == "Slot")
  1843. {
  1844. if (strMonitorPos == "BetweenCassette")
  1845. {
  1846. if (strPitch == "DoublePitch")
  1847. {
  1848. layoutRecipe = ProductSlotMonitorBetweenCassetteDoublePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorBetweenCasseteNo, strBoatRule);
  1849. }
  1850. else if (strPitch == "TriplePitch")
  1851. {
  1852. layoutRecipe = ProductSlotMonitorBetweenCassetteTriplePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorBetweenCasseteNo, strBoatRule);
  1853. }
  1854. else
  1855. {
  1856. layoutRecipe = ProductSlotMonitorBetweenCassetteStandardPitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorBetweenCasseteNo, strBoatRule);
  1857. }
  1858. }
  1859. else if (strMonitorPos == "Slot")
  1860. {
  1861. if (strPitch == "DoublePitch")
  1862. {
  1863. layoutRecipe = ProductSlotMonitorSlotDoublePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorSlotNo, strBoatRule);
  1864. }
  1865. else if (strPitch == "TriplePitch")
  1866. {
  1867. layoutRecipe = ProductSlotMonitorSlotTriplePitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorSlotNo, strBoatRule);
  1868. }
  1869. else
  1870. {
  1871. layoutRecipe = ProductSlotMonitorSlotStandardPitch(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strMonitorSlotNo, strBoatRule);
  1872. }
  1873. }
  1874. else
  1875. {
  1876. //reason = "MonitorPosition is invalid";
  1877. return layoutRecipe;
  1878. }
  1879. }
  1880. else
  1881. {
  1882. //reason = "ProductPosition is invalid";
  1883. return layoutRecipe;
  1884. }
  1885. }
  1886. }
  1887. catch (Exception ex)
  1888. {
  1889. LOG.Write(ex);
  1890. return layoutRecipe;
  1891. }
  1892. return layoutRecipe;
  1893. }
  1894. private List<string> ProductAutoMonitorBetweenCassetteStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  1895. {
  1896. var layoutRecipe = new List<string>();
  1897. for (int i = 0; i < iSlotCount; i++)
  1898. {
  1899. layoutRecipe.Add(string.Empty);
  1900. }
  1901. try
  1902. {
  1903. // insert Upper Dummy
  1904. for (int i = 0; i < iDummyUpperSlot; i++)
  1905. {
  1906. layoutRecipe[i] = "Dummy";
  1907. }
  1908. // insert Lower Dummy
  1909. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  1910. {
  1911. layoutRecipe[i] = "Dummy";
  1912. }
  1913. var monitorBetweenCassetteNo = new List<string>();
  1914. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  1915. // insert Monitor
  1916. int iIndex, iMonitorCount = 7;
  1917. iIndex = iDummyUpperSlot;
  1918. for (int i = 0; i < iMonitorCount; i++)
  1919. {
  1920. iIndex = iDummyUpperSlot + i * iCassetteSlotCount + i;
  1921. if (iIndex < iSlotCount - iDummyLowerSlot - 1)
  1922. {
  1923. if (monitorBetweenCassetteNo[i] == "ON")
  1924. {
  1925. layoutRecipe[iIndex] = "Monitor";
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if (monitorBetweenCassetteNo[i] == "ON")
  1931. {
  1932. iIndex = iSlotCount - iDummyLowerSlot - 1;
  1933. layoutRecipe[iIndex] = "Monitor";
  1934. }
  1935. }
  1936. }
  1937. // insert Production
  1938. int iFirstMonitorIndex = 0;
  1939. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  1940. {
  1941. if (layoutRecipe[i] == "Monitor")
  1942. {
  1943. iFirstMonitorIndex = i;
  1944. break;
  1945. }
  1946. }
  1947. // Search Up
  1948. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot; i--)
  1949. {
  1950. if (layoutRecipe[i] == "")
  1951. {
  1952. layoutRecipe[i] = "Production";
  1953. }
  1954. else
  1955. {
  1956. break;
  1957. }
  1958. }
  1959. // Search Down
  1960. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 1; i++)
  1961. {
  1962. if (layoutRecipe[i] == "")
  1963. {
  1964. layoutRecipe[i] = "Production";
  1965. }
  1966. }
  1967. }
  1968. catch (Exception ex)
  1969. {
  1970. LOG.Write(ex);
  1971. return layoutRecipe;
  1972. }
  1973. return layoutRecipe;
  1974. }
  1975. private List<string> ProductAutoMonitorBetweenCassetteDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  1976. {
  1977. var layoutRecipe = new List<string>();
  1978. for (int i = 0; i < iSlotCount; i++)
  1979. {
  1980. layoutRecipe.Add(string.Empty);
  1981. }
  1982. try
  1983. {
  1984. // insert Upper Dummy
  1985. for (int i = 0; i < iDummyUpperSlot; i++)
  1986. {
  1987. layoutRecipe[i] = "Dummy";
  1988. }
  1989. // insert Lower Dummy
  1990. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  1991. {
  1992. layoutRecipe[i] = "Dummy";
  1993. }
  1994. var monitorBetweenCassetteNo = new List<string>();
  1995. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  1996. // insert Monitor
  1997. int iIndex, iMonitorCount = 7;
  1998. iIndex = iDummyUpperSlot;
  1999. for (int i = 0; i < iMonitorCount; i += 2)
  2000. {
  2001. iIndex = iDummyUpperSlot + 1 + i * iCassetteSlotCount * 2 + i * 2;
  2002. if (iIndex < iSlotCount - iDummyLowerSlot - 2)
  2003. {
  2004. if (monitorBetweenCassetteNo[i] == "ON")
  2005. {
  2006. layoutRecipe[iIndex] = "Monitor";
  2007. }
  2008. }
  2009. else
  2010. {
  2011. if (monitorBetweenCassetteNo[i] == "ON")
  2012. {
  2013. iIndex = iSlotCount - iDummyLowerSlot - 2;
  2014. layoutRecipe[iIndex] = "Monitor";
  2015. }
  2016. }
  2017. }
  2018. // insert Production
  2019. int iFirstMonitorIndex = 0;
  2020. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2021. {
  2022. if (layoutRecipe[i] == "Monitor")
  2023. {
  2024. iFirstMonitorIndex = i;
  2025. break;
  2026. }
  2027. }
  2028. // search Up
  2029. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot + 1; i -= 2)
  2030. {
  2031. if (layoutRecipe[i] == "" && layoutRecipe[i - 1] == "")
  2032. {
  2033. layoutRecipe[i] = "Production";
  2034. }
  2035. else
  2036. {
  2037. break;
  2038. }
  2039. }
  2040. // serach Down
  2041. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 2; i += 2)
  2042. {
  2043. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  2044. {
  2045. layoutRecipe[i] = "Production";
  2046. }
  2047. }
  2048. }
  2049. catch (Exception ex)
  2050. {
  2051. LOG.Write(ex);
  2052. return layoutRecipe;
  2053. }
  2054. return layoutRecipe;
  2055. }
  2056. private List<string> ProductAutoMonitorBetweenCassetteTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  2057. {
  2058. var layoutRecipe = new List<string>();
  2059. for (int i = 0; i < iSlotCount; i++)
  2060. {
  2061. layoutRecipe.Add(string.Empty);
  2062. }
  2063. try
  2064. {
  2065. // insert Upper Dummy
  2066. for (int i = 0; i < iDummyUpperSlot; i++)
  2067. {
  2068. layoutRecipe[i] = "Dummy";
  2069. }
  2070. // insert Lower Dummy
  2071. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2072. {
  2073. layoutRecipe[i] = "Dummy";
  2074. }
  2075. var monitorBetweenCassetteNo = new List<string>();
  2076. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  2077. // insert Monitor
  2078. int iIndex, iMonitorCount = 7;
  2079. iIndex = iDummyUpperSlot;
  2080. for (int i = 0; i < iMonitorCount; i += 3)
  2081. {
  2082. iIndex = iDummyUpperSlot + 2 + i * iCassetteSlotCount * 3 + i * 3;
  2083. if (iIndex < iSlotCount - iDummyLowerSlot - 3)
  2084. {
  2085. if (monitorBetweenCassetteNo[i] == "ON")
  2086. {
  2087. layoutRecipe[iIndex] = "Monitor";
  2088. }
  2089. }
  2090. else
  2091. {
  2092. if (monitorBetweenCassetteNo[i] == "ON")
  2093. {
  2094. iIndex = iSlotCount - iDummyLowerSlot - 3;
  2095. layoutRecipe[iIndex] = "Monitor";
  2096. }
  2097. }
  2098. }
  2099. // insert Production
  2100. int iFirstMonitorIndex = 0;
  2101. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2102. {
  2103. if (layoutRecipe[i] == "Monitor")
  2104. {
  2105. iFirstMonitorIndex = i;
  2106. break;
  2107. }
  2108. }
  2109. // search Up
  2110. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot + 2; i -= 3)
  2111. {
  2112. if (layoutRecipe[i] == "" && layoutRecipe[i - 1] == "" && layoutRecipe[i - 2] == "")
  2113. {
  2114. layoutRecipe[i] = "Production";
  2115. }
  2116. else
  2117. {
  2118. break;
  2119. }
  2120. }
  2121. // serach Down
  2122. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 3; i += 3)
  2123. {
  2124. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  2125. {
  2126. layoutRecipe[i] = "Production";
  2127. }
  2128. }
  2129. }
  2130. catch (Exception ex)
  2131. {
  2132. LOG.Write(ex);
  2133. return layoutRecipe;
  2134. }
  2135. return layoutRecipe;
  2136. }
  2137. private List<string> ProductAutoMonitorSlotStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  2138. {
  2139. var layoutRecipe = new List<string>();
  2140. for (int i = 0; i < iSlotCount; i++)
  2141. {
  2142. layoutRecipe.Add(string.Empty);
  2143. }
  2144. try
  2145. {
  2146. // insert Upper Dummy
  2147. for (int i = 0; i < iDummyUpperSlot; i++)
  2148. {
  2149. layoutRecipe[i] = "Dummy";
  2150. }
  2151. // insert Lower Dummy
  2152. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2153. {
  2154. layoutRecipe[i] = "Dummy";
  2155. }
  2156. var monitorSlotList = new List<string>();
  2157. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2158. var monitorSlotNo = new List<int>();
  2159. foreach (string str in monitorSlotList)
  2160. {
  2161. int iPos = 0;
  2162. int.TryParse(str, out iPos);
  2163. iPos--;
  2164. if (!monitorSlotNo.Contains(iPos))
  2165. {
  2166. monitorSlotNo.Add(iPos);
  2167. }
  2168. }
  2169. monitorSlotNo.Sort();
  2170. // insert Monitor
  2171. List<int> monitorNo = new List<int>();
  2172. foreach (int vm in monitorSlotNo)
  2173. {
  2174. if (layoutRecipe[vm] != "Dummy")
  2175. {
  2176. layoutRecipe[vm] = "Monitor";
  2177. }
  2178. }
  2179. // insert Production
  2180. int iFirstMonitorIndex = 0;
  2181. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2182. {
  2183. if (layoutRecipe[i] == "Monitor")
  2184. {
  2185. iFirstMonitorIndex = i;
  2186. break;
  2187. }
  2188. }
  2189. for (int i = iDummyUpperSlot; i < iFirstMonitorIndex; i++)
  2190. {
  2191. if (layoutRecipe[i] == "")
  2192. {
  2193. layoutRecipe[i] = "Production";
  2194. }
  2195. else
  2196. {
  2197. break;
  2198. }
  2199. }
  2200. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 1; i++)
  2201. {
  2202. if (layoutRecipe[i] == "")
  2203. {
  2204. layoutRecipe[i] = "Production";
  2205. }
  2206. }
  2207. }
  2208. catch (Exception ex)
  2209. {
  2210. LOG.Write(ex);
  2211. return layoutRecipe;
  2212. }
  2213. return layoutRecipe;
  2214. }
  2215. private List<string> ProductAutoMonitorSlotDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  2216. {
  2217. var layoutRecipe = new List<string>();
  2218. for (int i = 0; i < iSlotCount; i++)
  2219. {
  2220. layoutRecipe.Add(string.Empty);
  2221. }
  2222. try
  2223. {
  2224. // insert Upper Dummy
  2225. for (int i = 0; i < iDummyUpperSlot; i++)
  2226. {
  2227. layoutRecipe[i] = "Dummy";
  2228. }
  2229. // insert Lower Dummy
  2230. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2231. {
  2232. layoutRecipe[i] = "Dummy";
  2233. }
  2234. var monitorSlotList = new List<string>();
  2235. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2236. var monitorSlotNo = new List<int>();
  2237. foreach (string str in monitorSlotList)
  2238. {
  2239. int iPos = 0;
  2240. int.TryParse(str, out iPos);
  2241. iPos--;
  2242. if (!monitorSlotNo.Contains(iPos))
  2243. {
  2244. monitorSlotNo.Add(iPos);
  2245. }
  2246. }
  2247. monitorSlotNo.Sort();
  2248. // insert Monitor
  2249. List<int> monitorNo = new List<int>();
  2250. foreach (int vm in monitorSlotNo)
  2251. {
  2252. if (layoutRecipe[vm] != "Dummy" && vm >= iDummyUpperSlot + 1 && vm <= iSlotCount - iDummyLowerSlot - 2)
  2253. {
  2254. layoutRecipe[vm] = "Monitor";
  2255. }
  2256. }
  2257. // insert Production
  2258. int iFirstMonitorIndex = 0;
  2259. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2260. {
  2261. if (layoutRecipe[i] == "Monitor")
  2262. {
  2263. iFirstMonitorIndex = i;
  2264. break;
  2265. }
  2266. }
  2267. for (int i = iDummyUpperSlot + 1; i < iFirstMonitorIndex; i += 2)
  2268. {
  2269. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  2270. {
  2271. layoutRecipe[i] = "Production";
  2272. }
  2273. else
  2274. {
  2275. break;
  2276. }
  2277. }
  2278. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 2; i += 2)
  2279. {
  2280. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  2281. {
  2282. layoutRecipe[i] = "Production";
  2283. }
  2284. }
  2285. }
  2286. catch (Exception ex)
  2287. {
  2288. LOG.Write(ex);
  2289. return layoutRecipe;
  2290. }
  2291. return layoutRecipe;
  2292. }
  2293. private List<string> ProductAutoMonitorSlotTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  2294. {
  2295. var layoutRecipe = new List<string>();
  2296. for (int i = 0; i < iSlotCount; i++)
  2297. {
  2298. layoutRecipe.Add(string.Empty);
  2299. }
  2300. try
  2301. {
  2302. // insert Upper Dummy
  2303. for (int i = 0; i < iDummyUpperSlot; i++)
  2304. {
  2305. layoutRecipe[i] = "Dummy";
  2306. }
  2307. // insert Lower Dummy
  2308. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2309. {
  2310. layoutRecipe[i] = "Dummy";
  2311. }
  2312. var monitorSlotList = new List<string>();
  2313. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2314. var monitorSlotNo = new List<int>();
  2315. foreach (string str in monitorSlotList)
  2316. {
  2317. int iPos = 0;
  2318. int.TryParse(str, out iPos);
  2319. iPos--;
  2320. if (!monitorSlotNo.Contains(iPos))
  2321. {
  2322. monitorSlotNo.Add(iPos);
  2323. }
  2324. }
  2325. monitorSlotNo.Sort();
  2326. // insert Monitor
  2327. List<int> monitorNo = new List<int>();
  2328. foreach (int vm in monitorSlotNo)
  2329. {
  2330. if (layoutRecipe[vm] != "Dummy" && vm >= iDummyUpperSlot + 2 && vm <= iSlotCount - iDummyLowerSlot - 3)
  2331. {
  2332. layoutRecipe[vm] = "Monitor";
  2333. }
  2334. }
  2335. // insert Production
  2336. int iFirstMonitorIndex = 0;
  2337. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2338. {
  2339. if (layoutRecipe[i] == "Monitor")
  2340. {
  2341. iFirstMonitorIndex = i;
  2342. break;
  2343. }
  2344. }
  2345. for (int i = iDummyUpperSlot + 2; i < iFirstMonitorIndex; i += 3)
  2346. {
  2347. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  2348. {
  2349. layoutRecipe[i] = "Production";
  2350. }
  2351. else
  2352. {
  2353. break;
  2354. }
  2355. }
  2356. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 3; i += 3)
  2357. {
  2358. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  2359. {
  2360. layoutRecipe[i] = "Production";
  2361. }
  2362. }
  2363. }
  2364. catch (Exception ex)
  2365. {
  2366. LOG.Write(ex);
  2367. return layoutRecipe;
  2368. }
  2369. return layoutRecipe;
  2370. }
  2371. private List<string> ProductSlotMonitorBetweenCassetteStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  2372. {
  2373. var layoutRecipe = new List<string>();
  2374. for (int i = 0; i < iSlotCount; i++)
  2375. {
  2376. layoutRecipe.Add(string.Empty);
  2377. }
  2378. try
  2379. {
  2380. // insert Upper Dummy
  2381. for (int i = 0; i < iDummyUpperSlot; i++)
  2382. {
  2383. layoutRecipe[i] = "Dummy";
  2384. }
  2385. // insert Lower Dummy
  2386. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2387. {
  2388. layoutRecipe[i] = "Dummy";
  2389. }
  2390. var productSlotList = new List<string>();
  2391. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2392. var productSloNo = new List<int>();
  2393. foreach (string str in productSlotList)
  2394. {
  2395. int iPos = 0;
  2396. int.TryParse(str, out iPos);
  2397. iPos--;
  2398. if (!productSloNo.Contains(iPos))
  2399. {
  2400. productSloNo.Add(iPos);
  2401. }
  2402. }
  2403. productSloNo.Sort();
  2404. var monitorBetweenCassetteNo = new List<string>();
  2405. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  2406. // insert Monitor
  2407. int iIndex, iMonitorCount = 7;
  2408. iIndex = iDummyUpperSlot;
  2409. for (int i = 0; i < iMonitorCount; i++)
  2410. {
  2411. iIndex = iDummyUpperSlot + i * iCassetteSlotCount + i;
  2412. if (iIndex < iSlotCount - iDummyLowerSlot - 1)
  2413. {
  2414. if (monitorBetweenCassetteNo[i] == "ON")
  2415. {
  2416. layoutRecipe[iIndex] = "Monitor";
  2417. }
  2418. }
  2419. else
  2420. {
  2421. if (monitorBetweenCassetteNo[i] == "ON")
  2422. {
  2423. iIndex = iSlotCount - iDummyLowerSlot - 1;
  2424. layoutRecipe[iIndex] = "Monitor";
  2425. }
  2426. }
  2427. }
  2428. // insert Production
  2429. foreach (int vm in productSloNo)
  2430. {
  2431. if (layoutRecipe[vm] == "" && vm >= iDummyUpperSlot && vm <= iSlotCount - iDummyLowerSlot - 1)
  2432. {
  2433. layoutRecipe[vm] = "Production";
  2434. }
  2435. }
  2436. }
  2437. catch (Exception ex)
  2438. {
  2439. LOG.Write(ex);
  2440. return layoutRecipe;
  2441. }
  2442. return layoutRecipe;
  2443. }
  2444. private List<string> ProductSlotMonitorBetweenCassetteDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  2445. {
  2446. var layoutRecipe = new List<string>();
  2447. for (int i = 0; i < iSlotCount; i++)
  2448. {
  2449. layoutRecipe.Add(string.Empty);
  2450. }
  2451. try
  2452. {
  2453. // insert Upper Dummy
  2454. for (int i = 0; i < iDummyUpperSlot; i++)
  2455. {
  2456. layoutRecipe[i] = "Dummy";
  2457. }
  2458. // insert Lower Dummy
  2459. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2460. {
  2461. layoutRecipe[i] = "Dummy";
  2462. }
  2463. var productSlotList = new List<string>();
  2464. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2465. var productSloNo = new List<int>();
  2466. foreach (string str in productSlotList)
  2467. {
  2468. int iPos = 0;
  2469. int.TryParse(str, out iPos);
  2470. iPos--;
  2471. if (!productSloNo.Contains(iPos))
  2472. {
  2473. productSloNo.Add(iPos);
  2474. }
  2475. }
  2476. productSloNo.Sort();
  2477. var monitorBetweenCassetteNo = new List<string>();
  2478. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  2479. // insert Monitor
  2480. int iIndex, iMonitorCount = 7;
  2481. iIndex = iDummyUpperSlot;
  2482. for (int i = 0; i < iMonitorCount; i += 2)
  2483. {
  2484. iIndex = iDummyUpperSlot + 1 + i * iCassetteSlotCount * 2 + i * 2;
  2485. if (iIndex < iSlotCount - iDummyLowerSlot - 2)
  2486. {
  2487. if (monitorBetweenCassetteNo[i] == "ON")
  2488. {
  2489. layoutRecipe[iIndex] = "Monitor";
  2490. }
  2491. }
  2492. else
  2493. {
  2494. if (monitorBetweenCassetteNo[i] == "ON")
  2495. {
  2496. iIndex = iSlotCount - iDummyLowerSlot - 2;
  2497. layoutRecipe[iIndex] = "Monitor";
  2498. }
  2499. }
  2500. }
  2501. // insert Production
  2502. foreach (int vm in productSloNo)
  2503. {
  2504. if (layoutRecipe[vm] == "" && layoutRecipe[vm - 1] == "" && layoutRecipe[vm + 1] == "" && vm >= iDummyUpperSlot + 1 && vm <= iSlotCount - iDummyLowerSlot - 2)
  2505. {
  2506. layoutRecipe[vm] = "Production";
  2507. }
  2508. }
  2509. }
  2510. catch (Exception ex)
  2511. {
  2512. LOG.Write(ex);
  2513. return layoutRecipe;
  2514. }
  2515. return layoutRecipe;
  2516. }
  2517. private List<string> ProductSlotMonitorBetweenCassetteTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  2518. {
  2519. var layoutRecipe = new List<string>();
  2520. for (int i = 0; i < iSlotCount; i++)
  2521. {
  2522. layoutRecipe.Add(string.Empty);
  2523. }
  2524. try
  2525. {
  2526. // insert Upper Dummy
  2527. for (int i = 0; i < iDummyUpperSlot; i++)
  2528. {
  2529. layoutRecipe[i] = "Dummy";
  2530. }
  2531. // insert Lower Dummy
  2532. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2533. {
  2534. layoutRecipe[i] = "Dummy";
  2535. }
  2536. var productSlotList = new List<string>();
  2537. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2538. var productSloNo = new List<int>();
  2539. foreach (string str in productSlotList)
  2540. {
  2541. int iPos = 0;
  2542. int.TryParse(str, out iPos);
  2543. iPos--;
  2544. if (!productSloNo.Contains(iPos))
  2545. {
  2546. productSloNo.Add(iPos);
  2547. }
  2548. }
  2549. productSloNo.Sort();
  2550. var monitorBetweenCassetteNo = new List<string>();
  2551. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  2552. // insert Monitor
  2553. int iIndex, iMonitorCount = 7;
  2554. iIndex = iDummyUpperSlot;
  2555. for (int i = 0; i < iMonitorCount; i += 3)
  2556. {
  2557. iIndex = iDummyUpperSlot + 2 + i * iCassetteSlotCount * 3 + i * 3;
  2558. if (iIndex < iSlotCount - iDummyLowerSlot - 3)
  2559. {
  2560. if (monitorBetweenCassetteNo[i] == "ON")
  2561. {
  2562. layoutRecipe[iIndex] = "Monitor";
  2563. }
  2564. }
  2565. else
  2566. {
  2567. if (monitorBetweenCassetteNo[i] == "ON")
  2568. {
  2569. iIndex = iSlotCount - iDummyLowerSlot - 3;
  2570. layoutRecipe[iIndex] = "Monitor";
  2571. }
  2572. }
  2573. }
  2574. // insert Production
  2575. foreach (int vm in productSloNo)
  2576. {
  2577. if (layoutRecipe[vm] == "" && layoutRecipe[vm - 1] == "" && layoutRecipe[vm - 2] == "" &&
  2578. layoutRecipe[vm + 1] == "" && layoutRecipe[vm + 2] == "" && vm >= iDummyUpperSlot + 2 && vm <= iSlotCount - iDummyLowerSlot - 3)
  2579. {
  2580. layoutRecipe[vm] = "Production";
  2581. }
  2582. }
  2583. }
  2584. catch (Exception ex)
  2585. {
  2586. LOG.Write(ex);
  2587. return layoutRecipe;
  2588. }
  2589. return layoutRecipe;
  2590. }
  2591. private List<string> ProductSlotMonitorSlotStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  2592. {
  2593. var layoutRecipe = new List<string>();
  2594. for (int i = 0; i < iSlotCount; i++)
  2595. {
  2596. layoutRecipe.Add(string.Empty);
  2597. }
  2598. try
  2599. {
  2600. // insert Upper Dummy
  2601. for (int i = 0; i < iDummyUpperSlot; i++)
  2602. {
  2603. layoutRecipe[i] = "Dummy";
  2604. }
  2605. // insert Lower Dummy
  2606. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2607. {
  2608. layoutRecipe[i] = "Dummy";
  2609. }
  2610. var productSlotNo = new List<string>();
  2611. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2612. var monitorSlotNo = new List<string>();
  2613. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2614. // insert Production
  2615. foreach (string str in productSlotNo)
  2616. {
  2617. int iPos = 0;
  2618. int.TryParse(str, out iPos);
  2619. if (layoutRecipe[iPos - 1] != "Dummy")
  2620. {
  2621. layoutRecipe[iPos - 1] = "Production";
  2622. }
  2623. }
  2624. // insert Monitor
  2625. foreach (string str in monitorSlotNo)
  2626. {
  2627. int iPos = 0;
  2628. int.TryParse(str, out iPos);
  2629. if (layoutRecipe[iPos - 1] != "Dummy")
  2630. {
  2631. layoutRecipe[iPos - 1] = "Monitor";
  2632. }
  2633. }
  2634. }
  2635. catch (Exception ex)
  2636. {
  2637. LOG.Write(ex);
  2638. return layoutRecipe;
  2639. }
  2640. return layoutRecipe;
  2641. }
  2642. private List<string> ProductSlotMonitorSlotDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  2643. {
  2644. var layoutRecipe = new List<string>();
  2645. for (int i = 0; i < iSlotCount; i++)
  2646. {
  2647. layoutRecipe.Add(string.Empty);
  2648. }
  2649. try
  2650. {
  2651. // insert Upper Dummy
  2652. for (int i = 0; i < iDummyUpperSlot; i++)
  2653. {
  2654. layoutRecipe[i] = "Dummy";
  2655. }
  2656. // insert Lower Dummy
  2657. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2658. {
  2659. layoutRecipe[i] = "Dummy";
  2660. }
  2661. var productSlotNo = new List<string>();
  2662. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2663. var monitorSlotNo = new List<string>();
  2664. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2665. // insert Production
  2666. foreach (string str in productSlotNo)
  2667. {
  2668. int iPos = 0;
  2669. int.TryParse(str, out iPos);
  2670. if (layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" && layoutRecipe[iPos] == string.Empty)
  2671. {
  2672. layoutRecipe[iPos - 1] = "Production";
  2673. }
  2674. }
  2675. // insert Monitor
  2676. foreach (string str in monitorSlotNo)
  2677. {
  2678. int iPos = 0;
  2679. int.TryParse(str, out iPos);
  2680. if (layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" && layoutRecipe[iPos] == string.Empty)
  2681. {
  2682. layoutRecipe[iPos - 1] = "Monitor";
  2683. }
  2684. }
  2685. }
  2686. catch (Exception ex)
  2687. {
  2688. LOG.Write(ex);
  2689. return layoutRecipe;
  2690. }
  2691. return layoutRecipe;
  2692. }
  2693. private List<string> ProductSlotMonitorSlotTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  2694. {
  2695. var layoutRecipe = new List<string>();
  2696. for (int i = 0; i < iSlotCount; i++)
  2697. {
  2698. layoutRecipe.Add(string.Empty);
  2699. }
  2700. try
  2701. {
  2702. // insert Upper Dummy
  2703. for (int i = 0; i < iDummyUpperSlot; i++)
  2704. {
  2705. layoutRecipe[i] = "Dummy";
  2706. }
  2707. // insert Lower Dummy
  2708. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2709. {
  2710. layoutRecipe[i] = "Dummy";
  2711. }
  2712. var productSlotNo = new List<string>();
  2713. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2714. var monitorSlotNo = new List<string>();
  2715. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  2716. // insert Production
  2717. foreach (string str in productSlotNo)
  2718. {
  2719. int iPos = 0;
  2720. int.TryParse(str, out iPos);
  2721. if (layoutRecipe[iPos - 3] == string.Empty && layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" &&
  2722. layoutRecipe[iPos] == string.Empty && layoutRecipe[iPos + 1] == string.Empty)
  2723. {
  2724. layoutRecipe[iPos - 1] = "Production";
  2725. }
  2726. }
  2727. // insert Monitor
  2728. foreach (string str in monitorSlotNo)
  2729. {
  2730. int iPos = 0;
  2731. int.TryParse(str, out iPos);
  2732. if (layoutRecipe[iPos - 3] == string.Empty && layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" &&
  2733. layoutRecipe[iPos] == string.Empty && layoutRecipe[iPos + 1] == string.Empty)
  2734. {
  2735. layoutRecipe[iPos - 1] = "Monitor";
  2736. }
  2737. }
  2738. }
  2739. catch (Exception ex)
  2740. {
  2741. LOG.Write(ex);
  2742. return layoutRecipe;
  2743. }
  2744. return layoutRecipe;
  2745. }
  2746. private List<string> GetLayoutProductionMonitorSlot(string strParam)
  2747. {
  2748. var slot = new List<string>();
  2749. if (strParam == string.Empty)
  2750. {
  2751. return slot;
  2752. }
  2753. slot = strParam.Split(',').ToList();
  2754. return slot;
  2755. }
  2756. #region Sequence
  2757. private string GetSequenceConfig(string nodePath)
  2758. {
  2759. if (_seqContext == null)
  2760. return string.Empty;
  2761. string schema = _seqContext.GetConfigXml();
  2762. XmlDocument dom = new XmlDocument();
  2763. dom.LoadXml(schema);
  2764. XmlNode node = dom.SelectSingleNode(nodePath);
  2765. return node.OuterXml;
  2766. }
  2767. public string GetWaferFlowRecipe(string recipeName, bool needValidation)
  2768. {
  2769. string seq = string.Empty;
  2770. try
  2771. {
  2772. using (StreamReader fs = new StreamReader(GenerateRecipeFilePath($"{SC.GetStringValue("System.Recipe.RecipeChamberType")}\\{WaferFlowFolder}", recipeName)))
  2773. {
  2774. seq = fs.ReadToEnd();
  2775. fs.Close();
  2776. }
  2777. if (needValidation && !_seqContext.Validation(seq))
  2778. {
  2779. EV.PostWarningLog(SourceModule, $"Read {recipeName} failed, validation failed");
  2780. seq = string.Empty;
  2781. }
  2782. }
  2783. catch (Exception ex)
  2784. {
  2785. LOG.Write(ex);
  2786. EV.PostWarningLog(SourceModule, $"Read {recipeName} failed, " + ex.Message);
  2787. seq = string.Empty;
  2788. }
  2789. return seq;
  2790. }
  2791. public string GetSequence(string sequenceName, bool needValidation)
  2792. {
  2793. string seq = string.Empty;
  2794. try
  2795. {
  2796. using (StreamReader fs = new StreamReader(GenerateSequenceFilePath(SequenceFolder, sequenceName)))
  2797. {
  2798. seq = fs.ReadToEnd();
  2799. fs.Close();
  2800. }
  2801. if (needValidation && !_seqContext.Validation(seq))
  2802. {
  2803. EV.PostWarningLog(SourceModule, $"Read {sequenceName} failed, validation failed");
  2804. seq = string.Empty;
  2805. }
  2806. }
  2807. catch (Exception ex)
  2808. {
  2809. LOG.Write(ex);
  2810. EV.PostWarningLog(SourceModule, $"Read {sequenceName} failed, " + ex.Message);
  2811. seq = string.Empty;
  2812. }
  2813. return seq;
  2814. }
  2815. public List<string> GetSequenceNameList()
  2816. {
  2817. var result = new List<string>();
  2818. try
  2819. {
  2820. string recipePath = PathManager.GetRecipeDir() + SequenceFolder + "\\";
  2821. var di = new DirectoryInfo(recipePath);
  2822. var fis = di.GetFiles("*.seq", SearchOption.AllDirectories);
  2823. foreach (var fi in fis)
  2824. {
  2825. string str = fi.FullName.Substring(recipePath.Length);
  2826. str = str.Substring(0, str.LastIndexOf('.'));
  2827. result.Add(str);
  2828. }
  2829. }
  2830. catch (Exception ex)
  2831. {
  2832. LOG.Write(ex);
  2833. EV.PostWarningLog(SourceModule, "Get sequence list failed, " + ex.Message);
  2834. }
  2835. return result;
  2836. }
  2837. public bool DeleteSequence(string sequenceName)
  2838. {
  2839. try
  2840. {
  2841. File.Delete(GenerateSequenceFilePath(SequenceFolder, sequenceName));
  2842. EV.PostInfoLog(SourceModule, $"sequence {sequenceName} deleted");
  2843. }
  2844. catch (Exception ex)
  2845. {
  2846. LOG.Write(ex);
  2847. EV.PostWarningLog(SourceModule, $"delete {sequenceName} failed, " + ex.Message);
  2848. return false;
  2849. }
  2850. return true;
  2851. }
  2852. public bool SaveSequence(string sequenceName, string sequenceContent, bool notifyUI)
  2853. {
  2854. bool ret = true;
  2855. try
  2856. {
  2857. var path = GenerateSequenceFilePath(SequenceFolder, sequenceName);
  2858. FileInfo fi = new FileInfo(path);
  2859. if (!fi.Directory.Exists)
  2860. {
  2861. fi.Directory.Create();
  2862. }
  2863. XmlDocument xml = new XmlDocument();
  2864. xml.LoadXml(sequenceContent);
  2865. XmlTextWriter writer = new XmlTextWriter(path, null);
  2866. writer.Formatting = Formatting.Indented;
  2867. xml.Save(writer);
  2868. writer.Close();
  2869. if (notifyUI)
  2870. {
  2871. EV.PostPopDialogMessage(EventLevel.Information, "Save Complete", $"Sequence {sequenceName} saved ");
  2872. }
  2873. else
  2874. {
  2875. EV.PostInfoLog(SourceModule, $"Sequence {sequenceName} saved ");
  2876. }
  2877. }
  2878. catch (Exception ex)
  2879. {
  2880. LOG.Write(ex);
  2881. EV.PostWarningLog(SourceModule, $"save sequence {sequenceName} failed, " + ex.Message);
  2882. if (notifyUI)
  2883. {
  2884. EV.PostPopDialogMessage(EventLevel.Alarm, "Save Error", $"save sequence {sequenceName} failed, " + ex.Message);
  2885. }
  2886. ret = false;
  2887. }
  2888. return ret;
  2889. }
  2890. public bool SaveAsSequence(string sequenceName, string sequenceContent)
  2891. {
  2892. var path = GenerateSequenceFilePath(SequenceFolder, sequenceName);
  2893. if (File.Exists(path))
  2894. {
  2895. EV.PostWarningLog(SourceModule, $"save sequence {sequenceName} failed, already exist");
  2896. return false;
  2897. }
  2898. return SaveSequence(sequenceName, sequenceContent, false);
  2899. }
  2900. public bool RenameSequence(string oldName, string newName)
  2901. {
  2902. try
  2903. {
  2904. if (File.Exists(GenerateSequenceFilePath(SequenceFolder, newName)))
  2905. {
  2906. EV.PostWarningLog(SourceModule, $"{newName} already exist, rename failed");
  2907. return false;
  2908. }
  2909. else
  2910. {
  2911. File.Move(GenerateSequenceFilePath(SequenceFolder, oldName), GenerateSequenceFilePath(SequenceFolder, newName));
  2912. EV.PostInfoLog(SourceModule, $"sequence {oldName} renamed to {newName}");
  2913. }
  2914. }
  2915. catch (Exception ex)
  2916. {
  2917. LOG.Write(ex);
  2918. EV.PostWarningLog(SourceModule, $"rename {oldName} failed, " + ex.Message);
  2919. return false;
  2920. }
  2921. return true;
  2922. }
  2923. public string GetSequenceFormatXml()
  2924. {
  2925. return GetSequenceConfig("/Aitex/TableSequenceFormat");
  2926. }
  2927. internal bool DeleteSequenceFolder(string folderName)
  2928. {
  2929. try
  2930. {
  2931. Directory.Delete(PathManager.GetRecipeDir() + SequenceFolder + "\\" + folderName, true);
  2932. EV.PostInfoLog(SourceModule, "Folder " + folderName + "deleted");
  2933. }
  2934. catch (Exception ex)
  2935. {
  2936. LOG.Write(ex, "delete sequence folder exception");
  2937. EV.PostWarningLog(SourceModule, $"can not delete folder {folderName}, {ex.Message}");
  2938. return false;
  2939. }
  2940. return true;
  2941. }
  2942. internal bool CreateSequenceFolder(string folderName)
  2943. {
  2944. try
  2945. {
  2946. Directory.CreateDirectory(PathManager.GetRecipeDir() + SequenceFolder + "\\" + folderName);
  2947. EV.PostInfoLog(SourceModule, "Folder " + folderName + "created");
  2948. }
  2949. catch (Exception ex)
  2950. {
  2951. LOG.Write(ex, "sequence folder create exception");
  2952. EV.PostWarningLog(SourceModule, $"can not create folder {folderName}, {ex.Message}");
  2953. return false;
  2954. }
  2955. return true;
  2956. }
  2957. internal bool RenameSequenceFolder(string oldName, string newName)
  2958. {
  2959. try
  2960. {
  2961. string oldPath = PathManager.GetRecipeDir() + SequenceFolder + "\\" + oldName;
  2962. string newPath = PathManager.GetRecipeDir() + SequenceFolder + "\\" + newName;
  2963. Directory.Move(oldPath, newPath);
  2964. EV.PostInfoLog(SourceModule, $"rename folder from {oldName} to {newName}");
  2965. }
  2966. catch (Exception ex)
  2967. {
  2968. LOG.Write(ex, "rename sequence folder failed");
  2969. EV.PostWarningLog(SourceModule, $"can not rename folder {oldName}, {ex.Message}");
  2970. return false;
  2971. }
  2972. return true;
  2973. }
  2974. public string GetXmlSequenceList(string chamberId)
  2975. {
  2976. XmlDocument doc = new XmlDocument();
  2977. DirectoryInfo curFolderInfo = new DirectoryInfo(PathManager.GetRecipeDir() + SequenceFolder + "\\");
  2978. doc.AppendChild(GenerateSequenceList(chamberId, curFolderInfo, doc));
  2979. return doc.OuterXml;
  2980. }
  2981. XmlElement GenerateSequenceList(string chamberId, DirectoryInfo currentDir, XmlDocument doc)
  2982. {
  2983. int trimLength = (PathManager.GetRecipeDir() + SequenceFolder + "\\").Length;
  2984. XmlElement folderEle = doc.CreateElement("Folder");
  2985. folderEle.SetAttribute("Name", currentDir.FullName.Substring(trimLength));
  2986. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  2987. foreach (DirectoryInfo dirInfo in dirInfos)
  2988. {
  2989. folderEle.AppendChild(GenerateSequenceList(chamberId, dirInfo, doc));
  2990. }
  2991. FileInfo[] fileInfos = currentDir.GetFiles("*.seq");
  2992. foreach (FileInfo fileInfo in fileInfos)
  2993. {
  2994. XmlElement fileNd = doc.CreateElement("File");
  2995. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  2996. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  2997. fileNd.SetAttribute("Name", fileStr);
  2998. folderEle.AppendChild(fileNd);
  2999. }
  3000. return folderEle;
  3001. }
  3002. #endregion
  3003. }
  3004. }