Пример #1
0
        private static void createECNObject()
        {
            // 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 = "A9_AutoCN";

            itemCreateIn.StringProps.Add("object_name", "Name of A9_AutoCN");
            itemCreateIn.StringProps.Add("object_desc", "Description of 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 = "A9_AutoCNRevision";
            //revisionCreateIn.StringProps.Add("item_revision_id", "A");

            DateTime currentdate      = DateTime.Now;
            DateTime SyncStartdate    = new DateTime(currentdate.Year, currentdate.Month, currentdate.Day, currentdate.Hour, currentdate.Minute, currentdate.Second);
            String   SyncStartdateStr = SyncStartdate.ToString("yyyyMMMddHHmmsssss");

            //Calendar cal = Calendar..getInstance();
            //cal.SetTime(new Date());

            DateTime dateValue = Teamcenter.Soa.Client.Model.Property.ParseDate(currentdate.ToString());


            revisionCreateIn.DateProps.Add("a9_EstImpDate", dateValue);


            // 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 = "Create ECN-10000";
            cnCreateIn.Data     = itemCreateIn;

            CreateResponse createResponse = dmService.CreateObjects(new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateIn[] { cnCreateIn });

            if (createResponse.ServiceData.sizeOfPartialErrors() > 0)
            {
                //logErrors(createResponse.serviceData);
            }
            else
            {
                //for (DataManagement.CreateOut createOut : createResponse.output)
                //{
                //    logger.info("Response for client ID " + createOut.clientId);
                //    for (ModelObject modelObject : createOut.objects)
                //    {
                //        logger.info("Created Object " + modelObject.getTypeObject().getName() + " : " + modelObject.getUid());
                //    }
                //}
            }
        }
        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);
        }