RecipeFileManager.cs 194 KB

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