static void Main() { System.Console.WriteLine("PLEASE NOTE: Following user input will be buffered in directory " + System.IO.Path.GetTempPath()); string username = InputLine("username"); string customerno = InputLine("customer no."); string password = InputLine("password"); OpenScopeApiClient OpenScopeClient = new OpenScopeApiClient(); try { //Authorize initially with user credentials -> recieved access token will be saved for following requests OpenScopeClient.AuthorizeWithUserCredentials(username, customerno, password); System.Console.WriteLine("Authorization successful, future requests can be executed with access token:\n" + OpenScopeClient.Token.AccessToken); System.Console.WriteLine(); //A 1st API method call for getting API version info (authorized by access token from initial request) CompuMaster.Scopevisio.OpenApi.Model.Version VersionResult = OpenScopeClient.AdditionalApi.GetVersionWithHttpInfo().Data; System.Console.WriteLine("Interface version=" + VersionResult.ToString()); System.Console.WriteLine(); //A 2nd API method call for getting HelloWorld data (authorized by access token from initial request) CompuMaster.Scopevisio.OpenApi.Model.Hello HelloResult = OpenScopeClient.AdditionalApi.HelloJsonWithHttpInfo().Data; System.Console.WriteLine("Hello world=" + HelloResult.HelloMessage); System.Console.WriteLine(); //A 3rd API method call for getting HelloWorld data (authorized by access token from initial request) //Demonstration of async requests Task <CompuMaster.Scopevisio.OpenApi.Model.Hello> t = HelloTask(OpenScopeClient); t.Wait(); System.Console.WriteLine("Async hello world=" + t.Result.HelloMessage); System.Console.WriteLine(); CompuMaster.Scopevisio.OpenApi.Model.Records <CompuMaster.Scopevisio.OpenApi.Model.Organisation> OrganisationResult = OpenScopeClient.AdditionalApi.OrganisationJsonWithHttpInfo().Data; foreach (CompuMaster.Scopevisio.OpenApi.Model.Organisation Org in OrganisationResult.Items) { System.Console.WriteLine("Org[" + OrganisationResult.Items.IndexOf(Org) + "]"); System.Console.WriteLine(" Org.ID=" + Org.Id); System.Console.WriteLine(" Org.Name=" + Org.Name); System.Console.WriteLine(" Org.TeamworkTenant.ID=" + Org.TeamworkTenantId); System.Console.WriteLine(" Org.TeamworkTenant.Name=" + Org.TeamworkTenantName); System.Console.WriteLine(); } } catch (ApiException e) { System.Console.WriteLine("Exception when calling API: " + e.Message); System.Console.WriteLine("Status Code: " + e.ErrorCode); System.Console.WriteLine(e.StackTrace); } catch (Exception e) { System.Console.WriteLine("Exception: " + e.ToString()); } }
/// <summary> /// Show information on current context /// </summary> /// <param name="OpenScopeClient"></param> static void ShowContextInfo(OpenScopeApiClient OpenScopeClient) { //A 1st API method call for getting API version info (authorized by access token from initial request) CompuMaster.Scopevisio.OpenApi.Model.Version VersionResult = OpenScopeClient.AdditionalApi.GetVersionWithHttpInfo().Data; System.Console.WriteLine("Interface version=" + VersionResult.ToString()); System.Console.WriteLine(); ////A 2nd API method call for getting HelloWorld data (authorized by access token from initial request) //CompuMaster.Scopevisio.OpenApi.Model.Hello HelloResult = OpenScopeClient.AdditionalApi.HelloJsonWithHttpInfo().Data; //System.Console.WriteLine("Hello world=" + HelloResult.HelloMessage); //System.Console.WriteLine(); ////A 3rd API method call for getting HelloWorld data (authorized by access token from initial request) ////Demonstration of async requests //Task<CompuMaster.Scopevisio.OpenApi.Model.Hello> t = HelloTask(OpenScopeClient); //t.Wait(); //System.Console.WriteLine("Async hello world=" + t.Result.HelloMessage); //System.Console.WriteLine(); //Show current context CompuMaster.Scopevisio.OpenApi.Model.Records <CompuMaster.Scopevisio.OpenApi.Model.Organisation> OrganisationResult = OpenScopeClient.AdditionalApi.OrganisationJsonWithHttpInfo().Data; System.Console.WriteLine("Organisationen={"); { var sb = new StringBuilder(); foreach (CompuMaster.Scopevisio.OpenApi.Model.Organisation Org in OrganisationResult.Items) { if (OrganisationResult.Items.IndexOf(Org) > 0) { System.Console.WriteLine(); } sb.AppendLine("Org[" + (OrganisationResult.Items.IndexOf(Org) + 1) + "/" + OrganisationResult.Items.Count + "]"); sb.AppendLine(" Org.ID=" + Org.Id); sb.AppendLine(" Org.Name=" + Org.Name); sb.AppendLine(" Org.TeamworkTenant.ID=" + Org.TeamworkTenantId); sb.AppendLine(" Org.TeamworkTenant.Name=" + Org.TeamworkTenantName); } System.Console.Write(Indent(sb.ToString())); } System.Console.WriteLine("}"); System.Console.WriteLine(); //Show current context CompuMaster.Scopevisio.OpenApi.Model.AccountInfo ScopevisioAppContext = OpenScopeClient.AdditionalApi.GetApplicationContextWithHttpInfo().Data; System.Console.WriteLine(ScopevisioAppContext.ToString()); System.Console.WriteLine(); }