public void Intercept(IInvocation invocation) { invocation.Proceed(); //handle saving if it was a setter, not INotifyPropertyChanged/INotifyCollectionChanged and has CompilerGeneratedAttribute if (_module.AutosavingState != AutosavingState.SuspendedChanged && invocation.Method.ReturnType == typeof(void) && invocation.Arguments.Length > 0 && invocation.Method.Name.StartsWith("set_", StringComparison.Ordinal)) { var type = invocation.Arguments[0]?.GetType(); if (type != null && typeof(INotifyPropertyChanged).IsAssignableFrom(type) != true && typeof(INotifyCollectionChanged).IsAssignableFrom(type) != true && invocation.MethodInvocationTarget.IsDefined(typeof(CompilerGeneratedAttribute), false)) { var propName = invocation.Method.Name.Substring(4); if (!_module.NotificationsHandler !.CanHandleProperty(propName)) { return; } //save. if (_module.UpdatesSuspended) { _module.AutosavingState = AutosavingState.SuspendedChanged; } else { _settings.Save(); } } } }
private string SafeRead(string key) { try { return(_jsonSettings.GetValue(key)); } catch (Exception ex) { _tracer.TraceError(ex); // if setting file happen to be invalid, e.g w3wp.exe was kill while writting // treat it as failed, and suggest user to re-install or un-install JObject newSettings = new JObject(); newSettings[_provisioningStateSetting] = Constants.SiteExtensionProvisioningStateFailed; newSettings[_commentMessageSetting] = "Corrupted site extension, please re-install or uninstall extension."; newSettings[_statusSetting] = Enum.GetName(typeof(HttpStatusCode), HttpStatusCode.BadRequest); _jsonSettings.Save(newSettings); } return(_jsonSettings.GetValue(key)); }
public async Task DownloadChromium() { if (File.Exists(_settings.ChromiumPath)) { return; } Console.WriteLine(MessageResources.DownloadChromiumStart); var fetcher = new BrowserFetcher(); var result = await fetcher.DownloadAsync(BrowserFetcher.DefaultRevision); _settings.ChromiumPath = result.ExecutablePath; JsonSettings.Save(_settings, SettingsPath); }
public void Intercept(IInvocation invocation) { invocation.Proceed(); //handle saving if it was a setter if (_module.AutosavingState != AutosavingState.SuspendedChanged && invocation.Method.Name.StartsWith("set_", StringComparison.Ordinal)) { if (!_monitoredProperties.Contains(invocation.Method.Name.Substring(4))) { return; } //save. if (_module.UpdatesSuspended) { _module.AutosavingState = AutosavingState.SuspendedChanged; } else { _settings.Save(); } } }
protected virtual void HandleRecovery(JsonSettings sender, RecoveryAction action, ref bool recovered, ref bool handled) { //versions mismatch, handle if (recovered || handled) { return; } switch (action) { case RecoveryAction.Throw: throw new JsonSettingsRecoveryException($"Loading {sender._childtype.Name} settings{(sender is IVersionable v ? $" version '{v.Version}'" : "")}"); case RecoveryAction.RenameAndLoadDefault: { if (loadedPath == null) { throw new ArgumentNullException(nameof(loadedPath)); } //parse current name var versionMatch = VersioningModule.VersionMatcher.Match(loadedPath); int fileVersion = versionMatch.Success ? int.Parse(versionMatch.Groups[2].Value) + 1 : 0; var cleanName = loadedPath; if (!string.IsNullOrEmpty(versionMatch.Groups[0].Value)) { cleanName = cleanName.Replace(versionMatch.Groups[0].Value, ""); } var lastIdx = cleanName.LastIndexOf('.'); if (lastIdx == -1) { lastIdx = loadedPath.Length; } uint nonVersionable = 0; //figure naming of existing and rename string newFileName = cleanName; if (File.Exists(newFileName)) { do { newFileName = cleanName.Insert(lastIdx, $".{(sender is IVersionable versionable ? versionable.Version : "")}{(fileVersion++ == 0 ? "" : $"-{fileVersion}")}"); } while (File.Exists(newFileName)); try { File.Move(cleanName, newFileName); } catch (Exception) { // swallow try { File.Delete(loadedPath); } catch (Exception) { // swallow } } } //save internalCalls++; try { sender.FileName = loadedPath = cleanName; sender.LoadDefault(ConstructingParameters); sender.Save(); recovered = true; handled = true; } finally { internalCalls--; } return; } case RecoveryAction.LoadDefault: sender.LoadDefault(ConstructingParameters); recovered = true; handled = true; return; case RecoveryAction.LoadDefaultAndSave: sender.LoadDefault(ConstructingParameters); sender.Save(); recovered = true; handled = true; return; default: throw new ArgumentOutOfRangeException(); } }