RecipeFileManager.cs 196 KB

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