private static void preloadPrograms() { Logger.StopWatchNormal("Preload programs cost", () => { _win32Storage = new BinaryStorage <Win32[]>("Win32"); _win32s = _win32Storage.TryLoad(new Win32[] { }); _uwpStorage = new BinaryStorage <UWP.Application[]>("UWP"); _uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); }); Logger.WoxInfo($"Number of preload win32 programs <{_win32s.Length}>"); Logger.WoxInfo($"Number of preload uwps <{_uwps.Length}>"); }
public static long StopWatchNormal(this NLog.Logger logger, string message, Action action, [CallerMemberName] string methodName = "") { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); action(); stopWatch.Stop(); var milliseconds = stopWatch.ElapsedMilliseconds; string info = $"{message} <{milliseconds}ms>"; logger.WoxInfo(info, methodName); return(milliseconds); }
private void InitializePinyinHelpers() { Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); Logger.StopWatchNormal("Preload pinyin cache", () => { _pinyinStorage = new BinaryStorage <ConcurrentDictionary <string, string[][]> >("Pinyin"); PinyinCache = _pinyinStorage.TryLoad(new ConcurrentDictionary <string, string[][]>()); // force pinyin library static constructor initialize PinyinHelper.toHanyuPinyinStringArray('T', Format); }); Logger.WoxInfo($"Number of preload pinyin combination<{PinyinCache.Count}>"); }
public T TryLoad(T defaultData) { if (File.Exists(FilePath)) { if (new FileInfo(FilePath).Length == 0) { Logger.WoxError($"Zero length cache file <{FilePath}>"); Save(defaultData); return(defaultData); } using (var stream = new FileStream(FilePath, FileMode.Open)) { var d = Deserialize(stream, defaultData); return(d); } } else { Logger.WoxInfo("Cache file not exist, load default data"); Save(defaultData); return(defaultData); } }