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); }
/// <summary> /// Updates the <see cref="UnitOfMeasure"/> cache. All <see cref="UnitOfMeasure"/> objects are obtained using a Get() call. Then, <see cref="UnitOfMeasure"/> objects that are already in the cache are replaced and any <see cref="UnitOfMeasure"/> objects not in the cache are added to the cache. /// </summary> /// <returns></returns> async Task UpdateUnitOfMeasureCacheAsync() { ConsoleUtility.LogInfoStart("Updating UnitsOfMeasure cache..."); List <UnitOfMeasure> returnedUnitsOfMeasure = await api.GetUnitsOfMeasureAsync() as List <UnitOfMeasure>; foreach (UnitOfMeasure returnedUnitOfMeasure in returnedUnitsOfMeasure) { if (unitOfMeasureCache.ContainsKey(returnedUnitOfMeasure.Id)) { unitOfMeasureCache[returnedUnitOfMeasure.Id] = returnedUnitOfMeasure; } else { unitOfMeasureCache.Add(returnedUnitOfMeasure.Id, returnedUnitOfMeasure); } } ConsoleUtility.LogComplete(Common.ConsoleColorForUnchangedData); ConsoleUtility.LogListItem($"UnitsOfMeasure cache records added/updated:", returnedUnitsOfMeasure.Count.ToString(), Common.ConsoleColorForListItems, (returnedUnitsOfMeasure.Count > 0) ? Common.ConsoleColorForChangedData : Common.ConsoleColorForUnchangedData); }