public ParameterValuePredictor(ITelemetryClient telemetryClient, IAzContext azContext) { Validation.CheckArgument(telemetryClient, $"{nameof(telemetryClient)} cannot be null."); _telemetryClient = telemetryClient; _azContext = azContext; var fileInfo = new FileInfo(typeof(Settings).Assembly.Location); var directory = fileInfo.DirectoryName; var mappingFilePath = Path.Join(directory, "command_param_to_resource_map.json"); Exception exception = null; try { _commandParamToResourceMap = JsonSerializer.Deserialize <Dictionary <string, Dictionary <string, string> > >(File.ReadAllText(mappingFilePath), JsonUtilities.DefaultSerializerOptions); } catch (Exception e) { // We don't want it to crash the module when the file doesn't exist or when it's mal-formatted. exception = e; } _telemetryClient.OnLoadParameterMap(new ParameterMapTelemetryData(exception)); String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string[] paths = new string[] { path, "Microsoft", "Windows", "PowerShell", "AzPredictor", "paramValueHistory.json" }; _paramValueHistoryFilePath = System.IO.Path.Combine(paths); Directory.CreateDirectory(Path.GetDirectoryName(_paramValueHistoryFilePath)); Task.Run(() => { if (System.IO.File.Exists(_paramValueHistoryFilePath)) { _mutex.WaitOne(); try { var localParameterValues = JsonSerializer.Deserialize <ConcurrentDictionary <string, string> >(File.ReadAllText(_paramValueHistoryFilePath), JsonUtilities.DefaultSerializerOptions); foreach (var v in localParameterValues) { _localParameterValues.AddOrUpdate(v.Key, key => v.Value, (key, oldValue) => oldValue); } } finally { _mutex.ReleaseMutex(); } } }); }
public ParameterValuePredictor(ITelemetryClient telemetryClient) { Validation.CheckArgument(telemetryClient, $"{nameof(telemetryClient)} cannot be null."); _telemetryClient = telemetryClient; var fileInfo = new FileInfo(typeof(Settings).Assembly.Location); var directory = fileInfo.DirectoryName; var mappingFilePath = Path.Join(directory, "command_param_to_resource_map.json"); Exception exception = null; try { _command_param_to_resource_map = JsonSerializer.Deserialize <Dictionary <string, Dictionary <string, string> > >(File.ReadAllText(mappingFilePath), JsonUtilities.DefaultSerializerOptions); } catch (Exception e) { // We don't want it to crash the module when the file doesn't exist or when it's mal-formatted. exception = e; } _telemetryClient.OnLoadParameterMap(new ParameterMapTelemetryData(exception)); }