Teamcenter SOA实例: AddToFolder

职场   2024-09-11 16:07   澳大利亚  
/* This example was tested with the C# HelloTeamcenter example provided in the soa_client.zip file.It assumes you have the HelloTeamcenter example working correctly.
The following code will show how to add a Business object to a Folder business object.
Create folder in the HelloTeamceter C# project called, 'Teamcenter/Code' add file AddToFolder.cs to it.
Add the following code the Hello.cs to call/use the AddToFolder code.
--------------------------------------------------------------
var folder = new AddToFolder();
if (folder.loadItem()) folder.AddFile("Dataset Folder"); // Update with your folder name.
------------------------------------------------------------ */
using System;using System.Collections;
using Teamcenter.Services.Strong.Core;using Teamcenter.Services.Strong.Query;using Teamcenter.Soa.Client.Model;using Teamcenter.Soa.Client.Model.Strong;using Teamcenter.Soa.Common;using Teamcenter.Soa.Exceptions;
using Core = Teamcenter.Services.Strong.Core;using Query = Teamcenter.Services.Strong.Query;using Finder = Teamcenter.Services.Strong.Query._2007_06.Finder;
namespace Teamcenter.Code{ public class AddToFolder { private readonly Core.DataManagementService dmService; private readonly Query.FinderService finderService;
private readonly String datasetUID = "wcrRIf1cLSjhKA"; // Update with your Dataset UID value. private Dataset dataset;
public AddToFolder() { dmService = Core.DataManagementService.getService(Teamcenter.ClientX.Session.getConnection()); finderService = Query.FinderService.getService(Teamcenter.ClientX.Session.getConnection());
SetObjectPolicy(); }
public bool loadItem() { ServiceData sData = dmService.LoadObjects(new string[] { datasetUID });
if (sData.sizeOfPlainObjects() > 0) { ModelObject mObj = sData.GetPlainObject(0);
if (mObj is Dataset) { dataset = mObj as Dataset; return true; } }
return false; }
public bool AddFile(String folderName) { try { var find = new Finder.WSOFindCriteria(); var findSet = new Finder.WSOFindSet();
find.ObjectName = folderName; find.ObjectType = "Folder"; find.Scope = "WSO_scope_All"; findSet.Criterias = new Finder.WSOFindCriteria[] { find };
var resp = finderService.FindWorkspaceObjects(new Finder.WSOFindSet[] { findSet });
if (!ServiceDataError(resp.ServiceData)) { if (resp.OutputList.Length > 0 && resp.OutputList[0].FoundObjects.Length > 0) { var list = new ArrayList(); var map = new Hashtable(); var vec = new Core._2007_01.DataManagement.VecStruct(); var folder = (Folder)resp.OutputList[0].FoundObjects[0];
list.Add(dataset.Uid); // Add the new object.
foreach (var content in folder.Contents) // copy the current objects in the folder. list.Add(content.Uid);
vec.StringVec = (string[])list.ToArray(typeof(string)); map.Add("contents", vec);
var serviceData = dmService.SetProperties(new ModelObject[] { folder }, map); // Update/replace the 'contents' property list.
if (!ServiceDataError(serviceData)) return true; } } } catch (NotLoadedException e) { Console.WriteLine(e.StackTrace); }
return false; }
protected bool ServiceDataError(ServiceData data) { if (data.sizeOfPartialErrors() > 0) { for (int i = 0; i < data.sizeOfPartialErrors(); i++) { foreach (string msg in data.GetPartialError(i).Messages) Console.WriteLine(msg); }
return true; }
return false; } protected void SetObjectPolicy() { var session = SessionService.getService(Teamcenter.ClientX.Session.getConnection()); var policy = new ObjectPropertyPolicy();
policy.AddType(new PolicyType("Folder", new string[] { "contents" }));
session.SetObjectPropertyPolicy(policy); } }}

Teamcenter笔记
PLM学习,智能制造加油站,畅聊汽车工业、工业4.0、智慧工厂、工业软件,揭秘核心技术,探讨行业发展方向,PLM/MES/MOM/ERP/SCADA/IIOT/DT交流学习园地
 最新文章