當前位置: 首頁>>代碼示例>>C#>>正文


C# API.authenticate方法代碼示例

本文整理匯總了C#中API.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:C# API.authenticate方法的具體用法?C# API.authenticate怎麽用?C# API.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在API的用法示例。


在下文中一共展示了API.authenticate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main(string[] args)
        {
            string username = "[email protected]";
            string password = "supersecretpassword";
            string server = "https://api.velasystems.com";

            switch (args.Length)
            {
                case 0:
                case 1:
                    Console.WriteLine("You must specify a username, password and optionally the server to connect to");
                    Console.WriteLine(string.Format("APIExample.exe {0} {1} {2}", username, password, server));
                    Environment.Exit(1);
                    break;
                case 2:
                    username = args[0];
                    password = args[1];
                    break;
                case 3:
                    username = args[0];
                    password = args[1];
                    server = args[2];
                    break;
            }

            Console.WriteLine(string.Format("Connecting to BIM 360 Field API service on {0} as {1}", server, username));

            try
            {
                API api = new API(server);

                api.authenticate(username, password);

                Console.WriteLine("Authenticated successfully. Retrieving project list.\n\n");

                List<Project> projects = api.getProjects();

                Console.WriteLine("Project ID\t\t\t\tProject Name");
                Console.WriteLine("----------\t\t\t\t------------");
                foreach (Project project in projects)
                {
                    Console.WriteLine(string.Format("{0}\t{1}", project.project_id, project.name));
                }

                Console.WriteLine("Retrieving list of Checklists for first project\n\n");

                // Set the default project on the API service object and you won't have to pass it each time you make a call.
                // Just DON'T forget to change it if you need to interact with other projects!
                api.DefaultProject = projects[0];

                List<Checklist> checklists = api.getChecklists(null, null, 0, 10000); // Defaults to 25
                Console.WriteLine(string.Format("The project {0} has {1} checklist(s)", api.DefaultProject.name, checklists.Count));

                if (checklists.Count > 0)
                {
                    Console.WriteLine("Checklist ID\t\t\t\tName");
                    Console.WriteLine("------------\t\t\t\t----");

                    foreach (Checklist checklist in checklists)
                    {
                        Console.WriteLine(string.Format("{0}\t{1}", checklist.id, checklist.name));
                    }

                    Console.WriteLine("\n\n");

                    Checklist firstChecklist = api.getChecklist(checklists[0].id);
                    Console.WriteLine(string.Format("The checklist with ID {0} has {1} sections. Please inspect this object to see what else is available!", firstChecklist.id, firstChecklist.sections.Count));
                }
            }
            catch (BIM360FieldAPIException ex)
            {
                Console.WriteLine(string.Format("API service threw an exception: {0} {1}", ex.Code, ex.Message));
            }
            catch (UnauthorizedAccessException ua)
            {
                Console.WriteLine("Failed to authenticate with the supplied credentials.");
            }
        }
開發者ID:BIM360API,項目名稱:FieldAPIExample,代碼行數:78,代碼來源:APIExample.cs


注:本文中的API.authenticate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。