Пример #1
0
        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);
        }
        /// <summary>
        /// Returns a fully populated <see cref="FailureMode"/> from the cache if it exists, otherwise gets it from the server and adds it to the cache before returning it.
        /// </summary>
        /// <param name="failureMode">The <see cref="FailureMode"/> to populate.</param>
        /// <returns>A fully-populated <see cref="FailureMode"/>.</returns>
        async Task <FailureMode> GetFailureModeAsync(FailureMode failureMode)
        {
            if (failureMode == null || failureMode is NoFailureMode)
            {
                return(NoFailureMode.Value);
            }
            Id id = failureMode.Id;

            if (failureModeCache.TryGetValue(id, out failureMode))
            {
                return(failureMode);
            }
            IList <FailureMode> returnedFailureModes = await api.GetFailureModesAsync(id.ToString());

            if (!returnedFailureModes.Any())
            {
                return(null);
            }
            failureMode = returnedFailureModes.First();
            failureModeCache.Add(id, failureMode);
            return(failureMode);
        }