RecipeFileManager.cs 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms.VisualStyles;
  6. using System.Xml.Schema;
  7. using System.Xml;
  8. using System.IO;
  9. using Aitex.Core.RT.Log;
  10. using System.Text.RegularExpressions;
  11. using Aitex.Common.Util;
  12. using Aitex.Core.RT.Event;
  13. using Aitex.Core.Util;
  14. using Aitex.Core.Utilities;
  15. using Aitex.Core.WCF;
  16. using MECF.Framework.Common.OperationCenter;
  17. using MECF.Framework.Common.Properties;
  18. using MECF.Framework.Common.RecipeCenter;
  19. using System.Collections.ObjectModel;
  20. using Aitex.Core.RT.SCCore;
  21. using MECF.Framework.Common.DataCenter;
  22. using Microsoft.VisualBasic.FileIO;
  23. using MECF.Framework.Common.CommonData;
  24. namespace Aitex.Core.RT.RecipeCenter
  25. {
  26. public class RecipeFileManager : Singleton<RecipeFileManager>
  27. {
  28. //sequence文件 统一放在 Recipes/Sequence 文件夹下面
  29. public const string SequenceFolder = "Sequence";
  30. public const string SourceModule = "Recipe";
  31. public const string WaferFlowFolder = "WaferFlow";
  32. string _chamberId;
  33. private bool _recipeIsValid;
  34. private List<string> _validationErrors = new List<string>();
  35. private List<string> _validationWarnings = new List<string>();
  36. private Dictionary<int, Dictionary<string, string>> _recipeItems;
  37. IRecipeFileContext _rcpContext;
  38. private ISequenceFileContext _seqContext;
  39. public RecipeFileManager()
  40. {
  41. _chamberId = SC.GetStringValue("System.Recipe.RecipeChamberType");
  42. if (_chamberId == null)
  43. _chamberId = "Track";
  44. }
  45. public void Initialize(IRecipeFileContext context)
  46. {
  47. Initialize(context, null, true);
  48. CheckFile();
  49. }
  50. public void Initialize(IRecipeFileContext context, bool enableService)
  51. {
  52. Initialize(context, null, enableService);
  53. }
  54. public void CheckFile()
  55. {
  56. try
  57. {
  58. if (!SC.ContainsItem("System.EnableCheckRecipe") || !SC.GetValue<bool>("System.EnableCheckRecipe"))
  59. {
  60. return;
  61. }
  62. string recipePath = PathManager.GetRecipeDir() + SC.GetStringValue("System.Recipe.SupportedChamberType") + "\\";
  63. var di = new DirectoryInfo(recipePath); if (!Directory.Exists(recipePath))
  64. {
  65. return;
  66. }
  67. var fis = di.GetFiles("*.rcp", System.IO.SearchOption.TopDirectoryOnly);
  68. if (fis.Length > 0)
  69. {
  70. }
  71. else
  72. {
  73. foreach (var item in di.GetDirectories())
  74. {
  75. var recipeFolderRecipe = item.GetFiles("*.rcp", System.IO.SearchOption.TopDirectoryOnly);
  76. if (recipeFolderRecipe.Length > 0)
  77. {
  78. var defaultFolder = $"{item.FullName}\\default";
  79. if (!Directory.Exists(defaultFolder))
  80. {
  81. Directory.CreateDirectory(defaultFolder);
  82. }
  83. var diDefault = new DirectoryInfo(defaultFolder);
  84. foreach (var errorRecipe in recipeFolderRecipe)
  85. { // 构建目标文件的完整路径
  86. string destinationPath = Path.Combine(defaultFolder, Path.GetFileName(errorRecipe.FullName));
  87. errorRecipe.CopyTo(destinationPath);
  88. errorRecipe.Delete();
  89. }
  90. }
  91. }
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. LOG.Error($"CheckFile:{ex.Message}");
  97. }
  98. }
  99. public void Initialize(IRecipeFileContext rcpContext, ISequenceFileContext seqContext, bool enableService)
  100. {
  101. _rcpContext = rcpContext == null ? new DefaultRecipeFileContext() : rcpContext;
  102. _seqContext = seqContext == null ? new DefaultSequenceFileContext() : seqContext;
  103. CultureSupported.UpdateCoreCultureResource(CultureSupported.English);
  104. if (enableService)
  105. {
  106. Singleton<WcfServiceManager>.Instance.Initialize(new Type[]
  107. {
  108. typeof(RecipeService)
  109. });
  110. }
  111. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), SequenceFolder);
  112. DirectoryInfo di = new DirectoryInfo(dir);
  113. if (!di.Exists)
  114. {
  115. di.Create();
  116. }
  117. }
  118. private void ValidationEventHandler(object sender, ValidationEventArgs e)
  119. {
  120. switch (e.Severity)
  121. {
  122. case XmlSeverityType.Error:
  123. _validationErrors.Add(e.Message);
  124. _recipeIsValid = false;
  125. break;
  126. case XmlSeverityType.Warning:
  127. _validationWarnings.Add(e.Message);
  128. break;
  129. }
  130. }
  131. /// <summary>
  132. /// XML schema checking
  133. /// </summary>
  134. /// <param name="chamId"></param>
  135. /// <param name="recipeName"></param>
  136. /// <param name="recipeContent"></param>
  137. /// <param name="reason"></param>
  138. /// <returns></returns>
  139. public bool ValidateRecipe(string chamberId, string recipeName, string recipeContent, out List<string> reason)
  140. {
  141. try
  142. {
  143. XmlDocument document = new XmlDocument();
  144. document.LoadXml(recipeContent);
  145. MemoryStream schemaStream = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(GetRecipeSchema(chamberId)));
  146. XmlReader xmlSchemaReader = XmlReader.Create(schemaStream);
  147. XmlSchema schema1 = XmlSchema.Read(xmlSchemaReader, ValidationEventHandler);
  148. document.Schemas.Add(schema1);
  149. document.LoadXml(recipeContent);
  150. ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
  151. _recipeIsValid = true;
  152. _validationErrors = new List<string>();
  153. _validationWarnings = new List<string>();
  154. // Validates recipe.
  155. document.Validate(eventHandler);
  156. }
  157. catch (Exception ex)
  158. {
  159. LOG.Write(ex.Message);
  160. _recipeIsValid = false;
  161. }
  162. if (!_recipeIsValid && _validationErrors.Count == 0)
  163. {
  164. _validationErrors.Add(Resources.RecipeFileManager_ValidateRecipe_XMLSchemaValidateFailed);
  165. }
  166. reason = _validationErrors;
  167. return _recipeIsValid;
  168. }
  169. /// <summary>
  170. /// 检查变量ramp rate
  171. /// </summary>
  172. /// <param name="stepNo"></param>
  173. /// <param name="rampEnable"></param>
  174. /// <param name="varName"></param>
  175. /// <param name="rampTime"></param>
  176. /// <param name="maxRampUpRate"></param>
  177. /// <param name="maxRampDownRate"></param>
  178. /// <returns>False:check ok, True: check failed</returns>
  179. public bool CheckRampRate(int stepNo, string rampEnable, string varName, string rampTime, double maxRampUpRate, double maxRampDownRate)
  180. {
  181. try
  182. {
  183. if (stepNo <= 0)
  184. return false;
  185. if (varName == "AZone.Setpoint" || varName == "BZone.Setpoint" || varName == "CZone.Setpoint" || varName == "DZone.Setpoint")
  186. {
  187. string curStepHeatCtrlMode = _recipeItems[stepNo]["Heater.Mode"];
  188. string lastStepHeatCtrlMode = _recipeItems[stepNo - 1]["Heater.Mode"];
  189. if (curStepHeatCtrlMode != lastStepHeatCtrlMode)
  190. return false;
  191. }
  192. bool isRampEnable = bool.Parse(rampEnable);
  193. string[] timeStr = rampTime.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  194. double hh = 0;
  195. double mm = 0;
  196. double ss = 0;
  197. if (timeStr.Length == 3)
  198. {
  199. hh = double.Parse(timeStr[0]);
  200. mm = double.Parse(timeStr[1]);
  201. ss = double.Parse(timeStr[2]);
  202. }
  203. else if (timeStr.Length == 2)
  204. {
  205. mm = double.Parse(timeStr[0]);
  206. ss = double.Parse(timeStr[1]);
  207. }
  208. else if (timeStr.Length == 1)
  209. {
  210. ss = double.Parse(timeStr[0]);
  211. }
  212. double totalTimeSec = hh * 3600 + mm * 60 + ss;
  213. double diff = double.Parse(_recipeItems[stepNo][varName]) - double.Parse(_recipeItems[stepNo - 1][varName]);
  214. if (!isRampEnable || totalTimeSec <= 0)
  215. {
  216. //jump
  217. if (diff != 0) return true;
  218. return false;
  219. }
  220. else
  221. {
  222. double rampRate = diff / totalTimeSec;
  223. if ((rampRate > 0 && rampRate >= maxRampUpRate) ||
  224. (rampRate < 0 && rampRate <= -maxRampDownRate))
  225. return true;
  226. return false;
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. LOG.Write(ex.Message);
  232. return true;
  233. }
  234. }
  235. public bool GetRecipeChecked(string chamberId, string recipeName)
  236. {
  237. string chamberType = chamberId.Split('\\')[0];
  238. string processType = chamberId.Split('\\')[1];
  239. string recipeContent = LoadRecipe(chamberId, recipeName, false);
  240. var xmlRecipe = new XmlDocument();
  241. try
  242. {
  243. if (string.IsNullOrEmpty(recipeContent))
  244. throw new Exception("invalid recipe file.");
  245. xmlRecipe.LoadXml(recipeContent);
  246. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  247. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  248. foreach (var item in nodeSteps)
  249. {
  250. XmlElement step = item as XmlElement;
  251. string strModuleName = step.Attributes["ModuleName"]?.Value;
  252. if (string.IsNullOrEmpty(strModuleName)) continue;
  253. if (!string.IsNullOrEmpty(strModuleName))
  254. {
  255. string[] temp = strModuleName.Split(',')[0].Split(' ');
  256. if (temp.Length > 1)
  257. strModuleName = temp[1];
  258. }
  259. else
  260. continue;
  261. if (ovenModuleName.Contains(strModuleName))
  262. strModuleName = "Oven";
  263. string linkRecipeName = step.Attributes["RecipeName"]?.Value;
  264. if (string.IsNullOrEmpty(linkRecipeName)) continue;
  265. string[] subRecipeNames = linkRecipeName.Split(',');
  266. foreach (var subItem in subRecipeNames)
  267. {
  268. string subRecipeName = string.Empty;
  269. string[] subRecipeNameStrings = subItem.Split(':');
  270. if (subRecipeNameStrings.Length > 1)
  271. {
  272. subRecipeName = subRecipeNameStrings[1];
  273. }
  274. else
  275. {
  276. subRecipeName = subRecipeNameStrings[0];
  277. }
  278. if (!GetRecipeChecked($"{_chamberId}\\{strModuleName}", subRecipeName))
  279. {
  280. return false;
  281. }
  282. }
  283. }
  284. //check system reicpe
  285. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  286. if (!string.IsNullOrEmpty(strSystemReicpeName))
  287. {
  288. if (!GetRecipeChecked($"{_chamberId}\\System", strSystemReicpeName))
  289. {
  290. return false;
  291. }
  292. }
  293. //check pump recipe
  294. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  295. if (!string.IsNullOrEmpty(pumpRecipeName))
  296. {
  297. if (!GetRecipeChecked($"{_chamberId}\\Pump", pumpRecipeName))
  298. {
  299. return false;
  300. }
  301. }
  302. XmlElement nodeData = xmlRecipe.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  303. string checkResult = nodeData.Attributes["CheckResult"].Value;
  304. if (string.IsNullOrEmpty(checkResult))
  305. return false;
  306. else
  307. return true;
  308. }
  309. catch (Exception ex)
  310. {
  311. LOG.Write(ex);
  312. return false;
  313. }
  314. }
  315. public List<RecipeFileNode> GetRecipeByPathFileNodes(string prefix, string recipeName)
  316. {
  317. List<RecipeFileNode> recipeFileNodes = new List<RecipeFileNode>();
  318. return recipeFileNodes;
  319. }
  320. public string LoadRecipeByFullPath(string fullPath)
  321. {
  322. string rcp = string.Empty;
  323. try
  324. {
  325. //_IsURecipe = false;
  326. using (StreamReader fs = new StreamReader(fullPath))
  327. {
  328. rcp = fs.ReadToEnd();
  329. fs.Close();
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. try
  335. {
  336. using (StreamReader fs = new StreamReader(fullPath))
  337. {
  338. rcp = fs.ReadToEnd();
  339. fs.Close();
  340. //_IsURecipe = true;
  341. }
  342. }
  343. catch
  344. {
  345. LOG.Write(ex, $"load recipe file failed, {fullPath}");
  346. rcp = string.Empty;
  347. };
  348. }
  349. return rcp;
  350. }
  351. /// <summary>
  352. /// Check recipe content
  353. /// </summary>
  354. /// <param name="chamId"></param>
  355. /// <param name="recipeContent"></param>
  356. /// <param name="reasons"></param>
  357. /// <returns></returns>
  358. public bool CheckRecipe(string chamberId, string recipeName, out List<string> reasons)
  359. {
  360. reasons = new List<string>();
  361. string chamberType = chamberId.Split('\\')[0];
  362. string processType = chamberId.Split('\\')[1];
  363. string recipeContent = LoadRecipe(chamberId, recipeName, false);
  364. var xmlRecipe = new XmlDocument();
  365. try
  366. {
  367. if (string.IsNullOrEmpty(recipeContent))
  368. throw new Exception("invalid recipe file.");
  369. xmlRecipe.LoadXml(recipeContent);
  370. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  371. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  372. switch (processType)
  373. {
  374. case "WaferFlow":
  375. CheckWaferFlowRecipe(nodeConfig, nodeSteps, out reasons);
  376. break;
  377. case "COT":
  378. CheckSpinRecipe(nodeConfig, nodeSteps, true, out reasons);
  379. break;
  380. case "DEV":
  381. CheckSpinRecipe(nodeConfig, nodeSteps, false, out reasons);
  382. break;
  383. case "ADH":
  384. CheckADHRecipe(nodeSteps, out reasons);
  385. break;
  386. case "Oven":
  387. CheckOvenRecipe(nodeSteps, out reasons);
  388. break;
  389. case "Dummy":
  390. CheckDummyRecipe(nodeSteps, out reasons);
  391. break;
  392. }
  393. }
  394. catch (Exception ex)
  395. {
  396. reasons.Add(ex.Message);
  397. LOG.Write(ex);
  398. return false;
  399. }
  400. XmlElement nodeData = xmlRecipe.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  401. bool bResult = reasons.Count == 0;
  402. if (bResult)
  403. {
  404. nodeData.SetAttribute("CheckResult", "Correct");
  405. }
  406. else
  407. {
  408. nodeData.SetAttribute("CheckResult", "Error");
  409. }
  410. SaveRecipe(chamberId, recipeName, xmlRecipe.OuterXml, false, false);
  411. return bResult;
  412. }
  413. /// <summary>
  414. /// Check recipe content
  415. /// </summary>
  416. /// <param name="chamId"></param>
  417. /// <param name="recipeContent"></param>
  418. /// <param name="reasons"></param>
  419. /// <returns></returns>
  420. public bool CheckRestoreRecipe(string chamberId, string recipeName, out List<string> reasons)
  421. {
  422. reasons = new List<string>();
  423. string chamberType = chamberId.Split('\\')[0];
  424. string processType = chamberId.Split('\\')[1];
  425. string recipeContent = LoadRestoreRecipe(chamberId, recipeName, false);
  426. var xmlRecipe = new XmlDocument();
  427. try
  428. {
  429. if (string.IsNullOrEmpty(recipeContent))
  430. throw new Exception("invalid recipe file.");
  431. xmlRecipe.LoadXml(recipeContent);
  432. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  433. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  434. switch (processType)
  435. {
  436. case "WaferFlow":
  437. CheckWaferFlowRecipe(nodeConfig, nodeSteps, out reasons);
  438. break;
  439. case "COT":
  440. CheckSpinRecipe(nodeConfig, nodeSteps, true, out reasons);
  441. break;
  442. case "DEV":
  443. CheckSpinRecipe(nodeConfig, nodeSteps, false, out reasons);
  444. break;
  445. case "ADH":
  446. CheckADHRecipe(nodeSteps, out reasons);
  447. break;
  448. case "Oven":
  449. CheckOvenRecipe(nodeSteps, out reasons);
  450. break;
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. reasons.Add(ex.Message);
  456. LOG.Write(ex);
  457. return false;
  458. }
  459. XmlElement nodeData = xmlRecipe.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  460. bool bResult = reasons.Count == 0;
  461. if (bResult)
  462. {
  463. nodeData.SetAttribute("CheckResult", "Correct");
  464. }
  465. else
  466. {
  467. nodeData.SetAttribute("CheckResult", "Error");
  468. }
  469. SaveRestoreRecipe(chamberId, recipeName, xmlRecipe.OuterXml, false, false);
  470. return bResult;
  471. }
  472. void CheckWaferFlowRecipe(XmlNode nodeConfig, XmlNodeList nodeSteps, out List<string> reasons)
  473. {
  474. reasons = new List<string>();
  475. if (nodeSteps.Count <= 0)
  476. {
  477. reasons.Add("steps count is 0");
  478. return;
  479. }
  480. if (nodeSteps.Count < 5)
  481. {
  482. reasons.Add("steps count is less than 5");
  483. return;
  484. }
  485. int beginStepIndex = 0;
  486. int endStepIndex = 1;
  487. for (int i = 0; i < nodeSteps.Count; i++)
  488. {
  489. if (nodeSteps[i].Attributes["ModuleName"].Value.Contains("End UNC"))
  490. {
  491. int.TryParse(nodeSteps[i].Attributes["StepNo"].Value, out endStepIndex);
  492. break;
  493. }
  494. }
  495. endStepIndex--;
  496. if (endStepIndex <= 0)
  497. {
  498. reasons.Add($"Current recipe muste contains end step");
  499. return;
  500. }
  501. string key = "System.SetUp.BlockNumber";
  502. string numberVlaue = SC.GetStringValue(key);
  503. var numberOfBlock = int.Parse((numberVlaue.Replace("Block", "")));
  504. for (int i = beginStepIndex; i <= endStepIndex; i++)
  505. {
  506. int stepNo = i + 1;
  507. string strModuleName = nodeSteps[i].Attributes["ModuleName"].Value;
  508. if (!string.IsNullOrEmpty(strModuleName))
  509. {
  510. //check module name is changed
  511. var modules = strModuleName.Split(',');
  512. strModuleName = modules[0].Split(' ')[1];
  513. foreach (var item in modules)
  514. {
  515. string blockIndex = item.Split(' ')[0].Split('-')[0];
  516. if (blockIndex == "1")
  517. continue;
  518. if (numberOfBlock == 3 && blockIndex == "3")
  519. blockIndex = "4";
  520. string moduleIndex = item.Split(' ')[0].Split('-')[1];
  521. string moduleKey = $"System.SetUp.Block{blockIndex}.{moduleIndex}.Name";
  522. var value = SC.GetStringValue(moduleKey);
  523. if (strModuleName != value?.ToString())
  524. {
  525. reasons.Add($"Step{stepNo} module name has been changed to {value}");
  526. }
  527. }
  528. }
  529. else
  530. {
  531. reasons.Add($"Step{stepNo} module name is empty");
  532. return;
  533. }
  534. if (i == 0)//check step1
  535. {
  536. string moduleName = "UNC";
  537. if (!strModuleName.Equals(moduleName))
  538. {
  539. reasons.Add($"Step{stepNo} module muste be {moduleName}");
  540. }
  541. continue;
  542. }
  543. if (i == 1)//check step2
  544. {
  545. string moduleName = "TRS,TCP";
  546. if (!moduleName.Contains(strModuleName))
  547. {
  548. reasons.Add($"Step{stepNo} module muste be {moduleName} module");
  549. }
  550. }
  551. if (i == endStepIndex - 1)//check last second step
  552. {
  553. string moduleName = "TRS,TCP";
  554. if (!moduleName.Contains(strModuleName))
  555. {
  556. reasons.Add($"Step{stepNo} module muste be {moduleName} module");
  557. }
  558. if (strModuleName == nodeSteps[1].Attributes["ModuleName"].Value)
  559. {
  560. reasons.Add($"Step{stepNo} module muste be different with step1 module");
  561. }
  562. }
  563. if (i == endStepIndex)//check last step
  564. {
  565. string moduleName = "UNC";
  566. if (!strModuleName.Equals(moduleName))
  567. {
  568. reasons.Add($"Step{stepNo} module muste be {moduleName}");
  569. }
  570. continue;
  571. }
  572. //check linked recipe
  573. string unCheckModuleName = "SHU,TRS,SUB,EIS";
  574. if (!unCheckModuleName.Contains(strModuleName))
  575. {
  576. string ovenModuleName = "CPL,HHP,LHP,CHP,TCP";
  577. if (ovenModuleName.Contains(strModuleName))
  578. strModuleName = "Oven";
  579. string linkRecipeName = nodeSteps[i].Attributes["RecipeName"].Value;
  580. if (string.IsNullOrEmpty(linkRecipeName))
  581. {
  582. reasons.Add($"Step{stepNo} link recipe is empty.");
  583. }
  584. else
  585. {
  586. string[] subRecipeNames = linkRecipeName.Split(',');
  587. foreach (var item in subRecipeNames)
  588. {
  589. string subRecipeName = string.Empty;
  590. string[] subRecipeNameStrings = item.Split(':');
  591. if (subRecipeNameStrings.Length > 1)
  592. {
  593. subRecipeName = subRecipeNameStrings[1];
  594. }
  595. else
  596. {
  597. subRecipeName = subRecipeNameStrings[0];
  598. }
  599. if (!CheckRecipe($"{_chamberId}\\{strModuleName}", subRecipeName, out List<string> subReasons))
  600. {
  601. reasons.Add($"Step{stepNo} linked recipe check fail.");
  602. }
  603. }
  604. }
  605. }
  606. }
  607. //check system reicpe
  608. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  609. if (!string.IsNullOrEmpty(strSystemReicpeName))
  610. {
  611. if (!CheckRecipe($"{_chamberId}\\System", strSystemReicpeName, out List<string> subReasons))
  612. {
  613. reasons.Add($"Linked system recipe check fail.");
  614. }
  615. }
  616. else
  617. {
  618. reasons.Add($"Must link system recipe.");
  619. }
  620. }
  621. void CheckSpinRecipe(XmlNode nodeConfig, XmlNodeList nodeSteps, bool checkPumpRecipe, out List<string> reasons)
  622. {
  623. reasons = new List<string>();
  624. if (nodeSteps.Count <= 0)
  625. {
  626. reasons.Add("steps count is 0.");
  627. return;
  628. }
  629. List<int> loopStartStepsNo = new List<int>();
  630. List<int> loopEndStepsNo = new List<int>();
  631. bool hasDispense = false;
  632. List<bool> arm1HasMove = new List<bool>();
  633. List<bool> arm2HasMove = new List<bool>();
  634. for (int i = 0; i < nodeSteps.Count; i++)
  635. {
  636. int stepNo = i + 1;
  637. if (nodeSteps[i].Attributes["Loop"].Value.Contains("Start"))
  638. {
  639. loopStartStepsNo.Add(stepNo);
  640. }
  641. if (nodeSteps[i].Attributes["Loop"].Value.Contains("End"))
  642. {
  643. loopEndStepsNo.Add(stepNo);
  644. }
  645. string strDispense = nodeSteps[i].Attributes["Dispense"].Value;
  646. if (strDispense.Contains("Resist"))
  647. {
  648. hasDispense = true;
  649. }
  650. //check dispens
  651. if (!string.IsNullOrEmpty(strDispense))
  652. {
  653. bool bDispenseHasError = false;
  654. string[] strDispenseValues = strDispense.Split(',');
  655. string strFirstDispenseValue = strDispenseValues[0];
  656. foreach (var item in strDispenseValues)
  657. {
  658. if (strFirstDispenseValue.Split(' ')[0] != item.Split(' ')[0])
  659. bDispenseHasError = true;
  660. }
  661. if (bDispenseHasError)
  662. reasons.Add($"Step{stepNo} dispense must select same module.");
  663. }
  664. if (i > 0)
  665. {
  666. string arm1CurrentPosition = nodeSteps[i].Attributes["Arm1"].Value.Split(',')[2].Split(':')[1];
  667. string arm1PreviousPosition = nodeSteps[i - 1].Attributes["Arm1"].Value.Split(',')[2].Split(':')[1];
  668. if (!string.IsNullOrEmpty(arm1CurrentPosition))
  669. {
  670. if (arm1CurrentPosition.Equals(arm1PreviousPosition))
  671. arm1HasMove.Add(false);
  672. else
  673. arm1HasMove.Add(true);
  674. }
  675. string arm2CurrentPosition = nodeSteps[i].Attributes["Arm2"].Value.Split(',')[2].Split(':')[1];
  676. string arm2PreviousPosition = nodeSteps[i - 1].Attributes["Arm2"].Value.Split(',')[2].Split(':')[1];
  677. if (!string.IsNullOrEmpty(arm2CurrentPosition))
  678. {
  679. if (arm2CurrentPosition.Equals(arm2PreviousPosition))
  680. arm2HasMove.Add(false);
  681. else
  682. arm2HasMove.Add(true);
  683. }
  684. }
  685. }
  686. //check loop
  687. if (loopStartStepsNo.Count != loopEndStepsNo.Count) //判断个数
  688. {
  689. reasons.Add("loop set is incorrect");
  690. }
  691. //check pump recipe
  692. if (checkPumpRecipe && hasDispense)
  693. {
  694. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  695. if (string.IsNullOrEmpty(pumpRecipeName))
  696. reasons.Add("pump recipe is null");
  697. else
  698. {
  699. if (!CheckRecipe($"{_chamberId}\\Pump", pumpRecipeName, out List<string> subReasons))
  700. {
  701. reasons.Add($"Linked pump recipe check fail.");
  702. }
  703. }
  704. }
  705. //check arm move
  706. for (int i = 0; i < arm1HasMove.Count; i++)
  707. {
  708. if (arm1HasMove[i] && arm2HasMove[i])//同时移动
  709. reasons.Add($"step{i + 2} arm1 and arm2 move at the same time");
  710. }
  711. }
  712. void CheckADHRecipe(XmlNodeList nodeSteps, out List<string> reasons)
  713. {
  714. reasons = new List<string>();
  715. if (nodeSteps.Count <= 0)
  716. {
  717. reasons.Add("steps count is 0.");
  718. return;
  719. }
  720. for (int i = 0; i < nodeSteps.Count; i++)
  721. {
  722. int stepNo = i + 1;
  723. //check dispense
  724. if (!nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Process") && !string.IsNullOrEmpty(nodeSteps[i].Attributes["Dispense"].Value))
  725. {
  726. reasons.Add($"Step{stepNo} only position is process can select dispense.");
  727. }
  728. //check plate temp
  729. if (nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Process") && string.IsNullOrEmpty(nodeSteps[i].Attributes["PlateTemp"].Value))
  730. {
  731. reasons.Add($"Step{stepNo} must set plate temp.");
  732. }
  733. //check alrm
  734. double.TryParse(nodeSteps[i].Attributes["AlarmMax"].Value, out double alarmMax);
  735. double.TryParse(nodeSteps[i].Attributes["AlarmMin"].Value, out double alarmMin);
  736. double.TryParse(nodeSteps[i].Attributes["WarnMax"].Value, out double warnMax);
  737. double.TryParse(nodeSteps[i].Attributes["WarnMin"].Value, out double warnMin);
  738. bool bRightRange = false;
  739. if (alarmMax == 0 && alarmMin == 0 && warnMax == 0 && warnMin == 0) continue;
  740. if (alarmMax == 0 && alarmMin == 0)
  741. {
  742. bRightRange = warnMax > warnMin;
  743. if (!bRightRange)
  744. {
  745. reasons.Add($"Step{stepNo} warnMax>warnMin?");
  746. }
  747. }
  748. else if (warnMax == 0 && warnMax == 0)
  749. {
  750. bRightRange = alarmMax > alarmMin;
  751. if (!bRightRange)
  752. {
  753. reasons.Add($"Step{stepNo} alarmMax>alarmMin?");
  754. }
  755. }
  756. else
  757. {
  758. bRightRange = alarmMax > warnMax && warnMax > warnMin && warnMin > alarmMin;
  759. if (!bRightRange)
  760. {
  761. reasons.Add($"Step{stepNo} alarmMax>warnMax>warnMin>alarmMin?");
  762. }
  763. }
  764. }
  765. }
  766. void CheckOvenRecipe(XmlNodeList nodeSteps, out List<string> reasons)
  767. {
  768. reasons = new List<string>();
  769. if (nodeSteps.Count <= 0)
  770. {
  771. reasons.Add("steps count is 0.");
  772. return;
  773. }
  774. for (int i = 0; i < nodeSteps.Count; i++)
  775. {
  776. int stepNo = i + 1;
  777. //check plate temp
  778. if (nodeSteps[i].Attributes["ProcessPosition"].Value.Equals("Heat") && string.IsNullOrEmpty(nodeSteps[i].Attributes["PlateTemp"].Value))
  779. {
  780. reasons.Add($"Step{stepNo} must set plate temp.");
  781. }
  782. //check alrm
  783. double.TryParse(nodeSteps[i].Attributes["AlarmMax"].Value, out double alarmMax);
  784. double.TryParse(nodeSteps[i].Attributes["AlarmMin"].Value, out double alarmMin);
  785. double.TryParse(nodeSteps[i].Attributes["WarnMax"].Value, out double warnMax);
  786. double.TryParse(nodeSteps[i].Attributes["WarnMin"].Value, out double warnMin);
  787. bool bRightRange = false;
  788. if (alarmMax == 0 && alarmMin == 0 && warnMax == 0 && warnMin == 0) continue;
  789. if (alarmMax == 0 && alarmMin == 0)
  790. {
  791. bRightRange = warnMax > warnMin;
  792. if (!bRightRange)
  793. {
  794. reasons.Add($"Step{stepNo} warnMax>warnMin?");
  795. }
  796. }
  797. else if (warnMax == 0 && warnMax == 0)
  798. {
  799. bRightRange = alarmMax > alarmMin;
  800. if (!bRightRange)
  801. {
  802. reasons.Add($"Step{stepNo} alarmMax>alarmMin?");
  803. }
  804. }
  805. else
  806. {
  807. bRightRange = alarmMax > warnMax && warnMax > warnMin && warnMin > alarmMin;
  808. if (!bRightRange)
  809. {
  810. reasons.Add($"Step{stepNo} alarmMax>warnMax>warnMin>alarmMin?");
  811. }
  812. }
  813. }
  814. }
  815. void CheckDummyRecipe(XmlNodeList nodeSteps, out List<string> reasons)
  816. {
  817. reasons = new List<string>();
  818. if (nodeSteps.Count <= 0)
  819. {
  820. reasons.Add("steps count is 0.");
  821. return;
  822. }
  823. int enableItemCount = 0;
  824. for (int i = 0; i < nodeSteps.Count; i++)
  825. {
  826. int stepNo = i + 1;
  827. bool IsEnable = false;
  828. bool.TryParse(nodeSteps[i].Attributes["IsEnable"].Value, out IsEnable);
  829. if (IsEnable)//有效才检查
  830. {
  831. enableItemCount++;//有效Item加1
  832. //check item invalid
  833. string strRegularSequence = nodeSteps[i].Attributes["RegularSequence"]?.Value;
  834. if (string.IsNullOrEmpty(strRegularSequence))
  835. reasons.Add($"Step{stepNo} RegularSequence is null");
  836. string strWaferCount = nodeSteps[i].Attributes["WaferCount"]?.Value;
  837. string strRegularTime = nodeSteps[i].Attributes["RegularTime"]?.Value;
  838. if (string.IsNullOrEmpty(strWaferCount) && string.IsNullOrEmpty(strRegularTime))
  839. reasons.Add($"Step{stepNo} WaferCount and RegularTime is null");
  840. }
  841. }
  842. //check enbabled item count
  843. if (enableItemCount <= 0)
  844. {
  845. reasons.Add("invalaied item count is 0.");
  846. return;
  847. }
  848. }
  849. /// <summary>
  850. /// This method will be invoked by two places:
  851. /// (1) Load a recipe from server to GUI for editing (do not need validation when loading, do validation when saving);
  852. /// (2) Load a recipe from recipe engine to run process(always do a validation before run recipe);
  853. /// </summary>
  854. /// <param name="recipeName"></param>
  855. /// <param name="needValidation">indicate whether a recipe format validation is needed or not</param>
  856. /// <returns></returns>
  857. public string LoadRecipe(string chamberId, string recipeName, bool needValidation)
  858. {
  859. string rcp = string.Empty;
  860. try
  861. {
  862. using (StreamReader fs = new StreamReader(GenerateRecipeFilePath(chamberId, recipeName)))
  863. {
  864. rcp = fs.ReadToEnd();
  865. fs.Close();
  866. }
  867. //if (needValidation)
  868. //{
  869. // List<string> reason;
  870. // if (!ValidateRecipe(chamberId, recipeName, rcp, out reason))
  871. // {
  872. // rcp = string.Empty;
  873. // LOG.Write("校验recipe file 出错, " + string.Join(",", reason.ToArray()));
  874. // }
  875. //}
  876. }
  877. catch (Exception ex)
  878. {
  879. LOG.Write(ex, $"load recipe file failed, {recipeName}");
  880. rcp = string.Empty;
  881. }
  882. return rcp;
  883. }
  884. /// <summary>
  885. /// Get recipe list
  886. /// </summary>
  887. /// <param name="chamId"></param>
  888. /// <param name="includingUsedRecipe"></param>
  889. /// <returns></returns>
  890. public IEnumerable<string> GetRecipes(string chamberId, bool includingUsedRecipe)
  891. {
  892. return _rcpContext.GetRecipes(chamberId, includingUsedRecipe);
  893. }
  894. /// <summary>
  895. /// Get recipe list in xml format
  896. /// </summary>
  897. /// <param name="chamId"></param>
  898. /// <param name="includingUsedRecipe"></param>
  899. /// <returns></returns>
  900. public string GetXmlRecipeList(string chamberId, bool includingUsedRecipe)
  901. {
  902. XmlDocument doc = new XmlDocument();
  903. var baseFolderPath = getRecipeDirPath(chamberId);
  904. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  905. doc.AppendChild(GenerateRecipeList(chamberId, curFolderInfo, doc, includingUsedRecipe));
  906. return doc.OuterXml;
  907. }
  908. public void SaveRecipeHistory(string chamberId, string recipeName, string recipeContent, bool needSaveAs = true)
  909. {
  910. try
  911. {
  912. if (!string.IsNullOrEmpty(recipeName) && needSaveAs)
  913. {
  914. string newRecipeName = string.Format("HistoryRecipe\\{0}\\{1}", DateTime.Now.ToString("yyyyMM"), recipeName);
  915. SaveRecipe(chamberId, newRecipeName, recipeContent, true, false);
  916. LOG.Write(string.Format("{0}通知TM保存工艺程序{1}", chamberId, recipeName));
  917. }
  918. }
  919. catch (Exception ex)
  920. {
  921. LOG.Write(ex, string.Format("保存{0}工艺程序{1}发生错误", chamberId, recipeName));
  922. }
  923. }
  924. /// <summary>
  925. /// generate recipe list information in current directory
  926. /// </summary>
  927. /// <param name="chamId"></param>
  928. /// <param name="currentDir"></param>
  929. /// <param name="doc"></param>
  930. /// <returns></returns>
  931. XmlElement GenerateRecipeList(string chamberId, DirectoryInfo currentDir, XmlDocument doc, bool includingUsedRecipe)
  932. {
  933. int trimLength = getRecipeDirPath(chamberId).Length;
  934. XmlElement folderEle = doc.CreateElement("Folder");
  935. folderEle.SetAttribute("Name", currentDir.FullName.Substring(trimLength));
  936. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  937. foreach (DirectoryInfo dirInfo in dirInfos)
  938. {
  939. if (!includingUsedRecipe && dirInfo.Name == "HistoryRecipe")
  940. continue;
  941. folderEle.AppendChild(GenerateRecipeList(chamberId, dirInfo, doc, includingUsedRecipe));
  942. }
  943. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  944. foreach (FileInfo fileInfo in fileInfos)
  945. {
  946. XmlElement fileNd = doc.CreateElement("File");
  947. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  948. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  949. fileNd.SetAttribute("Name", fileStr);
  950. folderEle.AppendChild(fileNd);
  951. }
  952. return folderEle;
  953. }
  954. XmlElement GeneratelRestoreRecipeList(string chamberId, DirectoryInfo currentDir, XmlDocument doc, bool includingUsedRecipe)
  955. {
  956. int trimLength = getRecipeBackupDirPath(chamberId).Length;
  957. XmlElement folderEle = doc.CreateElement("Folder");
  958. var name = currentDir.FullName.Substring(trimLength);
  959. folderEle.SetAttribute("Name", name);
  960. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  961. foreach (DirectoryInfo dirInfo in dirInfos)
  962. {
  963. if (!includingUsedRecipe && dirInfo.Name == "HistoryRecipe")
  964. continue;
  965. folderEle.AppendChild(GeneratelRestoreRecipeList(chamberId, dirInfo, doc, includingUsedRecipe));
  966. }
  967. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  968. foreach (FileInfo fileInfo in fileInfos)
  969. {
  970. XmlElement fileNd = doc.CreateElement("File");
  971. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  972. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  973. fileNd.SetAttribute("Name", fileStr);
  974. folderEle.AppendChild(fileNd);
  975. }
  976. return folderEle;
  977. }
  978. /// <summary>
  979. /// Delete a recipe by recipe name
  980. /// </summary>
  981. /// <param name="chamId"></param>
  982. /// <param name="recipeName"></param>
  983. /// <returns></returns>
  984. public bool DeleteRecipe(string chamberId, string recipeName)
  985. {
  986. try
  987. {
  988. //File.Delete(GenerateRecipeFilePath(chamberId, recipeName));
  989. FileSystem.DeleteFile(GenerateRecipeFilePath(chamberId, recipeName), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
  990. EventInfo(string.Format(Resources.RecipeFileManager_DeleteRecipe_RecipeFile0DeleteSucceeded, recipeName));
  991. }
  992. catch (Exception ex)
  993. {
  994. LOG.Write(ex, "删除recipe file 出错");
  995. EventWarning(string.Format(Resources.RecipeFileManager_DeleteRecipe_RecipeFile0DeleteFailed, recipeName));
  996. return false;
  997. }
  998. return true;
  999. }
  1000. /// <summary>
  1001. /// Rename recipe
  1002. /// </summary>
  1003. /// <param name="chamId"></param>
  1004. /// <param name="oldName"></param>
  1005. /// <param name="newName"></param>
  1006. /// <returns></returns>
  1007. public bool RenameRecipe(string chamId, string oldName, string newName)
  1008. {
  1009. try
  1010. {
  1011. if (File.Exists(GenerateRecipeFilePath(chamId, newName)))
  1012. {
  1013. EventWarning(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0FileExisted, oldName));
  1014. return false;
  1015. }
  1016. else
  1017. {
  1018. File.Move(GenerateRecipeFilePath(chamId, oldName), GenerateRecipeFilePath(chamId, newName));
  1019. EventInfo(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0Renamed, oldName, newName));
  1020. }
  1021. }
  1022. catch (Exception ex)
  1023. {
  1024. LOG.Write(ex, "重命名recipe file 出错");
  1025. EventWarning(string.Format(Resources.RecipeFileManager_RenameRecipe_RecipeFile0RenameFailed, oldName, newName));
  1026. return false;
  1027. }
  1028. return true;
  1029. }
  1030. private static string ovenModuleName = "CPL,HHP,LHP,CHP,TCP";
  1031. private string[] ovenModuleNames = ovenModuleName.Split(',');
  1032. private void UpdateCheckResult(string recipeName)
  1033. {
  1034. var xmlRecipe = new XmlDocument();
  1035. using (StreamReader fs = new StreamReader(recipeName))
  1036. {
  1037. string recipeContent = fs.ReadToEnd();
  1038. fs.Close();
  1039. xmlRecipe.LoadXml(recipeContent);
  1040. }
  1041. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData")[0];
  1042. nodeConfig.Attributes["CheckResult"].Value = string.Empty;
  1043. XmlTextWriter writer = new XmlTextWriter(recipeName, Encoding.UTF8);
  1044. writer.Formatting = Formatting.Indented;
  1045. xmlRecipe.Save(writer);
  1046. writer.Close();
  1047. }
  1048. public bool BackupRecipe(string fileOriginalPath, string fileDestinationPath, bool isSaveLinkRecipe, List<string> recipeNames)
  1049. {
  1050. try
  1051. {
  1052. string filePath = getRecipeBackupDirPath(fileOriginalPath);
  1053. foreach (var item in recipeNames)
  1054. {
  1055. string sourceFilePath = GenerateRecipeFilePath(fileOriginalPath, item);
  1056. string destFilePath = GenerateBackupRecipeFilePath(fileDestinationPath, item);
  1057. if (File.Exists(sourceFilePath))
  1058. {
  1059. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  1060. if (!di.Exists) di.Create();
  1061. File.Copy(sourceFilePath, destFilePath, true);
  1062. UpdateCheckResult(destFilePath);
  1063. }
  1064. if (isSaveLinkRecipe)
  1065. {
  1066. string recipeContent = LoadRecipe(fileOriginalPath, item, false);
  1067. var xmlRecipe = new XmlDocument();
  1068. try
  1069. {
  1070. string chamberType = fileOriginalPath.Split('\\')[0];
  1071. string processType = fileOriginalPath.Split('\\')[1];
  1072. if (string.IsNullOrEmpty(recipeContent))
  1073. continue;
  1074. xmlRecipe.LoadXml(recipeContent);
  1075. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  1076. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1077. switch (processType)
  1078. {
  1079. case "WaferFlow":
  1080. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  1081. if (!string.IsNullOrEmpty(strSystemReicpeName))
  1082. {
  1083. if (CheckRecipe($"{_chamberId}\\System", strSystemReicpeName, out List<string> subReasons))
  1084. {
  1085. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\System", strSystemReicpeName);
  1086. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\System", strSystemReicpeName);
  1087. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1088. if (!di.Exists) di.Create();
  1089. File.Copy(subSourceFilePath, subDestFilePath, true);
  1090. UpdateCheckResult(subDestFilePath);
  1091. }
  1092. }
  1093. foreach (var step in nodeSteps)
  1094. {
  1095. XmlElement nodestep = step as XmlElement;
  1096. string strModuleName = nodestep.Attributes["ModuleName"]?.Value;
  1097. if (string.IsNullOrEmpty(strModuleName))
  1098. { continue; }
  1099. else
  1100. {
  1101. string[] temp = strModuleName.Split(',')[0].Split(' ');
  1102. if (temp.Length > 1)
  1103. strModuleName = temp[1];
  1104. }
  1105. var linkRecipeName = nodestep.Attributes["RecipeName"].Value;
  1106. if (!string.IsNullOrEmpty(linkRecipeName))
  1107. {
  1108. string[] subRecipeNames = linkRecipeName.Split(',');
  1109. foreach (var subitem in subRecipeNames)
  1110. {
  1111. string subRecipeName = string.Empty;
  1112. string[] subRecipeNameStrings = subitem.Split(':');
  1113. if (subRecipeNameStrings.Length > 1)
  1114. {
  1115. subRecipeName = subRecipeNameStrings[1];
  1116. }
  1117. else
  1118. {
  1119. subRecipeName = subRecipeNameStrings[0];
  1120. }
  1121. if (ovenModuleName.Contains(strModuleName))
  1122. {
  1123. strModuleName = "Oven";
  1124. }
  1125. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\{strModuleName}", subRecipeName);
  1126. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\{strModuleName}", subRecipeName);
  1127. if (File.Exists(subSourceFilePath))
  1128. {
  1129. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1130. if (!di.Exists) di.Create();
  1131. File.Copy(subSourceFilePath, subDestFilePath, true);
  1132. UpdateCheckResult(subDestFilePath);
  1133. }
  1134. if (strModuleName == "COT")
  1135. {
  1136. string subCotPath = GenerateRecipeFilePath($"{_chamberId}\\{strModuleName}", subRecipeName);
  1137. var subXmlRecipe = new XmlDocument();
  1138. string subRecipeContent = LoadRecipe($"{_chamberId}\\{strModuleName}", subRecipeName, false);
  1139. if (string.IsNullOrEmpty(subRecipeContent))
  1140. continue;
  1141. subXmlRecipe.LoadXml(subRecipeContent);
  1142. XmlNode subNodeConfig = subXmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1143. string subPumpRecipeName = subNodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1144. if (!string.IsNullOrEmpty(subPumpRecipeName))
  1145. {
  1146. string subPumpSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", subPumpRecipeName);
  1147. string subPumpDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", subPumpRecipeName);
  1148. if (File.Exists(subPumpSourceFilePath))
  1149. {
  1150. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subPumpDestFilePath));
  1151. if (!di.Exists) di.Create();
  1152. File.Copy(subPumpSourceFilePath, subPumpDestFilePath, true);
  1153. UpdateCheckResult(subPumpDestFilePath);
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. break;
  1161. case "COT":
  1162. case "DEV":
  1163. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1164. if (!string.IsNullOrEmpty(pumpRecipeName))
  1165. {
  1166. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipeName);
  1167. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", pumpRecipeName);
  1168. if (File.Exists(subSourceFilePath))
  1169. {
  1170. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1171. if (!di.Exists) di.Create();
  1172. File.Copy(subSourceFilePath, subDestFilePath, true);
  1173. UpdateCheckResult(subDestFilePath);
  1174. }
  1175. }
  1176. break;
  1177. case "Dummy":
  1178. foreach (var step in nodeSteps)
  1179. {
  1180. XmlElement nodestep = step as XmlElement;
  1181. string regularSequence = nodestep.Attributes["RegularSequence"]?.Value;
  1182. string preSequence = nodestep.Attributes["PreSequence"]?.Value;
  1183. if (!string.IsNullOrEmpty(regularSequence))
  1184. {
  1185. string[] regularSequences = regularSequence.Split(';');
  1186. foreach (var subItem in regularSequences)
  1187. {
  1188. if (string.IsNullOrEmpty(subItem)) continue;
  1189. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1190. if (!string.IsNullOrEmpty(pumpRecipe))
  1191. {
  1192. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipe);
  1193. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", pumpRecipe);
  1194. if (File.Exists(subSourceFilePath))
  1195. {
  1196. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1197. if (!di.Exists) di.Create();
  1198. File.Copy(subSourceFilePath, subDestFilePath, true);
  1199. UpdateCheckResult(subDestFilePath);
  1200. }
  1201. }
  1202. }
  1203. }
  1204. if (!string.IsNullOrEmpty(preSequence))
  1205. {
  1206. string[] preSequences = preSequence.Split(';');
  1207. foreach (var subItem in preSequences)
  1208. {
  1209. if (string.IsNullOrEmpty(subItem)) continue;
  1210. var pumpRecipe = GetKeyValue(item, "PumpRecipe");
  1211. if (!string.IsNullOrEmpty(pumpRecipe))
  1212. {
  1213. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipe);
  1214. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", pumpRecipe);
  1215. if (File.Exists(subSourceFilePath))
  1216. {
  1217. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1218. if (!di.Exists) di.Create();
  1219. File.Copy(subSourceFilePath, subDestFilePath, true);
  1220. UpdateCheckResult(subDestFilePath);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. }
  1226. break;
  1227. case "Wash":
  1228. foreach (var step in nodeSteps)
  1229. {
  1230. XmlElement nodestep = step as XmlElement;
  1231. string sequence = nodestep.Attributes["Sequence"]?.Value;
  1232. if (string.IsNullOrEmpty(sequence))
  1233. { continue; }
  1234. var subSequences = sequence.Split(';');
  1235. foreach (var subSeq in subSequences)
  1236. {
  1237. if (string.IsNullOrEmpty(subSeq))
  1238. {
  1239. continue;
  1240. }
  1241. var pumpRecipe = GetKeyValue(subSeq, "PumpRecipe");
  1242. if (!string.IsNullOrEmpty(subSeq))
  1243. {
  1244. string subSourceFilePath = GenerateRecipeFilePath($"{_chamberId}\\Pump", pumpRecipe);
  1245. string subDestFilePath = GenerateBackupRecipeFilePath($"{fileDestinationPath.Split('\\')[0]}\\Pump", pumpRecipe);
  1246. if (File.Exists(subSourceFilePath))
  1247. {
  1248. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1249. if (!di.Exists) di.Create();
  1250. File.Copy(subSourceFilePath, subDestFilePath, true);
  1251. UpdateCheckResult(subDestFilePath);
  1252. }
  1253. }
  1254. }
  1255. }
  1256. break;
  1257. case "ADH":
  1258. case "Oven":
  1259. break;
  1260. }
  1261. }
  1262. catch (Exception ex)
  1263. {
  1264. LOG.Write(ex);
  1265. continue;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. catch (Exception ex)
  1271. {
  1272. LOG.Write(ex, "Backup Recipe file error");
  1273. }
  1274. return true;
  1275. }
  1276. public bool CheckBackRecipeIsLinkRecipe(string fileOriginalPath, List<string> recipeNames)
  1277. {
  1278. string chamberType = fileOriginalPath.Split('\\')[0];
  1279. string processType = fileOriginalPath.Split('\\')[1];
  1280. foreach (var item in recipeNames)
  1281. {
  1282. string recipeContent = LoadRecipe(fileOriginalPath, item, false);
  1283. var xmlRecipe = new XmlDocument();
  1284. try
  1285. {
  1286. if (string.IsNullOrEmpty(recipeContent))
  1287. continue;
  1288. xmlRecipe.LoadXml(recipeContent);
  1289. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  1290. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1291. switch (processType)
  1292. {
  1293. case "WaferFlow":
  1294. foreach (var step in nodeSteps)
  1295. {
  1296. XmlElement nodestep = step as XmlElement;
  1297. string strModuleName = nodestep.Attributes["ModuleName"]?.Value;
  1298. if (string.IsNullOrEmpty(strModuleName))
  1299. { continue; }
  1300. var linkRecipeName = nodestep.Attributes["RecipeName"].Value;
  1301. if (string.IsNullOrEmpty(linkRecipeName))
  1302. { continue; }
  1303. else
  1304. {
  1305. return true;
  1306. }
  1307. }
  1308. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  1309. if (!string.IsNullOrEmpty(strSystemReicpeName))
  1310. {
  1311. return true;
  1312. }
  1313. break;
  1314. case "COT":
  1315. case "DEV":
  1316. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1317. if (!string.IsNullOrEmpty(pumpRecipeName))
  1318. {
  1319. return true;
  1320. }
  1321. break;
  1322. case "Dummy":
  1323. foreach (var step in nodeSteps)
  1324. {
  1325. XmlElement nodestep = step as XmlElement;
  1326. string regularSequence = nodestep.Attributes["RegularSequence"]?.Value;
  1327. string preSequence = nodestep.Attributes["PreSequence"]?.Value;
  1328. if (!string.IsNullOrEmpty(regularSequence))
  1329. {
  1330. string[] regularSequences = regularSequence.Split(';');
  1331. foreach (var subItem in regularSequences)
  1332. {
  1333. if (string.IsNullOrEmpty(subItem)) continue;
  1334. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1335. if (!string.IsNullOrEmpty(pumpRecipe)) return true;
  1336. }
  1337. }
  1338. if (!string.IsNullOrEmpty(preSequence))
  1339. {
  1340. string[] preSequences = preSequence.Split(';');
  1341. foreach (var subItem in preSequences)
  1342. {
  1343. if (string.IsNullOrEmpty(subItem)) continue;
  1344. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1345. if (!string.IsNullOrEmpty(pumpRecipe)) return true;
  1346. }
  1347. }
  1348. }
  1349. break;
  1350. case "Wash":
  1351. foreach (var step in nodeSteps)
  1352. {
  1353. XmlElement nodestep = step as XmlElement;
  1354. string sequence = nodestep.Attributes["Sequence"]?.Value;
  1355. if (string.IsNullOrEmpty(sequence))
  1356. { continue; }
  1357. var subSequences = sequence.Split(';');
  1358. foreach (var subSeq in subSequences)
  1359. {
  1360. if (string.IsNullOrEmpty(subSeq))
  1361. {
  1362. continue;
  1363. }
  1364. var pumpRecipe = GetKeyValue(subSeq, "PumpRecipe");
  1365. if (!string.IsNullOrEmpty(subSeq))
  1366. {
  1367. return true;
  1368. }
  1369. }
  1370. }
  1371. break;
  1372. case "ADH":
  1373. case "Oven":
  1374. break;
  1375. }
  1376. }
  1377. catch (Exception ex)
  1378. {
  1379. LOG.Write(ex);
  1380. return false;
  1381. }
  1382. }
  1383. return false;
  1384. }
  1385. private static string GetKeyValue(string args, string name)
  1386. {
  1387. string indexString = $"{name}=";
  1388. string subString = args.Substring(args.IndexOf(indexString) + indexString.Length);
  1389. int endIndex = subString.IndexOf(',');
  1390. if (endIndex > 0)
  1391. return subString.Substring(0, endIndex);
  1392. else
  1393. return subString;
  1394. }
  1395. public string GetXmlRestoreRecipeList(string chamberId, bool includingUsedRecipe)
  1396. {
  1397. XmlDocument doc = new XmlDocument();
  1398. var baseFolderPath = getRecipeBackupDirPath(chamberId);
  1399. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  1400. doc.AppendChild(GeneratelRestoreRecipeList(chamberId, curFolderInfo, doc, includingUsedRecipe));
  1401. return doc.OuterXml;
  1402. }
  1403. public List<string> RestoreRecipeFolderList()
  1404. {
  1405. List<string> folderList = new List<string>();
  1406. var recipeBackupPath = PathManager.GetRecipeBackupDir();
  1407. DirectoryInfo directoryInfo = new DirectoryInfo(recipeBackupPath);
  1408. DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
  1409. foreach (var item in directoryInfos)
  1410. {
  1411. folderList.Add(item.Name);
  1412. }
  1413. return folderList;
  1414. }
  1415. public string LoadRestoreRecipe(string chamberId, string recipeName, bool needValidation)
  1416. {
  1417. string rcp = string.Empty;
  1418. try
  1419. {
  1420. using (StreamReader fs = new StreamReader(GenerateBackupRecipeFilePath(chamberId, recipeName)))
  1421. {
  1422. rcp = fs.ReadToEnd();
  1423. fs.Close();
  1424. }
  1425. }
  1426. catch (Exception ex)
  1427. {
  1428. LOG.Write(ex, $"load recipe file failed, {recipeName}");
  1429. rcp = string.Empty;
  1430. }
  1431. return rcp;
  1432. }
  1433. public bool SigRestoreRecipe(string chamId, List<string> recipeNames)
  1434. {
  1435. try
  1436. {
  1437. string filePath = getRecipeBackupDirPath(chamId);
  1438. foreach (var item in recipeNames)
  1439. {
  1440. string strdest = chamId;
  1441. string destFilePath = GenerateRecipeFilePath(strdest, item);
  1442. string sourceFilePath = GenerateBackupRecipeFilePath(chamId, item);
  1443. if (item.Contains("\\"))
  1444. {
  1445. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  1446. if (!di.Exists) di.Create();
  1447. }
  1448. File.Copy(sourceFilePath, destFilePath, true);
  1449. }
  1450. }
  1451. catch (Exception ex)
  1452. {
  1453. LOG.Write(ex, "Backup Recipe file error");
  1454. }
  1455. return true;
  1456. }
  1457. private static Dictionary<string, List<string>> CreateRestoreDirectory = new Dictionary<string, List<string>>();
  1458. private string RestoreDestFileCheck(string chamId, string recipeName)
  1459. {
  1460. string newRecipeName = recipeName;
  1461. //有文件夹的处理方式
  1462. if (recipeName.Contains("\\"))
  1463. {
  1464. int index = 1;
  1465. while (true)
  1466. {
  1467. int firstIndex = recipeName.IndexOf("\\");
  1468. string firstStr = recipeName.Substring(0, firstIndex);
  1469. string tempRecipeDirectory = "";
  1470. string lastStr = recipeName.Substring(firstIndex + 1, recipeName.Length - firstStr.Length - 1);
  1471. if (firstStr.Contains("(") && firstStr.Contains(")") && (firstStr.IndexOf("(") < firstStr.IndexOf(")")) && (firstStr.IndexOf(")") == firstStr.Length - 1))
  1472. {
  1473. var tempFirstStr = firstStr.Remove(firstStr.IndexOf("("), firstStr.IndexOf(")"));
  1474. newRecipeName = $"{tempFirstStr}({index}){lastStr}";
  1475. tempRecipeDirectory = $"{tempFirstStr}({index})";
  1476. }
  1477. else
  1478. {
  1479. newRecipeName = $"{firstStr}({index})\\{lastStr}";
  1480. tempRecipeDirectory = $"{firstStr}({index})";
  1481. }
  1482. var fileName = getRecipeDirPath(chamId) + newRecipeName + ".rcp";
  1483. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(fileName));
  1484. if (CreateRestoreDirectory.ContainsKey(chamId) && CreateRestoreDirectory[chamId].Contains(tempRecipeDirectory))
  1485. {
  1486. break;
  1487. }
  1488. else if (di.Exists)
  1489. {
  1490. index++;
  1491. }
  1492. else
  1493. {
  1494. if (!CreateRestoreDirectory.ContainsKey(chamId))
  1495. {
  1496. List<string> recipeDicectory = new List<string>();
  1497. recipeDicectory.Add(tempRecipeDirectory);
  1498. CreateRestoreDirectory.Add(chamId, recipeDicectory);
  1499. }
  1500. else
  1501. {
  1502. CreateRestoreDirectory[chamId].Add(tempRecipeDirectory);
  1503. }
  1504. di.Create();
  1505. break;
  1506. }
  1507. }
  1508. }
  1509. //直接文件的处理方式
  1510. else
  1511. {
  1512. int index = 1;
  1513. while (true)
  1514. {
  1515. if (recipeName.Contains("(") && recipeName.Contains(")") && (recipeName.IndexOf("(") < recipeName.IndexOf(")")) && (recipeName.IndexOf(")") == recipeName.Length - 1))
  1516. {
  1517. var tempFirstStr = recipeName.Remove(recipeName.IndexOf("("), recipeName.IndexOf(")"));
  1518. newRecipeName = $"{tempFirstStr}({index})";
  1519. }
  1520. else
  1521. {
  1522. newRecipeName = $"{recipeName}({index})";
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. return getRecipeDirPath(chamId) + newRecipeName + ".rcp";
  1528. }
  1529. public bool RestoreRecipe(string chamId, bool isSaveLink, List<string> recipeNames)
  1530. {
  1531. try
  1532. {
  1533. string filePath = getRecipeBackupDirPath(chamId);
  1534. CreateRestoreDirectory.Clear();
  1535. foreach (var item in recipeNames)
  1536. {
  1537. string strdest = chamId.Remove(5, 14);
  1538. //string destFilePath = GenerateRecipeFilePath(strdest, item);
  1539. string destFilePath = RestoreDestFileCheck(strdest, item);
  1540. string sourceFilePath = GenerateBackupRecipeFilePath(chamId, item);
  1541. if (File.Exists(sourceFilePath))
  1542. {
  1543. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
  1544. if (!di.Exists) di.Create();
  1545. File.Copy(sourceFilePath, destFilePath, true);
  1546. }
  1547. if (isSaveLink)
  1548. {
  1549. string recipeContent = LoadRestoreRecipe(chamId, item, false);
  1550. var xmlRecipe = new XmlDocument();
  1551. try
  1552. {
  1553. string chamberType = chamId.Split('\\')[0];
  1554. string processType = chamId.Split('\\')[1];
  1555. if (string.IsNullOrEmpty(recipeContent))
  1556. continue;
  1557. xmlRecipe.LoadXml(recipeContent);
  1558. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  1559. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1560. switch (processType)
  1561. {
  1562. case "WaferFlow":
  1563. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  1564. if (!string.IsNullOrEmpty(strSystemReicpeName))
  1565. {
  1566. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\System", strSystemReicpeName);
  1567. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\System", strSystemReicpeName);
  1568. if (File.Exists(subSourceFilePath))
  1569. {
  1570. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1571. if (!di.Exists) di.Create();
  1572. File.Copy(subSourceFilePath, subDestFilePath, true);
  1573. }
  1574. }
  1575. foreach (var step in nodeSteps)
  1576. {
  1577. XmlElement nodestep = step as XmlElement;
  1578. string strModuleName = nodestep.Attributes["ModuleName"]?.Value;
  1579. if (string.IsNullOrEmpty(strModuleName))
  1580. { continue; }
  1581. else
  1582. {
  1583. string[] temp = strModuleName.Split(',')[0].Split(' ');
  1584. if (temp.Length > 1)
  1585. strModuleName = temp[1];
  1586. }
  1587. var linkRecipeName = nodestep.Attributes["RecipeName"].Value;
  1588. if (string.IsNullOrEmpty(linkRecipeName))
  1589. { continue; }
  1590. string[] subRecipeNames = linkRecipeName.Split(',');
  1591. foreach (var subitem in subRecipeNames)
  1592. {
  1593. string subRecipeName = string.Empty;
  1594. string[] subRecipeNameStrings = subitem.Split(':');
  1595. if (subRecipeNameStrings.Length > 1)
  1596. {
  1597. subRecipeName = subRecipeNameStrings[1];
  1598. }
  1599. else
  1600. {
  1601. subRecipeName = subRecipeNameStrings[0];
  1602. }
  1603. if (ovenModuleName.Contains(strModuleName))
  1604. {
  1605. strModuleName = "Oven";
  1606. }
  1607. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\{strModuleName}", subRecipeName);
  1608. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\{strModuleName}", subRecipeName);
  1609. if (File.Exists(subSourceFilePath))
  1610. {
  1611. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1612. if (!di.Exists) di.Create();
  1613. File.Copy(subSourceFilePath, subDestFilePath, true);
  1614. }
  1615. if (strModuleName == "COT")
  1616. {
  1617. string subCotPath = GenerateBackupRecipeFilePath($"{_chamberId}\\{strModuleName}", subRecipeName);
  1618. var subXmlRecipe = new XmlDocument();
  1619. string subRecipeContent = LoadRecipe($"{_chamberId}\\{strModuleName}", subRecipeName, false);
  1620. if (string.IsNullOrEmpty(subRecipeContent))
  1621. continue;
  1622. subXmlRecipe.LoadXml(subRecipeContent);
  1623. XmlNode subNodeConfig = subXmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1624. string subPumpRecipeName = subNodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1625. if (!string.IsNullOrEmpty(subPumpRecipeName))
  1626. {
  1627. string subPumpSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", subPumpRecipeName);
  1628. string subPumpDestFilePath = RestoreDestFileCheck($"{_chamberId}\\Pump", subPumpRecipeName);
  1629. if (File.Exists(subPumpSourceFilePath))
  1630. {
  1631. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subPumpDestFilePath));
  1632. if (!di.Exists) di.Create();
  1633. File.Copy(subPumpSourceFilePath, subPumpDestFilePath, true);
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. break;
  1640. case "COT":
  1641. case "DEV":
  1642. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1643. if (!string.IsNullOrEmpty(pumpRecipeName))
  1644. {
  1645. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", pumpRecipeName);
  1646. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\Pump", pumpRecipeName);
  1647. if (File.Exists(subSourceFilePath))
  1648. {
  1649. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1650. if (!di.Exists) di.Create();
  1651. File.Copy(subSourceFilePath, subDestFilePath, true);
  1652. }
  1653. }
  1654. break;
  1655. case "Dummy":
  1656. foreach (var step in nodeSteps)
  1657. {
  1658. XmlElement nodestep = step as XmlElement;
  1659. string regularSequence = nodestep.Attributes["RegularSequence"]?.Value;
  1660. string preSequence = nodestep.Attributes["PreSequence"]?.Value;
  1661. if (!string.IsNullOrEmpty(regularSequence))
  1662. {
  1663. string[] regularSequences = regularSequence.Split(';');
  1664. foreach (var subItem in regularSequences)
  1665. {
  1666. if (string.IsNullOrEmpty(subItem)) continue;
  1667. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1668. if (!string.IsNullOrEmpty(pumpRecipe))
  1669. {
  1670. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", pumpRecipe);
  1671. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\Pump", pumpRecipe);
  1672. if (File.Exists(subSourceFilePath))
  1673. {
  1674. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1675. if (!di.Exists) di.Create();
  1676. File.Copy(subSourceFilePath, subDestFilePath, true);
  1677. }
  1678. }
  1679. }
  1680. }
  1681. if (!string.IsNullOrEmpty(preSequence))
  1682. {
  1683. string[] preSequences = preSequence.Split(';');
  1684. foreach (var subItem in preSequences)
  1685. {
  1686. if (string.IsNullOrEmpty(subItem)) continue;
  1687. var pumpRecipe = GetKeyValue(item, "PumpRecipe");
  1688. if (!string.IsNullOrEmpty(pumpRecipe))
  1689. {
  1690. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", pumpRecipe);
  1691. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\Pump", pumpRecipe);
  1692. if (File.Exists(subSourceFilePath))
  1693. {
  1694. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1695. if (!di.Exists) di.Create();
  1696. File.Copy(subSourceFilePath, subDestFilePath, true);
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. break;
  1703. case "Wash":
  1704. foreach (var step in nodeSteps)
  1705. {
  1706. XmlElement nodestep = step as XmlElement;
  1707. string sequence = nodestep.Attributes["Sequence"]?.Value;
  1708. if (string.IsNullOrEmpty(sequence))
  1709. { continue; }
  1710. var subSequences = sequence.Split(';');
  1711. foreach (var subSeq in subSequences)
  1712. {
  1713. if (string.IsNullOrEmpty(subSeq))
  1714. {
  1715. continue;
  1716. }
  1717. var pumpRecipe = GetKeyValue(subSeq, "PumpRecipe");
  1718. if (!string.IsNullOrEmpty(pumpRecipe))
  1719. {
  1720. string subSourceFilePath = GenerateBackupRecipeFilePath($"{chamId.Split('\\')[0]}\\Pump", pumpRecipe);
  1721. string subDestFilePath = RestoreDestFileCheck($"{_chamberId}\\Pump", pumpRecipe);
  1722. if (File.Exists(subSourceFilePath))
  1723. {
  1724. DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(subDestFilePath));
  1725. if (!di.Exists) di.Create();
  1726. File.Copy(subSourceFilePath, subDestFilePath, true);
  1727. }
  1728. }
  1729. }
  1730. }
  1731. break;
  1732. case "ADH":
  1733. case "Oven":
  1734. break;
  1735. }
  1736. }
  1737. catch (Exception ex)
  1738. {
  1739. LOG.Write(ex);
  1740. continue;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. catch (Exception ex)
  1746. {
  1747. LOG.Write(ex, "Backup Recipe file error");
  1748. }
  1749. return true;
  1750. }
  1751. public bool CheckRestoreRecipeIsLinkRecipe(string fileOriginalPath, List<string> recipeNames)
  1752. {
  1753. string chamberType = fileOriginalPath.Split('\\')[0];
  1754. string processType = fileOriginalPath.Split('\\')[1];
  1755. foreach (var item in recipeNames)
  1756. {
  1757. string recipeContent = LoadRestoreRecipe(fileOriginalPath, item, false);
  1758. var xmlRecipe = new XmlDocument();
  1759. try
  1760. {
  1761. if (string.IsNullOrEmpty(recipeContent))
  1762. continue;
  1763. xmlRecipe.LoadXml(recipeContent);
  1764. XmlNodeList nodeSteps = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Module[@Name='{processType}']/Step");
  1765. XmlNode nodeConfig = xmlRecipe.SelectNodes($"Aitex/TableRecipeData/Config")[0];
  1766. switch (processType)
  1767. {
  1768. case "WaferFlow":
  1769. foreach (var step in nodeSteps)
  1770. {
  1771. XmlElement nodestep = step as XmlElement;
  1772. string strModuleName = nodestep.Attributes["ModuleName"]?.Value;
  1773. if (string.IsNullOrEmpty(strModuleName))
  1774. { continue; }
  1775. var linkRecipeName = nodestep.Attributes["RecipeName"].Value;
  1776. if (string.IsNullOrEmpty(linkRecipeName))
  1777. { continue; }
  1778. else
  1779. {
  1780. return true;
  1781. }
  1782. }
  1783. string strSystemReicpeName = nodeConfig.Attributes["SystemRecipe"]?.Value;
  1784. if (!string.IsNullOrEmpty(strSystemReicpeName))
  1785. {
  1786. return true;
  1787. }
  1788. break;
  1789. case "COT":
  1790. case "DEV":
  1791. string pumpRecipeName = nodeConfig.Attributes["COTPumpRecipe"]?.Value;
  1792. if (!string.IsNullOrEmpty(pumpRecipeName))
  1793. {
  1794. return true;
  1795. }
  1796. break;
  1797. case "Dummy":
  1798. foreach (var step in nodeSteps)
  1799. {
  1800. XmlElement nodestep = step as XmlElement;
  1801. string regularSequence = nodestep.Attributes["RegularSequence"]?.Value;
  1802. string preSequence = nodestep.Attributes["PreSequence"]?.Value;
  1803. if (!string.IsNullOrEmpty(regularSequence))
  1804. {
  1805. string[] regularSequences = regularSequence.Split(';');
  1806. foreach (var subItem in regularSequences)
  1807. {
  1808. if (string.IsNullOrEmpty(subItem)) continue;
  1809. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1810. if (!string.IsNullOrEmpty(pumpRecipe)) return true;
  1811. }
  1812. }
  1813. if (!string.IsNullOrEmpty(preSequence))
  1814. {
  1815. string[] preSequences = preSequence.Split(';');
  1816. foreach (var subItem in preSequences)
  1817. {
  1818. if (string.IsNullOrEmpty(subItem)) continue;
  1819. var pumpRecipe = GetKeyValue(subItem, "PumpRecipe");
  1820. if (!string.IsNullOrEmpty(pumpRecipe)) return true;
  1821. }
  1822. }
  1823. }
  1824. break;
  1825. case "Wash":
  1826. foreach (var step in nodeSteps)
  1827. {
  1828. XmlElement nodestep = step as XmlElement;
  1829. string sequence = nodestep.Attributes["Sequence"]?.Value;
  1830. if (string.IsNullOrEmpty(sequence))
  1831. { continue; }
  1832. var subSequences = sequence.Split(';');
  1833. foreach (var subSeq in subSequences)
  1834. {
  1835. if (string.IsNullOrEmpty(subSeq))
  1836. {
  1837. continue;
  1838. }
  1839. var pumpRecipe = GetKeyValue(subSeq, "PumpRecipe");
  1840. if (!string.IsNullOrEmpty(subSeq))
  1841. {
  1842. return true;
  1843. }
  1844. }
  1845. }
  1846. break;
  1847. case "ADH":
  1848. case "Oven":
  1849. break;
  1850. }
  1851. }
  1852. catch (Exception ex)
  1853. {
  1854. LOG.Write(ex);
  1855. return false;
  1856. }
  1857. }
  1858. return false;
  1859. }
  1860. private void EventInfo(string message)
  1861. {
  1862. _rcpContext.PostInfoEvent(message);
  1863. }
  1864. private void EventWarning(string message)
  1865. {
  1866. _rcpContext.PostWarningEvent(message);
  1867. }
  1868. private void EventAlarm(string message)
  1869. {
  1870. _rcpContext.PostAlarmEvent(message);
  1871. }
  1872. private void InfoDialog(string message)
  1873. {
  1874. _rcpContext.PostInfoDialogMessage(message);
  1875. }
  1876. private void WarningDialog(string message)
  1877. {
  1878. _rcpContext.PostWarningDialogMessage(message);
  1879. }
  1880. //private void AlarmDialog(string message)
  1881. //{
  1882. // _rcpContext.PostAlarmDialogMessage(message);
  1883. //}
  1884. private void EventDialog(string message, List<string> reason)
  1885. {
  1886. string msg = message;
  1887. foreach (var r in reason)
  1888. {
  1889. msg += "\r\n" + r;
  1890. }
  1891. _rcpContext.PostDialogEvent(msg);
  1892. }
  1893. /// <summary>
  1894. /// get recipe's file path
  1895. /// </summary>
  1896. /// <param name="recipeName"></param>
  1897. /// <returns></returns>
  1898. private string GenerateRecipeFilePath(string chamId, string recipeName)
  1899. {
  1900. return getRecipeDirPath(chamId) + recipeName + ".rcp";
  1901. }
  1902. private string GenerateBackupRecipeFilePath(string chamId, string recipeName)
  1903. {
  1904. return getRecipeBackupDirPath(chamId) + recipeName + ".rcp";
  1905. }
  1906. private string GenerateSequenceFilePath(string chamId, string recipeName)
  1907. {
  1908. return getRecipeDirPath(chamId) + recipeName + ".seq";
  1909. }
  1910. /// <summary>
  1911. /// get recipe's dir path
  1912. /// </summary>
  1913. /// <param name="recipeName"></param>
  1914. /// <returns></returns>
  1915. private string getRecipeDirPath(string chamId)
  1916. {
  1917. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeDir(), chamId);
  1918. DirectoryInfo di = new DirectoryInfo(dir);
  1919. if (!di.Exists) di.Create();
  1920. return dir;
  1921. }
  1922. /// <summary>
  1923. /// get recipe's dir path
  1924. /// </summary>
  1925. /// <param name="recipeName"></param>
  1926. /// <returns></returns>
  1927. private string getRecipeBackupDirPath(string chamId)
  1928. {
  1929. var dir = string.Format("{0}{1}\\", PathManager.GetRecipeBackupDir(), chamId);
  1930. DirectoryInfo di = new DirectoryInfo(dir);
  1931. if (!di.Exists) di.Create();
  1932. return dir;
  1933. }
  1934. /// <summary>
  1935. /// delete a recipe folder
  1936. /// </summary>
  1937. /// <param name="chamId"></param>
  1938. /// <param name="folderName"></param>
  1939. /// <returns></returns>
  1940. public bool DeleteFolder(string chamId, string folderName)
  1941. {
  1942. try
  1943. {
  1944. Directory.Delete(getRecipeDirPath(chamId) + folderName, true);
  1945. EventInfo(string.Format(Resources.RecipeFileManager_DeleteFolder_RecipeFolder0DeleteSucceeded, folderName));
  1946. }
  1947. catch (Exception ex)
  1948. {
  1949. LOG.Write(ex, "删除recipe folder 出错");
  1950. EventAlarm(string.Format("recipe folder {0} delete failed", folderName));
  1951. return false;
  1952. }
  1953. return true;
  1954. }
  1955. /// <summary>
  1956. /// save as recipe content
  1957. /// </summary>
  1958. /// <param name="chamId"></param>
  1959. /// <param name="recipeName"></param>
  1960. /// <param name="recipeContent"></param>
  1961. /// <returns></returns>
  1962. public bool SaveAsRecipe(string chamId, string recipeName, string recipeContent)
  1963. {
  1964. var path = GenerateRecipeFilePath(chamId, recipeName);
  1965. if (File.Exists(path))
  1966. {
  1967. EventAlarm(string.Format(Resources.RecipeFileManager_SaveAsRecipe_RecipeFile0savefailed, recipeName));
  1968. return false;
  1969. }
  1970. return SaveRecipe(chamId, recipeName, recipeContent, true, true);
  1971. }
  1972. /// <summary>
  1973. /// save recipe content
  1974. /// </summary>
  1975. /// <param name="chamId"></param>
  1976. /// <param name="recipeName"></param>
  1977. /// <param name="recipeContent"></param>
  1978. /// <returns></returns>
  1979. public bool SaveRecipe(string chamId, string recipeName, string recipeContent, bool clearBarcode, bool notifyUI)
  1980. {
  1981. //validate recipe format when saving a recipe file
  1982. //var reasons1 = new List<string>();
  1983. //var reasons2 = new List<string>();
  1984. //ValidateRecipe(chamId, recipeName, recipeContent, out reasons1);
  1985. //CheckRecipe(chamId, recipeContent, out reasons2);
  1986. //reasons1.AddRange(reasons2);
  1987. //if (reasons1.Count > 0)
  1988. //{
  1989. // EventDialog(string.Format( Resources.RecipeFileManager_SaveRecipe_SaveRecipeContentError, recipeName), reasons1);
  1990. //}
  1991. bool ret = true;
  1992. try
  1993. {
  1994. var path = GenerateRecipeFilePath(chamId, recipeName);
  1995. FileInfo fi = new FileInfo(path);
  1996. if (!fi.Directory.Exists)
  1997. fi.Directory.Create();
  1998. XmlDocument xml = new XmlDocument();
  1999. xml.LoadXml(recipeContent);
  2000. XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);
  2001. writer.Formatting = Formatting.Indented;
  2002. xml.Save(writer);
  2003. writer.Close();
  2004. if (notifyUI)
  2005. {
  2006. InfoDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  2007. }
  2008. else
  2009. {
  2010. EV.PostMessage("System", EventEnum.GeneralInfo, string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  2011. }
  2012. }
  2013. catch (Exception ex)
  2014. {
  2015. LOG.Write(ex, "保存recipe file 出错");
  2016. if (notifyUI)
  2017. {
  2018. WarningDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveFailed, recipeName));
  2019. }
  2020. ret = false;
  2021. }
  2022. return ret;
  2023. }
  2024. /// <summary>
  2025. /// save recipe content
  2026. /// </summary>
  2027. /// <param name="chamId"></param>
  2028. /// <param name="recipeName"></param>
  2029. /// <param name="recipeContent"></param>
  2030. /// <returns></returns>
  2031. public bool SaveRestoreRecipe(string chamId, string recipeName, string recipeContent, bool clearBarcode, bool notifyUI)
  2032. {
  2033. //validate recipe format when saving a recipe file
  2034. //var reasons1 = new List<string>();
  2035. //var reasons2 = new List<string>();
  2036. //ValidateRecipe(chamId, recipeName, recipeContent, out reasons1);
  2037. //CheckRecipe(chamId, recipeContent, out reasons2);
  2038. //reasons1.AddRange(reasons2);
  2039. //if (reasons1.Count > 0)
  2040. //{
  2041. // EventDialog(string.Format( Resources.RecipeFileManager_SaveRecipe_SaveRecipeContentError, recipeName), reasons1);
  2042. //}
  2043. bool ret = true;
  2044. try
  2045. {
  2046. var path = GenerateBackupRecipeFilePath(chamId, recipeName);
  2047. FileInfo fi = new FileInfo(path);
  2048. if (!fi.Directory.Exists)
  2049. fi.Directory.Create();
  2050. XmlDocument xml = new XmlDocument();
  2051. xml.LoadXml(recipeContent);
  2052. XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);
  2053. writer.Formatting = Formatting.Indented;
  2054. xml.Save(writer);
  2055. writer.Close();
  2056. if (notifyUI)
  2057. {
  2058. InfoDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  2059. }
  2060. else
  2061. {
  2062. EV.PostMessage("System", EventEnum.GeneralInfo, string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveCompleted, recipeName));
  2063. }
  2064. }
  2065. catch (Exception ex)
  2066. {
  2067. LOG.Write(ex, "保存recipe file 出错");
  2068. if (notifyUI)
  2069. {
  2070. WarningDialog(string.Format(Resources.RecipeFileManager_SaveRecipe_RecipeFile0SaveFailed, recipeName));
  2071. }
  2072. ret = false;
  2073. }
  2074. return ret;
  2075. }
  2076. /// <summary>
  2077. /// create a new recipe folder
  2078. /// </summary>
  2079. /// <param name="chamId"></param>
  2080. /// <param name="folderName"></param>
  2081. /// <returns></returns>
  2082. public bool CreateFolder(string chamId, string folderName)
  2083. {
  2084. try
  2085. {
  2086. Directory.CreateDirectory(getRecipeDirPath(chamId) + folderName);
  2087. EventInfo(string.Format(Resources.RecipeFileManager_CreateFolder_RecipeFolder0Created, folderName));
  2088. }
  2089. catch (Exception ex)
  2090. {
  2091. LOG.Write(ex, "create recipe folder failed");
  2092. EventAlarm(string.Format(Resources.RecipeFileManager_CreateFolder_RecipeFolder0CreateFailed, folderName));
  2093. return false;
  2094. }
  2095. return true;
  2096. }
  2097. /// <summary>
  2098. /// Rename recipe folder name
  2099. /// </summary>
  2100. /// <param name="chamId"></param>
  2101. /// <param name="oldName"></param>
  2102. /// <param name="newName"></param>
  2103. /// <returns></returns>
  2104. public bool RenameFolder(string chamId, string oldName, string newName)
  2105. {
  2106. try
  2107. {
  2108. string oldPath = getRecipeDirPath(chamId) + oldName;
  2109. string newPath = getRecipeDirPath(chamId) + newName;
  2110. Directory.Move(oldPath, newPath);
  2111. EventInfo(string.Format(Resources.RecipeFileManager_RenameFolder_RecipeFolder0renamed, oldName, newName));
  2112. }
  2113. catch (Exception ex)
  2114. {
  2115. LOG.Write(ex, "Rename recipe folder failed");
  2116. EventAlarm(string.Format(Resources.RecipeFileManager_RenameFolder_RecipeFolder0RenameFailed, oldName, newName));
  2117. return false;
  2118. }
  2119. return true;
  2120. }
  2121. public XmlDocument RecipeDom = new XmlDocument();
  2122. private string GetRecipeBody(string chamberId, string nodePath)
  2123. {
  2124. if (_rcpContext == null)
  2125. return string.Empty;
  2126. string schema = _rcpContext.GetRecipeDefiniton(chamberId);
  2127. RecipeDom = new XmlDocument();
  2128. RecipeDom.LoadXml(schema);
  2129. XmlNode node = RecipeDom.SelectSingleNode(nodePath);
  2130. return node.OuterXml;
  2131. }
  2132. public string RecipeChamberType
  2133. {
  2134. get;
  2135. set;
  2136. }
  2137. public string RecipeVersion
  2138. {
  2139. get;
  2140. set;
  2141. }
  2142. public Dictionary<string, ObservableCollection<RecipeTemplateColumnBase>> GetGroupRecipeTemplate()
  2143. {
  2144. try
  2145. {
  2146. XmlNode nodeRoot = RecipeDom.SelectSingleNode("Aitex/TableRecipeFormat");
  2147. RecipeChamberType = nodeRoot.Attributes["RecipeChamberType"].Value;
  2148. RecipeVersion = nodeRoot.Attributes["RecipeVersion"].Value;
  2149. }
  2150. catch (Exception ex)
  2151. {
  2152. LOG.Write(ex);
  2153. return null;
  2154. }
  2155. var columns = new Dictionary<string, ObservableCollection<RecipeTemplateColumnBase>>();
  2156. RecipeTemplateColumnBase col = null;
  2157. XmlNodeList nodes = RecipeDom.SelectNodes("Aitex/TableRecipeFormat/Catalog/Group");
  2158. foreach (XmlNode node in nodes)
  2159. {
  2160. var sigcolumns = new ObservableCollection<RecipeTemplateColumnBase>();
  2161. XmlNodeList childNodes = node.SelectNodes("Step");
  2162. foreach (XmlNode step in childNodes)
  2163. {
  2164. //step number
  2165. if (step.Attributes["ControlName"].Value == "StepNo")
  2166. {
  2167. col = new RecipeTemplateColumnBase()
  2168. {
  2169. DisplayName = "Step",
  2170. ControlName = "StepNo",
  2171. };
  2172. sigcolumns.Add(col);
  2173. continue;
  2174. }
  2175. switch (step.Attributes["InputType"].Value)
  2176. {
  2177. case "TextInput":
  2178. col = new RecipeTemplateColumnBase()
  2179. {
  2180. ValueType = "TextInput",
  2181. ModuleName = step.Attributes["ModuleName"].Value,
  2182. ControlName = step.Attributes["ControlName"].Value,
  2183. DisplayName = step.Attributes["DisplayName"].Value,
  2184. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  2185. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2186. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2187. };
  2188. sigcolumns.Add(col);
  2189. break;
  2190. case "NumInput":
  2191. col = new RecipeTemplateColumnBase()
  2192. {
  2193. ValueType = "NumInput",
  2194. ModuleName = step.Attributes["ModuleName"].Value,
  2195. ControlName = step.Attributes["ControlName"].Value,
  2196. DisplayName = step.Attributes["DisplayName"].Value,
  2197. InputMode = step.Attributes["InputMode"].Value,
  2198. Minimun = double.Parse(step.Attributes["Min"].Value),
  2199. Maximun = double.Parse(step.Attributes["Max"].Value),
  2200. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  2201. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2202. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2203. };
  2204. sigcolumns.Add(col);
  2205. break;
  2206. case "DoubleInput":
  2207. col = new RecipeTemplateColumnBase()
  2208. {
  2209. ValueType = "DoubleInput",
  2210. ModuleName = step.Attributes["ModuleName"].Value,
  2211. ControlName = step.Attributes["ControlName"].Value,
  2212. DisplayName = step.Attributes["DisplayName"].Value,
  2213. InputMode = step.Attributes["InputMode"].Value,
  2214. Minimun = double.Parse(step.Attributes["Min"].Value),
  2215. Maximun = double.Parse(step.Attributes["Max"].Value),
  2216. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  2217. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2218. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2219. };
  2220. sigcolumns.Add(col);
  2221. break;
  2222. case "EditableSelection":
  2223. col = new RecipeTemplateColumnBase()
  2224. {
  2225. ValueType = "EditableSelection",
  2226. ModuleName = step.Attributes["ModuleName"].Value,
  2227. Default = step.Attributes["Default"] != null ? step.Attributes["Default"].Value : "",
  2228. ControlName = step.Attributes["ControlName"].Value,
  2229. DisplayName = step.Attributes["DisplayName"].Value,
  2230. IsEnable = !bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  2231. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2232. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2233. };
  2234. XmlNodeList items = step.SelectNodes("Item");
  2235. foreach (XmlNode item in items)
  2236. {
  2237. Option opt = new Option();
  2238. opt.ControlName = item.Attributes["ControlName"].Value;
  2239. opt.DisplayName = item.Attributes["DisplayName"].Value;
  2240. ((RecipeTemplateColumnBase)col).Options.Add(opt);
  2241. }
  2242. sigcolumns.Add(col);
  2243. break;
  2244. case "ReadOnlySelection":
  2245. case "LoopSelection":
  2246. col = new RecipeTemplateColumnBase()
  2247. {
  2248. ValueType = "LoopSelection",
  2249. IsReadOnly = bool.Parse(step.Attributes["ReadOnly"] != null ? step.Attributes["ReadOnly"].Value : "false"),
  2250. ModuleName = step.Attributes["ModuleName"].Value,
  2251. ControlName = step.Attributes["ControlName"].Value,
  2252. DisplayName = step.Attributes["DisplayName"].Value,
  2253. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2254. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2255. };
  2256. XmlNodeList options = step.SelectNodes("Item");
  2257. foreach (XmlNode item in options)
  2258. {
  2259. Option opt = new Option();
  2260. opt.ControlName = item.Attributes["ControlName"].Value;
  2261. opt.DisplayName = item.Attributes["DisplayName"].Value;
  2262. ((RecipeTemplateColumnBase)col).Options.Add(opt);
  2263. }
  2264. sigcolumns.Add(col);
  2265. break;
  2266. case "PopSetting":
  2267. col = new RecipeTemplateColumnBase()
  2268. {
  2269. ValueType = "LoopSelection",
  2270. ModuleName = step.Attributes["ModuleName"].Value,
  2271. ControlName = step.Attributes["ControlName"].Value,
  2272. DisplayName = step.Attributes["DisplayName"].Value,
  2273. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  2274. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  2275. };
  2276. sigcolumns.Add(col);
  2277. break;
  2278. }
  2279. }
  2280. columns.Add(node.Attributes["DisplayName"].Value, sigcolumns);
  2281. }
  2282. return columns;
  2283. }
  2284. /// <summary>
  2285. /// get reactor's recipe format define file
  2286. /// </summary>
  2287. /// <param name="chamId"></param>
  2288. /// <returns></returns>
  2289. public string GetRecipeFormatXml(string chamberId)
  2290. {
  2291. var rtn = GetRecipeBody(chamberId, "/Aitex/TableRecipeFormat");
  2292. return rtn;
  2293. }
  2294. /// <summary>
  2295. /// get reactor's template recipe file
  2296. /// </summary>
  2297. /// <param name="chamId"></param>
  2298. /// <returns></returns>
  2299. public string GetRecipeTemplate(string chamberId)
  2300. {
  2301. if (_rcpContext != null)
  2302. return _rcpContext.GetRecipeTemplate(chamberId);
  2303. return GetRecipeBody(chamberId, "/Aitex/TableRecipeData");
  2304. }
  2305. /// <summary>
  2306. /// get reactor's template recipe file
  2307. /// </summary>
  2308. /// <param name="chamId"></param>
  2309. /// <returns></returns>
  2310. public string GetRecipeSchema(string chamberId)
  2311. {
  2312. if (_rcpContext == null)
  2313. return string.Empty;
  2314. string schema = _rcpContext.GetRecipeDefiniton(chamberId);
  2315. XmlDocument dom = new XmlDocument();
  2316. dom.LoadXml(schema);
  2317. XmlNode node = dom.SelectSingleNode("/Aitex/TableRecipeSchema");
  2318. return node.InnerXml;
  2319. }
  2320. public string GetRecipeByBarcode(string chamberId, string barcode)
  2321. {
  2322. try
  2323. {
  2324. string recipePath = PathManager.GetRecipeDir() + chamberId + "\\";
  2325. var di = new DirectoryInfo(recipePath);
  2326. var fis = di.GetFiles("*.rcp", System.IO.SearchOption.AllDirectories);
  2327. XmlDocument xml = new XmlDocument();
  2328. foreach (var fi in fis)
  2329. {
  2330. string str = fi.FullName.Substring(recipePath.Length);
  2331. if (!str.Contains("HistoryRecipe\\"))
  2332. {
  2333. xml.Load(fi.FullName);
  2334. if (xml.SelectSingleNode(string.Format("/TableRecipeData[@Barcode='{0}']", barcode)) != null)
  2335. {
  2336. return str.Substring(0, str.LastIndexOf('.'));
  2337. }
  2338. }
  2339. }
  2340. return string.Empty;
  2341. }
  2342. catch (Exception ex)
  2343. {
  2344. LOG.Write(ex);
  2345. return string.Empty;
  2346. }
  2347. }
  2348. public List<string> ExpertLayoutRecipeParse(string chamberId, string recipeFile)
  2349. {
  2350. var layoutRecipe = new List<string>();
  2351. string content = LoadRecipe(chamberId, recipeFile, false);
  2352. if (string.IsNullOrEmpty(content))
  2353. {
  2354. //reason = $"{recipeFile} is not a valid recipe file";
  2355. return layoutRecipe;
  2356. }
  2357. try
  2358. {
  2359. XmlDocument rcpDataDoc = new XmlDocument();
  2360. rcpDataDoc.LoadXml(content);
  2361. XmlNode nodeModule;
  2362. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Expert']");
  2363. if (nodeModule == null)
  2364. {
  2365. return layoutRecipe;
  2366. }
  2367. else
  2368. {
  2369. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  2370. XmlElement stepNode = nodeModule as XmlElement;
  2371. //遍历Step节点
  2372. foreach (XmlAttribute att in stepNode.Attributes)
  2373. {
  2374. if (att.Name != "Name")
  2375. {
  2376. if (att.Value.ToLower() == "xd")
  2377. {
  2378. layoutRecipe.Add("XD");
  2379. }
  2380. else if (att.Value.ToLower() == "t")
  2381. {
  2382. layoutRecipe.Add("T");
  2383. }
  2384. else
  2385. {
  2386. layoutRecipe.Add("");
  2387. }
  2388. }
  2389. }
  2390. }
  2391. }
  2392. catch (Exception ex)
  2393. {
  2394. LOG.Write(ex);
  2395. return layoutRecipe;
  2396. }
  2397. return layoutRecipe;
  2398. }
  2399. public List<string> LayoutExpertRecipeParse(/*string chamberId, */string recipeContent, string slotCount, string cassetteSlotCount)
  2400. {
  2401. var layoutRecipe = new List<string>();
  2402. try
  2403. {
  2404. XmlDocument rcpDataDoc = new XmlDocument();
  2405. rcpDataDoc.LoadXml(recipeContent);
  2406. XmlNode nodeModule;
  2407. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Normal']");
  2408. if (nodeModule == null)
  2409. {
  2410. //reason = "Recipe file does not contains step content for Normal";
  2411. return layoutRecipe;
  2412. }
  2413. else
  2414. {
  2415. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  2416. XmlElement stepNode = nodeModule as XmlElement;
  2417. //遍历Step节点
  2418. foreach (XmlAttribute att in stepNode.Attributes)
  2419. {
  2420. if (att.Name != "Name")
  2421. {
  2422. recipeData[att.Name] = att.Value;
  2423. }
  2424. }
  2425. // 获取SlotCount
  2426. int iSlotCount = 0;
  2427. int.TryParse(slotCount, out iSlotCount);
  2428. // 获取CassetteSlotCount;
  2429. int iCassetteSlotCount = 0;
  2430. int.TryParse(cassetteSlotCount, out iCassetteSlotCount);
  2431. // 先往List里面添加SlotcCount数量的空值,后续再往里面insert具体的值
  2432. for (int i = 0; i < iSlotCount; i++)
  2433. {
  2434. layoutRecipe.Add(string.Empty);
  2435. }
  2436. // 获取DummyUpperSlot
  2437. int iDummyUpperSlot;
  2438. iDummyUpperSlot = 0;
  2439. if (recipeData.ContainsKey("DummyUpperSlot"))
  2440. {
  2441. int.TryParse(recipeData["DummyUpperSlot"], out iDummyUpperSlot);
  2442. }
  2443. string strProductPos, strXDSlotNo, strDummySlotNo;
  2444. strProductPos = string.Empty;
  2445. strXDSlotNo = string.Empty;
  2446. strDummySlotNo = string.Empty;
  2447. if (recipeData.ContainsKey("MonitorSlotNo"))
  2448. {
  2449. strDummySlotNo = recipeData["MonitorSlotNo"];
  2450. }
  2451. if (recipeData.ContainsKey("ProductSlotNo"))
  2452. {
  2453. strXDSlotNo = recipeData["ProductSlotNo"];
  2454. }
  2455. layoutRecipe = XDSlot(iSlotCount, iCassetteSlotCount, strXDSlotNo, strDummySlotNo, iDummyUpperSlot);
  2456. }
  2457. }
  2458. catch (Exception ex)
  2459. {
  2460. LOG.Write(ex);
  2461. return layoutRecipe;
  2462. }
  2463. return layoutRecipe;
  2464. }
  2465. public List<string> LayoutRecipeParse(/*string chamberId, */string recipeContent, string slotCount, string cassetteSlotCount)
  2466. {
  2467. var layoutRecipe = new List<string>();
  2468. //string content = loadrecipe(chamberid, recipefile, false);
  2469. //if (string.isnullorempty(content))
  2470. //{
  2471. // reason = $"{recipefile} is not a valid recipe file";
  2472. // return layoutrecipe;
  2473. //}
  2474. try
  2475. {
  2476. XmlDocument rcpDataDoc = new XmlDocument();
  2477. rcpDataDoc.LoadXml(recipeContent);
  2478. XmlNode nodeModule;
  2479. nodeModule = rcpDataDoc.SelectSingleNode("/Aitex/TableRecipeData/Module/Step[@Name='Normal']");
  2480. if (nodeModule == null)
  2481. {
  2482. //reason = "Recipe file does not contains step content for Normal";
  2483. return layoutRecipe;
  2484. }
  2485. else
  2486. {
  2487. Dictionary<string, string> recipeData = new Dictionary<string, string>();
  2488. XmlElement stepNode = nodeModule as XmlElement;
  2489. //遍历Step节点
  2490. foreach (XmlAttribute att in stepNode.Attributes)
  2491. {
  2492. if (att.Name != "Name")
  2493. {
  2494. recipeData[att.Name] = att.Value;
  2495. }
  2496. }
  2497. // 获取SlotCount
  2498. int iSlotCount = 0;
  2499. int.TryParse(slotCount, out iSlotCount);
  2500. // 获取CassetteSlotCount;
  2501. int iCassetteSlotCount = 0;
  2502. int.TryParse(cassetteSlotCount, out iCassetteSlotCount);
  2503. // 先往List里面添加SlotcCount数量的空值,后续再往里面insert具体的值
  2504. for (int i = 0; i < iSlotCount; i++)
  2505. {
  2506. layoutRecipe.Add(string.Empty);
  2507. }
  2508. // 获取DummyUpperSlot
  2509. int iDummyUpperSlot;
  2510. iDummyUpperSlot = 0;
  2511. //if (recipeData.ContainsKey("DummyUpperSlot"))
  2512. //{
  2513. // int.TryParse(recipeData["DummyUpperSlot"], out iDummyUpperSlot);
  2514. // if (iDummyUpperSlot == 0)
  2515. // {
  2516. // return layoutRecipe;
  2517. // }
  2518. //}
  2519. //else
  2520. //{
  2521. // return layoutRecipe;
  2522. //}
  2523. //// insert Upper Dummy
  2524. //for (int i = 0; i < iDummyUpperSlot; i++)
  2525. //{
  2526. // layoutRecipe[i] = "Dummy";
  2527. //}
  2528. //// 获取DummyLowerSlot
  2529. int iDummyLowerSlot;
  2530. iDummyLowerSlot = 0;
  2531. //if (recipeData.ContainsKey("DummyLowerSlot"))
  2532. //{
  2533. // int.TryParse(recipeData["DummyLowerSlot"], out iDummyLowerSlot);
  2534. // if (iDummyLowerSlot == 0)
  2535. // {
  2536. // return layoutRecipe;
  2537. // }
  2538. //}
  2539. //else
  2540. //{
  2541. // return layoutRecipe;
  2542. //}
  2543. // insert Lower Dummy
  2544. //for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2545. //{
  2546. // layoutRecipe[i] = "Dummy";
  2547. //}
  2548. string strProductPos, strProductSlotNo, strMonitor1Pos, strMonitor1SlotNo, strMonitor2SlotNo, strSDDummySlotNo, strFDDummySlotNo;
  2549. strProductPos = string.Empty;
  2550. strProductSlotNo = string.Empty;
  2551. strMonitor1Pos = string.Empty;
  2552. strMonitor1SlotNo = string.Empty;
  2553. strMonitor2SlotNo = string.Empty;
  2554. strSDDummySlotNo = string.Empty;
  2555. strFDDummySlotNo = string.Empty;
  2556. // 获取配置
  2557. if (recipeData.ContainsKey("ProductPosition"))
  2558. {
  2559. strProductPos = recipeData["ProductPosition"];
  2560. }
  2561. if (recipeData.ContainsKey("ProductSlotNo"))
  2562. {
  2563. strProductSlotNo = recipeData["ProductSlotNo"];
  2564. }
  2565. if (recipeData.ContainsKey("MonitorPosition"))
  2566. {
  2567. strMonitor1Pos = recipeData["MonitorPosition"];
  2568. }
  2569. if (recipeData.ContainsKey("Monitor1SlotNo"))
  2570. {
  2571. strMonitor1SlotNo = recipeData["Monitor1SlotNo"];
  2572. }
  2573. if (recipeData.ContainsKey("Monitor2SlotNo"))
  2574. {
  2575. strMonitor2SlotNo = recipeData["Monitor2SlotNo"];
  2576. }
  2577. if (recipeData.ContainsKey("SDDummySlotNo"))
  2578. {
  2579. strSDDummySlotNo = recipeData["SDDummySlotNo"];
  2580. }
  2581. if (recipeData.ContainsKey("FDDummySlotNo"))
  2582. {
  2583. strFDDummySlotNo = recipeData["FDDummySlotNo"];
  2584. }
  2585. // insert Production and Monitor and ExtraDummy
  2586. if (strProductPos == "Auto")
  2587. {
  2588. if (strMonitor1Pos == "Auto")
  2589. {
  2590. layoutRecipe = ProductAutoMonitorAuto(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot);
  2591. }
  2592. else if (strMonitor1Pos == "Slot")
  2593. {
  2594. layoutRecipe = ProductAutoMonitorSlot(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strSDDummySlotNo, strMonitor1SlotNo, strMonitor2SlotNo);
  2595. }
  2596. else
  2597. {
  2598. //reason = "MonitorPosition is invalid";
  2599. return layoutRecipe;
  2600. }
  2601. }
  2602. else if (strProductPos == "Slot")
  2603. {
  2604. if (strMonitor1Pos == "Auto")
  2605. {
  2606. layoutRecipe = ProductSlotMonitorAuto(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strSDDummySlotNo, strProductSlotNo);
  2607. }
  2608. else if (strMonitor1Pos == "Slot")
  2609. {
  2610. layoutRecipe = ProductSlotMonitorSlot(iSlotCount, iCassetteSlotCount, iDummyUpperSlot, iDummyLowerSlot, strProductSlotNo, strSDDummySlotNo, strMonitor1SlotNo, strMonitor2SlotNo, strFDDummySlotNo);
  2611. }
  2612. else
  2613. {
  2614. //reason = "MonitorPosition is invalid";
  2615. return layoutRecipe;
  2616. }
  2617. }
  2618. else
  2619. {
  2620. //reason = "ProductPosition is invalid";
  2621. return layoutRecipe;
  2622. }
  2623. }
  2624. }
  2625. catch (Exception ex)
  2626. {
  2627. LOG.Write(ex);
  2628. return layoutRecipe;
  2629. }
  2630. return layoutRecipe;
  2631. }
  2632. private List<string> ProductAutoMonitorAuto(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot)
  2633. {
  2634. var layoutRecipe = new List<string>();
  2635. for (int i = 0; i < iSlotCount; i++)
  2636. {
  2637. layoutRecipe.Add(string.Empty);
  2638. }
  2639. try
  2640. {
  2641. //// insert Upper Dummy
  2642. //for (int i = 0; i < iDummyUpperSlot; i++)
  2643. //{
  2644. // layoutRecipe[i] = "Dummy";
  2645. //}
  2646. //// insert Lower Dummy
  2647. //for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2648. //{
  2649. // layoutRecipe[i] = "Dummy";
  2650. //}
  2651. layoutRecipe[iDummyUpperSlot] = "M1";
  2652. layoutRecipe[iSlotCount - iDummyLowerSlot - 1] = "M1";
  2653. int iCount = 1;
  2654. int cassetteMaxCount = SC.ContainsItem("System.CassetteMaxCount") ? SC.GetValue<int>("System.CassetteMaxCount") : 6;
  2655. int iPCount = 0;
  2656. for (int i = iDummyUpperSlot + 1; i < iSlotCount - iDummyLowerSlot - 1; i++)
  2657. {
  2658. //if (iPCount >= cassetteMaxCount * iCassetteSlotCount)
  2659. // break;
  2660. if (iCount > iCassetteSlotCount && (iSlotCount - iDummyLowerSlot - 1 - i > iCassetteSlotCount))
  2661. {
  2662. layoutRecipe[i] = "M1";
  2663. iCount = 1;
  2664. }
  2665. else
  2666. {
  2667. layoutRecipe[i] = "PD";
  2668. iCount++;
  2669. iPCount++;
  2670. }
  2671. }
  2672. }
  2673. catch (Exception ex)
  2674. {
  2675. LOG.Write(ex);
  2676. return layoutRecipe;
  2677. }
  2678. return layoutRecipe;
  2679. }
  2680. private List<string> ProductAutoMonitorSlot(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strSDSlotNo, string strMonitor1SlotNo, string strMonitor2SlotNo)
  2681. {
  2682. var layoutRecipe = new List<string>();
  2683. for (int i = 0; i < iSlotCount; i++)
  2684. {
  2685. layoutRecipe.Add(string.Empty);
  2686. }
  2687. try
  2688. {
  2689. // insert Upper Dummy
  2690. //for (int i = 0; i < iDummyUpperSlot; i++)
  2691. //{
  2692. // layoutRecipe[i] = "Dummy";
  2693. //}
  2694. //// insert Lower Dummy
  2695. //for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2696. //{
  2697. // layoutRecipe[i] = "Dummy";
  2698. //}
  2699. var dummySlotList = GetLayoutProductionMonitorSlot(strSDSlotNo);
  2700. foreach (var item in dummySlotList)
  2701. {
  2702. int iPos = 0;
  2703. int.TryParse(item, out iPos);
  2704. iPos--;
  2705. layoutRecipe[iPos] = "SD";
  2706. }
  2707. var monitor1SlotList = new List<string>();
  2708. monitor1SlotList = GetLayoutProductionMonitorSlot(strMonitor1SlotNo);
  2709. var monitor1SlotNo = new List<int>();
  2710. foreach (string str in monitor1SlotList)
  2711. {
  2712. int iPos = 0;
  2713. int.TryParse(str, out iPos);
  2714. iPos--;
  2715. if (!monitor1SlotNo.Contains(iPos))
  2716. {
  2717. monitor1SlotNo.Add(iPos);
  2718. }
  2719. }
  2720. monitor1SlotNo.Sort();
  2721. // insert Monitor
  2722. List<int> monitorNo = new List<int>();
  2723. foreach (int vm in monitor1SlotNo)
  2724. {
  2725. //if (layoutRecipe[vm] != "Dummy")
  2726. //{
  2727. layoutRecipe[vm] = "M1";
  2728. //}
  2729. }
  2730. int cassetteMaxCount = SC.ContainsItem("System.CassetteMaxCount") ? SC.GetValue<int>("System.CassetteMaxCount") : 6;
  2731. int iCount = 0;
  2732. var productSlotList = new List<string>();
  2733. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2734. var productSlotNo = new List<int>();
  2735. foreach (string str in productSlotList)
  2736. {
  2737. int iPos = 0;
  2738. int.TryParse(str, out iPos);
  2739. iPos--;
  2740. if (!productSlotNo.Contains(iPos))
  2741. {
  2742. productSlotNo.Add(iPos);
  2743. }
  2744. }
  2745. productSlotNo.Sort();
  2746. foreach (int vm in productSlotNo)
  2747. {
  2748. //if (layoutRecipe[vm] != "Dummy")
  2749. //{
  2750. layoutRecipe[vm] = "PD";
  2751. //}
  2752. }
  2753. // insert Production
  2754. //for (int i = iDummyUpperSlot; i < iSlotCount - iDummyLowerSlot; i++)
  2755. //{
  2756. // //if (iCount >= cassetteMaxCount * iCassetteSlotCount)
  2757. // // break;
  2758. // if (layoutRecipe[i] == "")
  2759. // {
  2760. // layoutRecipe[i] = "Production";
  2761. // iCount++;
  2762. // }
  2763. //}
  2764. }
  2765. catch (Exception ex)
  2766. {
  2767. LOG.Write(ex);
  2768. return layoutRecipe;
  2769. }
  2770. return layoutRecipe;
  2771. }
  2772. private List<string> ProductSlotMonitorAuto(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strDummySlotNo, string strProductSlotNo)
  2773. {
  2774. var layoutRecipe = new List<string>();
  2775. for (int i = 0; i < iSlotCount; i++)
  2776. {
  2777. layoutRecipe.Add(string.Empty);
  2778. }
  2779. try
  2780. {
  2781. //// insert Upper Dummy
  2782. //for (int i = 0; i < iDummyUpperSlot; i++)
  2783. //{
  2784. // layoutRecipe[i] = "Dummy";
  2785. //}
  2786. //// insert Lower Dummy
  2787. //for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2788. //{
  2789. // layoutRecipe[i] = "Dummy";
  2790. //}
  2791. var dummySlotList = GetLayoutProductionMonitorSlot(strDummySlotNo);
  2792. foreach (var item in dummySlotList)
  2793. {
  2794. int iPos = 0;
  2795. int.TryParse(item, out iPos);
  2796. iPos--;
  2797. layoutRecipe[iPos] = "SD";
  2798. }
  2799. var productSlotList = new List<string>();
  2800. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2801. var productSloNo = new List<int>();
  2802. foreach (string str in productSlotList)
  2803. {
  2804. int iPos = 0;
  2805. int.TryParse(str, out iPos);
  2806. iPos--;
  2807. if (!productSloNo.Contains(iPos))
  2808. {
  2809. productSloNo.Add(iPos);
  2810. }
  2811. }
  2812. productSloNo.Sort();
  2813. // insert Production
  2814. foreach (int vm in productSloNo)
  2815. {
  2816. if (layoutRecipe[vm] == "" && vm >= iDummyUpperSlot && vm <= iSlotCount - iDummyLowerSlot - 1)
  2817. {
  2818. layoutRecipe[vm] = "PD";
  2819. }
  2820. }
  2821. layoutRecipe[iDummyUpperSlot] = "M1";
  2822. layoutRecipe[iSlotCount - iDummyLowerSlot - 1] = "M1";
  2823. int iCount = 1;
  2824. for (int i = iDummyUpperSlot + 1; i < iSlotCount - iDummyLowerSlot - 1; i++)
  2825. {
  2826. if (iCount > iCassetteSlotCount && (iSlotCount - iDummyLowerSlot - 1 - i > iCassetteSlotCount))
  2827. {
  2828. layoutRecipe[i] = "M1";
  2829. iCount = 1;
  2830. }
  2831. else
  2832. {
  2833. iCount++;
  2834. }
  2835. }
  2836. }
  2837. catch (Exception ex)
  2838. {
  2839. LOG.Write(ex);
  2840. return layoutRecipe;
  2841. }
  2842. return layoutRecipe;
  2843. }
  2844. private List<string> ProductSlotMonitorSlot(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strSDDummySlotNo, string strMonitor1SlotNo, string strMonitor2SlotNo, string strFDDummySlotNo)
  2845. {
  2846. var layoutRecipe = new List<string>();
  2847. for (int i = 0; i < iSlotCount; i++)
  2848. {
  2849. layoutRecipe.Add(string.Empty);
  2850. }
  2851. try
  2852. {
  2853. var sddummySlotList = GetLayoutProductionMonitorSlot(strSDDummySlotNo);
  2854. foreach (var item in sddummySlotList)
  2855. {
  2856. int iPos = 0;
  2857. int.TryParse(item, out iPos);
  2858. iPos--;
  2859. layoutRecipe[iPos] = "SD";
  2860. }
  2861. var fddummySlotList = GetLayoutProductionMonitorSlot(strFDDummySlotNo);
  2862. foreach (var item in fddummySlotList)
  2863. {
  2864. int iPos = 0;
  2865. int.TryParse(item, out iPos);
  2866. iPos--;
  2867. layoutRecipe[iPos] = "FD";
  2868. }
  2869. var productSlotNo = new List<string>();
  2870. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  2871. var monitor1SlotNo = new List<string>();
  2872. monitor1SlotNo = GetLayoutProductionMonitorSlot(strMonitor1SlotNo);
  2873. var monitor2SlotNo = new List<string>();
  2874. monitor2SlotNo = GetLayoutProductionMonitorSlot(strMonitor2SlotNo);
  2875. // insert Production
  2876. foreach (string str in productSlotNo)
  2877. {
  2878. int iPos = 0;
  2879. int.TryParse(str, out iPos);
  2880. layoutRecipe[iPos - 1] = "PD";
  2881. }
  2882. // insert Monitor
  2883. foreach (string str in monitor1SlotNo)
  2884. {
  2885. int iPos = 0;
  2886. int.TryParse(str, out iPos);
  2887. layoutRecipe[iPos - 1] = "M1";
  2888. }
  2889. foreach (string str in monitor2SlotNo)
  2890. {
  2891. int iPos = 0;
  2892. int.TryParse(str, out iPos);
  2893. layoutRecipe[iPos - 1] = "M2";
  2894. }
  2895. }
  2896. catch (Exception ex)
  2897. {
  2898. LOG.Write(ex);
  2899. return layoutRecipe;
  2900. }
  2901. return layoutRecipe;
  2902. }
  2903. private List<string> ProductAutoMonitorBetweenCassetteStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  2904. {
  2905. var layoutRecipe = new List<string>();
  2906. for (int i = 0; i < iSlotCount; i++)
  2907. {
  2908. layoutRecipe.Add(string.Empty);
  2909. }
  2910. try
  2911. {
  2912. // insert Upper Dummy
  2913. for (int i = 0; i < iDummyUpperSlot; i++)
  2914. {
  2915. layoutRecipe[i] = "SD";
  2916. }
  2917. // insert Lower Dummy
  2918. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  2919. {
  2920. layoutRecipe[i] = "SD";
  2921. }
  2922. var monitorBetweenCassetteNo = new List<string>();
  2923. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  2924. // insert Monitor
  2925. int iIndex, iMonitorCount = 7;
  2926. iIndex = iDummyUpperSlot;
  2927. for (int i = 0; i < iMonitorCount; i++)
  2928. {
  2929. iIndex = iDummyUpperSlot + i * iCassetteSlotCount + i;
  2930. if (iIndex < iSlotCount - iDummyLowerSlot - 1)
  2931. {
  2932. if (monitorBetweenCassetteNo[i] == "ON")
  2933. {
  2934. layoutRecipe[iIndex] = "M1";
  2935. }
  2936. }
  2937. else
  2938. {
  2939. if (monitorBetweenCassetteNo[i] == "ON")
  2940. {
  2941. iIndex = iSlotCount - iDummyLowerSlot - 1;
  2942. layoutRecipe[iIndex] = "M1";
  2943. }
  2944. }
  2945. }
  2946. // insert Production
  2947. int iFirstMonitorIndex = 0;
  2948. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  2949. {
  2950. if (layoutRecipe[i] == "M1")
  2951. {
  2952. iFirstMonitorIndex = i;
  2953. break;
  2954. }
  2955. }
  2956. // Search Up
  2957. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot; i--)
  2958. {
  2959. if (layoutRecipe[i] == "")
  2960. {
  2961. layoutRecipe[i] = "PD";
  2962. }
  2963. else
  2964. {
  2965. break;
  2966. }
  2967. }
  2968. // Search Down
  2969. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 1; i++)
  2970. {
  2971. if (layoutRecipe[i] == "")
  2972. {
  2973. layoutRecipe[i] = "PD";
  2974. }
  2975. }
  2976. }
  2977. catch (Exception ex)
  2978. {
  2979. LOG.Write(ex);
  2980. return layoutRecipe;
  2981. }
  2982. return layoutRecipe;
  2983. }
  2984. private List<string> ProductAutoMonitorBetweenCassetteDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  2985. {
  2986. var layoutRecipe = new List<string>();
  2987. for (int i = 0; i < iSlotCount; i++)
  2988. {
  2989. layoutRecipe.Add(string.Empty);
  2990. }
  2991. try
  2992. {
  2993. // insert Upper Dummy
  2994. for (int i = 0; i < iDummyUpperSlot; i++)
  2995. {
  2996. layoutRecipe[i] = "SD";
  2997. }
  2998. // insert Lower Dummy
  2999. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3000. {
  3001. layoutRecipe[i] = "SD";
  3002. }
  3003. var monitorBetweenCassetteNo = new List<string>();
  3004. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  3005. // insert Monitor
  3006. int iIndex, iMonitorCount = 7;
  3007. iIndex = iDummyUpperSlot;
  3008. for (int i = 0; i < iMonitorCount; i += 2)
  3009. {
  3010. iIndex = iDummyUpperSlot + 1 + i * iCassetteSlotCount * 2 + i * 2;
  3011. if (iIndex < iSlotCount - iDummyLowerSlot - 2)
  3012. {
  3013. if (monitorBetweenCassetteNo[i] == "ON")
  3014. {
  3015. layoutRecipe[iIndex] = "M1";
  3016. }
  3017. }
  3018. else
  3019. {
  3020. if (monitorBetweenCassetteNo[i] == "ON")
  3021. {
  3022. iIndex = iSlotCount - iDummyLowerSlot - 2;
  3023. layoutRecipe[iIndex] = "M1";
  3024. }
  3025. }
  3026. }
  3027. // insert Production
  3028. int iFirstMonitorIndex = 0;
  3029. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  3030. {
  3031. if (layoutRecipe[i] == "M1")
  3032. {
  3033. iFirstMonitorIndex = i;
  3034. break;
  3035. }
  3036. }
  3037. // search Up
  3038. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot + 1; i -= 2)
  3039. {
  3040. if (layoutRecipe[i] == "" && layoutRecipe[i - 1] == "")
  3041. {
  3042. layoutRecipe[i] = "PD";
  3043. }
  3044. else
  3045. {
  3046. break;
  3047. }
  3048. }
  3049. // serach Down
  3050. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 2; i += 2)
  3051. {
  3052. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  3053. {
  3054. layoutRecipe[i] = "PD";
  3055. }
  3056. }
  3057. }
  3058. catch (Exception ex)
  3059. {
  3060. LOG.Write(ex);
  3061. return layoutRecipe;
  3062. }
  3063. return layoutRecipe;
  3064. }
  3065. private List<string> ProductAutoMonitorBetweenCassetteTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorBetweenCasseteNo, string strBoatRule)
  3066. {
  3067. var layoutRecipe = new List<string>();
  3068. for (int i = 0; i < iSlotCount; i++)
  3069. {
  3070. layoutRecipe.Add(string.Empty);
  3071. }
  3072. try
  3073. {
  3074. // insert Upper Dummy
  3075. for (int i = 0; i < iDummyUpperSlot; i++)
  3076. {
  3077. layoutRecipe[i] = "SD";
  3078. }
  3079. // insert Lower Dummy
  3080. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3081. {
  3082. layoutRecipe[i] = "SD";
  3083. }
  3084. var monitorBetweenCassetteNo = new List<string>();
  3085. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  3086. // insert Monitor
  3087. int iIndex, iMonitorCount = 7;
  3088. iIndex = iDummyUpperSlot;
  3089. for (int i = 0; i < iMonitorCount; i += 3)
  3090. {
  3091. iIndex = iDummyUpperSlot + 2 + i * iCassetteSlotCount * 3 + i * 3;
  3092. if (iIndex < iSlotCount - iDummyLowerSlot - 3)
  3093. {
  3094. if (monitorBetweenCassetteNo[i] == "ON")
  3095. {
  3096. layoutRecipe[iIndex] = "M1";
  3097. }
  3098. }
  3099. else
  3100. {
  3101. if (monitorBetweenCassetteNo[i] == "ON")
  3102. {
  3103. iIndex = iSlotCount - iDummyLowerSlot - 3;
  3104. layoutRecipe[iIndex] = "M1";
  3105. }
  3106. }
  3107. }
  3108. // insert Production
  3109. int iFirstMonitorIndex = 0;
  3110. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  3111. {
  3112. if (layoutRecipe[i] == "M1")
  3113. {
  3114. iFirstMonitorIndex = i;
  3115. break;
  3116. }
  3117. }
  3118. // search Up
  3119. for (int i = iFirstMonitorIndex; i >= iDummyUpperSlot + 2; i -= 3)
  3120. {
  3121. if (layoutRecipe[i] == "" && layoutRecipe[i - 1] == "" && layoutRecipe[i - 2] == "")
  3122. {
  3123. layoutRecipe[i] = "PD";
  3124. }
  3125. else
  3126. {
  3127. break;
  3128. }
  3129. }
  3130. // serach Down
  3131. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 3; i += 3)
  3132. {
  3133. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  3134. {
  3135. layoutRecipe[i] = "PD";
  3136. }
  3137. }
  3138. }
  3139. catch (Exception ex)
  3140. {
  3141. LOG.Write(ex);
  3142. return layoutRecipe;
  3143. }
  3144. return layoutRecipe;
  3145. }
  3146. private List<string> ProductAutoMonitorSlotStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  3147. {
  3148. var layoutRecipe = new List<string>();
  3149. for (int i = 0; i < iSlotCount; i++)
  3150. {
  3151. layoutRecipe.Add(string.Empty);
  3152. }
  3153. try
  3154. {
  3155. // insert Upper Dummy
  3156. for (int i = 0; i < iDummyUpperSlot; i++)
  3157. {
  3158. layoutRecipe[i] = "SD";
  3159. }
  3160. // insert Lower Dummy
  3161. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3162. {
  3163. layoutRecipe[i] = "SD";
  3164. }
  3165. var monitorSlotList = new List<string>();
  3166. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3167. var monitorSlotNo = new List<int>();
  3168. foreach (string str in monitorSlotList)
  3169. {
  3170. int iPos = 0;
  3171. int.TryParse(str, out iPos);
  3172. iPos--;
  3173. if (!monitorSlotNo.Contains(iPos))
  3174. {
  3175. monitorSlotNo.Add(iPos);
  3176. }
  3177. }
  3178. monitorSlotNo.Sort();
  3179. // insert Monitor
  3180. List<int> monitorNo = new List<int>();
  3181. foreach (int vm in monitorSlotNo)
  3182. {
  3183. if (layoutRecipe[vm] != "SD")
  3184. {
  3185. layoutRecipe[vm] = "M1";
  3186. }
  3187. }
  3188. // insert Production
  3189. int iFirstMonitorIndex = 0;
  3190. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  3191. {
  3192. if (layoutRecipe[i] == "M1")
  3193. {
  3194. iFirstMonitorIndex = i;
  3195. break;
  3196. }
  3197. }
  3198. for (int i = iDummyUpperSlot; i < iFirstMonitorIndex; i++)
  3199. {
  3200. if (layoutRecipe[i] == "")
  3201. {
  3202. layoutRecipe[i] = "PD";
  3203. }
  3204. else
  3205. {
  3206. break;
  3207. }
  3208. }
  3209. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 1; i++)
  3210. {
  3211. if (layoutRecipe[i] == "")
  3212. {
  3213. layoutRecipe[i] = "PD";
  3214. }
  3215. }
  3216. }
  3217. catch (Exception ex)
  3218. {
  3219. LOG.Write(ex);
  3220. return layoutRecipe;
  3221. }
  3222. return layoutRecipe;
  3223. }
  3224. private List<string> ProductAutoMonitorSlotDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  3225. {
  3226. var layoutRecipe = new List<string>();
  3227. for (int i = 0; i < iSlotCount; i++)
  3228. {
  3229. layoutRecipe.Add(string.Empty);
  3230. }
  3231. try
  3232. {
  3233. // insert Upper Dummy
  3234. for (int i = 0; i < iDummyUpperSlot; i++)
  3235. {
  3236. layoutRecipe[i] = "SD";
  3237. }
  3238. // insert Lower Dummy
  3239. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3240. {
  3241. layoutRecipe[i] = "SD";
  3242. }
  3243. var monitorSlotList = new List<string>();
  3244. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3245. var monitorSlotNo = new List<int>();
  3246. foreach (string str in monitorSlotList)
  3247. {
  3248. int iPos = 0;
  3249. int.TryParse(str, out iPos);
  3250. iPos--;
  3251. if (!monitorSlotNo.Contains(iPos))
  3252. {
  3253. monitorSlotNo.Add(iPos);
  3254. }
  3255. }
  3256. monitorSlotNo.Sort();
  3257. // insert Monitor
  3258. List<int> monitorNo = new List<int>();
  3259. foreach (int vm in monitorSlotNo)
  3260. {
  3261. if (layoutRecipe[vm] != "SD" && vm >= iDummyUpperSlot + 1 && vm <= iSlotCount - iDummyLowerSlot - 2)
  3262. {
  3263. layoutRecipe[vm] = "M1";
  3264. }
  3265. }
  3266. // insert Production
  3267. int iFirstMonitorIndex = 0;
  3268. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  3269. {
  3270. if (layoutRecipe[i] == "M1")
  3271. {
  3272. iFirstMonitorIndex = i;
  3273. break;
  3274. }
  3275. }
  3276. for (int i = iDummyUpperSlot + 1; i < iFirstMonitorIndex; i += 2)
  3277. {
  3278. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  3279. {
  3280. layoutRecipe[i] = "PD";
  3281. }
  3282. else
  3283. {
  3284. break;
  3285. }
  3286. }
  3287. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 2; i += 2)
  3288. {
  3289. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "")
  3290. {
  3291. layoutRecipe[i] = "PD";
  3292. }
  3293. }
  3294. }
  3295. catch (Exception ex)
  3296. {
  3297. LOG.Write(ex);
  3298. return layoutRecipe;
  3299. }
  3300. return layoutRecipe;
  3301. }
  3302. private List<string> ProductAutoMonitorSlotTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strMonitorSlotNo, string strBoatRule)
  3303. {
  3304. var layoutRecipe = new List<string>();
  3305. for (int i = 0; i < iSlotCount; i++)
  3306. {
  3307. layoutRecipe.Add(string.Empty);
  3308. }
  3309. try
  3310. {
  3311. // insert Upper Dummy
  3312. for (int i = 0; i < iDummyUpperSlot; i++)
  3313. {
  3314. layoutRecipe[i] = "SD";
  3315. }
  3316. // insert Lower Dummy
  3317. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3318. {
  3319. layoutRecipe[i] = "SD";
  3320. }
  3321. var monitorSlotList = new List<string>();
  3322. monitorSlotList = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3323. var monitorSlotNo = new List<int>();
  3324. foreach (string str in monitorSlotList)
  3325. {
  3326. int iPos = 0;
  3327. int.TryParse(str, out iPos);
  3328. iPos--;
  3329. if (!monitorSlotNo.Contains(iPos))
  3330. {
  3331. monitorSlotNo.Add(iPos);
  3332. }
  3333. }
  3334. monitorSlotNo.Sort();
  3335. // insert Monitor
  3336. List<int> monitorNo = new List<int>();
  3337. foreach (int vm in monitorSlotNo)
  3338. {
  3339. if (layoutRecipe[vm] != "SD" && vm >= iDummyUpperSlot + 2 && vm <= iSlotCount - iDummyLowerSlot - 3)
  3340. {
  3341. layoutRecipe[vm] = "M1";
  3342. }
  3343. }
  3344. // insert Production
  3345. int iFirstMonitorIndex = 0;
  3346. for (int i = iDummyUpperSlot; i < iSlotCount; i++)
  3347. {
  3348. if (layoutRecipe[i] == "M1")
  3349. {
  3350. iFirstMonitorIndex = i;
  3351. break;
  3352. }
  3353. }
  3354. for (int i = iDummyUpperSlot + 2; i < iFirstMonitorIndex; i += 3)
  3355. {
  3356. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  3357. {
  3358. layoutRecipe[i] = "PD";
  3359. }
  3360. else
  3361. {
  3362. break;
  3363. }
  3364. }
  3365. for (int i = iFirstMonitorIndex; i <= iSlotCount - iDummyLowerSlot - 3; i += 3)
  3366. {
  3367. if (layoutRecipe[i] == "" && layoutRecipe[i + 1] == "" && layoutRecipe[i + 2] == "")
  3368. {
  3369. layoutRecipe[i] = "PD";
  3370. }
  3371. }
  3372. }
  3373. catch (Exception ex)
  3374. {
  3375. LOG.Write(ex);
  3376. return layoutRecipe;
  3377. }
  3378. return layoutRecipe;
  3379. }
  3380. private List<string> ProductSlotMonitorBetweenCassetteStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  3381. {
  3382. var layoutRecipe = new List<string>();
  3383. for (int i = 0; i < iSlotCount; i++)
  3384. {
  3385. layoutRecipe.Add(string.Empty);
  3386. }
  3387. try
  3388. {
  3389. // insert Upper Dummy
  3390. for (int i = 0; i < iDummyUpperSlot; i++)
  3391. {
  3392. layoutRecipe[i] = "SD";
  3393. }
  3394. // insert Lower Dummy
  3395. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3396. {
  3397. layoutRecipe[i] = "SD";
  3398. }
  3399. var productSlotList = new List<string>();
  3400. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3401. var productSloNo = new List<int>();
  3402. foreach (string str in productSlotList)
  3403. {
  3404. int iPos = 0;
  3405. int.TryParse(str, out iPos);
  3406. iPos--;
  3407. if (!productSloNo.Contains(iPos))
  3408. {
  3409. productSloNo.Add(iPos);
  3410. }
  3411. }
  3412. productSloNo.Sort();
  3413. var monitorBetweenCassetteNo = new List<string>();
  3414. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  3415. // insert Monitor
  3416. int iIndex, iMonitorCount = 7;
  3417. iIndex = iDummyUpperSlot;
  3418. for (int i = 0; i < iMonitorCount; i++)
  3419. {
  3420. iIndex = iDummyUpperSlot + i * iCassetteSlotCount + i;
  3421. if (iIndex < iSlotCount - iDummyLowerSlot - 1)
  3422. {
  3423. if (monitorBetweenCassetteNo[i] == "ON")
  3424. {
  3425. layoutRecipe[iIndex] = "M1";
  3426. }
  3427. }
  3428. else
  3429. {
  3430. if (monitorBetweenCassetteNo[i] == "ON")
  3431. {
  3432. iIndex = iSlotCount - iDummyLowerSlot - 1;
  3433. layoutRecipe[iIndex] = "M1";
  3434. }
  3435. }
  3436. }
  3437. // insert Production
  3438. foreach (int vm in productSloNo)
  3439. {
  3440. if (layoutRecipe[vm] == "" && vm >= iDummyUpperSlot && vm <= iSlotCount - iDummyLowerSlot - 1)
  3441. {
  3442. layoutRecipe[vm] = "PD";
  3443. }
  3444. }
  3445. }
  3446. catch (Exception ex)
  3447. {
  3448. LOG.Write(ex);
  3449. return layoutRecipe;
  3450. }
  3451. return layoutRecipe;
  3452. }
  3453. private List<string> ProductSlotMonitorBetweenCassetteDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  3454. {
  3455. var layoutRecipe = new List<string>();
  3456. for (int i = 0; i < iSlotCount; i++)
  3457. {
  3458. layoutRecipe.Add(string.Empty);
  3459. }
  3460. try
  3461. {
  3462. // insert Upper Dummy
  3463. for (int i = 0; i < iDummyUpperSlot; i++)
  3464. {
  3465. layoutRecipe[i] = "SD";
  3466. }
  3467. // insert Lower Dummy
  3468. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3469. {
  3470. layoutRecipe[i] = "SD";
  3471. }
  3472. var productSlotList = new List<string>();
  3473. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3474. var productSloNo = new List<int>();
  3475. foreach (string str in productSlotList)
  3476. {
  3477. int iPos = 0;
  3478. int.TryParse(str, out iPos);
  3479. iPos--;
  3480. if (!productSloNo.Contains(iPos))
  3481. {
  3482. productSloNo.Add(iPos);
  3483. }
  3484. }
  3485. productSloNo.Sort();
  3486. var monitorBetweenCassetteNo = new List<string>();
  3487. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  3488. // insert Monitor
  3489. int iIndex, iMonitorCount = 7;
  3490. iIndex = iDummyUpperSlot;
  3491. for (int i = 0; i < iMonitorCount; i += 2)
  3492. {
  3493. iIndex = iDummyUpperSlot + 1 + i * iCassetteSlotCount * 2 + i * 2;
  3494. if (iIndex < iSlotCount - iDummyLowerSlot - 2)
  3495. {
  3496. if (monitorBetweenCassetteNo[i] == "ON")
  3497. {
  3498. layoutRecipe[iIndex] = "M1";
  3499. }
  3500. }
  3501. else
  3502. {
  3503. if (monitorBetweenCassetteNo[i] == "ON")
  3504. {
  3505. iIndex = iSlotCount - iDummyLowerSlot - 2;
  3506. layoutRecipe[iIndex] = "M1";
  3507. }
  3508. }
  3509. }
  3510. // insert Production
  3511. foreach (int vm in productSloNo)
  3512. {
  3513. if (layoutRecipe[vm] == "" && layoutRecipe[vm - 1] == "" && layoutRecipe[vm + 1] == "" && vm >= iDummyUpperSlot + 1 && vm <= iSlotCount - iDummyLowerSlot - 2)
  3514. {
  3515. layoutRecipe[vm] = "PD";
  3516. }
  3517. }
  3518. }
  3519. catch (Exception ex)
  3520. {
  3521. LOG.Write(ex);
  3522. return layoutRecipe;
  3523. }
  3524. return layoutRecipe;
  3525. }
  3526. private List<string> ProductSlotMonitorBetweenCassetteTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorBetweenCasseteNo, string strBoatRule)
  3527. {
  3528. var layoutRecipe = new List<string>();
  3529. for (int i = 0; i < iSlotCount; i++)
  3530. {
  3531. layoutRecipe.Add(string.Empty);
  3532. }
  3533. try
  3534. {
  3535. // insert Upper Dummy
  3536. for (int i = 0; i < iDummyUpperSlot; i++)
  3537. {
  3538. layoutRecipe[i] = "SD";
  3539. }
  3540. // insert Lower Dummy
  3541. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3542. {
  3543. layoutRecipe[i] = "SD";
  3544. }
  3545. var productSlotList = new List<string>();
  3546. productSlotList = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3547. var productSloNo = new List<int>();
  3548. foreach (string str in productSlotList)
  3549. {
  3550. int iPos = 0;
  3551. int.TryParse(str, out iPos);
  3552. iPos--;
  3553. if (!productSloNo.Contains(iPos))
  3554. {
  3555. productSloNo.Add(iPos);
  3556. }
  3557. }
  3558. productSloNo.Sort();
  3559. var monitorBetweenCassetteNo = new List<string>();
  3560. monitorBetweenCassetteNo = GetLayoutProductionMonitorSlot(strMonitorBetweenCasseteNo);
  3561. // insert Monitor
  3562. int iIndex, iMonitorCount = 7;
  3563. iIndex = iDummyUpperSlot;
  3564. for (int i = 0; i < iMonitorCount; i += 3)
  3565. {
  3566. iIndex = iDummyUpperSlot + 2 + i * iCassetteSlotCount * 3 + i * 3;
  3567. if (iIndex < iSlotCount - iDummyLowerSlot - 3)
  3568. {
  3569. if (monitorBetweenCassetteNo[i] == "ON")
  3570. {
  3571. layoutRecipe[iIndex] = "M1";
  3572. }
  3573. }
  3574. else
  3575. {
  3576. if (monitorBetweenCassetteNo[i] == "ON")
  3577. {
  3578. iIndex = iSlotCount - iDummyLowerSlot - 3;
  3579. layoutRecipe[iIndex] = "M1";
  3580. }
  3581. }
  3582. }
  3583. // insert Production
  3584. foreach (int vm in productSloNo)
  3585. {
  3586. if (layoutRecipe[vm] == "" && layoutRecipe[vm - 1] == "" && layoutRecipe[vm - 2] == "" &&
  3587. layoutRecipe[vm + 1] == "" && layoutRecipe[vm + 2] == "" && vm >= iDummyUpperSlot + 2 && vm <= iSlotCount - iDummyLowerSlot - 3)
  3588. {
  3589. layoutRecipe[vm] = "PD";
  3590. }
  3591. }
  3592. }
  3593. catch (Exception ex)
  3594. {
  3595. LOG.Write(ex);
  3596. return layoutRecipe;
  3597. }
  3598. return layoutRecipe;
  3599. }
  3600. private List<string> ProductSlotMonitorSlotStandardPitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  3601. {
  3602. var layoutRecipe = new List<string>();
  3603. for (int i = 0; i < iSlotCount; i++)
  3604. {
  3605. layoutRecipe.Add(string.Empty);
  3606. }
  3607. try
  3608. {
  3609. // insert Upper Dummy
  3610. for (int i = 0; i < iDummyUpperSlot; i++)
  3611. {
  3612. layoutRecipe[i] = "SD";
  3613. }
  3614. // insert Lower Dummy
  3615. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3616. {
  3617. layoutRecipe[i] = "SD";
  3618. }
  3619. var productSlotNo = new List<string>();
  3620. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3621. var monitorSlotNo = new List<string>();
  3622. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3623. // insert Production
  3624. foreach (string str in productSlotNo)
  3625. {
  3626. int iPos = 0;
  3627. int.TryParse(str, out iPos);
  3628. if (layoutRecipe[iPos - 1] != "SD")
  3629. {
  3630. layoutRecipe[iPos - 1] = "PD";
  3631. }
  3632. }
  3633. // insert Monitor
  3634. foreach (string str in monitorSlotNo)
  3635. {
  3636. int iPos = 0;
  3637. int.TryParse(str, out iPos);
  3638. if (layoutRecipe[iPos - 1] != "SD")
  3639. {
  3640. layoutRecipe[iPos - 1] = "PD";
  3641. }
  3642. }
  3643. }
  3644. catch (Exception ex)
  3645. {
  3646. LOG.Write(ex);
  3647. return layoutRecipe;
  3648. }
  3649. return layoutRecipe;
  3650. }
  3651. private List<string> ProductSlotMonitorSlotDoublePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  3652. {
  3653. var layoutRecipe = new List<string>();
  3654. for (int i = 0; i < iSlotCount; i++)
  3655. {
  3656. layoutRecipe.Add(string.Empty);
  3657. }
  3658. try
  3659. {
  3660. // insert Upper Dummy
  3661. for (int i = 0; i < iDummyUpperSlot; i++)
  3662. {
  3663. layoutRecipe[i] = "SD";
  3664. }
  3665. // insert Lower Dummy
  3666. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3667. {
  3668. layoutRecipe[i] = "SD";
  3669. }
  3670. var productSlotNo = new List<string>();
  3671. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3672. var monitorSlotNo = new List<string>();
  3673. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3674. // insert Production
  3675. foreach (string str in productSlotNo)
  3676. {
  3677. int iPos = 0;
  3678. int.TryParse(str, out iPos);
  3679. if (layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "SD" && layoutRecipe[iPos] == string.Empty)
  3680. {
  3681. layoutRecipe[iPos - 1] = "PD";
  3682. }
  3683. }
  3684. // insert Monitor
  3685. foreach (string str in monitorSlotNo)
  3686. {
  3687. int iPos = 0;
  3688. int.TryParse(str, out iPos);
  3689. if (layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "SD" && layoutRecipe[iPos] == string.Empty)
  3690. {
  3691. layoutRecipe[iPos - 1] = "PD";
  3692. }
  3693. }
  3694. }
  3695. catch (Exception ex)
  3696. {
  3697. LOG.Write(ex);
  3698. return layoutRecipe;
  3699. }
  3700. return layoutRecipe;
  3701. }
  3702. private List<string> ProductSlotMonitorSlotTriplePitch(int iSlotCount, int iCassetteSlotCount, int iDummyUpperSlot, int iDummyLowerSlot, string strProductSlotNo, string strMonitorSlotNo, string strBoatRule)
  3703. {
  3704. var layoutRecipe = new List<string>();
  3705. for (int i = 0; i < iSlotCount; i++)
  3706. {
  3707. layoutRecipe.Add(string.Empty);
  3708. }
  3709. try
  3710. {
  3711. // insert Upper Dummy
  3712. for (int i = 0; i < iDummyUpperSlot; i++)
  3713. {
  3714. layoutRecipe[i] = "SD";
  3715. }
  3716. // insert Lower Dummy
  3717. for (int i = iSlotCount - 1; i >= iSlotCount - iDummyLowerSlot; i--)
  3718. {
  3719. layoutRecipe[i] = "SD";
  3720. }
  3721. var productSlotNo = new List<string>();
  3722. productSlotNo = GetLayoutProductionMonitorSlot(strProductSlotNo);
  3723. var monitorSlotNo = new List<string>();
  3724. monitorSlotNo = GetLayoutProductionMonitorSlot(strMonitorSlotNo);
  3725. // insert Production
  3726. foreach (string str in productSlotNo)
  3727. {
  3728. int iPos = 0;
  3729. int.TryParse(str, out iPos);
  3730. if (layoutRecipe[iPos - 3] == string.Empty && layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" &&
  3731. layoutRecipe[iPos] == string.Empty && layoutRecipe[iPos + 1] == string.Empty)
  3732. {
  3733. layoutRecipe[iPos - 1] = "PD";
  3734. }
  3735. }
  3736. // insert Monitor
  3737. foreach (string str in monitorSlotNo)
  3738. {
  3739. int iPos = 0;
  3740. int.TryParse(str, out iPos);
  3741. if (layoutRecipe[iPos - 3] == string.Empty && layoutRecipe[iPos - 2] == string.Empty && layoutRecipe[iPos - 1] != "Dummy" &&
  3742. layoutRecipe[iPos] == string.Empty && layoutRecipe[iPos + 1] == string.Empty)
  3743. {
  3744. layoutRecipe[iPos - 1] = "M1";
  3745. }
  3746. }
  3747. }
  3748. catch (Exception ex)
  3749. {
  3750. LOG.Write(ex);
  3751. return layoutRecipe;
  3752. }
  3753. return layoutRecipe;
  3754. }
  3755. private List<string> GetLayoutProductionMonitorSlot(string strParam)
  3756. {
  3757. var slot = new List<string>();
  3758. if (strParam == string.Empty)
  3759. {
  3760. return slot;
  3761. }
  3762. slot = strParam.Split(',').ToList();
  3763. return slot;
  3764. }
  3765. private List<string> XDSlot(int iSlotCount, int iCassetteSlotCount, string strXDSlotNo, string strDummySlotNo, int iDummyUpperSlot)
  3766. {
  3767. var layoutRecipe = new List<string>();
  3768. for (int i = 0; i < iSlotCount; i++)
  3769. {
  3770. layoutRecipe.Add(string.Empty);
  3771. }
  3772. try
  3773. {
  3774. if (iDummyUpperSlot > 0)
  3775. {
  3776. for (int i = 0; i < iDummyUpperSlot; i++)
  3777. {
  3778. layoutRecipe[i] = "XD";
  3779. }
  3780. }
  3781. else
  3782. {
  3783. var TSlotNo = new List<string>();
  3784. TSlotNo = GetLayoutProductionMonitorSlot(strXDSlotNo);
  3785. var XDSlotNo = new List<string>();
  3786. XDSlotNo = GetLayoutProductionMonitorSlot(strDummySlotNo);
  3787. // insert Production
  3788. foreach (string str in TSlotNo)
  3789. {
  3790. int iPos = 0;
  3791. int.TryParse(str, out iPos);
  3792. if (layoutRecipe[iPos - 1] != "XD")
  3793. {
  3794. layoutRecipe[iPos - 1] = "T";
  3795. }
  3796. }
  3797. foreach (string str in XDSlotNo)
  3798. {
  3799. int iPos = 0;
  3800. int.TryParse(str, out iPos);
  3801. if (layoutRecipe[iPos - 1] != "T")
  3802. {
  3803. layoutRecipe[iPos - 1] = "XD";
  3804. }
  3805. }
  3806. }
  3807. }
  3808. catch (Exception ex)
  3809. {
  3810. LOG.Write(ex);
  3811. return layoutRecipe;
  3812. }
  3813. return layoutRecipe;
  3814. }
  3815. #region Sequence
  3816. private string GetSequenceConfig(string nodePath)
  3817. {
  3818. if (_seqContext == null)
  3819. return string.Empty;
  3820. string schema = _seqContext.GetConfigXml();
  3821. XmlDocument dom = new XmlDocument();
  3822. dom.LoadXml(schema);
  3823. XmlNode node = dom.SelectSingleNode(nodePath);
  3824. return node.OuterXml;
  3825. }
  3826. public string GetWaferFlowRecipe(string recipeName, bool needValidation)
  3827. {
  3828. string seq = string.Empty;
  3829. try
  3830. {
  3831. using (StreamReader fs = new StreamReader(GenerateRecipeFilePath($"{SC.GetStringValue("System.Recipe.RecipeChamberType")}\\{WaferFlowFolder}", recipeName)))
  3832. {
  3833. seq = fs.ReadToEnd();
  3834. fs.Close();
  3835. }
  3836. if (needValidation && !_seqContext.Validation(seq))
  3837. {
  3838. EV.PostWarningLog(SourceModule, $"Read {recipeName} failed, validation failed");
  3839. seq = string.Empty;
  3840. }
  3841. }
  3842. catch (Exception ex)
  3843. {
  3844. LOG.Write(ex);
  3845. EV.PostWarningLog(SourceModule, $"Read {recipeName} failed, " + ex.Message);
  3846. seq = string.Empty;
  3847. }
  3848. return seq;
  3849. }
  3850. public string GetSequence(string sequenceName, bool needValidation)
  3851. {
  3852. string seq = string.Empty;
  3853. try
  3854. {
  3855. using (StreamReader fs = new StreamReader(GenerateSequenceFilePath(SequenceFolder, sequenceName)))
  3856. {
  3857. seq = fs.ReadToEnd();
  3858. fs.Close();
  3859. }
  3860. if (needValidation && !_seqContext.Validation(seq))
  3861. {
  3862. EV.PostWarningLog(SourceModule, $"Read {sequenceName} failed, validation failed");
  3863. seq = string.Empty;
  3864. }
  3865. }
  3866. catch (Exception ex)
  3867. {
  3868. LOG.Write(ex);
  3869. EV.PostWarningLog(SourceModule, $"Read {sequenceName} failed, " + ex.Message);
  3870. seq = string.Empty;
  3871. }
  3872. return seq;
  3873. }
  3874. public List<string> GetSequenceNameList()
  3875. {
  3876. var result = new List<string>();
  3877. try
  3878. {
  3879. string recipePath = PathManager.GetRecipeDir() + SequenceFolder + "\\";
  3880. var di = new DirectoryInfo(recipePath);
  3881. var fis = di.GetFiles("*.seq", System.IO.SearchOption.AllDirectories);
  3882. foreach (var fi in fis)
  3883. {
  3884. string str = fi.FullName.Substring(recipePath.Length);
  3885. str = str.Substring(0, str.LastIndexOf('.'));
  3886. result.Add(str);
  3887. }
  3888. }
  3889. catch (Exception ex)
  3890. {
  3891. LOG.Write(ex);
  3892. EV.PostWarningLog(SourceModule, "Get sequence list failed, " + ex.Message);
  3893. }
  3894. return result;
  3895. }
  3896. public bool DeleteSequence(string sequenceName)
  3897. {
  3898. try
  3899. {
  3900. File.Delete(GenerateSequenceFilePath(SequenceFolder, sequenceName));
  3901. EV.PostInfoLog(SourceModule, $"sequence {sequenceName} deleted");
  3902. }
  3903. catch (Exception ex)
  3904. {
  3905. LOG.Write(ex);
  3906. EV.PostWarningLog(SourceModule, $"delete {sequenceName} failed, " + ex.Message);
  3907. return false;
  3908. }
  3909. return true;
  3910. }
  3911. public bool SaveSequence(string sequenceName, string sequenceContent, bool notifyUI)
  3912. {
  3913. bool ret = true;
  3914. try
  3915. {
  3916. var path = GenerateSequenceFilePath(SequenceFolder, sequenceName);
  3917. FileInfo fi = new FileInfo(path);
  3918. if (!fi.Directory.Exists)
  3919. {
  3920. fi.Directory.Create();
  3921. }
  3922. XmlDocument xml = new XmlDocument();
  3923. xml.LoadXml(sequenceContent);
  3924. XmlTextWriter writer = new XmlTextWriter(path, null);
  3925. writer.Formatting = Formatting.Indented;
  3926. xml.Save(writer);
  3927. writer.Close();
  3928. if (notifyUI)
  3929. {
  3930. EV.PostPopDialogMessage(EventLevel.Information, "Save Complete", $"Sequence {sequenceName} saved ");
  3931. }
  3932. else
  3933. {
  3934. EV.PostInfoLog(SourceModule, $"Sequence {sequenceName} saved ");
  3935. }
  3936. }
  3937. catch (Exception ex)
  3938. {
  3939. LOG.Write(ex);
  3940. EV.PostWarningLog(SourceModule, $"save sequence {sequenceName} failed, " + ex.Message);
  3941. if (notifyUI)
  3942. {
  3943. EV.PostPopDialogMessage(EventLevel.Alarm, "Save Error", $"save sequence {sequenceName} failed, " + ex.Message);
  3944. }
  3945. ret = false;
  3946. }
  3947. return ret;
  3948. }
  3949. public bool SaveAsSequence(string sequenceName, string sequenceContent)
  3950. {
  3951. var path = GenerateSequenceFilePath(SequenceFolder, sequenceName);
  3952. if (File.Exists(path))
  3953. {
  3954. EV.PostWarningLog(SourceModule, $"save sequence {sequenceName} failed, already exist");
  3955. return false;
  3956. }
  3957. return SaveSequence(sequenceName, sequenceContent, false);
  3958. }
  3959. public bool RenameSequence(string oldName, string newName)
  3960. {
  3961. try
  3962. {
  3963. if (File.Exists(GenerateSequenceFilePath(SequenceFolder, newName)))
  3964. {
  3965. EV.PostWarningLog(SourceModule, $"{newName} already exist, rename failed");
  3966. return false;
  3967. }
  3968. else
  3969. {
  3970. File.Move(GenerateSequenceFilePath(SequenceFolder, oldName), GenerateSequenceFilePath(SequenceFolder, newName));
  3971. EV.PostInfoLog(SourceModule, $"sequence {oldName} renamed to {newName}");
  3972. }
  3973. }
  3974. catch (Exception ex)
  3975. {
  3976. LOG.Write(ex);
  3977. EV.PostWarningLog(SourceModule, $"rename {oldName} failed, " + ex.Message);
  3978. return false;
  3979. }
  3980. return true;
  3981. }
  3982. public string GetSequenceFormatXml()
  3983. {
  3984. return GetSequenceConfig("/Aitex/TableSequenceFormat");
  3985. }
  3986. internal bool DeleteSequenceFolder(string folderName)
  3987. {
  3988. try
  3989. {
  3990. Directory.Delete(PathManager.GetRecipeDir() + SequenceFolder + "\\" + folderName, true);
  3991. EV.PostInfoLog(SourceModule, "Folder " + folderName + "deleted");
  3992. }
  3993. catch (Exception ex)
  3994. {
  3995. LOG.Write(ex, "delete sequence folder exception");
  3996. EV.PostWarningLog(SourceModule, $"can not delete folder {folderName}, {ex.Message}");
  3997. return false;
  3998. }
  3999. return true;
  4000. }
  4001. internal bool CreateSequenceFolder(string folderName)
  4002. {
  4003. try
  4004. {
  4005. Directory.CreateDirectory(PathManager.GetRecipeDir() + SequenceFolder + "\\" + folderName);
  4006. EV.PostInfoLog(SourceModule, "Folder " + folderName + "created");
  4007. }
  4008. catch (Exception ex)
  4009. {
  4010. LOG.Write(ex, "sequence folder create exception");
  4011. EV.PostWarningLog(SourceModule, $"can not create folder {folderName}, {ex.Message}");
  4012. return false;
  4013. }
  4014. return true;
  4015. }
  4016. internal bool RenameSequenceFolder(string oldName, string newName)
  4017. {
  4018. try
  4019. {
  4020. string oldPath = PathManager.GetRecipeDir() + SequenceFolder + "\\" + oldName;
  4021. string newPath = PathManager.GetRecipeDir() + SequenceFolder + "\\" + newName;
  4022. Directory.Move(oldPath, newPath);
  4023. EV.PostInfoLog(SourceModule, $"rename folder from {oldName} to {newName}");
  4024. }
  4025. catch (Exception ex)
  4026. {
  4027. LOG.Write(ex, "rename sequence folder failed");
  4028. EV.PostWarningLog(SourceModule, $"can not rename folder {oldName}, {ex.Message}");
  4029. return false;
  4030. }
  4031. return true;
  4032. }
  4033. public string GetXmlSequenceList(string chamberId)
  4034. {
  4035. XmlDocument doc = new XmlDocument();
  4036. DirectoryInfo curFolderInfo = new DirectoryInfo(PathManager.GetRecipeDir() + SequenceFolder + "\\");
  4037. doc.AppendChild(GenerateSequenceList(chamberId, curFolderInfo, doc));
  4038. return doc.OuterXml;
  4039. }
  4040. XmlElement GenerateSequenceList(string chamberId, DirectoryInfo currentDir, XmlDocument doc)
  4041. {
  4042. int trimLength = (PathManager.GetRecipeDir() + SequenceFolder + "\\").Length;
  4043. XmlElement folderEle = doc.CreateElement("Folder");
  4044. folderEle.SetAttribute("Name", currentDir.FullName.Substring(trimLength));
  4045. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  4046. foreach (DirectoryInfo dirInfo in dirInfos)
  4047. {
  4048. folderEle.AppendChild(GenerateSequenceList(chamberId, dirInfo, doc));
  4049. }
  4050. FileInfo[] fileInfos = currentDir.GetFiles("*.seq");
  4051. foreach (FileInfo fileInfo in fileInfos)
  4052. {
  4053. XmlElement fileNd = doc.CreateElement("File");
  4054. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  4055. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  4056. fileNd.SetAttribute("Name", fileStr);
  4057. folderEle.AppendChild(fileNd);
  4058. }
  4059. return folderEle;
  4060. }
  4061. #endregion
  4062. public List<FileNodeItem> GetFileNodeParameterListByPath(string chamberId)
  4063. {
  4064. List<FileNodeItem> files = new List<FileNodeItem>();
  4065. var baseFolderPath = getRecipeDirPath(chamberId);
  4066. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  4067. FileNodeItem nodeItem = new FileNodeItem();
  4068. nodeItem.IsFile = false;
  4069. GenerateFileNodeParameterList(chamberId, curFolderInfo, nodeItem);
  4070. files.Add(nodeItem);
  4071. return files;
  4072. }
  4073. FileNodeItem GenerateFileNodeParameterList(string chamberId, DirectoryInfo currentDir, FileNodeItem nodeItem)
  4074. {
  4075. int trimLength = getRecipeDirPath(chamberId).Length;
  4076. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  4077. foreach (DirectoryInfo dirInfo in dirInfos)
  4078. {
  4079. FileNodeItem subFileNodeItem = new FileNodeItem();
  4080. subFileNodeItem.IsFile = false;
  4081. subFileNodeItem.PrefixPath = chamberId;
  4082. subFileNodeItem.Name = dirInfo.Name;
  4083. var fullStr = dirInfo.FullName.Substring(dirInfo.FullName.IndexOf(chamberId), dirInfo.FullName.Length - dirInfo.FullName.IndexOf(chamberId));
  4084. subFileNodeItem.FullPath = fullStr;// $"{chamberId}\\{dirInfo.Name}";
  4085. nodeItem.Files.Add(subFileNodeItem);
  4086. GenerateFileNodeParameterList(chamberId, dirInfo, subFileNodeItem);
  4087. }
  4088. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  4089. foreach (FileInfo fileInfo in fileInfos)
  4090. {
  4091. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  4092. FileNodeItem subNodeItem = new FileNodeItem();
  4093. subNodeItem.Name = fileInfo.Name.Replace(".rcp", "");
  4094. if (!string.IsNullOrEmpty(currentDir.Name) && (currentDir.FullName.IndexOf(chamberId) + chamberId.Length + 1 != currentDir.FullName.Length))
  4095. {
  4096. subNodeItem.FullPath = $"{currentDir.Name}\\{subNodeItem.Name}";
  4097. }
  4098. else
  4099. {
  4100. subNodeItem.FullPath = subNodeItem.Name;
  4101. }
  4102. subNodeItem.PrefixPath = chamberId;
  4103. subNodeItem.IsFile = true;
  4104. ReadFileSetFileNode(chamberId, subNodeItem.FullPath, subNodeItem);
  4105. nodeItem.Files.Add(subNodeItem);
  4106. }
  4107. return nodeItem;
  4108. }
  4109. public string LoadRecipeByFullPathForFA(string fullPath)
  4110. {
  4111. string rcp = string.Empty;
  4112. try
  4113. {
  4114. var dir = string.Format("{0}{1}.rcp", PathManager.GetRecipeDir(), fullPath);
  4115. //_IsURecipe = false;
  4116. using (StreamReader fs = new StreamReader(dir))
  4117. {
  4118. rcp = fs.ReadToEnd();
  4119. fs.Close();
  4120. }
  4121. }
  4122. catch (Exception ex)
  4123. {
  4124. try
  4125. {
  4126. using (StreamReader fs = new StreamReader(fullPath))
  4127. {
  4128. rcp = fs.ReadToEnd();
  4129. fs.Close();
  4130. //_IsURecipe = true;
  4131. }
  4132. }
  4133. catch
  4134. {
  4135. LOG.Write(ex, $"load recipe file failed, {fullPath}");
  4136. rcp = string.Empty;
  4137. };
  4138. }
  4139. return rcp;
  4140. }
  4141. List<string> GenerateRecipeNameList(string chamberId, DirectoryInfo currentDir, XmlDocument doc, bool includingUsedRecipe)
  4142. {
  4143. int trimLength = getRecipeDirPath(chamberId).Length;
  4144. XmlElement folderEle = doc.CreateElement("Folder");
  4145. folderEle.SetAttribute("Name", currentDir.FullName.Substring(trimLength));
  4146. List<string> namelist = new List<string>();
  4147. DirectoryInfo[] dirInfos = currentDir.GetDirectories();
  4148. foreach (DirectoryInfo dirInfo in dirInfos)
  4149. {
  4150. if (!includingUsedRecipe && dirInfo.Name == "HistoryRecipe")
  4151. continue;
  4152. folderEle.AppendChild(GenerateRecipeList(chamberId, dirInfo, doc, includingUsedRecipe));
  4153. FileInfo[] tempFileInfos = dirInfo.GetFiles("*.rcp");
  4154. foreach (FileInfo fileInfo in tempFileInfos)
  4155. {
  4156. XmlElement fileNd = doc.CreateElement("File");
  4157. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  4158. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  4159. namelist.Add(chamberId + "\\" + fileStr);
  4160. }
  4161. }
  4162. FileInfo[] fileInfos = currentDir.GetFiles("*.rcp");
  4163. foreach (FileInfo fileInfo in fileInfos)
  4164. {
  4165. XmlElement fileNd = doc.CreateElement("File");
  4166. string fileStr = fileInfo.FullName.Substring(trimLength).TrimStart(new char[] { '\\' }); ;
  4167. fileStr = fileStr.Substring(0, fileStr.LastIndexOf("."));
  4168. namelist.Add(chamberId + "\\" + fileStr);
  4169. }
  4170. return namelist;
  4171. }
  4172. public List<string> GetXmlRecipeNmaeList(string chamberId, bool includingUsedRecipe)
  4173. {
  4174. XmlDocument doc = new XmlDocument();
  4175. var baseFolderPath = getRecipeDirPath(chamberId);
  4176. DirectoryInfo curFolderInfo = new DirectoryInfo(baseFolderPath);
  4177. return GenerateRecipeNameList(chamberId, curFolderInfo, doc, includingUsedRecipe);
  4178. }
  4179. private void ReadFileSetFileNode(string chamberId, string fileName, FileNodeItem fileNodeItem)
  4180. {
  4181. string content = LoadRecipe(chamberId, fileName, false);
  4182. if (string.IsNullOrEmpty(content)) { return; }
  4183. XmlDocument _doc = new XmlDocument();
  4184. _doc.LoadXml(content);
  4185. XmlElement nodeData = _doc.SelectSingleNode($"Aitex/TableRecipeData") as XmlElement;
  4186. fileNodeItem.Creator = nodeData.GetAttribute("CreatedBy");
  4187. fileNodeItem.Description = nodeData.GetAttribute("Description");
  4188. fileNodeItem.CreatTime = nodeData.GetAttribute("CreationTime");
  4189. fileNodeItem.ReviseTime = nodeData.GetAttribute("LastRevisionTime");
  4190. fileNodeItem.Revisor = nodeData.GetAttribute("LastRevisedBy");
  4191. fileNodeItem.Permission = nodeData.GetAttribute("Permission");
  4192. fileNodeItem.Level = nodeData.GetAttribute("Level");
  4193. fileNodeItem.IsChecked = nodeData.GetAttribute("CheckResult") == "Correct";
  4194. }
  4195. }
  4196. }