//Methods public static HotKey CreateHotKey(enu.HotKeyStatus status, string key, System.Windows.Input.Key modifier = System.Windows.Input.Key.None) { HotKey temp = new HotKey(); temp.KeyStatus = status; temp.Key = key; temp.Modifier = modifier; for (int i = 0; i < 1000; i++) { if (!IdSet.Contains(i)) { IdSet.Add(i); temp.Id = i; break; } if (i == 999) { #if DEBUGLOG Logger.GetLogger().WriteToLog($"HotKey: CreateHotKey : Exception{{ID limit}} : Code{{{0}}}"); #endif throw new Exception(); } } if (key != null) { WinWrapper.RegisterKey(temp); } return(temp); }
private void LoadFromFile(object param) { var path = param as string; try { ProjectPath = path ?? throw new Exception("null path"); SelectedTemplate.EditingMode = false; SelectedTemplate = null; BinaryFormatter formatter = new BinaryFormatter(); WinWrapper.UnregisterAll(); using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate)) { ViewModelArgs args = (ViewModelArgs)formatter.Deserialize(stream); MacroList = args.MacroList; Scenarios = args.Scenarios; foreach (var action in Scenarios) { WinWrapper.RegisterKey(action.HotKey); } ActionTemplates = args.ActionTemplates; foreach (var action in ActionTemplates) { WinWrapper.RegisterKey(action.HotKey); } SelectedMacro = args.SelectedMacro; SelectedScenario = args.SelectedScenario; } } catch (Exception e) { Logger.GetLogger().CatchException("ViewModel", "LoadFromFile", e.Message); throw; } #if DEBUGLOG Logger.GetLogger().WriteToLog($"ViewModel: LoadFromFile: Path{{{path}}} : Code{{{1}}}"); #endif }