private bool NodeCheckAndCreate(int i, CutSKernel.Kinematic.AKinBaseObject UpperNode, string[] asNodes) { if (i > asNodes.Length - 1) { return(false); } VirtualTwin.DataNode currentNode = (VirtualTwin.DataNode)UpperNode.GetChildByName(asNodes[i]); if (currentNode == null) { VirtualTwin.DataNode NewNode = new VirtualTwin.DataNode(); DateTime dt = new DateTime(); dt = DateTime.Now; NewNode.Name = asNodes[i]; NewNode.MetaData.Add("lastmodified", dt.ToString("yyyy/MM/dd HH:mm:ss")); UpperNode.AddChild(NewNode); } bool berr = false; berr = NodeCheckAndCreate(i + 1, (CutSKernel.Kinematic.AKinBaseObject)UpperNode.GetChildByName(asNodes[i]), asNodes); return(berr); }
public bool TwinModePutToTwin(string cutSFolder, string sSource, string sValueNode, string sTarget, string sValueFile, string sWPID) { try { string sNameOfData; if (sWPID == "") { sWPID = "Muster.cutsproj"; sNameOfData = "VirtualTwin"; } else { sNameOfData = sWPID; sWPID = sWPID + ".cutsproj"; } CutSKernel.Controller.CutSController cutSController = CutSKernel.Controller.CutSController.GetController(); cutSController.ScanKernelTypes(); cutSController.ClearMachineModel(); CutSKernel.Controller.ExporterController.Instance.ActiveExporter.Clear(); cutSController.PluginHost.FindPlugins(cutSFolder); string sProjectFile = System.IO.Path.Combine(sTarget, sNameOfData); sProjectFile = System.IO.Path.Combine(sProjectFile, sWPID); CutSKernel.Serialization.ProjectSerializer projectSerializer = new CutSKernel.Serialization.ProjectSerializer(cutSController.PluginHost, sProjectFile); var savedPlugins = projectSerializer.GetSavedPlugins(); foreach (var PlugInName in savedPlugins) { var pluginInfo = cutSController.PluginHost.GetPluginInfoForTypeName(PlugInName); if (pluginInfo == null) { string exep = "Plug in not found"; return(false); } else { if (!pluginInfo.Plugin.IsLoaded) { cutSController.PluginHost.LoadPlugin(pluginInfo); } projectSerializer.DeserializePlugin(PlugInName); } } cutSController.LoadProject(sProjectFile, Log, false); CutSKernel.Kinematic.AKinBaseObject newModel = projectSerializer.DeserializeModel(); cutSController.AddChildsToModel(newModel, true); // Schleife string[] asNodes = sValueNode.Split('\\'); // Kontrollschleife ob Nodes Vorhanden sind, wenn nicht erstellen int i = 0; // Rekursives hinein Itterieren in den Pfad (Falls ein Knoten nicht vorhanden ist wird dieser erstellt) if (NodeCheckAndCreate(i, newModel, asNodes)) { Console.WriteLine("ErrorFileNoder Creation NodeCheckAndCreate"); return(false); } i = 0; VirtualTwin.DataNode iterNode = (VirtualTwin.DataNode)newModel.GetChildByName(asNodes[0]); // Den Letzten DatenKnoten vor dem FileObjekt finden foreach (string sNode in asNodes) { if ((i > 0) && i < (asNodes.Length)) { iterNode = (VirtualTwin.DataNode)newModel.GetChildByName(sNode); } i++; } // File Knoten holen und die Datei Importieren VirtualTwin.FileNode newFileNode = new VirtualTwin.FileNode(/*System.IO.Path.Combine(sSource, sValueFile)*/); if (!System.IO.File.Exists(System.IO.Path.Combine(sSource, sValueFile))) { Console.WriteLine("File not found"); return(false); } newFileNode.ImportFile = System.IO.Path.Combine(sSource, sValueFile); newFileNode.Name = sValueFile; DateTime dt = new DateTime(); dt = DateTime.Now; newFileNode.MetaData.Add("lastmodified", dt.ToString("yyyy/MM/dd HH:mm:ss")); // Meta-Daten schreiben wenn meta.json vorhanden if (System.IO.File.Exists(System.IO.Path.Combine(sSource, "meta.json"))) { string sJSon = ""; // Meta einlesen try { using (StreamReader sr = new StreamReader(System.IO.Path.Combine(sSource, "meta.json"))) { sJSon = sr.ReadToEnd(); } } catch (IOException e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } var dicConfig = JsonConvert.DeserializeObject <Dictionary <string, string> >(sJSon); foreach (var Pair in dicConfig) { newFileNode.MetaData.Add(Pair.Key, Pair.Value); } } iterNode.AddChild(newFileNode); projectSerializer.Serialize(sProjectFile); cutSController.PluginHost.UnloadPlugins(); } catch (Exception e) { Console.WriteLine("Exception:" + e.Message); return(false); } return(true); }