本文整理汇总了C#中Api.Authorize方法的典型用法代码示例。如果您正苦于以下问题:C# Api.Authorize方法的具体用法?C# Api.Authorize怎么用?C# Api.Authorize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Api
的用法示例。
在下文中一共展示了Api.Authorize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
private static void Run()
{
var api1 = new Api( url, clientKey, clientSecret );
var tokenResponse = api1.Authenticate();
var apiData = api1.Root;
// create a new instance of Api and reuse previously received token
var api2 = new Api( url, clientKey, clientSecret );
tokenResponse = api2.Authorize( tokenResponse );
var createdUser = api2.Navigate( apiData.GetLink( "create-user" ), new UserData() );
var user = api2.Navigate<UserData>( createdUser.Location );
var problems = api2.Navigate<RoutingProblemDataSet>( user.GetLink( "list-problems" ) );
var created = api2.Navigate( user.GetLink( "create-problem" ), new RoutingProblemUpdateRequest { Name = "test" } );
var problem = api2.Navigate<RoutingProblemData>( created.Location );
CreateDemoData( problem, api2 );
// refresh to get up to date set of operations
problem = api2.Navigate<RoutingProblemData>( problem.GetLink( "self" ) );
var res = api2.Navigate<ResponseData>( problem.GetLink( "toggle-optimization" ), new RoutingProblemUpdateRequest { Name = problem.Name, State = "Running" } );
RoutingProblemData rb = null;
while ( true )
{
Thread.Sleep( 1000 );
rb = api2.Navigate<RoutingProblemData>( problem.GetLink( "self" ) );
Console.WriteLine( "State: {0}", rb.State );
if ( rb.State == "Running" || rb.Progress == 100 ) break;
}
while ( true )
{
Thread.Sleep( 1000 );
int start = 0;
int end = 1;
var routingProblem = api2.Navigate<RoutingProblemData>( problem.GetLink( "self" ) );
var queryParameters = new Dictionary<string, string>
{
{"Start", start.ToString() },
{"End", end.ToString() }
};
var objectiveValues = api2.Navigate<ObjectiveValueDataSet>( problem.GetLink( "objective-values" ), queryParameters );
Console.WriteLine( routingProblem.State + " (" + routingProblem.Progress + "%)" );
Console.WriteLine( "---------------" );
foreach ( var obj in objectiveValues.Items )
{
Console.WriteLine( "Objective values from {0} to {1}: [{2}] {3}", start, end, obj.TimeStamp, obj.Value );
}
Console.WriteLine( "---------------" );
if ( routingProblem.State == "Stopped" )
{
var resultVehicles = api2.Navigate<VehicleDataSet>( routingProblem.GetLink( "list-vehicles" ) );
var resultTasks = api2.Navigate<TaskDataSet>( routingProblem.GetLink( "list-tasks" ) );
foreach ( var vehicleData in resultVehicles.Items )
{
var veh = api2.Navigate<VehicleData>( vehicleData.GetLink( "self" ) );
Console.Write( "Vehicle {0}({1}): ", vehicleData.Id, vehicleData.Name );
var routeEvents = api2.Navigate<RouteEventDataSet>( veh.GetLink( "list-events" ) );
var sequence = api2.Navigate<RouteData>( veh.GetLink( "get-route" ) );
sequence.Items.Insert( 0, veh.StartLocation.Id );
sequence.Items.Add( veh.EndLocation.Id );
for ( int i = 0; i < routeEvents.Items.Count; i++ )
{
var point = sequence.Items[i];
var routeEvent = routeEvents.Items[i];
Console.WriteLine( "{0}: {1}-{2} ", point, routeEvent.ArrivalTime, routeEvent.DepartureTime );
}
Console.WriteLine();
}
break;
}
}
}