RecipeFileManager.cs 191 KB

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