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);
        }
Beispiel #2
0
        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 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);
        }
Beispiel #4
0
        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);
        }
Beispiel #7
0
        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);
        }