当前位置: 首页>>代码示例>>C#>>正文


C# Api.Authorize方法代码示例

本文整理汇总了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;
                }
            }
        }
开发者ID:nfleet,项目名称:.net-sdk,代码行数:88,代码来源:Program.cs


注:本文中的Api.Authorize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。