123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- using System;
- using System.Collections.Generic;
- using System.ServiceModel;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Key;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.RecipeCenter;
- using MECF.Framework.Common.Equipment;
- using Aitex.Core.RT.Log;
- using System.Collections.ObjectModel;
- using System.Reflection;
- using Newtonsoft.Json;
- using Aitex.Common.Util;
- using System.IO;
- namespace MECF.Framework.Common.RecipeCenter
- {
- public class RecipeService : IRecipeService
- {
- /// <summary>
- /// Load a recipe from server to client for editing.
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <returns></returns>
- public string LoadRecipe(ModuleName chamId, string recipeName)
- {
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Read {0} Recipe: {1}", chamId, recipeName));
- return RecipeFileManager.Instance.LoadRecipe(chamId.ToString(), recipeName, false);
- }
- /// <summary>
- /// Delete a recipe by recipe name
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <returns></returns>
- public bool DeleteRecipe(ModuleName chamId, string recipeName)
- {
- if (CheckSoftwareExpired())
- return false;
- //if (!ChamberOperationService.IsSuperEnter()) return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Delete {0} Recipe: {1}", chamId, recipeName));
- return RecipeFileManager.Instance.DeleteRecipe(chamId.ToString(), recipeName);
- }
- /// <summary>
- /// Get recipe list in xml format
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="includingUsedRecipe"></param>
- /// <returns></returns>
- public string GetXmlRecipeList(ModuleName chamId, bool includingUsedRecipe)
- {
- return RecipeFileManager.Instance.GetXmlRecipeList(chamId.ToString(), includingUsedRecipe);
- }
- /// <summary>
- /// Get recipe data by recipe name
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="includingUsedRecipe"></param>
- /// <returns></returns>
- public IEnumerable<string> GetRecipes(ModuleName chamId, bool includingUsedRecipe)
- {
- return RecipeFileManager.Instance.GetRecipes(chamId.ToString(), includingUsedRecipe);
- }
- public ObservableCollection<RecipeNode> GetRecipesByType(string recipeType)
- {
- return RecipeFileManager.Instance.GetRecipesByType(recipeType);
- }
- /// <summary>
- /// 加载工程指定类型的Recipe
- /// </summary>
- /// <param name="recipeType"></param>
- /// <returns></returns>
- public ObservableCollection<RecipeNode> GetEngineeringRecipesByType(string recipeType)
- {
- return RecipeFileManager.Instance.GetEngineeringRecipesByType(recipeType);
- }
- /// <summary>
- /// 获取目录集合Recipe节点
- /// </summary>
- /// <param name="directories"></param>
- /// <returns></returns>
- public ObservableCollection<RecipeNode> GetRecipeByDirectoryList(List<string> directories)
- {
- return RecipeFileManager.Instance.GetRecipeByDirectoryList(directories);
- }
- /// <summary>
- /// 通过绝对路径删除recipe
- /// </summary>
- /// <param name="fullPath"></param>
- /// <returns></returns>
- public bool DeleteRecipeByFullPath(string fullPath)
- {
- return RecipeFileManager.Instance.DeleteRecipeByFullPath(fullPath);
- }
- /// <summary>
- /// promote recipe
- /// </summary>
- /// <param name="FilePaths"></param>
- /// <returns></returns>
- public bool PromoteRecipe(List<string> FilePaths)
- {
- return RecipeFileManager.Instance.PromoteRecipe(FilePaths);
- }
- /// <summary>
- /// 加载 Recipe
- /// </summary>
- /// <param name="recipeFullName"></param>
- /// <returns></returns>
- public string LoadGenericityRecipe(string type, string recipeFullName)
- {
- Type dataType=Type.GetType(type);
- Type t = typeof(RecipeFileManager);
- MethodInfo loadGenaricityRecipeMethod = t.GetMethod("LoadGenericityRecipe");
- if(loadGenaricityRecipeMethod!=null)
- {
- MethodInfo methodInfo =loadGenaricityRecipeMethod.MakeGenericMethod(dataType);
- var obj= methodInfo.Invoke(RecipeFileManager.Instance, new object[] { recipeFullName });
- string str= JsonConvert.SerializeObject(obj,dataType,new JsonSerializerSettings() { NullValueHandling=NullValueHandling.Ignore});
- return str;
- }
- return null;
- }
- /// <summary>
- /// 保存Hvd Recipe
- /// </summary>
- /// <param name="recipeFullName"></param>
- /// <returns></returns>
- public void SaveRecipeTypeRecipe(string root, string recipeName,string recipeType,string recipe,string dataType)
- {
- Type type = Type.GetType(dataType);
- object obj = JsonConvert.DeserializeObject(recipe,type,new JsonSerializerSettings());
- Type t = typeof(RecipeFileManager);
- MethodInfo saveGenaricityRecipeMethod = t.GetMethod("SaveGenericityRecipe");
- if (saveGenaricityRecipeMethod != null)
- {
- saveGenaricityRecipeMethod.Invoke(RecipeFileManager.Instance, new object[] { root,recipeName,recipeType,obj });
- }
- }
- /// <summary>
- /// Get recipe data by recipe name
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="includingUsedRecipe"></param>
- /// <returns></returns>
- public IEnumerable<string> GetAllRecipes(string chamId)
- {
- return RecipeFileManager.Instance.GetRecipes(chamId, true);
- }
- /// <summary>
- /// Rename recipe
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="oldName"></param>
- /// <param name="newName"></param>
- /// <returns></returns>
- public bool RenameRecipe(ModuleName chamId, string oldName, string newName)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Rename {0} Recipe {1}为{2}", chamId, oldName, newName));
- //if (!ChamberOperationService.IsSuperEnter()) return false;
- return RecipeFileManager.Instance.RenameRecipe(chamId.ToString(), oldName, newName);
- }
- /// <summary>
- /// delete a recipe folder
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="folderName"></param>
- /// <returns></returns>
- public bool DeleteFolder(ModuleName chamId, string folderName)
- {
- if (CheckSoftwareExpired())
- return false;
- //if (!ChamberOperationService.IsSuperEnter()) return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Delete {0} Recipe Folder: {1}", chamId, folderName));
- return RecipeFileManager.Instance.DeleteFolder(chamId.ToString(), folderName);
- }
- /// <summary>
- /// save recipe content
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <param name="recipeContent"></param>
- /// <returns></returns>
- public bool SaveRecipe(ModuleName chamId, string recipeName, string recipeContent)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save {0} Recipe: {1}", chamId, recipeName));
- return RecipeFileManager.Instance.SaveRecipe(chamId.ToString(), recipeName, recipeContent, false, false);
- }
-
- /// <summary>
- /// move recipe content
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <returns></returns>
- public bool MoveRecipeFile(ModuleName chamId, string recipeName, string tragetFolderName)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Move {0} recipe :{1}", chamId, recipeName));
- return RecipeFileManager.Instance.MoveRecipeFile(chamId.ToString(), recipeName, tragetFolderName, false, false);
- }
- /// <summary>
- /// save recipe content
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <param name="recipeContent"></param>
- /// <returns></returns>
- public bool SaveAsRecipe(ModuleName chamId, string recipeName, string recipeContent)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save as {0} recipe {1}", chamId, recipeName));
- return RecipeFileManager.Instance.SaveAsRecipe(chamId.ToString(), recipeName, recipeContent);
- }
- /// <summary>
- /// save recipe content
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="recipeName"></param>
- /// <param name="recipeContent"></param>
- /// <returns></returns>
- public bool SaveAsRecipe2(ModuleName chamId,string type, string recipeName, string recipeContent)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Modify and save as {0} recipe {1}", chamId, recipeName));
- return RecipeFileManager.Instance.SaveAsRecipe2(chamId.ToString(),type, recipeName, recipeContent);
- }
- /// <summary>
- /// create a new recipe folder
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="folderName"></param>
- /// <returns></returns>
- public bool CreateFolder(ModuleName chamId, string folderName)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Create {0} recipe foler {1}", chamId, folderName));
- return RecipeFileManager.Instance.CreateFolder(chamId.ToString(), folderName);
- }
- /// <summary>
- /// Rename recipe folder name
- /// </summary>
- /// <param name="chamId"></param>
- /// <param name="oldName"></param>
- /// <param name="newName"></param>
- /// <returns></returns>
- public bool RenameFolder(ModuleName chamId, string oldName, string newName)
- {
- if (CheckSoftwareExpired())
- return false;
- LOG.Write(eEvent.EV_SEQUENCE, ModuleName.System, string.Format("Rename {0} recipe folder {1} to {2}", chamId, oldName, newName));
- return RecipeFileManager.Instance.RenameFolder(chamId.ToString(), oldName, newName);
- }
- private bool CheckSoftwareExpired()
- {
- bool isExpired = KeyManager.Instance.IsExpired;
- if (isExpired)
- LOG.Write(eEvent.WARN_SEQUENCE,ModuleName.System, "Software is expired. Can not do the operation");
- return isExpired;
- }
- /// <summary>
- /// get reactor's recipe format define file
- /// </summary>
- /// <param name="chamId"></param>
- /// <returns></returns>
- public string GetRecipeFormatXml(ModuleName chamId)
- {
- return RecipeFileManager.Instance.GetRecipeFormatXml(chamId.ToString());
- }
- /// <summary>
- /// get reactor's template recipe file
- /// </summary>
- /// <param name="chamId"></param>
- /// <returns></returns>
- public string GetRecipeTemplate(ModuleName chamId)
- {
- return RecipeFileManager.Instance.GetRecipeTemplate(chamId.ToString());
- }
- /// <summary>
- /// 获取当前反应腔正在运行的Recipe信息
- /// </summary>
- /// <param name="chamId"></param>
- /// <returns>recipeName + recipeContent</returns>
- public Tuple<string, string> LoadRunTimeRecipeInfo(ModuleName chamId)
- {
- return null;
- //var pm = PmManager.GetReactor(chamId);
- //if (pm != null) return pm.LoadRunTimeRecipeInfo();
- //return Singleton<PMEntity>.Instance.GetRecipeInfo();
- }
- public string GetRecipeByBarcode(ModuleName chamId, string barcode)
- {
- return "";
- //return RecipeFileManager.Instance.GetRecipeByBarcode(chamId.ToString(), barcode);
- }
- public string GetXmlSequenceList(ModuleName chamId )
- {
- return RecipeFileManager.Instance.GetXmlSequenceList(chamId.ToString() );
- }
- public string GetSequence(string sequenceName)
- {
- return RecipeFileManager.Instance.GetSequence(sequenceName, true);
- }
- public List<string> GetSequenceNameList()
- {
- return RecipeFileManager.Instance.GetSequenceNameList();
- }
- public bool DeleteSequence(string sequenceName)
- {
- return RecipeFileManager.Instance.DeleteSequence(sequenceName);
- }
- public bool SaveSequence(string sequenceName, string sequenceContent)
- {
- return RecipeFileManager.Instance.SaveSequence(sequenceName, sequenceContent, false);
- }
- public bool SaveAsSequence(string sequenceName, string sequenceContent)
- {
- return RecipeFileManager.Instance.SaveAsSequence(sequenceName, sequenceContent);
- }
- public bool RenameSequence(string oldName, string newName)
- {
- return RecipeFileManager.Instance.RenameSequence(oldName, newName);
- }
- public string GetSequenceFormatXml()
- {
- return RecipeFileManager.Instance.GetSequenceFormatXml();
- }
- public bool RenameSequenceFolder(string oldName, string newName)
- {
- return RecipeFileManager.Instance.RenameSequenceFolder(oldName, newName);
- }
- public bool CreateSequenceFolder(string folderName)
- {
- return RecipeFileManager.Instance.CreateSequenceFolder(folderName);
- }
- public bool DeleteSequenceFolder(string folderName)
- {
- return RecipeFileManager.Instance.DeleteSequenceFolder(folderName);
- }
- #region extended recipe interface
- public string LoadRecipeByPath(string path)
- {
- return RecipeFileManager.Instance.LoadRecipeByPath(path);
- }
- public bool DeleteRecipeByPath(string pathName, string recipeName)
- {
- return RecipeFileManager.Instance.DeleteRecipe(pathName, recipeName);
- }
- public string GetXmlRecipeListByPath(string pathName, bool includingUsedRecipe)
- {
- return RecipeFileManager.Instance.GetXmlRecipeList(pathName, includingUsedRecipe);
- }
- public IEnumerable<string> GetRecipesByPath(string pathName, bool includingUsedRecipe)
- {
- return RecipeFileManager.Instance.GetRecipes(pathName, includingUsedRecipe);
- }
- public bool RenameRecipeByPath(string pathName, string oldName, string newName)
- {
- return RecipeFileManager.Instance.RenameRecipe(pathName, oldName, newName);
- }
- public bool DeleteFolderByPath(string pathName, string folderName)
- {
- return RecipeFileManager.Instance.DeleteFolder(pathName, folderName);
- }
- public bool SaveRecipeByPath(string pathName, string recipeName, string recipeContent)
- {
- return RecipeFileManager.Instance.SaveRecipe(pathName, recipeName, recipeContent, false, false);
- }
- public bool SaveAsRecipeByPath(string pathName, string recipeName, string recipeContent)
- {
- return RecipeFileManager.Instance.SaveAsRecipe(pathName, recipeName, recipeContent);
- }
- public bool CreateFolderByPath(string pathName, string folderName)
- {
- return RecipeFileManager.Instance.CreateFolder(pathName, folderName);
- }
- public bool RenameFolderByPath(string pathName, string oldName, string newName)
- {
- return RecipeFileManager.Instance.RenameFolder(pathName, oldName, newName);
- }
- public string GetRecipeFormatXmlByPath(string pathName)
- {
- return RecipeFileManager.Instance.GetRecipeFormatXml(pathName);
- }
- public string GetRecipeTemplateByPath(string pathName)
- {
- return RecipeFileManager.Instance.GetRecipeTemplate(pathName);
- }
- public Tuple<string, string> LoadRunTimeRecipeInfoByPath(string pathName)
- {
- return null;
- }
- public string GetRecipeByBarcodeByPath(string pathName, string barcode)
- {
- return "";
- }
- public void SaveRecipe(string root, string recipeName, string recipeType, object recipe)
- {
- throw new NotImplementedException();
- }
- public List<string> GetSequenceList(string recipeType, string sequenceType)
- {
- return RecipeFileManager.Instance.GetSequenceList(recipeType, sequenceType);
- }
- #endregion
- }
- }
|