public ExampleForm() { InitializeComponent(); MyFormAppSession session = new MyFormAppSession("http://192.168.0.51/tc"); HomeFolder home = new HomeFolder(this); Query query = new Query(this); DataManagement dm = new DataManagement(this); User user = session.login(); DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection()); String[] attributes = { "os_username" }; dmService.GetProperties(new ModelObject[] { user }, attributes); appendTxt("User name: " + user.Os_username); home.listHomeFolder(user); query.queryItems(); dm.createReviseAndDelete(); session.logout(); }
/** * List the contents of the Home folder. * */ public void listHomeFolder(User user) { Folder home = null; WorkspaceObject[] contents = null; // Get the service stub DataManagementService dmService = DataManagementService.getService(Session.getConnection()); try { // User was a primary object returned from the login command // the Object Property Policy should be configured to include the // 'home_folder' property. However the actuall 'home_folder' object // was a secondary object returned from the login request and // therefore does not have any properties associated with it. We will need to // get those properties explicitly with a 'getProperties' service request. home = user.Home_folder; } catch (NotLoadedException e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine("The Object Property Policy ($TC_DATA/soa/policies/Default.xml) is not configured with this property."); return; } try { ModelObject[] objects = { home }; String[] attributes = { "contents" }; // ***************************** // Execute the service operation // ***************************** dmService.GetProperties(objects, attributes); // The above getProperties call returns a ServiceData object, but it // just has pointers to the same object we passed into the method, so the // input object have been updated with new property values contents = home.Contents; } // This should never be thrown, since we just explicitly asked for this // property catch (NotLoadedException /*e*/) {} Console.Out.WriteLine(""); Console.Out.WriteLine("Home Folder:"); Session.printObjects(contents); }
/// <summary> /// 找TC的文件位置,如果没有则创建。 /// 如:"10原材料-1011钢材",分隔符为"-",根目录为"XY"。 /// 最终会返回 XY-->10原材料文件夹目录中的1011钢材文件夹。 /// XY /// | /// --10原材料 /// | /// ---1011钢材 /// </summary> /// <param name="FolderName">文件夹路径</param> /// <param name="RootFolder">根目录</param> /// <param name="SplitStr">文件夹路径分隔符</param> /// <returns></returns> public ModelObject findFolder(string FolderName, ModelObject RootFolder, string SplitStr) { ModelObject resul = null; var arry = Regex.Split(FolderName, SplitStr, RegexOptions.IgnoreCase); //取第一层级 var CurrentFolderName = arry[0]; DataManagementService dmService = DataManagementService.getService(Session.getConnection()); dmService.GetProperties(new ModelObject[] { RootFolder }, new string[] { "contents" }); var contents = ((Teamcenter.Soa.Client.Model.Strong.Folder)RootFolder).Contents; for (int i = 0, len = contents.Length; i < len; i++) { if (contents[i].Object_string.Equals(CurrentFolderName) && null != findModel(cfg.get("query_builder_folder_name") , new string[] { cfg.get("query_builder_folder_queryKey1"), cfg.get("query_builder_folder_queryKey2") } , new string[] { CurrentFolderName, "XY_GROUP" })) { resul = contents[i]; break; } } if (null == resul) { //创建文件夹 var cf = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateFolderInput(); cf.Name = CurrentFolderName; cf.Desc = @"XY_GROUP"; Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateFoldersResponse cfr = dmService.CreateFolders(new Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateFolderInput[] { cf }, RootFolder, "child"); resul = cfr.Output[0].Folder; } //如果分组后数组大于1,则递归 if (arry.Length > 1) { arry[0] = ""; string RestStr = string.Join(SplitStr, arry); RestStr = RestStr.Substring(SplitStr.Length, RestStr.Length - SplitStr.Length); return(findFolder(RestStr, resul, SplitStr)); } else { return(resul); } }
private void getWFProcessandSignOff() { String QueryName = "Item Revision..."; System.Console.Out.WriteLine("Quering all the Project which are not in Setup status...... using the Saved Query -\"{0}\" ", QueryName); String[] SQEntries = new String[] { "Item ID", "Type" }; //Entries for the Saved Query String[] SQValues = new String[] { "ECN-000472", "Auto CN Revision" }; //Values for each of the Entries of the Saved Query ModelObject[] ItemRevisionIds = QueryObjects(QueryName, SQEntries, SQValues); dmService.GetProperties(ItemRevisionIds, new String[] { "fnd0AllWorkflows", "process_stage_list" }); //dmService.GetProperties(ItemRevisionIds, new String[] { "fnd0AllWorkflows" }); Teamcenter.Soa.Client.Model.Property allWFProps = ItemRevisionIds[0].GetProperty("fnd0AllWorkflows"); Teamcenter.Soa.Client.Model.Property processStgProps = ItemRevisionIds[0].GetProperty("process_stage_list"); ModelObject[] ProcessList = allWFProps.ModelObjectArrayValue; if (ProcessList[0].SoaType.ClassName == "EPMTask") { WorkflowService wfService = WorkflowService.getService(connection); EPMTask ePMTask = new EPMTask(ProcessList[0].SoaType, ProcessList[0].Uid); //workflowService.PerformAction() PerformActionInputInfo[] performActionInputInfo = new PerformActionInputInfo[1]; performActionInputInfo[0] = new PerformActionInputInfo(); performActionInputInfo[0].Action = "SOA_EPM_complete_action"; performActionInputInfo[0].ClientId = "001"; performActionInputInfo[0].ActionableObject = ItemRevisionIds[0]; performActionInputInfo[0].PropertyNameValues.Add("comments", new String[] { "OK" }); ServiceData serviceData = wfService.PerformAction3(performActionInputInfo); if (serviceData.sizeOfPartialErrors() > 0) { } //workflow.PerformAction(ProcessList[0], "SOA_EPM_complete_action","New Comments","",) } //throw new NotImplementedException(); Process_stage_list {Teamcenter.Soa.Client.Model.ModelObject[0]} Teamcenter.Soa.Client.Model.ModelObject[] }
public string demo() { string res = string.Empty; DataManagementService dmService = DataManagementService.getService(Session2.getConnection()); try { ModelObject itemReversion = findModel(cfg.get("query_builder_lastestRevisionById_name") , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { "JLD100158" }); var data = dmService.GetProperties(new ModelObject[] { itemReversion }, new string[] { "WL_REV_013" }); res = itemReversion.GetProperty("").ModelObjectValue.Uid; } catch (Exception e) { res = ""; } return(res); }
private static void getUsers(ModelObject[] objects) { if (objects == null) { return; } DataManagementService dmService = DataManagementService.getService(Session.getConnection()); ArrayList unKnownUsers = new ArrayList(); for (int i = 0; i < objects.Length; i++) { if (!(objects[i] is WorkspaceObject)) { continue; } WorkspaceObject wo = (WorkspaceObject)objects[i]; User owner = null; try { owner = (User)wo.Owning_user; String userName = owner.User_name; } catch (NotLoadedException /*e*/) { if (owner != null) { unKnownUsers.Add(owner); } } } User[] users = new User[unKnownUsers.Count]; unKnownUsers.CopyTo(users); String[] attributes = { "user_name" }; // ***************************** // Execute the service operation // ***************************** dmService.GetProperties(users, attributes); }
public void changeOnwer(String userName, ModelObject modl) { DataManagementService dmService = DataManagementService.getService(Session.getConnection()); //ModelObject user = findUser(userName); ModelObject user = findModel(cfg.get("query_builder_userByUname_name") , new string[] { cfg.get("query_builder_userByUname_queryKey") }, new string[] { userName }); if (null == user) { throw new Exception("构建器查找用户失败,请确认申请人在TC是否存在。"); } //根据USER查找GROUP dmService.GetProperties(new ModelObject[] { user }, new string[] { "default_group" }); ModelObject userGroup = user.GetProperty("default_group").ModelObjectValue; if (null == userGroup) { throw new Exception("构建器查找用户组失败。"); } ObjectOwner[] ownerData = new ObjectOwner[1]; ObjectOwner ownrObj = new ObjectOwner(); ownrObj.Object = modl; ownrObj.Group = (Teamcenter.Soa.Client.Model.Strong.Group)userGroup; ownrObj.Owner = (Teamcenter.Soa.Client.Model.Strong.User)user; ownerData[0] = ownrObj; ServiceData returnData = dmService.ChangeOwnership(ownerData); if (returnData.sizeOfPartialErrors() > 0) { throw new Exception("修改所有者失败" + returnData.GetPartialError(0).Messages[0]); } }
/** * Create Items * * @param itemIds Array of Item and Revision IDs * @param itemType Type of item to create * * @return Set of Items and ItemRevisions * * @throws ServiceException If any partial errors are returned */ public CreateItemsOutput[] createItems(ItemIdsAndInitialRevisionIds[] itemIds, String itemType) // throws ServiceException { // Get the service stub DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection()); // Populate form type GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemType, null); String[] formTypes = new String[0]; if (relatedResponse.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.getItemCretionRelatedInfo returned a partial error."); } formTypes = new String[relatedResponse.FormAttrs.Length]; for (int i = 0; i < relatedResponse.FormAttrs.Length; i++) { FormAttributesInfo attrInfo = relatedResponse.FormAttrs[i]; formTypes[i] = attrInfo.FormType; } ItemProperties[] itemProps = new ItemProperties[itemIds.Length]; for (int i = 0; i < itemIds.Length; i++) { // Create form in cache for form property population ModelObject[] forms = createForms(itemIds[i].NewItemId, formTypes[0], itemIds[i].NewRevId, formTypes[1], null, false); ItemProperties itemProperty = new ItemProperties(); itemProperty.ClientId = "AppX-Test"; itemProperty.ItemId = itemIds[i].NewItemId; itemProperty.RevId = itemIds[i].NewRevId; itemProperty.Name = "AppX-Test"; itemProperty.Type = itemType; itemProperty.Description = "Test Item for the SOA AppX sample application."; itemProperty.Uom = ""; // Retrieve one of form attribute value from Item master form. ServiceData serviceData = dmService.GetProperties(forms, new String[] { "project_id" }); if (serviceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.getProperties returned a partial error."); } Property property = null; try { property = forms[0].GetProperty("project_id"); } catch (NotLoadedException /*ex*/) {} // Only if value is null, we set new value if (property == null || property.StringValue == null || property.StringValue.Length == 0) { itemProperty.ExtendedAttributes = new ExtendedAttributes[1]; ExtendedAttributes theExtendedAttr = new ExtendedAttributes(); theExtendedAttr.Attributes = new Hashtable(); theExtendedAttr.ObjectType = formTypes[0]; theExtendedAttr.Attributes["project_id"] = "project_id"; itemProperty.ExtendedAttributes[0] = theExtendedAttr; } itemProps[i] = itemProperty; } // ***************************** // Execute the service operation // ***************************** CreateItemsResponse response = dmService.CreateItems(itemProps, null, ""); // before control is returned the ChangedHandler will be called with // newly created Item and ItemRevisions // The AppXPartialErrorListener is logging the partial errors returned // In this simple example if any partial errors occur we will throw a // ServiceException if (response.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.createItems returned a partial error."); } return(response.Output); }
/// <summary> /// </summary> /// <param name="itemType">创建TC中ITEM的类型</param> /// <param name="codeNumber">物料号</param> /// <param name="CodeName">物料名称</param> /// <param name="longDetail">详细描述</param> /// <param name="unit">单位</param> /// <param name="productionType">物料属性(自制、外购、委外)</param> /// <param name="ReqName">物料申请人</param> public String createTCItem(String codeNumber, String CodeName, String longDetail, String unit, String productionType, String ReqName, String group) { String erroMsg = ""; //处理详细描述,10-79插入详细描述,80-90不插入详细描述 longDetail = codeNumber.Length < 2 ? "" : (codeNumber.Substring(0, 2).CompareTo("80") >= 0 ? "" : longDetail); String itemType = codeNumber.Length >= 2 && codeNumber.Substring(0, 2).Equals("80") ? cfg.get("CPTyep") : cfg.get("LBJType"); try { DataManagementService dmService = DataManagementService.getService(Session.getConnection()); //查询最新的ITEM版本 //ModelObject LastestRevision = findModel("MY_WEB_ITEM_REVISION", new string[] { "iid" }, new string[] { codeNumber }); ModelObject LastestRevision = findModel(cfg.get("query_builder_lastestRevisionById_name") , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber }); if (null != LastestRevision && !string.IsNullOrEmpty(LastestRevision.Uid)) { dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "release_status_list" }); dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "item_revision_id" }); dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "object_name" }); dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "IMAN_master_form_rev" }); var master = LastestRevision.GetProperty("IMAN_master_form_rev").ModelObjectArrayValue[0]; dmService.GetProperties(new ModelObject[] { master }, new string[] { cfg.get("exAttr_detail") }); dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "IMAN_specification" }); String item_revision_id = LastestRevision.GetProperty("item_revision_id").StringValue.ToString(); //如果名称、规格相同,不执行更新。 if (LastestRevision.GetProperty("object_name").StringValue.Equals(CodeName) && master.GetProperty(cfg.get("exAttr_detail")).StringValue.Equals(longDetail)) { return(erroMsg); } if (LastestRevision.GetProperty("IMAN_specification").ModelObjectArrayValue.Length > 0) { return(codeNumber + "/" + item_revision_id + ":有图纸,请在TC中更新。"); } ModelObject release_status_obj = null; if (LastestRevision.GetProperty("release_status_list").ModelObjectArrayValue.Length > 0) { release_status_obj = LastestRevision.GetProperty("release_status_list").ModelObjectArrayValue[0]; dmService.GetProperties(new ModelObject[] { release_status_obj }, new string[] { "name" }); } String release_status = null == release_status_obj ? "" : release_status_obj.GetProperty("name").StringValue; //查询是否存在未发布版本 if (!release_status.Equals(cfg.get("publish_status_value"))) { workflow_publish(cfg.get("publish_workflow"), LastestRevision); } //创建新版本前,修改ITEM数据 updateItem(codeNumber, CodeName, longDetail); //创建新版本 reviseItem(LastestRevision, CodeName, longDetail, productionType, item_revision_id); } else { //开始新增ITEM //根据物料号创建ITEMID ItemProperties itemProperty = new ItemProperties(); itemProperty.Type = itemType; //创建ITEM的类型 itemProperty.ItemId = codeNumber; //物料代码 itemProperty.Name = CodeName; //物料名称 itemProperty.RevId = "00"; //版本 itemProperty.Description = ""; //描述 itemProperty.Uom = unit; //单位 //增加额外属性-对于同一个form,只用一次ExtendedAttributes,多个属性写在Hashtable上 ExtendedAttributes exAttr = new ExtendedAttributes(); exAttr.Attributes = new Hashtable(); exAttr.ObjectType = itemType + "RevisionMaster"; //对应哪个form表 exAttr.Attributes[cfg.get("exAttr_productionType")] = productionType; exAttr.Attributes[cfg.get("exAttr_detail")] = longDetail; itemProperty.ExtendedAttributes = new ExtendedAttributes[] { exAttr }; //创建前查找文件路径 var RootFile = (Teamcenter.Soa.Client.Model.Strong.Folder)findModel(cfg.get("query_builder_folder_name") , new string[] { cfg.get("query_builder_folder_queryKey1"), cfg.get("query_builder_folder_queryKey2") } , new string[] { cfg.get("query_builder_folder_queryval1"), cfg.get("query_builder_folder_queryval2") }); var TargetFolder = findFolder(group, RootFile, cfg.get("group_split_flag")); //链接服务器创建Item CreateItemsResponse response = dmService.CreateItems(new ItemProperties[] { itemProperty }, TargetFolder, "contents"); //CreateItemsResponse response = dmService.CreateItems(new ItemProperties[] { itemProperty }, null, ""); if (response.ServiceData.sizeOfPartialErrors() > 0) { return("创建ITEM失败。" + response.ServiceData.GetPartialError(0).Messages[0]); } //结束新增ITEM //新增完后附加文件。 ModelObject itemReversion2add = findModel(cfg.get("query_builder_lastestRevisionById_name") , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber }); //ModelObject datasets = createEmptyFile("Text",codeNumber, "./template/url.txt", "Text"); //createRelations(itemReversion2add, datasets, "IMAN_specification"); //changeOnwer(ReqName, datasets); //创建dataset并关联,修改所有者 if (codeNumber.Length > 4 && //codeNumber.Substring(0,2).CompareTo("80") >= 0) codeNumber.Substring(0, 2).Equals("80")) { var subCodeNumber = codeNumber.Substring(0, 4); var uploadCfgPramary = subCodeNumber.Equals("8102") || subCodeNumber.Equals("8301") ? "uploadFile_part" : "uploadFile_asm"; var cfgList = cfg.tc[uploadCfgPramary].ToObject <ArrayList>(); foreach (var uploadObj in cfgList) { var uploadCfg = JObject.Parse(uploadObj.ToString()); ModelObject datasets_temp = createEmptyFile(uploadCfg["datasetType"].ToString() , codeNumber , uploadCfg["filePath"].ToString() , uploadCfg["fileRefName"].ToString() , itemReversion2add , uploadCfg["relationType"].ToString() ); //createRelations(itemReversion2add, datasets_temp, uploadCfg["relationType"].ToString()); changeOnwer(ReqName, datasets_temp); } } } //调用查询构建器,查询ITEM和ITEMRevision ModelObject itemObj = findModel(cfg.get("query_builder_ItemById_name") , new string[] { cfg.get("query_builder_ItemById_queryKey") }, new string[] { codeNumber }); ModelObject itemReversion = findModel(cfg.get("query_builder_lastestRevisionById_name") , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber }); if (null == itemObj || null == itemReversion) { return("查询构建器失败。"); } //修改所有者 changeOnwer(ReqName, itemObj); changeOnwer(ReqName, itemReversion); //发布-外购件 if (codeNumber.Length >= 2 && (codeNumber.Substring(0, 2).CompareTo("80") < 0)) { workflow_publish(cfg.get("publish_workflow"), itemReversion); } } catch (Exception e) { deleteItem(codeNumber); throw e; } return(erroMsg); }
public static CreateObjectOutput CreateObjectinTCAndReturnTCItemIdAndRev(CreateObjectParameters[] createObjectParList, String ItemTypeName, String ItemRevisionName) { String item_id = ""; String revision_id = ""; InitializeProces(); // The create input for the ChangeNotice Item Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput itemCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); itemCreateIn.BoName = ItemTypeName; //itemCreateIn.BoName = "A9_AutoCN"; // The create input for the ChangeNoticeRevision Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput revisionCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput(); revisionCreateIn.BoName = ItemRevisionName; //revisionCreateIn.BoName = "A9_AutoCNRevision"; foreach (CreateObjectParameters createObjectPar in createObjectParList) { String propType = createObjectPar.propType; String propOn = createObjectPar.propOn; switch (propType.ToLower()) { case "string": if (propOn == "Item") { itemCreateIn.StringProps.Add(createObjectPar.propName, createObjectPar.propValue); } else { revisionCreateIn.StringProps.Add(createObjectPar.propName, createObjectPar.propValue); } break; case "date": DateTime dateValue = Teamcenter.Soa.Client.Model.Property.ParseDate(createObjectPar.propValue); if (propOn == "Item") { itemCreateIn.DateProps.Add(createObjectPar.propName, dateValue); } else { revisionCreateIn.DateProps.Add(createObjectPar.propName, dateValue); } break; } } // Tie the Revision CreateInput to the Item CreateInput itemCreateIn.CompoundCreateInput.Add("revision", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { revisionCreateIn }); // The data for the createObjects call Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn cnCreateIn = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn(); cnCreateIn.ClientId = "One"; cnCreateIn.Data = itemCreateIn; CreateResponse createResponse = dmService.CreateObjects(new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn[] { cnCreateIn }); if (createResponse.ServiceData.sizeOfPartialErrors() > 0) { //createResponse.ServiceData.; } else { //Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateOut[] createOut = createResponse.Output; foreach (Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateOut createOut in createResponse.Output) { //createOut.ClientId Console.WriteLine("Response for client ID " + createOut.ClientId); foreach (ModelObject modelObject in createOut.Objects) { //modelObject. //Console.WriteLine(); String[] uids = new String[1]; uids[0] = modelObject.Uid; ServiceData sd = dmService.LoadObjects(uids); ModelObject[] foundObjs = new ModelObject[sd.sizeOfPlainObjects()]; for (int k = 0; k < sd.sizeOfPlainObjects(); k++) { foundObjs[k] = sd.GetPlainObject(k); if (foundObjs[k].SoaType.ClassName == ItemRevisionName) { dmService.GetProperties(foundObjs, new String[] { "item_id" }); item_id = foundObjs[k].GetPropertyDisplayableValue("item_id"); dmService.GetProperties(foundObjs, new String[] { "item_revision_id" }); revision_id = foundObjs[k].GetPropertyDisplayableValue("item_revision_id"); } } } } } CreateObjectOutput createObjectOutput = new CreateObjectOutput(item_id, revision_id); return(createObjectOutput); }