本文整理汇总了C#中Api.Authenticate方法的典型用法代码示例。如果您正苦于以下问题:C# Api.Authenticate方法的具体用法?C# Api.Authenticate怎么用?C# Api.Authenticate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Api
的用法示例。
在下文中一共展示了Api.Authenticate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
string url = ConfigurationManager.AppSettings["url"];
string clientKey = ConfigurationManager.AppSettings["client-key"];
string clientSecret = ConfigurationManager.AppSettings["client-secret"];
responsePath = ConfigurationManager.AppSettings["response-path"];
Assert.IsNotNullOrEmpty(clientKey);
Assert.IsNotNullOrEmpty(clientSecret);
Assert.IsNotNullOrEmpty(url);
// ReSharper disable UnusedVariable
//##BEGIN EXAMPLE accessingapi##
var api = new Api(url, clientKey, clientSecret);
var tokenResponse = api.Authenticate();
var rootLinks = api.Root;
//##END EXAMPLE##
// ReSharper restore UnusedVariable
responses = ResponseReader.readResponses(responsePath);
deserializer = new JsonDeserializer();
TestUtils.Deserializer = deserializer;
}
示例2: Cleanup
public void Cleanup()
{
string url = ConfigurationManager.AppSettings["url"];
string clientKey = ConfigurationManager.AppSettings["client-key"];
string clientSecret = ConfigurationManager.AppSettings["client-secret"];
string responsePath = ConfigurationManager.AppSettings["response-path"];
var api = new Api( url, clientKey, clientSecret );
//##BEGIN EXAMPLE oauth##
var tokenResponse = api.Authenticate();
//##END EXAMPLE##
var rootLinks = api.Root;
var users = api.Navigate<UserDataSet>( rootLinks.GetLink( "list-users" ) );
foreach ( var user in users.Items )
{
var u = api.Navigate<UserData>( user.GetLink( "self" ) );
api.Navigate<ResponseData>( u.GetLink( "delete-user" ) );
}
ResponseWriter.WriteAll(responsePath, responsePath+"/nfleet-responses/nfleet-responses.txt", ".dat");
}
示例3: Authenticate
internal static Api Authenticate()
{
var api = new Api( url, clientKey, clientSecret );
api.Authenticate();
return api;
}
示例4: 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;
}
}
}
示例5: Main
private static void Main(string[] args)
{
//Specify this setting in the app.config file, under the appSetting key "api/clientid"
_clientId = ConfigurationManager.AppSettings["api/clientid"];
//Specify these setting in the app.config file, under the appSetting key "api/address" & "api/username"
_api = new Api(ConfigurationManager.AppSettings["api/address"], _clientId, ConfigurationManager.AppSettings["api/username"]);
//Specify this setting in the app.config file, under the appSetting key "api/password"
_api.Authenticate(ConfigurationManager.AppSettings["api/password"]);
// Typical routing integration workflow
// The fastest way to creata a route is by using a template
// In this scenario we are create a template using the API, however this can also be done through the front end
// Typically you would have a template per branch/depot in a milk run scenario
var templateId = "110/00983cfd-0131-4a52-9f44-64a3738662f5";
// Create a list of DECO's to be uploaded
var decos = new List<OLocation>
{
Decos.SandtonCity(_clientId),
Decos.TheCampus(_clientId),
Decos.FourwaysMall(_clientId),
Decos.Adhoc(_clientId, "My New Adhoc Deco", "MNAD")
};
// Create a list of actions to be uploaded
var actions = new[]
{
Actions.Collection(_clientId, decos[0], "4ACTION0_1"),
Actions.Collection(_clientId, decos[0], "4ACTION0_2"),
Actions.Collection(_clientId, decos[0], "4ACTION0_3"),
Actions.Collection(_clientId, decos[0], "4ACTION0_4"),
Actions.Collection(_clientId, decos[1], "4ACTION0_5"),
Actions.Collection(_clientId, decos[1], "4ACTION0_6"),
Actions.Collection(_clientId, decos[1], "4ACTION0_7"),
Actions.Collection(_clientId, decos[1], "4ACTION0_8"),
Actions.Collection(_clientId, decos[1], "4ACTION0_9")
};
// Create a list of entities to be uploaded
var entities = new[]
{
Entities.Entity(_clientId, "entity/demo/1", "Entity 1", e =>
{
// Requirements describe what the driver will be requried to capture when completing an entity visit
// This is only applicable if infinity devices are being used
e.Requirements = new ObservableCollection<EntityRequirement>()
{
new RequireRating
{
Ratings = new List<RatingDescription>
{
new RatingDescription {Name = "Service", Type = "Simple"}
}
}
};
}),
Entities.Entity(_clientId, "entity/demo/2", "Entity 2", e =>
{
e.Requirements = new ObservableCollection<EntityRequirement>
{
new RequireActionDebrief(),
new RequireRating
{
Ratings = new List<RatingDescription>
{
new RatingDescription {Name = "Service", Type = "Smiley"}
}
},
};
}),
Entities.Entity(_clientId, "entity/demo/3", "Entity 3", e =>
{
e.Requirements = new ObservableCollection<EntityRequirement>();
}),
Entities.Entity(_clientId, "entity/demo/4", "Entity 4", e =>
{
e.Requirements = new ObservableCollection<EntityRequirement>();
}),
Entities.Entity(_clientId, "entity/demo/5", "Entity 5", e =>
{
e.Requirements = new ObservableCollection<EntityRequirement>();
})
};
// Create the relationships between the various components
var relationships = new[]
{
Relationship.Link(actions[0]).To(entities[0]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
Relationship.Link(actions[1]).To(entities[0]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
Relationship.Link(actions[2]).To(entities[1]).At(decos[0]).OnRun(0).Customise(x => x.Mst = TimeSpan.FromMinutes(8)),
//.........这里部分代码省略.........