/**
         * 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);
        }
Example #2
0
        public void process(SAPConnection sapConnection)
        {
            DataTable projects = sapConnection.getJobList();

            serverHost = getPDM()["HOST"].ToString();

            try {
                ClientX.Session session = new ClientX.Session(serverHost);
                User            user    = session.login();
                foreach (DataRow project in projects.Rows)
                {
                    bomItems = session.getObjects(project["ITEMID"].ToString(), project["REVID"].ToString(), getAttributes());
                    sapConnection.send2SAP(project["PSPNR"].ToString(), getAttributes(), bomItems);
                }
            } catch (SystemException e) {
                Console.WriteLine(e.StackTrace);
            }
        }
Example #3
0
        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);
        }
Example #4
0
        public User login()
        {
            Teamcenter.Services.Strong.Core.SessionService sessionService = Teamcenter.Services.Strong.Core.SessionService.getService(getConnection());
            try {
                String[] credentials = new string[5];

                while (true)
                {
                    try {
                        LoginResponse resp = sessionService.Login(Credentials.getUserID(), Credentials.getPassword(), credentials[2], credentials[3], credentials[4]);
                        user = resp.User;
                        return(resp.User);
                    } catch (InvalidCredentialsException e) {
                        credentials = credentialManager.GetCredentials(e);
                    }
                }
            } catch (CanceledOperationException /*e*/) {
            }

            return(null);
        }
Example #5
0
        /**
         * Print some basic information for a list of objects
         *
         * @param objects
         */
        public static void printObjects(ModelObject[] objects)
        {
            if (objects == null)
            {
                return;
            }


            // Ensure that the referenced User objects that we will use below are loaded
            getUsers(objects);

            //Console.WriteLine("Name\t\tOwner\t\tLast Modified");
            //Console.WriteLine("====\t\t=====\t\t=============");
            for (int i = 0; i < objects.Length; i++)
            {
                if (!(objects[i] is WorkspaceObject))
                {
                    continue;
                }

                WorkspaceObject wo = (WorkspaceObject)objects[i];
                try
                {
                    String   name         = wo.Object_string;
                    User     owner        = (User)wo.Owning_user;
                    DateTime lastModified = wo.Last_mod_date;

                    //Console.WriteLine(name + "\t" + owner.User_name + "\t" + lastModified.ToString());
                }
                catch (NotLoadedException e)
                {
                    // Print out a message, and skip to the next item in the folder
                    // Could do a DataManagementService.getProperties call at this point
                    //Console.WriteLine(e.Message);
                    //Console.WriteLine("The Object Property Policy ($TC_DATA/soa/policies/Default.xml) is not configured with this property.");
                }
            }
        }
Example #6
0
        public static void Main(string[] arg)
        {
            String serverHost = "http://192.168.110.128:7001/tc";


            try
            {
                Session session = new Session(serverHost);
                //HomeFolder home = new HomeFolder();
                //Query query = new Query();
                DataManagement dm = new DataManagement();

                // Establish a session with the Teamcenter Server
                User user = session.login();

                Session2 session2 = new Session2(serverHost);
                User     user2    = session2.login();
                //// Using the User object returned from the login service request
                //// display the contents of the Home Folder
                //home.listHomeFolder(user);

                //// Perform a simple query of the database
                //query.queryItems();

                // Perform some basic data management functions
                //dm.createReviseAndDelete();
                dm.createMyItem("Item");


                //dm.queryItems();
                // Terminate the session with the Teamcenter server
                session.logout();
            }
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public String Handle(Func <String> action)
        {
            cfg.load();
            String Msg        = "执行成功";
            String serverHost = cfg.get("ip");

            Teamcenter.ClientX.Session  session  = null;
            Teamcenter.ClientX.Session2 session2 = null;
            try
            {
                session  = new Teamcenter.ClientX.Session(serverHost);
                session2 = new Teamcenter.ClientX.Session2(serverHost);

                Teamcenter.Soa.Client.Model.Strong.User user  = session.login(cfg.get("dbname"), cfg.get("dbpassword"), "", "", "", "SoaAppX");
                Teamcenter.Soa.Client.Model.Strong.User user2 = session2.login(cfg.get("powerful_user_name"), cfg.get("powerful_user_password"), "", "", "", "SoaAppX");

                var res = action.Invoke();
                Msg = res.Equals("") ? Msg : res;
            }
            catch (Exception e)
            {
                Msg = e.ToString();
            }
            finally
            {
                if (null != session)
                {
                    session.logout();
                }
                if (null != session2)
                {
                    session2.logout();
                }
            }

            return(Msg);
        }