public static async Task <string> Run(GeotabDataOnlyPlanAPI api, string deviceId, string userId) { ConsoleUtility.LogExampleStarted(typeof(AddDriverChangeAsyncExample).Name); string addedDriverChangeId = ""; try { // Set parameter values to apply when adding driver change. DateTime dateTime = DateTime.Now; List <Device> deviceCache = await ExampleUtility.GetAllDevicesAsync(api); List <User> userCache = await ExampleUtility.GetAllUsersAsync(api); Device device = deviceCache.Where(targetDevice => targetDevice.Id.ToString() == deviceId).First(); Driver driver = userCache.Where(targetUser => targetUser.Id.ToString() == userId).First() as Driver; DriverChangeType driverChangeType = DriverChangeType.Driver; ConsoleUtility.LogInfoStart($"Adding driverChange of type '{driverChangeType.ToString()}' for driver '{driver.Id.ToString()}' and device '{device.Id.ToString()}' to database '{api.Credentials.Database}'..."); addedDriverChangeId = await api.AddDriverChangeAsync(dateTime, device, driver, driverChangeType); ConsoleUtility.LogComplete(); ConsoleUtility.LogInfo($"Added driverChange Id: {addedDriverChangeId}"); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(AddDriverChangeAsyncExample).Name); return(addedDriverChangeId); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string userId) { ConsoleUtility.LogExampleStarted(typeof(SetUserAsyncExample).Name); try { // Update a driver with keys to a NON-driver. // Set parameter values to apply when adding device. string id = userId; DateTime activeTo = new(2037, 1, 31); string comment = "Driver with keys updated to NON-driver"; string designation = "Driver 2 Upd"; string employeeNo = "Employee 2 Upd"; string firstName = "John Upd"; bool isDriver = false; string lastName = "Smith2 Upd"; string name = "jsmith2Upd"; string password2 = "Password1!Upd"; ConsoleUtility.LogInfoStart($"Updating user '{id}' in database '{api.Credentials.Database}'..."); await api.SetUserAsync(id, activeTo, comment, designation, employeeNo, firstName, isDriver, lastName, name, password2); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(SetUserAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetControllersAsyncExample).Name); IList <Controller> controllers; Controller controller; try { // Example: Get all controllers: controllers = await api.GetControllersAsync(); // Example: Search for a controller based on id: string controllerId = KnownId.ControllerObdPowertrainId.ToString(); controllers = await api.GetControllersAsync(controllerId); controller = controllers.FirstOrDefault(); // Example: Search for controllers based on name: string controllerName = "Body (B)"; controllers = await api.GetControllersAsync("", controllerName); // Example: Search for controllers based on sourceId: string controllerSourceId = KnownId.SourceObdId.ToString(); controllers = await api.GetControllersAsync("", "", controllerSourceId); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetControllersAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetFailureModesAsyncExample).Name); IList <FailureMode> failureModes; FailureMode failureMode; try { // Example: Get all failureModes: failureModes = await api.GetFailureModesAsync(); // Example: Search for a failureMode based on id: if (failureModes.Any()) { string failureModeId = failureModes.FirstOrDefault().Id.ToString(); failureModes = await api.GetFailureModesAsync(failureModeId); failureMode = failureModes.FirstOrDefault(); } } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetFailureModesAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetBinaryDataAsyncExample).Name); IList <BinaryData> binaryData; try { // Get a random device Id for use in the following examples. List <Device> deviceCache = await ExampleUtility.GetAllDevicesAsync(api); string deviceId = ExampleUtility.GetRandomDeviceId(deviceCache); Device deviceForTextMessages = deviceCache.Where(targetDevice => targetDevice.Id.ToString() == deviceId).First(); // Example: Get all binary data: binaryData = await api.GetBinaryDataAsync(); // Example: Get all CalibrationId binary data for a single device: binaryData = await api.GetBinaryDataAsync("CalibrationId", null, null, "", deviceId); // Example: Get all CalibrationId binary data for a single device for the past week: DateTime fromDate = DateTime.Now - TimeSpan.FromDays(7); binaryData = await api.GetBinaryDataAsync("CalibrationId", fromDate, null, "", deviceId); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetBinaryDataAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetFeedTripAsyncExample).Name); try { // Feed parameters. int getFeedNumberOfCallsToMake = 5; int getFeedSecondsToWaitBetweenCalls = 5; DateTime getFeedStartTime = DateTime.UtcNow - TimeSpan.FromDays(1); // See MyGeotab SDK <a href="https://geotab.github.io/sdk/software/guides/concepts/#result-limits">Result Limits</a> and <a href="https://geotab.github.io/sdk/software/api/reference/#M:Geotab.Checkmate.Database.DataStore.GetFeed1">GetFeed()</a> documentation for information about the feed result limit defined below. int getFeedresultsLimit = 50000; long?feedVersion; FeedResult <Trip> feedResult; // Make initial GetFeed call using the "seed" time. The returned toVersion will be used as the fromVersion to start the subsequent GetFeed loop. feedResult = await api.GetFeedTripAsync(getFeedStartTime, getFeedresultsLimit); feedVersion = feedResult.ToVersion; // Log results to console. Console.WriteLine($"Initial feed start time: {getFeedStartTime}"); Console.WriteLine($"Initial FeedResult ToVersion: {feedVersion}"); Console.WriteLine($"Initial FeedResult Records: {feedResult.Data.Count}"); if (feedResult.Data.Count > 0) { Console.WriteLine($"Initial FeedResult first record DateTime: {feedResult.Data[0].DateTime}"); Console.WriteLine($"Initial FeedResult last record DateTime: {feedResult.Data[feedResult.Data.Count - 1].DateTime}"); } // Execute a GetFeed loop for the prescribed number of iterations, setting the fromVersion on the first iteration to the toVersion that was returned by the initial GetFeed call. for (int getFeedCallNumber = 1; getFeedCallNumber < getFeedNumberOfCallsToMake + 1; getFeedCallNumber++) { // Make GetFeed call. feedResult = await api.GetFeedTripAsync(feedVersion, getFeedresultsLimit); feedVersion = feedResult.ToVersion; // Log results to console. Console.WriteLine($"Feed iteration: {getFeedCallNumber}"); Console.WriteLine($"Feed iteration: {getFeedCallNumber} FeedResult ToVersion: {feedVersion}"); Console.WriteLine($"Feed iteration: {getFeedCallNumber} FeedResult Records: {feedResult.Data.Count}"); if (feedResult.Data.Count > 0) { Console.WriteLine($"Feed iteration: {getFeedCallNumber} FeedResult first record DateTime: {feedResult.Data[0].DateTime}"); Console.WriteLine($"Feed iteration: {getFeedCallNumber} FeedResult last record DateTime: {feedResult.Data[feedResult.Data.Count - 1].DateTime}"); } // Wait for the prescribed amount of time before making the next GetFeed call. Thread.Sleep(getFeedSecondsToWaitBetweenCalls * 1000); } } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetFeedTripAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetUnitsOfMeasureAsyncExample).Name); try { IList <UnitOfMeasure> unitsOfMeasure = await api.GetUnitsOfMeasureAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetUnitsOfMeasureAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetSystemTimeUtcAsyncExample).Name); try { DateTime systemTimeUtc = await api.GetSystemTimeUtcAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetSystemTimeUtcAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetTimeZonesAsyncExample).Name); try { IList <Geotab.Checkmate.ObjectModel.TimeZoneInfo> timeZones = await api.GetTimeZonesAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetTimeZonesAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetCountOfDeviceAsyncExample).Name); try { int deviceCount = await api.GetCountOfDeviceAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetCountOfDeviceAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetFlashCodesAsyncExample).Name); try { IList <FlashCode> flashCodes = await api.GetFlashCodesAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetFlashCodesAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetVersionInformationAsyncExample).Name); try { VersionInformation versionInformation = await api.GetVersionInformationAsync(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetVersionInformationAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetUnitOfMeasureAsyncExample).Name); try { string unitOfMeasureId = KnownId.UnitOfMeasureKilometersPerHourId.ToString(); UnitOfMeasure unitOfMeasure = await api.GetUnitOfMeasureAsync(unitOfMeasureId); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetUnitOfMeasureAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(DatabaseExistsAsyncExample).Name); try { string databaseName = "SomeDatabaseName"; bool databaseExists = await api.DatabaseExistsAsync(databaseName); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(DatabaseExistsAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetSourceAsyncExample).Name); try { string sourceId = "SourceJ1939Id"; Source source = await api.GetSourceAsync(sourceId); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetSourceAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GenerateCaptchaAsyncExample).Name); try { string id = Guid.NewGuid().ToString(); string captchaImage = await api.GenerateCaptchaAsync(id); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GenerateCaptchaAsyncExample).Name); }
public static async Task <string> Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(AddDeviceAsyncExample).Name); string addedDeviceId = ""; try { // Set parameter values to apply when adding device. string serialNumber = ConsoleUtility.GetUserInput("serial number of device to be added"); string name = "Vehicle 1"; bool enableDeviceBeeping = true; bool enableDriverIdentificationReminder = true; int driverIdentificationReminderImmobilizeSeconds = 20; bool enableBeepOnEngineRpm = true; int engineRpmBeepValue = 3000; bool enableBeepOnIdle = true; int idleMinutesBeepValue = 4; bool enableBeepOnSpeeding = true; int speedingStartBeepingSpeed = 110; int speedingStopBeepingSpeed = 100; bool enableBeepBrieflyWhenApprocahingWarningSpeed = true; bool enableBeepOnDangerousDriving = true; int accelerationWarningThreshold = 23; int brakingWarningThreshold = -35; int corneringWarningThreshold = 27; bool enableBeepWhenSeatbeltNotUsed = true; int seatbeltNotUsedWarningSpeed = 11; bool enableBeepWhenPassengerSeatbeltNotUsed = true; bool beepWhenReversing = true; ConsoleUtility.LogInfoStart($"Adding device with serial number '{serialNumber}' to database '{api.Credentials.Database}'..."); addedDeviceId = await api.AddDeviceAsync(serialNumber, name, enableDeviceBeeping, enableDriverIdentificationReminder, driverIdentificationReminderImmobilizeSeconds, enableBeepOnEngineRpm, engineRpmBeepValue, enableBeepOnIdle, idleMinutesBeepValue, enableBeepOnSpeeding, speedingStartBeepingSpeed, speedingStopBeepingSpeed, enableBeepBrieflyWhenApprocahingWarningSpeed, enableBeepOnDangerousDriving, accelerationWarningThreshold, brakingWarningThreshold, corneringWarningThreshold, enableBeepWhenSeatbeltNotUsed, seatbeltNotUsedWarningSpeed, enableBeepWhenPassengerSeatbeltNotUsed, beepWhenReversing); ConsoleUtility.LogComplete(); ConsoleUtility.LogInfo($"Added device Id: {addedDeviceId}"); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(AddDeviceAsyncExample).Name); return(addedDeviceId); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string deviceId) { ConsoleUtility.LogExampleStarted(typeof(SetDeviceAsyncExample).Name); try { // Set parameter values to apply when adding device. string id = deviceId; string name = "Vehicle 1 Upd"; bool enableDeviceBeeping = false; bool enableDriverIdentificationReminder = false; int driverIdentificationReminderImmobilizeSeconds = 21; bool enableBeepOnEngineRpm = false; int engineRpmBeepValue = 3001; bool enableBeepOnIdle = false; int idleMinutesBeepValue = 5; bool enableBeepOnSpeeding = false; int speedingStartBeepingSpeed = 111; int speedingStopBeepingSpeed = 101; bool enableBeepBrieflyWhenApprocahingWarningSpeed = false; bool enableBeepOnDangerousDriving = false; int accelerationWarningThreshold = 24; int brakingWarningThreshold = -36; int corneringWarningThreshold = 28; bool enableBeepWhenSeatbeltNotUsed = false; int seatbeltNotUsedWarningSpeed = 12; bool enableBeepWhenPassengerSeatbeltNotUsed = false; bool beepWhenReversing = false; ConsoleUtility.LogInfoStart($"Updating device '{id}' in database '{api.Credentials.Database}'..."); List <Device> deviceCache = await ExampleUtility.GetAllDevicesAsync(api); Device deviceToSet = deviceCache.Where(targetDevice => targetDevice.Id.ToString() == deviceId).First(); await api.SetDeviceAsync(deviceToSet, name, enableDeviceBeeping, enableDriverIdentificationReminder, driverIdentificationReminderImmobilizeSeconds, enableBeepOnEngineRpm, engineRpmBeepValue, enableBeepOnIdle, idleMinutesBeepValue, enableBeepOnSpeeding, speedingStartBeepingSpeed, speedingStopBeepingSpeed, enableBeepBrieflyWhenApprocahingWarningSpeed, enableBeepOnDangerousDriving, accelerationWarningThreshold, brakingWarningThreshold, corneringWarningThreshold, enableBeepWhenSeatbeltNotUsed, seatbeltNotUsedWarningSpeed, enableBeepWhenPassengerSeatbeltNotUsed, beepWhenReversing); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(SetDeviceAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(AuthenticateAsyncExample).Name); try { string server = ConsoleUtility.GetUserInput("server").ToLower(); string database = ConsoleUtility.GetUserInput("database").ToLower(); string username = ConsoleUtility.GetUserInput("username"); string password = ConsoleUtility.GetUserInputMasked("password"); await api.AuthenticateAsync(server, database, username, password); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(AuthenticateAsyncExample).Name); }
public static async Task <string> Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(AddUserAsyncExample).Name); string addedUserId = ""; try { // Add a user that is a driver with a key. // Set parameter values to apply when adding user. List <Key> keys = new List <Key>(); Key key = new Key(DriverKeyType.CustomNfc, null, "1234567890"); keys.Add(key); string comment = "User added as driver with key."; string designation = "Driver 2"; string employeeNo = "Employee 2"; string firstName = "John"; bool isDriver = true; string lastName = "Smith2"; string name = "jsmith2"; string password2 = "Password1!"; string licenseNumber = "ABC123"; string licenseProvinceOrState = "ON"; ConsoleUtility.LogInfoStart($"Adding user with username '{name}' to database '{api.Credentials.Database}'..."); addedUserId = await api.AddUserAsync(comment, designation, employeeNo, firstName, isDriver, lastName, name, password2, keys, licenseNumber, licenseProvinceOrState); ConsoleUtility.LogComplete(); ConsoleUtility.LogInfo($"Added user Id: {addedUserId}"); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(AddUserAsyncExample).Name); return(addedUserId); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string deviceId) { ConsoleUtility.LogExampleStarted(typeof(ArchiveDeviceAsyncExample).Name); try { ConsoleUtility.LogInfoStart($"Archiving device '{deviceId}' in database '{api.Credentials.Database}'..."); List <Device> deviceCache = await ExampleUtility.GetAllDevicesAsync(api); Device deviceToArchive = deviceCache.Where(targetDevice => targetDevice.Id.ToString() == deviceId).First(); await api.ArchiveDeviceAsync(deviceToArchive); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(ArchiveDeviceAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string driverChangeId) { ConsoleUtility.LogExampleStarted(typeof(RemoveDriverChangeAsyncExample).Name); try { ConsoleUtility.LogInfoStart($"Removing driverChange '{driverChangeId}' from database '{api.Credentials.Database}'..."); IList <DriverChange> driverChanges = await ExampleUtility.GetAllDriverChangesAsync(api); DriverChange driverChangeToRemove = driverChanges.Where(targetDriverChange => targetDriverChange.Id.ToString() == driverChangeId).First(); await api.RemoveDriverChangeAsync(driverChangeToRemove); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(RemoveDriverChangeAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string userId) { ConsoleUtility.LogExampleStarted(typeof(RemoveUserAsyncExample).Name); try { ConsoleUtility.LogInfoStart($"Removing user '{userId}' from database '{api.Credentials.Database}'..."); List <User> userCache = await ExampleUtility.GetAllUsersAsync(api); User userToRemove = userCache.Where(targetUser => targetUser.Id.ToString() == userId).First(); await api.RemoveUserAsync(userToRemove); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(RemoveUserAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GenerateCaptchaAsyncExample).Name); try { string id = Guid.NewGuid().ToString(); string filePath = "C:\\TEMP"; if (!Directory.Exists(filePath)) { filePath = ConsoleUtility.GetUserInputDirectory(); } string outputFilePath = $"{filePath}\\GeotabDataOnlyPlanAPI_CAPTCHA_{id}.jpg"; var result = await api.GenerateCaptchaAsync(id, outputFilePath); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GenerateCaptchaAsyncExample).Name); }
public static async Task Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(GetFeedDiagnosticAsyncExample).Name); try { // Feed parameters. // See MyGeotab SDK <a href="https://geotab.github.io/sdk/software/guides/concepts/#result-limits">Result Limits</a> and <a href="https://geotab.github.io/sdk/software/api/reference/#M:Geotab.Checkmate.Database.DataStore.GetFeed1">GetFeed()</a> documentation for information about the feed result limit defined below. const int DefaultFeedResultsLimitDiagnostic = 50000; int getFeedNumberOfCallsToMake = 5; int getFeedSecondsToWaitBetweenCalls = 5; long? feedVersion = 0; List <Diagnostic> diagnosticCache = new(); FeedResult <Diagnostic> feedResult; // Start by populating the diagnosticCache with a list of all diagnostics. ConsoleUtility.LogListItem($"Population of diagnosticCache started."); bool isFirstCall = true; bool keepGoing = true; while (keepGoing == true) { feedResult = await api.GetFeedDiagnosticAsync(feedVersion); feedVersion = feedResult.ToVersion; ConsoleUtility.LogListItem("GetFeedDiagnosticAsync executed:"); ConsoleUtility.LogListItem("FeedResult ToVersion:", feedVersion.ToString(), Common.ConsoleColorForUnchangedData, Common.ConsoleColorForSuccess); ConsoleUtility.LogListItem("FeedResult Records:", feedResult.Data.Count.ToString(), Common.ConsoleColorForUnchangedData, Common.ConsoleColorForSuccess); if (isFirstCall == true) { diagnosticCache.AddRange(feedResult.Data); isFirstCall = false; } else { // Add new items to the cache, or update existing items with their changed counterparts. foreach (Diagnostic feedResultDiagnostic in feedResult.Data) { Diagnostic cachedDiagnosticToUpdate = diagnosticCache.Where(diagnostic => diagnostic.Id == feedResultDiagnostic.Id).FirstOrDefault(); if (cachedDiagnosticToUpdate == null) { diagnosticCache.Add(feedResultDiagnostic); } else { var index = diagnosticCache.IndexOf(cachedDiagnosticToUpdate); diagnosticCache[index] = feedResultDiagnostic; } } } if (feedResult.Data.Count < DefaultFeedResultsLimitDiagnostic) { keepGoing = false; } } ConsoleUtility.LogListItem($"Population of diagnosticCache completed."); // Execute a GetFeed loop for the prescribed number of iterations, adding new items to the cache, or updating existing items with their changed counterparts. for (int getFeedCallNumber = 1; getFeedCallNumber < getFeedNumberOfCallsToMake + 1; getFeedCallNumber++) { feedResult = await api.GetFeedDiagnosticAsync(feedVersion); feedVersion = feedResult.ToVersion; ConsoleUtility.LogListItem("GetFeedDiagnosticAsync executed. Iteration:", getFeedCallNumber.ToString(), Common.ConsoleColorForUnchangedData, Common.ConsoleColorForSuccess); ConsoleUtility.LogListItem("FeedResult ToVersion:", feedVersion.ToString(), Common.ConsoleColorForUnchangedData, Common.ConsoleColorForSuccess); ConsoleUtility.LogListItem("FeedResult Records:", feedResult.Data.Count.ToString(), Common.ConsoleColorForUnchangedData, Common.ConsoleColorForSuccess); // Add new items to the cache, or update existing items with their changed counterparts. foreach (Diagnostic feedResultDiagnostic in feedResult.Data) { Diagnostic cachedDiagnosticToUpdate = diagnosticCache.Where(diagnostic => diagnostic.Id == feedResultDiagnostic.Id).FirstOrDefault(); if (cachedDiagnosticToUpdate == null) { diagnosticCache.Add(feedResultDiagnostic); } else { var index = diagnosticCache.IndexOf(cachedDiagnosticToUpdate); diagnosticCache[index] = feedResultDiagnostic; } } // Wait for the prescribed amount of time before making the next GetFeed call. Thread.Sleep(getFeedSecondsToWaitBetweenCalls * 1000); } } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(GetFeedDiagnosticAsyncExample).Name); }
/// <summary> /// IMPORTANT: This example should be used sparingly - only when a new database is actually required! /// </summary> /// <param name="api"></param> /// <returns></returns> public static async Task <string> Run(GeotabDataOnlyPlanAPI api) { ConsoleUtility.LogExampleStarted(typeof(CreateDatabaseAsyncExample).Name); string createDatabaseResult = ""; try { // Confirm user wishes to proceed with database creation. ConsoleUtility.LogWarning("By proceeding, you will be requesting the creation of a new MyGeotab database."); string input = ConsoleUtility.GetUserInput("'y' to confirm you wish to create a new database, or 'n' to cancel."); if (input != "y") { ConsoleUtility.LogInfo("Cancelled CreateDatabaseAsync example."); return(createDatabaseResult); } // Re-authenticate against "my.geotab.com". ConsoleUtility.LogInfoStart("Reauthenticating against my.geotab.com..."); await api.AuthenticateAsync("my.geotab.com", "", api.Credentials.UserName, api.Credentials.Password); ConsoleUtility.LogComplete(); string database = ""; // Generate a database name and ensure that it is not already used. bool databaseExists = true; while (databaseExists == true) { database = Guid.NewGuid().ToString().Replace("-", ""); databaseExists = await api.DatabaseExistsAsync(database); } ConsoleUtility.LogInfoStartMultiPart($"Creating database named '{database}'.", $"THIS MAY TAKE SEVERAL MINUTES...", Common.ConsoleColorForWarnings); // Set parameter values for CreateDatabaseAsync call. string username = api.Credentials.UserName; string password = api.Credentials.Password; string companyName = "Customer XYZ Ltd."; string firstName = "John"; string lastName = "Smith"; string phoneNumber = "+1 (555) 123-4567"; string resellerName = "Reseller 123 Inc."; int fleetSize = 1; bool signUpForNews = false; string timeZoneId = "America/Toronto"; string comments = "some comments"; // Create database. createDatabaseResult = await api.CreateDatabaseAsync(database, username, password, companyName, firstName, lastName, phoneNumber, resellerName, fleetSize, signUpForNews, timeZoneId, comments); ConsoleUtility.LogComplete(); // Get the server and database information for the new database. string[] serverAndDatabase = (createDatabaseResult).Split('/'); string server = serverAndDatabase.First(); string createdDatabase = serverAndDatabase.Last(); ConsoleUtility.LogInfo($"Created database '{createdDatabase}' on server '{server}'."); // Authenticate against the new database so that additional api calls (the 'Add', 'Set' and 'Remove' ones in particular) can be executed. ConsoleUtility.LogInfoStart($"Authenticating against '{createdDatabase}' database..."); await api.AuthenticateAsync(server, createdDatabase, api.Credentials.UserName, api.Credentials.Password); ConsoleUtility.LogComplete(); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(CreateDatabaseAsyncExample).Name); return(createDatabaseResult); }
public static async Task Run(GeotabDataOnlyPlanAPI api, string deviceId, string userId) { ConsoleUtility.LogExampleStarted(typeof(AddTextMessageAsyncExample).Name); try { List <Device> deviceCache = await ExampleUtility.GetAllDevicesAsync(api); List <User> userCache = await ExampleUtility.GetAllUsersAsync(api); Device deviceForTextMessages = deviceCache.Where(targetDevice => targetDevice.Id.ToString() == deviceId).First(); User userForTextMessages = userCache.Where(targetUser => targetUser.Id.ToString() == userId).First(); /** * Example: Add basic text message: */ // Set-up the message content. TextContent messageContent = new TextContent("Testing: Geotab API example text message", false); // Construct the text message. DateTime utcNow = DateTime.UtcNow; TextMessage basicTextMessage = new TextMessage(null, null, utcNow, utcNow, deviceForTextMessages, userForTextMessages, messageContent, true, true, null, null, null); // Add the text message. MyGeotab will take care of the actual sending. string addedTextMessageId = await api.AddTextMessageAsync(basicTextMessage); /** * Example: Add location message: * Note: A location message is a message with a location. A series of location messages can be sent in succession to comprise a route. A clear message can be sent to clear any previous location messages. */ // Set up message and GPS location LocationContent clearStopsContent = new LocationContent("Testing: Geotab API example clear all stops message", "Reset Stops", 0, 0); // Construct a "Clear Previous Stops" message TextMessage clearMessage = new TextMessage(deviceForTextMessages, userForTextMessages, clearStopsContent, true); // Add the clear stops text message, Geotab will take care of the sending process. string addedClearMessageId = await api.AddTextMessageAsync(clearMessage); // Set up message and GPS location LocationContent withGPSLocation = new LocationContent("Testing: Geotab API example location message", "Geotab", 43.452879, -79.701648); // Construct the location text message. TextMessage locationMessage = new TextMessage(deviceForTextMessages, userForTextMessages, withGPSLocation, true); // Add the text message, Geotab will take care of the sending process. string addedLocationMessageId = await api.AddTextMessageAsync(locationMessage); /** * Example: IoXOutput Message */ IoxOutputContent ioxOutputContent = new IoxOutputContent(true); TextMessage ioxOutputMessage = new TextMessage(deviceForTextMessages, userForTextMessages, ioxOutputContent, true); string addedIoxOutputMessageId = await api.AddTextMessageAsync(ioxOutputMessage); /** * Example: MimeContent Message */ string messageString = "Secret Message!"; byte[] bytes = Encoding.ASCII.GetBytes(messageString); TimeSpan binaryDataPacketDelay = new TimeSpan(0, 0, 0); MimeContent mimeContent = new MimeContent("multipart/byteranges", bytes, binaryDataPacketDelay, null); TextMessage mimeContentTextMessage = new TextMessage(deviceForTextMessages, userForTextMessages, mimeContent, true); string addedMimeContentTextMessageId = await api.AddTextMessageAsync(mimeContentTextMessage); /** * Example: GoTalk Message */ GoTalkContent goTalkContent = new GoTalkContent("You're following too closely!"); TextMessage goTalkMessage = new TextMessage(deviceForTextMessages, userForTextMessages, goTalkContent, true); string addedGoTalkMessageId = await api.AddTextMessageAsync(goTalkMessage); } catch (Exception ex) { ConsoleUtility.LogError(ex); } ConsoleUtility.LogExampleFinished(typeof(AddTextMessageAsyncExample).Name); }