private void CopyTreeNodeRecursively(PPDataContext db, IProcessingCallback callback) { if (null != callback) { callback.Info("Tree nodes..."); } PLMPackSR.PLMPackServiceClient client = new PLMPackSR.PLMPackServiceClient(); client.ClientCredentials.UserName.UserName = UserName; client.ClientCredentials.UserName.Password = Password; List <TreeNode> rootNodes = TreeNode.GetRootNodes(db); string offset = string.Empty; PLMPackSR.DCTreeNode userRootNode = client.GetUserRootNode(); client.Close(); foreach (TreeNode root in rootNodes) { List <TreeNode> rootChildrens = root.Childrens(db); foreach (TreeNode tn in rootChildrens) { RecursiveInsert(db, tn, userRootNode, string.Empty, callback); } } }
private void RecursiveInsert(PPDataContext db, TreeNode tn, PLMPackSR.DCTreeNode wsNode, string offset, IProcessingCallback callback) { PLMPackSR.PLMPackServiceClient client = new PLMPackSR.PLMPackServiceClient(); client.ClientCredentials.UserName.UserName = UserName; client.ClientCredentials.UserName.Password = Password; PLMPackSR.DCTreeNode wsNodeChild = null; string docType = string.Empty; try { // create node thumbnail string thumbPath = tn.Thumbnail.File.PathWRepo(RepositoryPath); DCFile thFile = Upload(thumbPath, callback, client); PLMPackSR.DCThumbnail wsThumbnail = client.CreateNewThumbnailFromFile(thFile); if (tn.IsDocument) { // get document Document doc = tn.Documents(db)[0]; string docPath = doc.File.PathWRepo(RepositoryPath); // upload document PLMPackSR.DCFile wsDocFile = Upload(docPath, callback, client); if (tn.IsComponent) { docType = "COMPONENT"; Component comp = doc.Components[0]; // get majorations List <PLMPackSR.DCMajorationSet> majorationSets = new List <PLMPackSR.DCMajorationSet>(); foreach (MajorationSet majoSet in comp.MajorationSets) { DCCardboardProfile cbProfile = client.GetCardboardProfileByName(majoSet.CardboardProfile.Name); string sMajo = string.Empty; List <DCMajoration> dcMajorationList = new List <DCMajoration>(); foreach (Majoration majo in majoSet.Majorations) { sMajo += string.Format("({0}={1})", majo.Name, majo.Value); dcMajorationList.Add(new DCMajoration() { Name = majo.Name, Value = majo.Value }); } majorationSets.Add( new DCMajorationSet() { Profile = cbProfile, Majorations = dcMajorationList.ToArray() } ); if (null != callback) { callback.Info(string.Format("{0} - {1}", majoSet.CardboardProfile.Name, sMajo)); } } // get default parameter values List <PLMPackSR.DCParamDefaultValue> paramDefaultValues = new List <PLMPackSR.DCParamDefaultValue>(); foreach (ParamDefaultValue pdv in comp.ParamDefaultValues) { paramDefaultValues.Add(new DCParamDefaultValue() { Name = pdv.Name, Value = pdv.Value }); } PLMPackSR.DCTreeNode wsNodeComp = client.CreateNewNodeComponent( wsNode, tn.Name, tn.Description , wsThumbnail, wsDocFile, doc.Components[0].Guid , majorationSets.ToArray(), paramDefaultValues.ToArray()); client.ShareEveryone(wsNodeComp); } else { docType = "DOCUMENT"; PLMPackSR.DCTreeNode wsNodeDocument = client.CreateNewNodeDocument(wsNode, tn.Name, tn.Description , wsThumbnail, wsDocFile); client.ShareEveryone(wsNodeDocument); } } else { docType = "BRANCH"; wsNodeChild = client.CreateNewNodeBranch(wsNode, tn.Name, tn.Description, wsThumbnail); client.ShareEveryone(wsNodeChild); } client.Close(); } catch (Exception ex) { client.Abort(); if (null != callback) { callback.Error(ex.ToString()); } } if (null == wsNodeChild) { return; } if (null != callback) { callback.Info(string.Format("{0}-> {1} ({2})", offset, tn.Name, docType)); } offset += " "; foreach (TreeNode tnChild in tn.Childrens(db)) { RecursiveInsert(db, tnChild, wsNodeChild, offset, callback); } }